From bbef4050e055a33ece199dca5387a2753c99e01f Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Mon, 30 Dec 2024 08:16:06 +0800 Subject: [PATCH 1/2] chore(release): 1.2.36 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f4bf92e..c094971c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines. +## [1.2.36](https://github.com/bipproduction/hipmi/compare/v1.2.35...v1.2.36) (2024-12-30) + ## [1.2.35](https://github.com/bipproduction/hipmi/compare/v1.2.34...v1.2.35) (2024-12-27) ## [1.2.34](https://github.com/bipproduction/hipmi/compare/v1.2.33...v1.2.34) (2024-12-24) diff --git a/package.json b/package.json index 01b6a487..273e1449 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.2.35", + "version": "1.2.36", "private": true, "prisma": { "seed": "npx tsx prisma/seed.ts --yes" From 1c162c199ad10c5425643008f73b039e4e935ce7 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Mon, 30 Dec 2024 08:19:43 +0800 Subject: [PATCH 2/2] Fix voting, intergarsi ke API --- src/app/api/voting/[id]/route.ts | 47 ++ src/app/api/voting/check/route.ts | 76 +++ src/app/api/voting/hasil/route.ts | 30 ++ src/app/api/voting/kontributor/route.ts | 46 ++ .../detail/daftar-kontributor/[id]/page.tsx | 8 +- src/app/dev/vote/detail/main/[id]/page.tsx | 17 - src/app/zCoba/page.tsx | 115 ++--- src/app/zCoba/skeleton/page.tsx | 62 +-- src/app_modules/vote/_lib/api_voting.ts | 34 ++ .../detail/ui_detail_kontributor_voting.tsx | 8 +- .../_view/view_detail_kontributor_voting.tsx | 115 ++++- .../vote/component/skeleton_view.tsx | 98 +++- src/app_modules/vote/detail/main/index.tsx | 478 ++++++++++-------- .../vote/fun/create/create_hasil.ts | 11 +- 14 files changed, 773 insertions(+), 372 deletions(-) create mode 100644 src/app/api/voting/[id]/route.ts create mode 100644 src/app/api/voting/check/route.ts create mode 100644 src/app/api/voting/hasil/route.ts create mode 100644 src/app/api/voting/kontributor/route.ts diff --git a/src/app/api/voting/[id]/route.ts b/src/app/api/voting/[id]/route.ts new file mode 100644 index 00000000..f9a59a1c --- /dev/null +++ b/src/app/api/voting/[id]/route.ts @@ -0,0 +1,47 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET( + request: Request, + context: { params: { id: string } } +) { + try { + let fixData; + const { id } = context.params; + + fixData = await prisma.voting.findFirst({ + where: { + id: id, + }, + include: { + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + where: { + isActive: true, + }, + }, + Author: { + select: { + Profile: true, + }, + }, + }, + }); + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Gagal mendapatkan data voting by id", error); + return NextResponse.json( + { success: false, message: "Gagal mendapatkan data" }, + { status: 500 } + ); + } +} diff --git a/src/app/api/voting/check/route.ts b/src/app/api/voting/check/route.ts new file mode 100644 index 00000000..b6639349 --- /dev/null +++ b/src/app/api/voting/check/route.ts @@ -0,0 +1,76 @@ +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; +import backendLogger from "@/util/backendLogger"; +import _ from "lodash"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +/** + * + * @param id | votingId + * @param kategori | kontribusi + * @returns + */ +export async function GET(request: Request) { + try { + let fixData; + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + const kategori = searchParams.get("kategori"); + + const userLoginId = await funGetUserIdByToken(); + if (!userLoginId) { + return NextResponse.json( + { success: false, message: "Gagal mendapatkan data, coba lagi nanti " }, + { status: 500 } + ); + } + + if (kategori == "isKontributor") { + const cek = await prisma.voting_Kontributor.count({ + where: { + authorId: userLoginId, + votingId: id, + }, + }); + + if (cek > 0) { + fixData = true; + } else { + fixData = false; + } + } else if (kategori == "pilihan") { + const cekPilihan = await prisma.voting_Kontributor.findFirst({ + where: { + authorId: userLoginId, + votingId: id, + }, + select: { + Voting_DaftarNamaVote: { + select: { + value: true, + }, + }, + }, + }); + + fixData = cekPilihan?.Voting_DaftarNamaVote?.value + } + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get hitung voting", error); + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/api/voting/hasil/route.ts b/src/app/api/voting/hasil/route.ts new file mode 100644 index 00000000..e5ba208c --- /dev/null +++ b/src/app/api/voting/hasil/route.ts @@ -0,0 +1,30 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET(request: Request) { + try { + let fixData; + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + + fixData = await prisma.voting_DaftarNamaVote.findMany({ + where: { + votingId: id, + }, + }); + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error(error); + return NextResponse.json( + { success: false, message: "Gagal mendapatkan data" }, + { status: 500 } + ); + } +} diff --git a/src/app/api/voting/kontributor/route.ts b/src/app/api/voting/kontributor/route.ts new file mode 100644 index 00000000..ece9792c --- /dev/null +++ b/src/app/api/voting/kontributor/route.ts @@ -0,0 +1,46 @@ +import { prisma } from "@/app/lib"; +import backendLogger from "@/util/backendLogger"; +import { NextResponse } from "next/server"; + +export const dynamic = "force-dynamic"; + +export async function GET(request: Request) { + try { + let fixData; + const { searchParams } = new URL(request.url); + const id = searchParams.get("id"); + const page = searchParams.get("page"); + const takeData = 10; + const dataSkip = Number(page) * takeData - takeData; + fixData = await prisma.voting_Kontributor.findMany({ + // take: takeData, + // skip: dataSkip, + orderBy: { + createdAt: "desc", + }, + where: { + votingId: id, + }, + include: { + Author: { + include: { + Profile: true, + }, + }, + Voting_DaftarNamaVote: { + select: { + value: true, + }, + }, + }, + }); + + return NextResponse.json({ success: true, data: fixData }, { status: 200 }); + } catch (error) { + backendLogger.error(error); + return NextResponse.json( + { success: false, reason: (error as Error).message || (error as Error) }, + { status: 500 } + ); + } +} diff --git a/src/app/dev/vote/detail/daftar-kontributor/[id]/page.tsx b/src/app/dev/vote/detail/daftar-kontributor/[id]/page.tsx index 451b4a9a..97d0e1d5 100644 --- a/src/app/dev/vote/detail/daftar-kontributor/[id]/page.tsx +++ b/src/app/dev/vote/detail/daftar-kontributor/[id]/page.tsx @@ -1,13 +1,9 @@ import { Voting_UiDetailKontributorVoting } from "@/app_modules/vote/_ui"; -import { Vote_getListKontributorById } from "@/app_modules/vote/fun/get/get_list_kontributor_by_id"; - -export default async function Page({ params }: { params: { id: string } }) { - const votingId = params.id; - const listKontributor = await Vote_getListKontributorById(votingId); +export default async function Page() { return ( <> - + ); } diff --git a/src/app/dev/vote/detail/main/[id]/page.tsx b/src/app/dev/vote/detail/main/[id]/page.tsx index cd88b898..19084182 100644 --- a/src/app/dev/vote/detail/main/[id]/page.tsx +++ b/src/app/dev/vote/detail/main/[id]/page.tsx @@ -1,29 +1,12 @@ import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Vote_MainDetail } from "@/app_modules/vote"; -import { Vote_cekKontributorById } from "@/app_modules/vote/fun/get/cek_kontributor_by_id"; -import { voting_funGetOneVotingbyId } from "@/app_modules/vote/fun/get/fun_get_one_by_id"; -import { Vote_getHasilVoteById } from "@/app_modules/vote/fun/get/get_list_hasil_by_id"; -import { Vote_getListKontributorById } from "@/app_modules/vote/fun/get/get_list_kontributor_by_id"; -import { Vote_getOnePilihanVotingByUserId } from "@/app_modules/vote/fun/get/get_one_pilihan_voting_by_user_id"; export default async function Page({ params }: { params: { id: string } }) { const voteId = params.id; const userLoginId = await funGetUserIdByToken(); - - const dataVote = await voting_funGetOneVotingbyId(voteId); - const hasilVoting = await Vote_getHasilVoteById(voteId as any); - const isKontributor = await Vote_cekKontributorById(voteId); - const pilihanKontributor = await Vote_getOnePilihanVotingByUserId(voteId); - const listKontributor = await Vote_getListKontributorById(voteId); - return ( <> diff --git a/src/app/zCoba/page.tsx b/src/app/zCoba/page.tsx index 148b1e76..1d0782f7 100644 --- a/src/app/zCoba/page.tsx +++ b/src/app/zCoba/page.tsx @@ -14,93 +14,46 @@ import { useState } from "react"; import { DIRECTORY_ID } from "../lib"; export default function Page() { - const [filePP, setFilePP] = useState(null); - const [imgPP, setImgPP] = useState(); - - async function onSave() { - const body = { - file: filePP, - dirId: DIRECTORY_ID.profile_foto, - }; - - const token = - "QWERTYUIOPLKJHGFDSAZXCVBNMQAZWSXEDCRFVTGBYHNUJMIKOLPPOIUYTREWQLKJHGFDSAMNBVCXZlghvftyguhijknhbgvcfytguu8okjnhbgvfty7u8oilkjnhgvtygu7u8ojilnkhbgvhujnkhghvjhukjnhb"; - - const formData = new FormData(); - formData.append("file", filePP as any); - - const res = await fetch("/api/image/upload", { - method: "POST", - body: formData, - }); - - console.log(await res.json()); - } + const [data, setData] = useState({ + name: "bagas", + hobi: [ + { + id: "1", + name: "mancing", + }, + { + id: "2", + name: "game", + }, + ], + }); return ( <> - -
- {imgPP ? ( - - - - ) : ( - - - - )} -
+ +
{JSON.stringify(data, null, 2)}
- { - try { - const buffer = URL.createObjectURL( - new Blob([new Uint8Array(await files.arrayBuffer())]) - ); - setImgPP(buffer); - setFilePP(files); - } catch (error) { - console.log(error); - } + - )} - - - + Ganti +
); diff --git a/src/app/zCoba/skeleton/page.tsx b/src/app/zCoba/skeleton/page.tsx index 4e6e0004..a25e6542 100644 --- a/src/app/zCoba/skeleton/page.tsx +++ b/src/app/zCoba/skeleton/page.tsx @@ -11,40 +11,44 @@ export default function Voting_ComponentSkeletonViewPuh() { return ( <> } + header={} > - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - + {/* + +
+ +
- - + + + + + + + + + + -
-
+
*/} +
); diff --git a/src/app_modules/vote/_lib/api_voting.ts b/src/app_modules/vote/_lib/api_voting.ts index 244a3d19..82f82521 100644 --- a/src/app_modules/vote/_lib/api_voting.ts +++ b/src/app_modules/vote/_lib/api_voting.ts @@ -40,3 +40,37 @@ export const apiGetAllVoting = async ({ ); return await respone.json().catch(() => null); }; + +export const apiGetOneVotingById = async ({ id }: { id: string }) => { + const respone = await fetch(`/api/voting/${id}`); + return await respone.json().catch(() => null); +}; + +export const apiCheckKontributorToOneVoting = async ({ + id, + kategori, +}: { + id: string; + kategori: "isKontributor" | "pilihan"; +}) => { + const respone = await fetch( + `/api/voting/check?id=${id}&kategori=${kategori}` + ); + return await respone.json().catch(() => null); +}; + +export const apiGetHasilVotingById = async ({ id }: { id: string }) => { + const respone = await fetch(`/api/voting/hasil?id=${id}`); + return await respone.json().catch(() => null); +}; + +export const apiGetKontributorById = async ({ + id, + page, +}: { + id: string; + page: string; +}) => { + const respone = await fetch(`/api/voting/kontributor?id=${id}&page=${page}`); + return await respone.json().catch(() => null); +}; diff --git a/src/app_modules/vote/_ui/detail/ui_detail_kontributor_voting.tsx b/src/app_modules/vote/_ui/detail/ui_detail_kontributor_voting.tsx index cce59a87..89d02b2a 100644 --- a/src/app_modules/vote/_ui/detail/ui_detail_kontributor_voting.tsx +++ b/src/app_modules/vote/_ui/detail/ui_detail_kontributor_voting.tsx @@ -6,17 +6,13 @@ import { } from "@/app_modules/_global/ui"; import { Voting_ViewDetailKontributorVoting } from "../../_view"; -export function Voting_UiDetailKontributorVoting({ - listKontributor, -}: { - listKontributor: any[]; -}) { +export function Voting_UiDetailKontributorVoting() { return ( <> } > - + ); diff --git a/src/app_modules/vote/_view/view_detail_kontributor_voting.tsx b/src/app_modules/vote/_view/view_detail_kontributor_voting.tsx index d833ebb6..97fe39a6 100644 --- a/src/app_modules/vote/_view/view_detail_kontributor_voting.tsx +++ b/src/app_modules/vote/_view/view_detail_kontributor_voting.tsx @@ -3,23 +3,107 @@ import { ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; -import { Badge, Group, Stack, Text } from "@mantine/core"; +import { + Badge, + Center, + Group, + Stack, + Text, + Loader, + Paper, + Box, +} from "@mantine/core"; import _ from "lodash"; import { MODEL_VOTE_KONTRIBUTOR } from "../model/interface"; +import { useShallowEffect } from "@mantine/hooks"; +import { apiGetKontributorById } from "../_lib/api_voting"; +import { useParams } from "next/navigation"; +import { useState } from "react"; +import { clientLogger } from "@/util/clientLogger"; +import { Voting_ComponentSkeletonDaftarKontributor } from "../component/skeleton_view"; +import { ScrollOnly } from "next-scroll-loader"; + +export function Voting_ViewDetailKontributorVoting() { + const params = useParams<{ id: string }>(); + const [data, setData] = useState(null); + const [activePage, setActivePage] = useState(1); + + useShallowEffect(() => { + onLoadData(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetKontributorById({ + id: params.id, + page: `${activePage}`, + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data kontributor", error); + } + } + + if (_.isNull(data)) { + return ; + } -export function Voting_ViewDetailKontributorVoting({ - listKontributor, -}: { - listKontributor: MODEL_VOTE_KONTRIBUTOR[]; -}) { return ( <> - - {_.isEmpty(listKontributor) ? ( - - ) : ( - - {listKontributor?.map((e, i) => ( + {_.isEmpty(data) ? ( + + ) : ( + + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={async () => { + const respone = await apiGetKontributorById({ + id: params.id, + page: `${activePage + 1}`, + }); + + setActivePage((val) => val + 1); + + return respone.data; + }} + > + {(item) => ( + + + + 10 + ? 8 + : 10 + } + > + {item.Voting_DaftarNamaVote.value} + + + + } + /> + + )} +
+ + {/* {data?.map((e, i) => ( } /> - ))} -
- )} -
+ ))} */} + + )} ); } diff --git a/src/app_modules/vote/component/skeleton_view.tsx b/src/app_modules/vote/component/skeleton_view.tsx index 0068886e..21baff8c 100644 --- a/src/app_modules/vote/component/skeleton_view.tsx +++ b/src/app_modules/vote/component/skeleton_view.tsx @@ -1,7 +1,15 @@ import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; -import { Grid, Group, Skeleton, Stack } from "@mantine/core"; +import { Center, Grid, Group, Skeleton, Stack } from "@mantine/core"; -export function Voting_ComponentSkeletonViewPublish() { +export { + Voting_ComponentSkeletonDetail, + Voting_ComponentSkeletonViewKontribusi, + Voting_ComponentSkeletonViewPublish, + Voting_ComponentSkeletonViewStatus, + Voting_ComponentSkeletonDaftarKontributor, +}; + +function Voting_ComponentSkeletonViewPublish() { return ( <> {Array.from({ length: 2 }).map((e, i) => ( @@ -39,7 +47,7 @@ export function Voting_ComponentSkeletonViewPublish() { ); } -export function Voting_ComponentSkeletonViewStatus() { +function Voting_ComponentSkeletonViewStatus() { return ( <> {Array.from({ length: 2 }).map((e, i) => ( @@ -54,7 +62,7 @@ export function Voting_ComponentSkeletonViewStatus() { ); } -export function Voting_ComponentSkeletonViewKontribusi() { +function Voting_ComponentSkeletonViewKontribusi() { return ( <> {Array.from({ length: 2 }).map((e, i) => ( @@ -93,5 +101,85 @@ export function Voting_ComponentSkeletonViewKontribusi() { ))} ); - +} + +function Voting_ComponentSkeletonDetail() { + return ( + <> + + + + + + + + + + + + + + + + + + + + + + {/* + + + + */} + + + + + + + + + +
+ +
+ + + + + + + + + + + +
+
+
+ + ); +} + +function Voting_ComponentSkeletonDaftarKontributor(){ + return ( + <> + + + + + + + + + + + + + + + + + ); } \ No newline at end of file diff --git a/src/app_modules/vote/detail/main/index.tsx b/src/app_modules/vote/detail/main/index.tsx index 4433d37d..13b695f9 100644 --- a/src/app_modules/vote/detail/main/index.tsx +++ b/src/app_modules/vote/detail/main/index.tsx @@ -1,5 +1,6 @@ "use client"; +import { IRealtimeData } from "@/app/lib/global_state"; import { AccentColor, MainColor, @@ -9,263 +10,324 @@ import { ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information"; +import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import notifikasiToUser_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_user"; -import mqtt_client from "@/util/mqtt_client"; +import { clientLogger } from "@/util/clientLogger"; import { Badge, Box, Button, Center, - Group, Radio, Stack, Text, Title, } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import moment from "moment"; +import "moment/locale/id"; +import { useParams } from "next/navigation"; import { useState } from "react"; -import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_voting"; -import { Vote_funCreateHasil } from "../../fun/create/create_hasil"; -import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id"; -import { MODEL_VOTING } from "../../model/interface"; -import { IRealtimeData } from "@/app/lib/global_state"; import { WibuRealtime } from "wibu-pkg"; +import { + apiCheckKontributorToOneVoting, + apiGetHasilVotingById, + apiGetOneVotingById, +} from "../../_lib/api_voting"; +import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_voting"; +import { Voting_ComponentSkeletonDetail } from "../../component/skeleton_view"; +import { Vote_funCreateHasil } from "../../fun/create/create_hasil"; +import { MODEL_VOTING } from "../../model/interface"; export default function Vote_MainDetail({ - dataVote, - hasilVoting, - isKontributor, - pilihanKontributor, - listKontributor, userLoginId, }: { - dataVote: MODEL_VOTING; - hasilVoting: any; - isKontributor: boolean; - pilihanKontributor: string; - listKontributor: any[]; userLoginId: string; }) { - const [data, setData] = useState(dataVote); + const params = useParams<{ id: string }>(); const today = new Date(); + const [data, setData] = useState(null); + const [hasil, setHasil] = useState(null); + const [pilihanVotingId, setPilihanVotingId] = useState(""); + const [pilihanKontributor, setPilihanKontributor] = useState( + null + ); + + const [isKontributor, setIsKontributor] = useState(null); + + useShallowEffect(() => { + onLoadData(); + onLoadHasil(); + }, []); + + async function onLoadData() { + try { + const respone = await apiGetOneVotingById({ + id: params.id, + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data detail", error); + } + } + + async function onLoadHasil() { + try { + const respone = await apiGetHasilVotingById({ + id: params.id, + }); + + if (respone) { + setHasil(respone.data); + } + } catch (error) { + clientLogger.error("Error get data hasil voting", error); + } + } + + useShallowEffect(() => { + onCheckKontribusi(); + onLoadPilihan(); + }, []); + + async function onCheckKontribusi() { + try { + const respone = await apiCheckKontributorToOneVoting({ + id: params.id, + kategori: "isKontributor", + }); + + if (respone) { + setIsKontributor(respone.data); + } + } catch (error) { + clientLogger.error("Error check kontibusi", error); + } + } + + async function onLoadPilihan() { + try { + const respone = await apiCheckKontributorToOneVoting({ + id: params.id, + kategori: "pilihan", + }); + + if (respone) { + setPilihanKontributor(respone.data); + } + } catch (error) { + clientLogger.error("Error check pilihan", error); + } + } + + async function onVote() { + try { + const res = await Vote_funCreateHasil({ + pilihanVotingId: pilihanVotingId, + votingId: params.id, + }); + if (res.status === 201) { + const respone = await apiGetHasilVotingById({ + id: params.id, + }); + + if (respone) { + setHasil(respone.data); + ComponentGlobal_NotifikasiBerhasil(res.message); + + const checkKontibutor = await apiCheckKontributorToOneVoting({ + id: params.id, + kategori: "isKontributor", + }); + + if (checkKontibutor) { + setIsKontributor(checkKontibutor.data); + } + + const checkPilihan = await apiCheckKontributorToOneVoting({ + id: params.id, + kategori: "pilihan", + }); + + if (checkPilihan) { + setPilihanKontributor(checkPilihan.data); + } + } + + if (userLoginId !== res?.data?.Voting?.authorId) { + const dataNotifikasi: IRealtimeData = { + appId: res?.data?.Voting?.id as string, + userId: res?.data?.Voting?.authorId as string, + pesan: res?.pilihan as string, + status: "Voting Masuk", + kategoriApp: "VOTING", + title: "User lain telah melakukan voting !", + }; + + const createNotifikasi = await notifikasiToUser_funCreate({ + data: dataNotifikasi as any, + }); + + if (createNotifikasi.status === 201) { + WibuRealtime.setData({ + type: "notification", + pushNotificationTo: "USER", + dataMessage: dataNotifikasi, + }); + } + } + } else { + ComponentGlobal_NotifikasiPeringatan(res.message); + } + } catch (error) { + clientLogger.error("Error vote", error); + ComponentGlobal_NotifikasiGagal("Gagal melakukan voting"); + } + } + + if (_.isNull(data) || _.isNull(hasil) || _.isNull(isKontributor)) { + return ; + } return ( <> - {moment(dataVote?.awalVote).diff(today, "hours") < 0 ? ( + {moment(data?.awalVote).diff(today, "hours") < 0 ? ( "" ) : ( )} - - - - - ); -} -function TampilanDataVoting({ - dataVote, - setData, - isKontributor, - pilihanKontributor, - userLoginId, -}: { - dataVote?: MODEL_VOTING; - setData: any; - isKontributor: boolean; - pilihanKontributor: any; - userLoginId: string; -}) { - const [votingNameId, setVotingNameId] = useState(""); - const today = new Date(); + + + - return ( - <> - - - - {/* */} - -
- - {dataVote?.title} - -
- {dataVote?.deskripsi} + +
+ + {data?.title} + +
+ {data?.deskripsi} - - - - Batas Voting - + + + + Batas Voting + - - + - {dataVote?.awalVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} + {data + ? moment(data.awalVote).format("ll") + : "tgl awal voting"}{" "} + -{" "} + {data + ? moment(data.akhirVote).format("ll") + : "tgl akhir voting"} - - - - {dataVote?.akhirVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} - - - + + - - {isKontributor ? ( - - - Pilihan anda: - - - {pilihanKontributor.Voting_DaftarNamaVote.value} - - - ) : ( - - { - setVotingNameId(val); - }} - label={ - - Pilihan : - - } > - - {dataVote?.Voting_DaftarNamaVote.map((v) => ( - - - - ))} - - -
- {_.isEmpty(votingNameId) ? ( - - ) : ( + + Pilihan anda: + + {pilihanKontributor} + + ) : ( + + { + setPilihanVotingId(val); + }} + label={ + + Pilihan : + + } + > + + {_.isEmpty(data?.Voting_DaftarNamaVote) ? ( + Pilihan Tidak Ditemukan + ) : ( + data?.Voting_DaftarNamaVote.map((v) => ( + + + + )) + )} + + + +
- )} -
-
- )} - - +
+
+ )} +
+
+ + +
); -} - -async function onVote( - pilihanVotingId: string, - voteId: string, - setData: any, - userLoginId: string -) { - const res = await Vote_funCreateHasil(pilihanVotingId, voteId); - if (res.status === 201) { - await voting_funGetOneVotingbyId(voteId).then((val) => { - setData(val); - ComponentGlobal_NotifikasiBerhasil(res.message); - }); - - if (userLoginId !== res?.data?.Voting?.authorId) { - const dataNotifikasi: IRealtimeData = { - appId: res?.data?.Voting?.id as string, - userId: res?.data?.Voting?.authorId as string, - pesan: res?.pilihan as string, - status: "Voting Masuk", - kategoriApp: "VOTING", - title: "User lain telah melakukan voting !", - }; - - const createNotifikasi = await notifikasiToUser_funCreate({ - data: dataNotifikasi as any, - }); - - if (createNotifikasi.status === 201) { - WibuRealtime.setData({ - type: "notification", - pushNotificationTo: "USER", - dataMessage: dataNotifikasi, - }); - } - } - } else { - ComponentGlobal_NotifikasiPeringatan(res.message); - } -} +} \ No newline at end of file diff --git a/src/app_modules/vote/fun/create/create_hasil.ts b/src/app_modules/vote/fun/create/create_hasil.ts index 3d199d6b..195df58b 100644 --- a/src/app_modules/vote/fun/create/create_hasil.ts +++ b/src/app_modules/vote/fun/create/create_hasil.ts @@ -4,10 +4,13 @@ import prisma from "@/app/lib/prisma"; import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { revalidatePath } from "next/cache"; -export async function Vote_funCreateHasil( - pilihanVotingId: string, - votingId: string -) { +export async function Vote_funCreateHasil({ + pilihanVotingId, + votingId, +}: { + pilihanVotingId: string; + votingId: string; +}) { const userLoginId = await funGetUserIdByToken(); const get = await prisma.voting_DaftarNamaVote.findFirst({