From 5f8a1c38d0f53eddc53c016433a2628cc7b55778 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 26 Dec 2024 10:47:08 +0800 Subject: [PATCH 1/3] Fix assets image Deksripsi: - Asset image pada halaman home dan crowd --- src/app_modules/crowd/main/view.tsx | 35 ++++++++++---------- src/app_modules/home/component/body_home.tsx | 26 +++++++++++++-- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/app_modules/crowd/main/view.tsx b/src/app_modules/crowd/main/view.tsx index b3d4787d..f9ea5e9b 100644 --- a/src/app_modules/crowd/main/view.tsx +++ b/src/app_modules/crowd/main/view.tsx @@ -5,8 +5,6 @@ import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; -import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; -import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import { gs_donasi_hot_menu } from "@/app_modules/donasi/global_state"; import { gs_investas_menu } from "@/app_modules/investasi/g_state"; import { Grid, Image, Paper, Stack, Text, Title } from "@mantine/core"; @@ -21,26 +19,27 @@ export default function MainCrowd() { const [donasiHotMenu, setDonasiHotMenu] = useAtom(gs_donasi_hot_menu); const [loadingInv, setLoadingInv] = useState(false); const [loadingDon, setLoadingDon] = useState(false); + const [isLoading, setLoading] = useState(true); return ( <> - - {/* - - - */} - Logo - + logo setLoading(false)} + styles={{ + imageWrapper: { + border: `2px solid ${AccentColor.blue}`, + borderRadius: "10px 10px 10px 10px", + }, + image: { + borderRadius: "8px 8px 8px 8px", + }, + }} + /> {/* INVESTASI */} diff --git a/src/app_modules/home/component/body_home.tsx b/src/app_modules/home/component/body_home.tsx index 9535b5eb..41ebcb52 100644 --- a/src/app_modules/home/component/body_home.tsx +++ b/src/app_modules/home/component/body_home.tsx @@ -26,6 +26,7 @@ export default function BodyHome() { const [dataUser, setDataUser] = useState({}); const [dataJob, setDataJob] = useState([]); const [loadingJob, setLoadingJob] = useState(true); + const [loading, setLoading] = useState(true); useShallowEffect(() => { cekUserLogin(); @@ -59,16 +60,35 @@ export default function BodyHome() { return ( - - logo - + + */} + + logo setLoading(false)} + styles={{ + imageWrapper: { + border: `2px solid ${AccentColor.blue}`, + borderRadius: "10px 10px 10px 10px", + }, + image: { + borderRadius: "8px 8px 8px 8px", + }, + }} + /> From 924e994236c90647322cc16c222b482c7a850ea3 Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Fri, 27 Dec 2024 11:04:55 +0800 Subject: [PATCH 2/3] Fix voting Deksripsi: - Fix user server to API di tampilan utama voting --- src/app/api/notifikasi/count/route.ts | 4 +- .../notifikasi/get-all-by-category/route.ts | 4 +- src/app/api/user/route.ts | 21 +- src/app/api/voting/get/route.ts | 312 ++++++++++++++++++ src/app/api/voting/master/route.ts | 22 ++ src/app/dev/event/create/page.tsx | 4 +- src/app/dev/event/detail/main/[id]/page.tsx | 4 +- src/app/dev/event/konfirmasi/[id]/page.tsx | 4 +- src/app/dev/layout.tsx | 4 +- src/app/dev/vote/main/beranda/page.tsx | 4 +- src/app/dev/vote/main/kontribusi/page.tsx | 4 +- src/app/dev/vote/main/riwayat/[id]/page.tsx | 42 +-- src/app/dev/vote/main/status/[id]/page.tsx | 20 +- src/app/lib/new_fun_user_id.ts | 31 +- src/app/zCoba/skeleton/page.tsx | 51 +++ .../fun/get/fun_get_user_id_by_token.ts | 60 ++-- src/app_modules/crowd/main/layout.tsx | 2 +- src/app_modules/vote/_lib/api_voting.ts | 42 +++ .../vote/component/card_view_publish.tsx | 46 +-- .../vote/component/card_view_status.tsx | 34 +- src/app_modules/vote/component/index.tsx | 6 + .../vote/component/skeleton_view.tsx | 97 ++++++ src/app_modules/vote/index.tsx | 1 + src/app_modules/vote/main/beranda.tsx | 95 +++--- src/app_modules/vote/main/kontribusi.tsx | 112 ++++--- src/app_modules/vote/main/riwayat/index.tsx | 48 +-- src/app_modules/vote/main/riwayat/saya.tsx | 60 ++-- src/app_modules/vote/main/riwayat/semua.tsx | 48 ++- src/app_modules/vote/main/status/draft.tsx | 61 ++-- src/app_modules/vote/main/status/index.tsx | 61 ++-- src/app_modules/vote/main/status/publish.tsx | 104 +++--- src/app_modules/vote/main/status/reject.tsx | 49 ++- src/app_modules/vote/main/status/review.tsx | 49 ++- src/middleware.ts | 1 + 34 files changed, 1039 insertions(+), 468 deletions(-) create mode 100644 src/app/api/voting/get/route.ts create mode 100644 src/app/api/voting/master/route.ts create mode 100644 src/app/zCoba/skeleton/page.tsx create mode 100644 src/app_modules/vote/_lib/api_voting.ts create mode 100644 src/app_modules/vote/component/skeleton_view.tsx diff --git a/src/app/api/notifikasi/count/route.ts b/src/app/api/notifikasi/count/route.ts index c54ea290..715f0583 100644 --- a/src/app/api/notifikasi/count/route.ts +++ b/src/app/api/notifikasi/count/route.ts @@ -1,5 +1,5 @@ import { prisma } from "@/app/lib"; -import { newFunGetUserId } from "@/app/lib/new_fun_user_id"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import backendLogger from "@/util/backendLogger"; import { NextResponse } from "next/server"; @@ -7,7 +7,7 @@ export const dynamic = "force-dynamic"; export async function GET(request: Request) { try { - const userLoginId = await newFunGetUserId(); + const userLoginId = await funGetUserIdByToken(); const count = await prisma.notifikasi.findMany({ where: { diff --git a/src/app/api/notifikasi/get-all-by-category/route.ts b/src/app/api/notifikasi/get-all-by-category/route.ts index bfa9aefd..fc76b58b 100644 --- a/src/app/api/notifikasi/get-all-by-category/route.ts +++ b/src/app/api/notifikasi/get-all-by-category/route.ts @@ -1,5 +1,5 @@ import { prisma } from "@/app/lib"; -import { newFunGetUserId } from "@/app/lib/new_fun_user_id"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { ICategoryapp } from "@/app_modules/notifikasi/model/interface"; import backendLogger from "@/util/backendLogger"; import _ from "lodash"; @@ -13,7 +13,7 @@ export async function GET(request: Request) { const category = searchParams.get("category") as ICategoryapp; const page = searchParams.get("page"); - const userLoginId = await newFunGetUserId(); + const userLoginId = await funGetUserIdByToken(); const fixPage = _.toNumber(page); const takeData = 10; const skipData = fixPage * takeData - takeData; diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts index 33b4d093..258227c5 100644 --- a/src/app/api/user/route.ts +++ b/src/app/api/user/route.ts @@ -1,4 +1,4 @@ -import { jwtVerify } from "jose"; +import { decrypt } from "@/app/auth/_lib/decrypt"; import _ from "lodash"; import { cookies } from "next/headers"; import { NextResponse } from "next/server"; @@ -20,22 +20,3 @@ export async function GET() { return NextResponse.json({ status: 200, message: "OK", data: dataUser }); } - -async function decrypt({ - token, - encodedKey, -}: { - token: string; - encodedKey: string; -}): Promise | null> { - try { - const enc = new TextEncoder().encode(encodedKey); - const { payload } = await jwtVerify(token, enc, { - algorithms: ["HS256"], - }); - return (payload.user as Record) || null; - } catch (error) { - console.error("Gagal verifikasi session", error); - return null; - } -} diff --git a/src/app/api/voting/get/route.ts b/src/app/api/voting/get/route.ts new file mode 100644 index 00000000..99af6d9b --- /dev/null +++ b/src/app/api/voting/get/route.ts @@ -0,0 +1,312 @@ +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; +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 search = searchParams.get("search"); + const kategori = searchParams.get("kategori"); + const status = searchParams.get("status"); + const page = searchParams.get("page"); + + const takeData = 5; + const skipData = Number(page) * 5 - 5; + + const userLoginId = await funGetUserIdByToken(); + + if (userLoginId == null) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data, user id tidak ada", + }, + { status: 500 } + ); + } + + if (kategori == "beranda" && search != null && search != "") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: "1", + isArsip: false, + isActive: true, + akhirVote: { + gte: new Date(), + }, + title: { + contains: search, + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + isActive: true, + createdAt: true, + updatedAt: true, + deskripsi: true, + awalVote: true, + akhirVote: true, + catatan: true, + authorId: true, + voting_StatusId: true, + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + include: { + Voting_Kontributor: { + include: { + Author: true, + }, + }, + }, + }, + Author: { + select: { + id: true, + username: true, + nomor: true, + Profile: true, + }, + }, + }, + }); + } else if (kategori == "beranda") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: "1", + isArsip: false, + isActive: true, + akhirVote: { + gte: new Date(), + }, + title: { + // contains: search, + mode: "insensitive", + }, + }, + select: { + id: true, + title: true, + isActive: true, + createdAt: true, + updatedAt: true, + deskripsi: true, + awalVote: true, + akhirVote: true, + catatan: true, + authorId: true, + voting_StatusId: true, + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + include: { + Voting_Kontributor: { + include: { + Author: true, + }, + }, + }, + }, + Author: { + select: { + id: true, + username: true, + nomor: true, + Profile: true, + }, + }, + }, + }); + } else if (kategori == "status" && status == "1") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: status, + authorId: userLoginId as string, + isActive: true, + akhirVote: { + gte: new Date(), + }, + }, + include: { + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + }, + }); + } else if (kategori == "status" && status != "1") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: status, + authorId: userLoginId as string, + isActive: true, + }, + }); + } else if (kategori == "kontribusi") { + fixData = await prisma.voting_Kontributor.findMany({ + take: takeData, + skip: skipData, + orderBy: { + createdAt: "desc", + }, + where: { + authorId: userLoginId, + }, + select: { + id: true, + Voting: { + select: { + id: true, + title: true, + isActive: true, + awalVote: true, + akhirVote: true, + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + Author: { + select: { + Profile: true, + }, + }, + }, + }, + Voting_DaftarNamaVote: true, + Author: true, + }, + }); + } else if (kategori == "riwayat" && status == "1") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + + orderBy: { + createdAt: "asc", + }, + where: { + voting_StatusId: "1", + isActive: true, + akhirVote: { + lte: new Date(), + }, + }, + select: { + id: true, + title: true, + isActive: true, + createdAt: true, + updatedAt: true, + deskripsi: true, + awalVote: true, + akhirVote: true, + catatan: true, + authorId: true, + voting_StatusId: true, + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + Author: { + select: { + id: true, + username: true, + nomor: true, + Profile: true, + }, + }, + }, + }); + } else if (kategori == "riwayat" && status == "2") { + fixData = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + + orderBy: { + createdAt: "asc", + }, + where: { + voting_StatusId: "1", + authorId: userLoginId as string, + isActive: true, + akhirVote: { + lte: new Date(), + }, + }, + select: { + id: true, + title: true, + isActive: true, + createdAt: true, + updatedAt: true, + deskripsi: true, + awalVote: true, + akhirVote: true, + catatan: true, + authorId: true, + voting_StatusId: true, + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + Author: { + select: { + id: true, + username: true, + nomor: true, + Profile: true, + }, + }, + }, + }); + } + + return NextResponse.json( + { success: true, message: "Berhasil mendapatkan data", data: fixData }, + { status: 200 } + ); + } catch (error) { + backendLogger.error("Error get 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/master/route.ts b/src/app/api/voting/master/route.ts new file mode 100644 index 00000000..098d04e2 --- /dev/null +++ b/src/app/api/voting/master/route.ts @@ -0,0 +1,22 @@ +import { prisma } from "@/app/lib"; +import { NextResponse } from "next/server"; + +export async function GET(request: Request) { + try { + const data = await prisma.voting_Status.findMany(); + return NextResponse.json({ + success: true, + message: "Berhasil mendapatkan data", + data: data, + }); + } catch (error) { + return NextResponse.json( + { + success: false, + message: "Gagal mendapatkan data", + reason: (error as Error).message, + }, + { status: 500 } + ); + } +} diff --git a/src/app/dev/event/create/page.tsx b/src/app/dev/event/create/page.tsx index b731e460..5363ccb1 100644 --- a/src/app/dev/event/create/page.tsx +++ b/src/app/dev/event/create/page.tsx @@ -1,9 +1,9 @@ -import { newFunGetUserId } from "@/app/lib/new_fun_user_id"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Event_Create } from "@/app_modules/event"; import { Event_getMasterTipeAcara } from "@/app_modules/event/fun/master/get_tipe_acara"; export default async function Page() { - const userLoginId = await newFunGetUserId(); + const userLoginId = await funGetUserIdByToken(); const listTipeAcara = await Event_getMasterTipeAcara(); return ( diff --git a/src/app/dev/event/detail/main/[id]/page.tsx b/src/app/dev/event/detail/main/[id]/page.tsx index 11850c4e..62fca07e 100644 --- a/src/app/dev/event/detail/main/[id]/page.tsx +++ b/src/app/dev/event/detail/main/[id]/page.tsx @@ -1,10 +1,10 @@ -import { newFunGetUserId } from "@/app/lib/new_fun_user_id"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Event_DetailMain } from "@/app_modules/event"; import { Event_countTotalPesertaById } from "@/app_modules/event/fun/count/count_total_peserta_by_id"; export default async function Page({ params }: { params: { id: string } }) { let eventId = params.id; - const userLoginId = await newFunGetUserId(); + const userLoginId = await funGetUserIdByToken(); const totalPeserta = await Event_countTotalPesertaById(eventId); return ( diff --git a/src/app/dev/event/konfirmasi/[id]/page.tsx b/src/app/dev/event/konfirmasi/[id]/page.tsx index bb2200b5..7d8b033a 100644 --- a/src/app/dev/event/konfirmasi/[id]/page.tsx +++ b/src/app/dev/event/konfirmasi/[id]/page.tsx @@ -1,4 +1,4 @@ -import { newFunGetUserId } from "@/app/lib/new_fun_user_id"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import Ui_Konfirmasi from "@/app_modules/event/_ui/konfirmasi"; export default async function Page({ @@ -7,7 +7,7 @@ export default async function Page({ params: Promise<{ id: string }>; }) { const eventId = (await params).id; - const userLoginId = await newFunGetUserId(); + const userLoginId = await funGetUserIdByToken(); return ( <> diff --git a/src/app/dev/layout.tsx b/src/app/dev/layout.tsx index bfb694c1..d27b62d5 100644 --- a/src/app/dev/layout.tsx +++ b/src/app/dev/layout.tsx @@ -1,5 +1,5 @@ +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { RealtimeProvider } from "../lib"; -import { newFunGetUserId } from "../lib/new_fun_user_id"; import { ServerEnv } from "../lib/server_env"; export default async function Layout({ @@ -8,7 +8,7 @@ export default async function Layout({ children: React.ReactNode; }) { - const userId = await newFunGetUserId(); + const userId = await funGetUserIdByToken(); return ( <> diff --git a/src/app/dev/vote/main/beranda/page.tsx b/src/app/dev/vote/main/beranda/page.tsx index 28904aca..4c507454 100644 --- a/src/app/dev/vote/main/beranda/page.tsx +++ b/src/app/dev/vote/main/beranda/page.tsx @@ -1,12 +1,10 @@ import { Vote_Beranda } from "@/app_modules/vote"; -import { vote_getAllListPublish } from "@/app_modules/vote/fun/get/get_all_list_publish"; export default async function Page() { - const dataVote = await vote_getAllListPublish({ page: 1 }); return ( <> - + ); } diff --git a/src/app/dev/vote/main/kontribusi/page.tsx b/src/app/dev/vote/main/kontribusi/page.tsx index 31e1f35f..2074ba5a 100644 --- a/src/app/dev/vote/main/kontribusi/page.tsx +++ b/src/app/dev/vote/main/kontribusi/page.tsx @@ -1,11 +1,9 @@ import { Vote_Kontribusi } from "@/app_modules/vote"; -import { vote_getAllListKontribusiByAuthorId } from "@/app_modules/vote/fun/get/get_list_kontribusi_by_author_id"; export default async function Page() { - const dataKontribusi = await vote_getAllListKontribusiByAuthorId({ page: 1 }); return ( <> - + ); } diff --git a/src/app/dev/vote/main/riwayat/[id]/page.tsx b/src/app/dev/vote/main/riwayat/[id]/page.tsx index 10988a8f..2730d771 100644 --- a/src/app/dev/vote/main/riwayat/[id]/page.tsx +++ b/src/app/dev/vote/main/riwayat/[id]/page.tsx @@ -1,41 +1,9 @@ import { Vote_Riwayat } from "@/app_modules/vote"; -import { vote_getAllListRiwayat } from "@/app_modules/vote/fun/get/get_all_list_riwayat"; -import { Vote_getAllListRiwayatSaya as vote_getAllListRiwayatSaya } from "@/app_modules/vote/fun/get/get_all_list_riwayat_saya"; export default async function Page({ params }: { params: { id: string } }) { - let statusRiwayatId = params.id; - - const listRiwayat = await vote_getAllListRiwayat({ page: 1 }); - const listRiwayatSaya = await vote_getAllListRiwayatSaya({ page: 1 }); - - if (statusRiwayatId == "1") { - return ( - <> - - - ); - } - if (statusRiwayatId == "2") { - return ( - <> - - - ); - } - - // return ( - // <> - // - // - // ); + return ( + <> + + + ); } diff --git a/src/app/dev/vote/main/status/[id]/page.tsx b/src/app/dev/vote/main/status/[id]/page.tsx index 9e3fa9a2..afed972f 100644 --- a/src/app/dev/vote/main/status/[id]/page.tsx +++ b/src/app/dev/vote/main/status/[id]/page.tsx @@ -1,25 +1,9 @@ import { Vote_Status } from "@/app_modules/vote"; -import { - vote_funGetAllByStatusId, - voting_getMasterStatus, -} from "@/app_modules/vote/fun"; - -export default async function Page({ params }: { params: { id: string } }) { - const statusId = params.id; - - const listStatus = await voting_getMasterStatus(); - const dataVoting = await vote_funGetAllByStatusId({ - page: 1, - statusId: statusId, - }); +export default async function Page() { return ( <> - + ); } diff --git a/src/app/lib/new_fun_user_id.ts b/src/app/lib/new_fun_user_id.ts index d69660c2..c147ff22 100644 --- a/src/app/lib/new_fun_user_id.ts +++ b/src/app/lib/new_fun_user_id.ts @@ -1,21 +1,28 @@ -"use server" +"use server"; import _ from "lodash"; import { cookies } from "next/headers"; import { decrypt } from "../auth/_lib/decrypt"; +import backendLogger from "@/util/backendLogger"; export async function newFunGetUserId() { - const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!); + try { + const key = process.env.NEXT_PUBLIC_BASE_SESSION_KEY; + const c = cookies().get("hipmi-key"); - if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) { + if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) { + return null; + } + + const token = c.value; + const dataUser = await decrypt({ + token: token, + encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, + }); + + return dataUser?.id; + } catch (error) { + backendLogger.log("Gagal mendapatkan user id", error); return null; } - - const token = c.value; - const dataUser = await decrypt({ - token: token, - encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, - }); - - return dataUser?.id; -} \ No newline at end of file +} diff --git a/src/app/zCoba/skeleton/page.tsx b/src/app/zCoba/skeleton/page.tsx new file mode 100644 index 00000000..4e6e0004 --- /dev/null +++ b/src/app/zCoba/skeleton/page.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; +import { + UIGlobal_LayoutHeaderTamplate, + UIGlobal_LayoutTamplate, +} from "@/app_modules/_global/ui"; +import { Center, Grid, Group, Skeleton, Stack } from "@mantine/core"; + +export default function Voting_ComponentSkeletonViewPuh() { + return ( + <> + } + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +} diff --git a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts index ed2d0ee0..799c46c4 100644 --- a/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts +++ b/src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts @@ -1,56 +1,36 @@ "use server"; -import { prisma } from "@/app/lib"; -import { ServerEnv } from "@/app/lib/server_env"; -import { unsealData } from "iron-session"; import { jwtVerify } from "jose"; import { cookies } from "next/headers"; +import { decrypt } from "../../../../app/auth/_lib/decrypt"; export async function funGetUserIdByToken() { const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!; - // console.log("SESSION_KEY", SESSION_KEY); - const c = cookies().get("hipmi-key"); + const c = cookies().get(SESSION_KEY); const cekUser = await decrypt({ token: c?.value as string, encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!, }); - // console.log("userid" , cekUser?.id) - - // const token = JSON.parse( - // await unsealData(c?.value as string, { - // password: process.env.WIBU_PWD as string, - // }) - // ); - // return token.id; - - // const token = c?.value; - // const cekToken = await prisma.userSession.findFirst({ - // where: { - // token: token, - // }, - // }); - - // if (cekToken === null) return null return cekUser?.id; } -async function decrypt({ - token, - encodedKey, -}: { - token: string; - encodedKey: string; -}): Promise | null> { - try { - const enc = new TextEncoder().encode(encodedKey); - const { payload } = await jwtVerify(token, enc, { - algorithms: ["HS256"], - }); - return (payload.user as Record) || null; - } catch (error) { - console.error("Gagal verifikasi session", error); - return null; - } -} +// async function decrypt({ +// token, +// encodedKey, +// }: { +// token: string; +// encodedKey: string; +// }): Promise | null> { +// try { +// const enc = new TextEncoder().encode(encodedKey); +// const { payload } = await jwtVerify(token, enc, { +// algorithms: ["HS256"], +// }); +// return (payload.user as Record) || null; +// } catch (error) { +// console.error("Gagal verifikasi session", error); +// return null; +// } +// } diff --git a/src/app_modules/crowd/main/layout.tsx b/src/app_modules/crowd/main/layout.tsx index 3484fa77..817e504b 100644 --- a/src/app_modules/crowd/main/layout.tsx +++ b/src/app_modules/crowd/main/layout.tsx @@ -15,7 +15,7 @@ export default function LayoutMainCrowd({ } diff --git a/src/app_modules/vote/_lib/api_voting.ts b/src/app_modules/vote/_lib/api_voting.ts new file mode 100644 index 00000000..244a3d19 --- /dev/null +++ b/src/app_modules/vote/_lib/api_voting.ts @@ -0,0 +1,42 @@ +/** + * Mengambil daftar semua voting dari API berdasarkan filter yang diberikan. + * + * @param {Object} params - Parameter untuk permintaan data voting. + * @param {"beranda"|"status"} params.kategori - Kategori voting yang diminta, hanya dapat berupa "beranda" atau "status". + * @param {string} params.page - Nomor halaman untuk pagination. + * @param {string|null|undefined} [params.search] - Kata kunci pencarian untuk memfilter voting (opsional). + * @param {"1"|"2"|"3"|"4"|undefined} [params.status] - Status voting, di mana: + * - "1": Publish, + * - "2": Review, + * - "3": Draft, + * - "4": Reject. + * Parameter ini bersifat opsional. + * @returns {Promise} Mengembalikan objek hasil permintaan dalam bentuk JSON jika berhasil, + * atau `null` jika terjadi kesalahan dalam parsing respons. + * + * @example + * // Contoh penggunaan: + * apiGetAllVoting({ + * kategori: "beranda", + * page: "1", + * search: "pemilu", + * status: "1", + * }).then(data => console.log(data)); + */ + +export const apiGetAllVoting = async ({ + kategori, + page, + search, + status, +}: { + kategori: "beranda" | "status" | "kontribusi" | "riwayat"; + page: string; + search?: string | null; + status?: "1" | "2" | "3" | "4"; +}) => { + const respone = await fetch( + `/api/voting/get?kategori=${kategori}&page=${page}&search=${search || ""}&status=${status || ""}` + ); + return await respone.json().catch(() => null); +}; diff --git a/src/app_modules/vote/component/card_view_publish.tsx b/src/app_modules/vote/component/card_view_publish.tsx index 90c1f433..bc5288a0 100644 --- a/src/app_modules/vote/component/card_view_publish.tsx +++ b/src/app_modules/vote/component/card_view_publish.tsx @@ -7,17 +7,9 @@ import { ComponentGlobal_CardStyles, } from "@/app_modules/_global/component"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; -import { - Avatar, - Badge, - Box, - Center, - Grid, - Group, - Stack, - Text, - Title -} from "@mantine/core"; +import { Avatar, Badge, Box, Center, Grid, Stack, Text } from "@mantine/core"; +import moment from "moment"; +import "moment/locale/id"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { MODEL_VOTING } from "../model/interface"; @@ -75,35 +67,23 @@ export default function ComponentVote_CardViewPublish({ backgroundColor: AccentColor.blue, border: `1px solid ${AccentColor.skyblue}`, color: "white", - width: "80%", + width: "70%", }, }} > - - - {data - ? data?.awalVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - }) - : "tgl awal voting"} - - - - - {data - ? data?.akhirVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - }) - : "tgl akhir voting"} - - + + {data + ? moment(data.awalVote).format("ll") + : "tgl awal voting"}{" "} + -{" "} + {data + ? moment(data.akhirVote).format("ll") + : "tgl akhir voting"} + {data ? ( -
- Hasil Voting -
- {data?.Voting_DaftarNamaVote.map((e) => ( { if (data?.id === undefined) { - ComponentGlobal_NotifikasiPeringatan("Path tidak ditemukan"); + ComponentGlobal_NotifikasiPeringatan("Halaman tidak ditemukan"); } else { setVisible(true); router.push((path as string) + data?.id); @@ -42,23 +47,14 @@ export default function ComponentVote_CardViewStatus({ backgroundColor: AccentColor.blue, border: `1px solid ${AccentColor.skyblue}`, color: "white", - width: "80%", + width: "70%", }, }} > - - - {data?.awalVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} - - - - - {data?.akhirVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} - - + + {data ? moment(data.awalVote).format("ll") : "tgl awal voting"} -{" "} + {data ? moment(data.akhirVote).format("ll") : "tgl akhir voting"} +
{visible && } diff --git a/src/app_modules/vote/component/index.tsx b/src/app_modules/vote/component/index.tsx index 6353e17d..e7b6001b 100644 --- a/src/app_modules/vote/component/index.tsx +++ b/src/app_modules/vote/component/index.tsx @@ -1,3 +1,9 @@ import { Voting_ComponentLayoutHeaderDetailPublish } from "./detail/comp_layout_header_detail_publish"; +import { + Voting_ComponentSkeletonViewPublish, + Voting_ComponentSkeletonViewStatus, +} from "./skeleton_view"; export { Voting_ComponentLayoutHeaderDetailPublish }; +export { Voting_ComponentSkeletonViewPublish }; +export { Voting_ComponentSkeletonViewStatus }; diff --git a/src/app_modules/vote/component/skeleton_view.tsx b/src/app_modules/vote/component/skeleton_view.tsx new file mode 100644 index 00000000..0068886e --- /dev/null +++ b/src/app_modules/vote/component/skeleton_view.tsx @@ -0,0 +1,97 @@ +import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; +import { Grid, Group, Skeleton, Stack } from "@mantine/core"; + +export function Voting_ComponentSkeletonViewPublish() { + return ( + <> + {Array.from({ length: 2 }).map((e, i) => ( + + + + + + + + + + + + + + + {/* */} + + + + {Array.from({ length: 2 }).map((e, i) => ( + + + + + + + ))} + + + + ))} + + ); +} + +export function Voting_ComponentSkeletonViewStatus() { + return ( + <> + {Array.from({ length: 2 }).map((e, i) => ( + + + + + + + ))} + + ); +} + +export function Voting_ComponentSkeletonViewKontribusi() { + return ( + <> + {Array.from({ length: 2 }).map((e, i) => ( + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ))} + + ); + +} \ No newline at end of file diff --git a/src/app_modules/vote/index.tsx b/src/app_modules/vote/index.tsx index 26e9cef9..0a8b2abf 100644 --- a/src/app_modules/vote/index.tsx +++ b/src/app_modules/vote/index.tsx @@ -53,3 +53,4 @@ export { Vote_DetailRiwayatSaya, LayoutVote_DetailRiwayatSaya, }; + diff --git a/src/app_modules/vote/main/beranda.tsx b/src/app_modules/vote/main/beranda.tsx index f33149fe..a0d8e193 100644 --- a/src/app_modules/vote/main/beranda.tsx +++ b/src/app_modules/vote/main/beranda.tsx @@ -1,8 +1,11 @@ "use client"; +import { gs_votingTiggerBeranda } from "@/app/lib/global_state"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; +import { AccentColor } from "@/app_modules/_global/color"; import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; import { Affix, Box, @@ -14,22 +17,17 @@ import { TextInput, } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; +import { useAtom } from "jotai"; import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; +import { apiGetAllVoting } from "../_lib/api_voting"; +import { Voting_ComponentSkeletonViewPublish } from "../component"; import ComponentVote_CardViewPublish from "../component/card_view_publish"; -import { vote_getAllListPublish } from "../fun/get/get_all_list_publish"; import { MODEL_VOTING } from "../model/interface"; -import { gs_votingTiggerBeranda } from "@/app/lib/global_state"; -import { useAtom } from "jotai"; -import { AccentColor } from "@/app_modules/_global/color"; -export default function Vote_Beranda({ - dataVote, -}: { - dataVote: MODEL_VOTING[]; -}) { - const [data, setData] = useState(dataVote); +export default function Vote_Beranda() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); // Realtime @@ -46,32 +44,50 @@ export default function Vote_Beranda({ }, [isTriggerVotingBeranda, setIsShowUpdate]); useShallowEffect(() => { - onLoad({ - newData(val) { - setData(val); - }, - }); - setIsTriggerVotingBeranda(false); - }, [setData, setIsTriggerVotingBeranda]); + onLoad(); + }, []); - async function onLoad({ newData }: { newData: (val: any) => void }) { - const loadData = await vote_getAllListPublish({ page: 1 }); - newData(loadData); + async function onLoad() { + try { + const loadData = await apiGetAllVoting({ + kategori: "beranda", + page: "1", + }); + setData(loadData.data as any); + setIsTriggerVotingBeranda(false); + } catch (error) { + clientLogger.error("Error get data beranda", error); + } } async function onSearch(s: string) { - const loadSearch = await vote_getAllListPublish({ page: 1, search: s }); - setData(loadSearch as any); + try { + const loadData = await apiGetAllVoting({ + kategori: "beranda", + page: "1", + search: s, + }); + setData(loadData.data as any); + } catch (error) { + clientLogger.error("Error get data beranda", error); + } } - async function onLoadData({ onPublish }: { onPublish: (val: any) => void }) { - setIsLoading(true); - const loadData = await vote_getAllListPublish({ page: 1 }); - onPublish(loadData); - - setIsShowUpdate(false); - setIsTriggerVotingBeranda(false); - setIsLoading(false); + async function onLoadData() { + try { + setIsLoading(true); + const loadData = await apiGetAllVoting({ + kategori: "beranda", + page: "1", + }); + setData(loadData.data as any); + setIsShowUpdate(false); + setIsTriggerVotingBeranda(false); + } catch (error) { + clientLogger.error("Error get data beranda", error); + } finally { + setIsLoading(false); + } } return ( @@ -90,11 +106,7 @@ export default function Vote_Beranda({ radius={"xl"} opacity={0.8} onClick={() => { - onLoadData({ - onPublish(val) { - setData(val); - }, - }); + onLoadData(); }} > Update beranda @@ -111,7 +123,9 @@ export default function Vote_Beranda({ - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( @@ -123,15 +137,16 @@ export default function Vote_Beranda({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await vote_getAllListPublish({ - page: activePage + 1, + const loadData = await apiGetAllVoting({ + kategori: "beranda", + page: `${activePage + 1}`, }); setActivePage((val) => val + 1); - return loadData; + return loadData.data; }} > {(item) => ( diff --git a/src/app_modules/vote/main/kontribusi.tsx b/src/app_modules/vote/main/kontribusi.tsx index dadbae4d..3b351b22 100644 --- a/src/app_modules/vote/main/kontribusi.tsx +++ b/src/app_modules/vote/main/kontribusi.tsx @@ -1,64 +1,80 @@ "use client"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; -import { Box, Center, Loader, Stack } from "@mantine/core"; -import _ from "lodash"; -import ComponentVote_CardViewPublish from "../component/card_view_publish"; -import ComponentVote_IsEmptyData from "../component/is_empty_data"; -import { MODEL_VOTE_KONTRIBUTOR } from "../model/interface"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; -import { data } from "autoprefixer"; +import { clientLogger } from "@/util/clientLogger"; +import { Box, Center, Loader, Stack } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; -import { vote_getAllListPublish } from "../fun/get/get_all_list_publish"; import { useState } from "react"; -import { vote_getAllListKontribusiByAuthorId } from "../fun/get/get_list_kontribusi_by_author_id"; +import { apiGetAllVoting } from "../_lib/api_voting"; +import ComponentVote_CardViewPublish from "../component/card_view_publish"; +import { MODEL_VOTE_KONTRIBUTOR } from "../model/interface"; +import { Voting_ComponentSkeletonViewKontribusi } from "../component/skeleton_view"; -export default function Vote_Kontribusi({ - dataKontribusi, -}: { - dataKontribusi: MODEL_VOTE_KONTRIBUTOR[]; -}) { - const [data, setData] = useState(dataKontribusi); +export default function Vote_Kontribusi() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const loadData = await apiGetAllVoting({ + kategori: "kontribusi", + page: "1", + }); + setData(loadData.data as any); + } catch (error) { + clientLogger.error("Error get data beranda", error); + } + } + return ( <> - {_.isEmpty(dataKontribusi) ? ( - - ) : ( - - ( -
- -
- )} - data={data} - setData={setData} - moreData={async () => { - const loadData = await vote_getAllListKontribusiByAuthorId({ - page: activePage + 1, - }); + + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( + + ) : ( + + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={async () => { + const loadData = await apiGetAllVoting({ + kategori: "kontribusi", + page: `${activePage + 1}`, + }); - setActivePage((val) => val + 1); + setActivePage((val) => val + 1); - return loadData; - }} - > - {(item) => ( - - )} -
-
- )} - {/*
{JSON.stringify(dataKontribusi, null, 2)}
*/} + return loadData.data; + }} + > + {(item) => ( + + )} +
+
+ )} +
); } diff --git a/src/app_modules/vote/main/riwayat/index.tsx b/src/app_modules/vote/main/riwayat/index.tsx index 89f4506f..8231546b 100644 --- a/src/app_modules/vote/main/riwayat/index.tsx +++ b/src/app_modules/vote/main/riwayat/index.tsx @@ -1,30 +1,18 @@ "use client"; -import { Stack, Tabs } from "@mantine/core"; -import { useState } from "react"; -import Vote_SemuaRiwayat from "./semua"; -import Vote_RiwayatSaya from "./saya"; -import { useAtom } from "jotai"; -import { gs_vote_riwayat } from "../../global_state"; -import { MODEL_VOTING } from "../../model/interface"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; -import { useRouter } from "next/navigation"; -import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; +import { Stack, Tabs } from "@mantine/core"; +import { useParams, useRouter } from "next/navigation"; +import Vote_RiwayatSaya from "./saya"; +import Vote_SemuaRiwayat from "./semua"; -export default function Vote_Riwayat({ - riwayatId, - listRiwayat, - listRiwayatSaya, -}: { - riwayatId: string; - listRiwayat?: MODEL_VOTING[]; - listRiwayatSaya?: MODEL_VOTING[]; -}) { +export default function Vote_Riwayat() { const router = useRouter(); - const [changeStatus, setChangeStatus] = useState(riwayatId); + const params = useParams<{ id: string }>(); const listTabs = [ { @@ -39,20 +27,15 @@ export default function Vote_Riwayat({ }, ]; - async function onChangeStatus({ statusId }: { statusId: string }) { - router.push(RouterVote.riwayat({ id: statusId })); - } - return ( <> { - setChangeStatus(val); - onChangeStatus({ statusId: val }); + router.replace(RouterVote.riwayat({ id: val })); }} styles={{ tabsList: { @@ -77,9 +60,9 @@ export default function Vote_Riwayat({ style={{ transition: "0.5s", backgroundColor: - changeStatus === e.id ? MainColor.yellow : "white", + params.id === e.id ? MainColor.yellow : "white", border: - changeStatus === e.id + params.id === e.id ? `1px solid ${AccentColor.yellow}` : `1px solid white`, }} @@ -89,13 +72,8 @@ export default function Vote_Riwayat({ ))} - {riwayatId === "1" && ( - - )} - - {riwayatId === "2" && ( - - )} + {params.id === "1" && } + {params.id === "2" && }
diff --git a/src/app_modules/vote/main/riwayat/saya.tsx b/src/app_modules/vote/main/riwayat/saya.tsx index f9822ff9..8ddefb5c 100644 --- a/src/app_modules/vote/main/riwayat/saya.tsx +++ b/src/app_modules/vote/main/riwayat/saya.tsx @@ -1,28 +1,47 @@ "use client"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; -import { Box, Center, Loader, Stack } from "@mantine/core"; -import _ from "lodash"; -import { useRouter } from "next/navigation"; -import ComponentVote_CardViewPublish from "../../component/card_view_publish"; -import ComponentVote_IsEmptyData from "../../component/is_empty_data"; -import { MODEL_VOTING } from "../../model/interface"; -import { useState } from "react"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; +import { Box, Center, Loader } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; -import { Vote_getAllListRiwayatSaya } from "../../fun/get/get_all_list_riwayat_saya"; +import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; +import { Voting_ComponentSkeletonViewPublish } from "../../component"; +import ComponentVote_CardViewPublish from "../../component/card_view_publish"; +import { MODEL_VOTING } from "../../model/interface"; -export default function Vote_RiwayatSaya({ - listRiwayatSaya, -}: { - listRiwayatSaya: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listRiwayatSaya); +export default function Vote_RiwayatSaya() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "riwayat", + page: "1", + status: "2", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( // --- Main component --- // @@ -35,14 +54,17 @@ export default function Vote_RiwayatSaya({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await Vote_getAllListRiwayatSaya({ - page: activePage + 1, + const respone = await apiGetAllVoting({ + kategori: "riwayat", + page: `${activePage + 1}`, + status: "2", }); + setActivePage((val) => val + 1); - return loadData; + return respone.data; }} > {(item) => ( diff --git a/src/app_modules/vote/main/riwayat/semua.tsx b/src/app_modules/vote/main/riwayat/semua.tsx index d28574d8..406e3ff5 100644 --- a/src/app_modules/vote/main/riwayat/semua.tsx +++ b/src/app_modules/vote/main/riwayat/semua.tsx @@ -2,25 +2,46 @@ import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; import { Box, Center, Loader } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; +import { Voting_ComponentSkeletonViewPublish } from "../../component"; import ComponentVote_CardViewPublish from "../../component/card_view_publish"; -import { vote_getAllListRiwayat } from "../../fun/get/get_all_list_riwayat"; import { MODEL_VOTING } from "../../model/interface"; -export default function Vote_SemuaRiwayat({ - listRiwayat, -}: { - listRiwayat: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listRiwayat); +export default function Vote_SemuaRiwayat() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "riwayat", + page: "1", + status: "1", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( // --- Main component --- // @@ -33,14 +54,17 @@ export default function Vote_SemuaRiwayat({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await vote_getAllListRiwayat({ - page: activePage + 1, + const respone = await apiGetAllVoting({ + kategori: "riwayat", + page: `${activePage + 1}`, + status: "1", }); + setActivePage((val) => val + 1); - return loadData; + return respone.data; }} > {(item) => ( diff --git a/src/app_modules/vote/main/status/draft.tsx b/src/app_modules/vote/main/status/draft.tsx index ef53fe86..7d0ab754 100644 --- a/src/app_modules/vote/main/status/draft.tsx +++ b/src/app_modules/vote/main/status/draft.tsx @@ -1,28 +1,47 @@ "use client"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; -import { Box, Center, Loader, Stack } from "@mantine/core"; -import _ from "lodash"; -import ComponentVote_CardViewStatus from "../../component/card_view_status"; -import ComponentVote_IsEmptyData from "../../component/is_empty_data"; -import { MODEL_VOTING } from "../../model/interface"; -import { useState } from "react"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; +import { Box, Center, Loader } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; -import { vote_getAllReview } from "../../fun/get/status/get_all_review"; -import { vote_getAllDraft } from "../../fun/get/status/get_all_draft"; +import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; +import { Voting_ComponentSkeletonViewStatus } from "../../component"; +import ComponentVote_CardViewStatus from "../../component/card_view_status"; +import { MODEL_VOTING } from "../../model/interface"; -export default function Vote_StatusDraft({ - listDraft, -}: { - listDraft: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listDraft); +export default function Vote_StatusDraft() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "status", + page: "1", + status: "3", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( // --- Main component --- // @@ -35,20 +54,22 @@ export default function Vote_StatusDraft({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await vote_getAllDraft({ - page: activePage + 1, + const respone = await apiGetAllVoting({ + kategori: "status", + page: `${activePage + 1}`, + status: "3", }); setActivePage((val) => val + 1); - return loadData; + return respone.data; }} > {(item) => ( )} diff --git a/src/app_modules/vote/main/status/index.tsx b/src/app_modules/vote/main/status/index.tsx index 3f55e91c..11a59a44 100644 --- a/src/app_modules/vote/main/status/index.tsx +++ b/src/app_modules/vote/main/status/index.tsx @@ -5,32 +5,34 @@ import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; -import { MODEL_NEW_DEFAULT_MASTER } from "@/app_modules/model_global/interface"; import { Box, Stack, Tabs } from "@mantine/core"; -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { MODEL_VOTING } from "../../model/interface"; +import { useParams, useRouter } from "next/navigation"; import Vote_StatusDraft from "./draft"; import Vote_StatusPublish from "./publish"; import Vote_StatusReject from "./reject"; import Vote_StatusReview from "./review"; -export default function Vote_Status({ - statusId, - dataVoting, - listStatus, -}: { - statusId: string; - dataVoting: MODEL_VOTING[]; - listStatus: MODEL_NEW_DEFAULT_MASTER[]; -}) { - +export default function Vote_Status() { const router = useRouter(); - const [changeStatus, setChangeStatus] = useState(statusId); - - async function onChangeStatus({ statusId }: { statusId: string }) { - router.replace(RouterVote.status({ id: statusId })); - } + const params = useParams<{ id: string }>(); + const status = [ + { + id: "1", + name: "Publish", + }, + { + id: "2", + name: "Review", + }, + { + id: "3", + name: "Draft", + }, + { + id: "4", + name: "Reject", + }, + ]; return ( <> @@ -38,10 +40,9 @@ export default function Vote_Status({ mt={1} variant="pills" radius={"xl"} - value={changeStatus} + value={params.id} onTabChange={(val: any) => { - setChangeStatus(val); - onChangeStatus({ statusId: val }); + router.replace(RouterVote.status({ id: val })); }} styles={{ tabsList: { @@ -57,7 +58,7 @@ export default function Vote_Status({ > - {listStatus.map((e) => ( + {status.map((e) => ( - {statusId === "1" && ( - - )} - {statusId === "2" && } - {statusId === "3" && } - {statusId === "4" && } + {params.id === "1" && } + {params.id === "2" && } + {params.id === "3" && } + {params.id === "4" && } diff --git a/src/app_modules/vote/main/status/publish.tsx b/src/app_modules/vote/main/status/publish.tsx index f8855e69..50dfd047 100644 --- a/src/app_modules/vote/main/status/publish.tsx +++ b/src/app_modules/vote/main/status/publish.tsx @@ -2,56 +2,82 @@ import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; -import job_getAllStatusPublish from "@/app_modules/job/fun/get/status/get_list_publish"; -import { Center, Loader } from "@mantine/core"; +import { clientLogger } from "@/util/clientLogger"; +import { Box, Center, Loader, Stack } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; import ComponentVote_CardViewPublish from "../../component/card_view_publish"; import { MODEL_VOTING } from "../../model/interface"; +import { Voting_ComponentSkeletonViewPublish } from "../../component"; -export default function Vote_StatusPublish({ - listPublish, -}: { - listPublish: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listPublish); +export default function Vote_StatusPublish() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "status", + page: "1", + status: "1", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( - - ) : ( - // --- Main component --- // - ( -
- -
- )} - data={data} - setData={setData} - moreData={async () => { - const loadData = await job_getAllStatusPublish({ - page: activePage + 1, - }); + + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( + + ) : ( + // --- Main component --- // + + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={async () => { + const respone = await apiGetAllVoting({ + kategori: "status", + page: `${activePage + 1}`, + status: "1", + }); + setActivePage((val) => val + 1); - setActivePage((val) => val + 1); - - return loadData; - }} - > - {(item) => ( - - )} -
- )} + return respone.data; + }} + > + {(item) => ( + + )} +
+ + )} + ); } diff --git a/src/app_modules/vote/main/status/reject.tsx b/src/app_modules/vote/main/status/reject.tsx index 9d5716dd..c66f902c 100644 --- a/src/app_modules/vote/main/status/reject.tsx +++ b/src/app_modules/vote/main/status/reject.tsx @@ -2,25 +2,46 @@ import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; import { Box, Center, Loader } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; +import { Voting_ComponentSkeletonViewStatus } from "../../component"; import ComponentVote_CardViewStatus from "../../component/card_view_status"; -import { vote_getAllReject } from "../../fun/get/status/get_all_reject"; import { MODEL_VOTING } from "../../model/interface"; -export default function Vote_StatusReject({ - listReject, -}: { - listReject: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listReject); +export default function Vote_StatusReject() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "status", + page: "1", + status: "4", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( // --- Main component --- // @@ -33,20 +54,22 @@ export default function Vote_StatusReject({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await vote_getAllReject({ - page: activePage + 1, + const respone = await apiGetAllVoting({ + kategori: "status", + page: `${activePage + 1}`, + status: "4", }); setActivePage((val) => val + 1); - return loadData; + return respone.data; }} > {(item) => ( )} diff --git a/src/app_modules/vote/main/status/review.tsx b/src/app_modules/vote/main/status/review.tsx index 3fc866c5..8cb512d3 100644 --- a/src/app_modules/vote/main/status/review.tsx +++ b/src/app_modules/vote/main/status/review.tsx @@ -2,29 +2,50 @@ import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data"; +import { clientLogger } from "@/util/clientLogger"; import { Box, Center, Loader } from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; +import { apiGetAllVoting } from "../../_lib/api_voting"; import ComponentVote_CardViewStatus from "../../component/card_view_status"; -import { vote_getAllReview } from "../../fun/get/status/get_all_review"; import { MODEL_VOTING } from "../../model/interface"; +import { Voting_ComponentSkeletonViewStatus } from "../../component"; -export default function Vote_StatusReview({ - listReview, -}: { - listReview: MODEL_VOTING[]; -}) { - const [data, setData] = useState(listReview); +export default function Vote_StatusReview() { + const [data, setData] = useState(null); const [activePage, setActivePage] = useState(1); + useShallowEffect(() => { + onLoad(); + }, []); + + async function onLoad() { + try { + const respone = await apiGetAllVoting({ + kategori: "status", + page: "1", + status: "2", + }); + + if (respone) { + setData(respone.data); + } + } catch (error) { + clientLogger.error("Error get data review", error); + } + } + return ( <> - {_.isEmpty(data) ? ( + {_.isNull(data) ? ( + + ) : _.isEmpty(data) ? ( ) : ( // --- Main component --- // - + ( @@ -33,14 +54,16 @@ export default function Vote_StatusReview({ )} data={data} - setData={setData} + setData={setData as any} moreData={async () => { - const loadData = await vote_getAllReview({ - page: activePage + 1, + const respone = await apiGetAllVoting({ + kategori: "status", + page: `${activePage + 1}`, + status: "2", }); setActivePage((val) => val + 1); - return loadData; + return respone.data; }} > {(item) => ( diff --git a/src/middleware.ts b/src/middleware.ts index 438450a2..ff423bab 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -19,6 +19,7 @@ const middlewareConfig: MiddlewareConfig = { userPath: "/dev/home", publicRoutes: [ "/", + "/api/voting/*", "/api/collaboration/*", "/api/notifikasi/*", "/api/logs/*", From 45a7a887c36233a4dddf9a2cc081b24f301cb47c Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Fri, 27 Dec 2024 11:05:10 +0800 Subject: [PATCH 3/3] chore(release): 1.2.35 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5a8efa..1f4bf92e 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.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) ## [1.2.33](https://github.com/bipproduction/hipmi/compare/v1.2.32...v1.2.33) (2024-12-22) diff --git a/package.json b/package.json index 04d7ebc3..01b6a487 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.2.34", + "version": "1.2.35", "private": true, "prisma": { "seed": "npx tsx prisma/seed.ts --yes"