diff --git a/package.json b/package.json index 5b8bc141..62dea927 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hipmi", - "version": "1.1.0", + "version": "1.1.1", "private": true, "prisma": { "seed": "npx tsx prisma/seed.ts" diff --git a/src/app/dev/event/detail/draft/[id]/page.tsx b/src/app/dev/event/detail/draft/[id]/page.tsx index d39a61ce..77fb8fc0 100644 --- a/src/app/dev/event/detail/draft/[id]/page.tsx +++ b/src/app/dev/event/detail/draft/[id]/page.tsx @@ -1,8 +1,10 @@ -import { Event_DetailDraft } from "@/app_modules/event" -import { event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id" +import { Event_DetailDraft } from "@/app_modules/event"; +import { event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id"; export default async function Page({ params }: { params: { id: string } }) { - let eventId = params.id - const dataEvent = await event_getOneById(eventId) - return + let eventId = params.id; + const dataEvent = await event_getOneById(eventId); + return ( + + ); } diff --git a/src/app/dev/event/edit/[id]/page.tsx b/src/app/dev/event/edit/[id]/page.tsx index 2305c522..e1991957 100644 --- a/src/app/dev/event/edit/[id]/page.tsx +++ b/src/app/dev/event/edit/[id]/page.tsx @@ -1,7 +1,6 @@ import { Event_Edit } from "@/app_modules/event"; import { event_getOneById } from "@/app_modules/event/fun/get/get_one_by_id"; import { Event_getMasterTipeAcara } from "@/app_modules/event/fun/master/get_tipe_acara"; -import { MODEL_EVENT } from "@/app_modules/event/model/interface"; import _ from "lodash"; export default async function Page({ params }: { params: { id: string } }) { @@ -15,7 +14,6 @@ export default async function Page({ params }: { params: { id: string } }) { "updatedAt", "active", ]); - // console.log(dataEvent) const listTipeAcara = await Event_getMasterTipeAcara() diff --git a/src/app/dev/event/main/status/[id]/page.tsx b/src/app/dev/event/main/status/[id]/page.tsx index 01ab75d3..b2c2c353 100644 --- a/src/app/dev/event/main/status/[id]/page.tsx +++ b/src/app/dev/event/main/status/[id]/page.tsx @@ -1,10 +1,8 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; import { Event_StatusPage } from "@/app_modules/event"; import { - event_getAllByStatusId, - event_getMasterStatus, + event_getAllByStatusId, + event_getMasterStatus, } from "@/app_modules/event/fun"; -import React from "react"; async function Page({ params }: { params: { id: string } }) { let statusId = params.id; diff --git a/src/app/dev/event/main/status_page/page.tsx b/src/app/dev/event/main/status_page/page.tsx deleted file mode 100644 index d99da96d..00000000 --- a/src/app/dev/event/main/status_page/page.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; -import { Event_StatusPage } from "@/app_modules/event"; -import { event_getAllDraft } from "@/app_modules/event/fun/get/status/get_all_draft"; -import { event_getAllReject } from "@/app_modules/event/fun/get/status/get_all_reject"; -import { event_getAllReview } from "@/app_modules/event/fun/get/status/get_all_review"; -import { event_funGetAllStatusPublish } from "@/app_modules/event/fun/get/status/get_all_status_publish"; - -export default async function Page() { - const userLoginId = await funGetUserIdByToken(); - - const listPublish = await event_funGetAllStatusPublish({ page: 1 }); - const listReview = await event_getAllReview({ page: 1 }); - const listDraft = await event_getAllDraft({ page: 1 }); - const listReject = await event_getAllReject({ page: 1 }); - - return ( - <>maintenace - // - ); -} diff --git a/src/app/dev/vote/main/riwayat/[id]/page.tsx b/src/app/dev/vote/main/riwayat/[id]/page.tsx new file mode 100644 index 00000000..10988a8f --- /dev/null +++ b/src/app/dev/vote/main/riwayat/[id]/page.tsx @@ -0,0 +1,41 @@ +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 ( + // <> + // + // + // ); +} diff --git a/src/app/dev/vote/main/riwayat/page.tsx b/src/app/dev/vote/main/riwayat/page.tsx deleted file mode 100644 index 067bdb85..00000000 --- a/src/app/dev/vote/main/riwayat/page.tsx +++ /dev/null @@ -1,17 +0,0 @@ -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() { - const listRiwayat = await vote_getAllListRiwayat({ page: 1 }); - const listRiwayatSaya = await vote_getAllListRiwayatSaya({ page: 1 }); - - return ( - <> - - - ); -} diff --git a/src/app/dev/vote/main/status/[id]/page.tsx b/src/app/dev/vote/main/status/[id]/page.tsx new file mode 100644 index 00000000..9e3fa9a2 --- /dev/null +++ b/src/app/dev/vote/main/status/[id]/page.tsx @@ -0,0 +1,25 @@ +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, + }); + + return ( + <> + + + ); +} diff --git a/src/app/dev/vote/main/status/page.tsx b/src/app/dev/vote/main/status/page.tsx deleted file mode 100644 index 9946bbbe..00000000 --- a/src/app/dev/vote/main/status/page.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import { Vote_Status } from "@/app_modules/vote"; -import { vote_getAllDraft } from "@/app_modules/vote/fun/get/status/get_all_draft"; -import { vote_getAllPublish } from "@/app_modules/vote/fun/get/status/get_all_publish"; -import { vote_getAllReject } from "@/app_modules/vote/fun/get/status/get_all_reject"; -import { vote_getAllReview } from "@/app_modules/vote/fun/get/status/get_all_review"; - -export default async function Page() { - const listPublish = await vote_getAllPublish({page: 1}); - const listReview = await vote_getAllReview({page: 1}); - const listDraft = await vote_getAllDraft({page: 1}); - const listReject = await vote_getAllReject({page: 1}); - - return ( - <> - - - ); -} diff --git a/src/app/lib/router_hipmi/router_vote.ts b/src/app/lib/router_hipmi/router_vote.ts index 2bcf428e..0f16880e 100644 --- a/src/app/lib/router_hipmi/router_vote.ts +++ b/src/app/lib/router_hipmi/router_vote.ts @@ -2,9 +2,15 @@ export const RouterVote = { // main splash: "/dev/vote/splash", beranda: "/dev/vote/main/beranda", - status: "/dev/vote/main/status", + status: ({ id }: { id?: string }) => `/dev/vote/main/status/${id}`, kontribusi: "/dev/vote/main/kontribusi", - riwayat: "/dev/vote/main/riwayat", + + /** + * + * @param riwayatId | 1 & 2 | 1: Semua, 2: Saya + * @type string + */ + riwayat: ({ id }: { id?: string }) => `/dev/vote/main/riwayat/${id}`, // create create: "/dev/vote/create", diff --git a/src/app_modules/admin/vote/child/table_review/index.tsx b/src/app_modules/admin/vote/child/table_review/index.tsx index 33e54f3f..f95ee845 100644 --- a/src/app_modules/admin/vote/child/table_review/index.tsx +++ b/src/app_modules/admin/vote/child/table_review/index.tsx @@ -336,6 +336,7 @@ async function onReject( const res = await AdminEvent_funEditCatatanById(data as any); if (res.status === 200) { + setSaveLoading(true); const dataNotif = { appId: res.data?.id, status: res.data?.Voting_Status?.name as any, @@ -358,7 +359,7 @@ async function onReject( await AdminVote_getListTableByStatusId("2").then((val) => { setData(val); - setSaveLoading(true); + setSaveLoading(false); ComponentGlobal_NotifikasiBerhasil(res.message); close(); }); diff --git a/src/app_modules/event/component/index.ts b/src/app_modules/event/component/index.ts new file mode 100644 index 00000000..ec2f933f --- /dev/null +++ b/src/app_modules/event/component/index.ts @@ -0,0 +1,3 @@ +import { Event_ComponentSkeletonDetailData } from "./skeleton/comp_skeleton_detail_data"; + +export { Event_ComponentSkeletonDetailData }; diff --git a/src/app_modules/event/component/skeleton/comp_skeleton_detail_data.tsx b/src/app_modules/event/component/skeleton/comp_skeleton_detail_data.tsx new file mode 100644 index 00000000..7d8cc8aa --- /dev/null +++ b/src/app_modules/event/component/skeleton/comp_skeleton_detail_data.tsx @@ -0,0 +1,35 @@ +"use client"; + +import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; +import { Stack, Title, Grid, Text, Center, Skeleton } from "@mantine/core"; +import { data } from "autoprefixer"; + +export function Event_ComponentSkeletonDetailData() { + return ( + <> + + +
+ +
+ {Array.from(new Array(4)).map((e, i) => ( + + + + + : + + + + + ))} + + + + + +
+
+ + ); +} diff --git a/src/app_modules/event/detail/draft/index.tsx b/src/app_modules/event/detail/draft/index.tsx index 4d0b7661..3aaeeea3 100644 --- a/src/app_modules/event/detail/draft/index.tsx +++ b/src/app_modules/event/detail/draft/index.tsx @@ -12,6 +12,7 @@ import { Button, Group, Stack } from "@mantine/core"; import moment from "moment"; import { useRouter } from "next/navigation"; import { useState } from "react"; +import { Event_ComponentSkeletonDetailData } from "../../component"; import ComponentEvent_DetailData from "../../component/detail/detail_data"; import { Event_funDeleteById } from "../../fun/delete/fun_delete"; import { Event_funEditStatusById } from "../../fun/edit/fun_edit_status_by_id"; @@ -19,19 +20,29 @@ import { MODEL_EVENT } from "../../model/interface"; export default function Event_DetailDraft({ dataEvent, + eventId, }: { dataEvent: MODEL_EVENT; + eventId: string; }) { - const [data, setData] = useState(dataEvent); + const [data, setData] = useState(dataEvent); + + console.log(data, "ini data dipage"); + + if (!data) { + return ( + <> + + + ); + } + return ( <> {/*
{JSON.stringify(dataEvent.tanggal)}
*/} - {dataEvent?.catatan ? ( - + {data?.catatan ? ( + ) : ( "" )} diff --git a/src/app_modules/event/edit/index.tsx b/src/app_modules/event/edit/index.tsx index b9d424e9..1d2a6cc6 100644 --- a/src/app_modules/event/edit/index.tsx +++ b/src/app_modules/event/edit/index.tsx @@ -200,6 +200,7 @@ export default function Event_Edit({ onClick={() => onUpdate(router, value, setLoading)} bg={MainColor.yellow} color="yellow" + c={"black"} > Update @@ -216,13 +217,14 @@ async function onUpdate( if (_.values(value).includes("")) return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data"); - await Event_funEditById(value).then((res) => { - if (res.status === 200) { - ComponentGlobal_NotifikasiBerhasil(res.message); - setLoading(true); - router.back(); - } else { - ComponentGlobal_NotifikasiGagal(res.message); - } - }); + const res = await Event_funEditById(value); + setLoading(true); + + if (res.status === 200) { + ComponentGlobal_NotifikasiBerhasil(res.message); + router.back(); + setLoading(false); + } else { + ComponentGlobal_NotifikasiGagal(res.message); + } } diff --git a/src/app_modules/event/fun/edit/fun_edit_by_id.ts b/src/app_modules/event/fun/edit/fun_edit_by_id.ts index d9c675d1..da4acc74 100644 --- a/src/app_modules/event/fun/edit/fun_edit_by_id.ts +++ b/src/app_modules/event/fun/edit/fun_edit_by_id.ts @@ -20,7 +20,7 @@ export async function Event_funEditById(data: MODEL_EVENT) { }); if (!updt) return { status: 400, message: "Update Gagal" }; - revalidatePath(RouterEvent.detail_draft + data.id); + revalidatePath(`/dev/event/detail/draft/`, "page"); return { status: 200, message: "Berhasil Update", diff --git a/src/app_modules/event/fun/get/get_one_by_id.ts b/src/app_modules/event/fun/get/get_one_by_id.ts index 3189bcc3..0c87abe6 100644 --- a/src/app_modules/event/fun/get/get_one_by_id.ts +++ b/src/app_modules/event/fun/get/get_one_by_id.ts @@ -1,6 +1,7 @@ "use server"; import prisma from "@/app/lib/prisma"; +import { revalidatePath } from "next/cache"; export async function event_getOneById(eventId: string) { const data = await prisma.event.findFirst({ @@ -31,5 +32,7 @@ export async function event_getOneById(eventId: string) { }, }); + revalidatePath("/dev/event/detail/draft/"); + return data; } diff --git a/src/app_modules/event/fun/get/status/get_all_by_status_id.tsx b/src/app_modules/event/fun/get/status/get_all_by_status_id.tsx index c9cb90dc..96428e5c 100644 --- a/src/app_modules/event/fun/get/status/get_all_by_status_id.tsx +++ b/src/app_modules/event/fun/get/status/get_all_by_status_id.tsx @@ -15,24 +15,50 @@ export async function event_getAllByStatusId({ const takeData = 10; const skipData = page * takeData - takeData; - const data = await prisma.event.findMany({ - take: takeData, - skip: skipData, - orderBy: { - updatedAt: "desc", - }, - where: { - active: true, - eventMaster_StatusId: statusId, - authorId: userLoginId, - }, - select: { - id: true, - title: true, - deskripsi: true, - tanggal: true, - }, - }); - - return data; + if (statusId == "1") { + const data = await prisma.event.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + active: true, + eventMaster_StatusId: "1", + authorId: userLoginId, + tanggal: { + gte: new Date(), + }, + }, + select: { + id: true, + title: true, + deskripsi: true, + tanggal: true, + }, + }); + + return data; + } else { + const data = await prisma.event.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + active: true, + eventMaster_StatusId: statusId, + authorId: userLoginId, + }, + select: { + id: true, + title: true, + deskripsi: true, + tanggal: true, + }, + }); + + return data; + } } diff --git a/src/app_modules/event/main/riwayat/index.tsx b/src/app_modules/event/main/riwayat/index.tsx index 69d4da09..4d00dcaf 100644 --- a/src/app_modules/event/main/riwayat/index.tsx +++ b/src/app_modules/event/main/riwayat/index.tsx @@ -22,7 +22,6 @@ export default function Event_Riwayat({ dataRiwayatSaya?: MODEL_EVENT[]; }) { const router = useRouter(); - // const [tabsRiwayat, setTabsRiwayat] = useAtom(gs_event_riwayat) const [changeStatus, setChangeStatus] = useState(statusId); const listTabs = [ diff --git a/src/app_modules/event/main/status_page/index.tsx b/src/app_modules/event/main/status_page/index.tsx index 903f14ed..d47484da 100644 --- a/src/app_modules/event/main/status_page/index.tsx +++ b/src/app_modules/event/main/status_page/index.tsx @@ -27,7 +27,7 @@ export default function Event_StatusPage({ const [changeStatus, setChangeStatus] = useState(statusId); async function onChangeStatus({ statusId }: { statusId: string }) { - router.push(RouterEvent.status({ id: statusId })); + router.replace(RouterEvent.status({ id: statusId })); } return ( @@ -36,7 +36,6 @@ export default function Event_StatusPage({ variant="pills" radius="xl" mt={1} - // defaultValue={"1"} value={changeStatus} onTabChange={(val: any) => { setChangeStatus(val); diff --git a/src/app_modules/notifikasi/component/path/voting.ts b/src/app_modules/notifikasi/component/path/voting.ts index b283034e..86b20f91 100644 --- a/src/app_modules/notifikasi/component/path/voting.ts +++ b/src/app_modules/notifikasi/component/path/voting.ts @@ -11,7 +11,7 @@ export function redirectVotingPage({ router: AppRouterInstance; onSetPage: (val: any) => void; }) { - const path = RouterVote.status; + const path = RouterVote.status({ id: "" }); if (data.status === "Publish") { onSetPage({ diff --git a/src/app_modules/vote/component/card_view_status.tsx b/src/app_modules/vote/component/card_view_status.tsx index 311417a1..5b589108 100644 --- a/src/app_modules/vote/component/card_view_status.tsx +++ b/src/app_modules/vote/component/card_view_status.tsx @@ -5,6 +5,8 @@ import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/noti import { Badge, Card, Group, Stack, Text } from "@mantine/core"; import { useRouter } from "next/navigation"; import { MODEL_VOTING } from "../model/interface"; +import { useState } from "react"; +import { ComponentGlobal_CardLoadingOverlay, ComponentGlobal_CardStyles } from "@/app_modules/_global/component"; export default function ComponentVote_CardViewStatus({ path, @@ -14,59 +16,53 @@ export default function ComponentVote_CardViewStatus({ data?: MODEL_VOTING; }) { const router = useRouter(); + const [visible, setVisible] = useState(false); + return ( <> - { + { if (data?.id === undefined) { ComponentGlobal_NotifikasiPeringatan("Path tidak ditemukan"); } else { + setVisible(true); router.push((path as string) + data?.id); } }} > {/* Isi deskripsi */} - - - - {data?.title} - - - - - {data?.awalVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} - - - - - {data?.akhirVote.toLocaleDateString(["id-ID"], { - dateStyle: "medium", - })} - - - - - - + + + {data?.title} + + + + + {data?.awalVote.toLocaleDateString(["id-ID"], { + dateStyle: "medium", + })} + + - + + {data?.akhirVote.toLocaleDateString(["id-ID"], { + dateStyle: "medium", + })} + + + + + {visible && } + ); } diff --git a/src/app_modules/vote/create/index.tsx b/src/app_modules/vote/create/index.tsx index 78f9fe6d..67983143 100644 --- a/src/app_modules/vote/create/index.tsx +++ b/src/app_modules/vote/create/index.tsx @@ -1,10 +1,13 @@ "use client"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; +import { MainColor } from "@/app_modules/_global/color/color_pallet"; import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; +import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; +import mqtt_client from "@/util/mqtt_client"; import { Box, Button, @@ -24,17 +27,13 @@ import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.share import { useRouter } from "next/navigation"; import { useState } from "react"; import { Vote_funCreate } from "../fun/create/create_vote"; -import { gs_vote_hotMenu, gs_vote_status } from "../global_state"; +import { gs_vote_hotMenu } from "../global_state"; import { MODEL_VOTING } from "../model/interface"; -import { MainColor } from "@/app_modules/_global/color/color_pallet"; -import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; -import mqtt_client from "@/util/mqtt_client"; export default function Vote_Create() { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); const [hotMenu, setHotMenu] = useAtom(gs_vote_hotMenu); - const [tabsStatus, setTabsStatus] = useAtom(gs_vote_status); const [data, setData] = useState({ title: "", @@ -209,14 +208,7 @@ export default function Vote_Create() { mt={"lg"} radius={"xl"} onClick={() => { - onSave( - router, - setHotMenu, - setTabsStatus, - data as any, - listVote, - setIsLoading - ); + onSave(router, setHotMenu, data as any, listVote, setIsLoading); }} c={"black"} bg={MainColor.yellow} @@ -235,7 +227,6 @@ export default function Vote_Create() { async function onSave( router: AppRouterInstance, setHotMenu: any, - setTabsStatus: any, data: MODEL_VOTING, listVote: any[], setIsLoading: any @@ -278,10 +269,9 @@ async function onSave( count: 1, }) ); - + setHotMenu(2); - setTabsStatus("Review"); - router.replace(RouterVote.status); + router.replace(RouterVote.status({ id: "2" })); ComponentGlobal_NotifikasiBerhasil(res.message); setIsLoading(true); } diff --git a/src/app_modules/vote/detail/draft/index.tsx b/src/app_modules/vote/detail/draft/index.tsx index 04b55895..d78f63dd 100644 --- a/src/app_modules/vote/detail/draft/index.tsx +++ b/src/app_modules/vote/detail/draft/index.tsx @@ -1,42 +1,39 @@ "use client"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import { MainColor } from "@/app_modules/_global/color/color_pallet"; import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan"; import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal"; +import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; +import mqtt_client from "@/util/mqtt_client"; import { Button, SimpleGrid, Stack } from "@mantine/core"; -import { useAtom } from "jotai"; import moment from "moment"; import { useRouter } from "next/navigation"; import { useState } from "react"; import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detail_data_sebelum_publish"; import { Vote_funDeleteById } from "../../fun/delete/fun_delete_by_id"; import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id"; -import { gs_vote_status } from "../../global_state"; import { MODEL_VOTING } from "../../model/interface"; -import mqtt_client from "@/util/mqtt_client"; -import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; export default function Vote_DetailDraft({ dataVote, }: { dataVote: MODEL_VOTING; }) { + const [data, setData] = useState(dataVote); return ( <> {dataVote?.catatan ? ( - + ) : ( "" )} - - + + ); @@ -50,7 +47,6 @@ function ButtonAction({ awalVote: Date; }) { const router = useRouter(); - const [tabsStatus, setTabsStatus] = useAtom(gs_vote_status); const [openModal1, setOpenModal1] = useState(false); const [openModal2, setOpenModal2] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -84,10 +80,10 @@ function ButtonAction({ count: 1, }) ); - setTabsStatus("Review"); + ComponentGlobal_NotifikasiBerhasil("Berhasil Ajukan Review", 2000); setIsLoading(true); - router.back(); + router.replace(RouterVote.status({ id: "2" })); } } else { ComponentGlobal_NotifikasiGagal(res.message); @@ -97,9 +93,9 @@ function ButtonAction({ async function onDelete() { await Vote_funDeleteById(voteId).then((res) => { if (res.status === 200) { - setTabsStatus("Draft"); + setOpenModal2(false); ComponentGlobal_NotifikasiBerhasil("Berhasil Hapus Vote", 2000); - router.back(); + router.replace(RouterVote.status({ id: "3" })); } else { ComponentGlobal_NotifikasiGagal(res.message); } diff --git a/src/app_modules/vote/detail/reject/index.tsx b/src/app_modules/vote/detail/reject/index.tsx index f53b1aa1..b2ee5f4c 100644 --- a/src/app_modules/vote/detail/reject/index.tsx +++ b/src/app_modules/vote/detail/reject/index.tsx @@ -4,11 +4,7 @@ import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal"; -import { - Button, - SimpleGrid, - Stack -} from "@mantine/core"; +import { Button, SimpleGrid, Stack } from "@mantine/core"; import { useAtom } from "jotai"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -17,21 +13,21 @@ import { Vote_funDeleteById } from "../../fun/delete/fun_delete_by_id"; import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id"; import { gs_vote_status } from "../../global_state"; import { MODEL_VOTING } from "../../model/interface"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; export default function Vote_DetailReject({ dataVote, }: { dataVote: MODEL_VOTING; }) { + const [data, setData] = useState(dataVote); + return ( <> - - - + + + ); @@ -39,8 +35,6 @@ export default function Vote_DetailReject({ function ButtonAction({ voteId }: { voteId: string }) { const router = useRouter(); - const [tabsStatus, setTabsStatus] = useAtom(gs_vote_status); - const [openModal1, setOpenModal1] = useState(false); const [openModal2, setOpenModal2] = useState(false); const [isLoading, setIsLoading] = useState(false); @@ -48,9 +42,9 @@ function ButtonAction({ voteId }: { voteId: string }) { async function onUpdate() { await Vote_funEditStatusByStatusId(voteId, "3").then((res) => { if (res.status === 200) { - setTabsStatus("Draft"); + setIsLoading(true); ComponentGlobal_NotifikasiBerhasil("Berhasil Masuk Draft", 2000); - router.back(); + router.replace(RouterVote.status({ id: "3" })); } else { ComponentGlobal_NotifikasiGagal(res.message); } @@ -60,9 +54,9 @@ function ButtonAction({ voteId }: { voteId: string }) { async function onDelete() { await Vote_funDeleteById(voteId).then((res) => { if (res.status === 200) { - setTabsStatus("Draft"); + setOpenModal2(false); ComponentGlobal_NotifikasiBerhasil("Berhasil Hapus Vote", 2000); - router.back(); + router.replace(RouterVote.status({ id: "4" })); } else { ComponentGlobal_NotifikasiGagal(res.message); } diff --git a/src/app_modules/vote/detail/review/index.tsx b/src/app_modules/vote/detail/review/index.tsx index c6044a40..914f2c39 100644 --- a/src/app_modules/vote/detail/review/index.tsx +++ b/src/app_modules/vote/detail/review/index.tsx @@ -1,18 +1,17 @@ "use client"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil"; import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal"; +import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal"; +import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; +import mqtt_client from "@/util/mqtt_client"; import { Button, Stack } from "@mantine/core"; -import { useAtom } from "jotai"; import { useRouter } from "next/navigation"; import { useState } from "react"; import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detail_data_sebelum_publish"; import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id"; -import { gs_vote_status } from "../../global_state"; import { MODEL_VOTING } from "../../model/interface"; -import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal"; -import mqtt_client from "@/util/mqtt_client"; -import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin"; export default function Vote_DetailReview({ dataVote, @@ -32,7 +31,6 @@ export default function Vote_DetailReview({ function ButtonAction({ voteId }: { voteId: string }) { const router = useRouter(); const [isLoading, setIsLoading] = useState(false); - const [tabsStatus, setTabsStatus] = useAtom(gs_vote_status); const [openModal, setOpenModal] = useState(false); async function onUpdate() { @@ -58,9 +56,9 @@ function ButtonAction({ voteId }: { voteId: string }) { count: 1, }) ); - setTabsStatus("Draft"); + ComponentGlobal_NotifikasiBerhasil("Berhasil Batalkan Review", 2000); - router.back(); + router.replace(RouterVote.status({ id: "3" })); setIsLoading(true); } } else { diff --git a/src/app_modules/vote/fun/delete/fun_delete_by_id.ts b/src/app_modules/vote/fun/delete/fun_delete_by_id.ts index 990613c5..455d05d3 100644 --- a/src/app_modules/vote/fun/delete/fun_delete_by_id.ts +++ b/src/app_modules/vote/fun/delete/fun_delete_by_id.ts @@ -4,21 +4,33 @@ import prisma from "@/app/lib/prisma"; import { revalidatePath } from "next/cache"; /** - * @param voteId - * @returns isActive berubah menjadi false + * @param votingId */ -export async function Vote_funDeleteById(voteId: string) { - const del = await prisma.voting.update({ +export async function Vote_funDeleteById(votingId: string) { + const del = await prisma.voting.delete({ where: { - id: voteId, + id: votingId, }, - data: { - isActive: false, + select: { + Voting_DaftarNamaVote: true, }, }); - if (!del) return { status: 400, message: "Gagal Hapus Data" }; - revalidatePath("/dev/vote/main/status"); + + for (let i of del.Voting_DaftarNamaVote) { + const hapusDaftarPilihan = await prisma.voting_DaftarNamaVote.delete({ + where: { + id: i.id, + }, + }); + + if (!hapusDaftarPilihan) + return { status: 400, message: "Gagal Hapus Daftar Pilihan" }; + } + + revalidatePath("/dev/vote/main/status/3"); + revalidatePath("/dev/vote/main/status/4"); + return { status: 200, message: "Hapus Berhasil", diff --git a/src/app_modules/vote/fun/edit/fun_edit_by_id.ts b/src/app_modules/vote/fun/edit/fun_edit_by_id.ts index abf4f950..ce6a8547 100644 --- a/src/app_modules/vote/fun/edit/fun_edit_by_id.ts +++ b/src/app_modules/vote/fun/edit/fun_edit_by_id.ts @@ -53,7 +53,7 @@ export async function Vote_funEditById( if (!namaPilihan) return { status: 400, message: "Gagal Membuat List" }; } - revalidatePath("/dev/vote/detail/draft"); + revalidatePath(`/dev/vote/detail/draft`); return { status: 200, message: "Berhasil Update", diff --git a/src/app_modules/vote/fun/get/get_list_status_voting.ts b/src/app_modules/vote/fun/get/get_list_status_voting.ts new file mode 100644 index 00000000..e676a8e2 --- /dev/null +++ b/src/app_modules/vote/fun/get/get_list_status_voting.ts @@ -0,0 +1,9 @@ +"use server"; + +import { prisma } from "@/app/lib"; + +export async function voting_getMasterStatus() { + const data = await prisma.voting_Status.findMany({}); + + return data; +} diff --git a/src/app_modules/vote/fun/get/status/get_all_by_status_id.ts b/src/app_modules/vote/fun/get/status/get_all_by_status_id.ts new file mode 100644 index 00000000..c294aa84 --- /dev/null +++ b/src/app_modules/vote/fun/get/status/get_all_by_status_id.ts @@ -0,0 +1,59 @@ +"use server"; + +import { prisma } from "@/app/lib"; +import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; + +export async function vote_funGetAllByStatusId({ + page, + statusId, +}: { + page: number; + statusId: string; +}) { + const userLoginId = await funGetUserIdByToken(); + + const takeData = 10; + const skipData = page * takeData - takeData; + + if (statusId == "1") { + const data = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: "1", + authorId: userLoginId, + isActive: true, + akhirVote: { + gte: new Date(), + }, + }, + include: { + Voting_DaftarNamaVote: { + orderBy: { + createdAt: "asc", + }, + }, + }, + }); + + return data; + } else { + const data = await prisma.voting.findMany({ + take: takeData, + skip: skipData, + orderBy: { + updatedAt: "desc", + }, + where: { + voting_StatusId: statusId, + authorId: userLoginId, + isActive: true, + }, + }); + + return data; + } +} diff --git a/src/app_modules/vote/fun/index.ts b/src/app_modules/vote/fun/index.ts index ce414853..2b7feb70 100644 --- a/src/app_modules/vote/fun/index.ts +++ b/src/app_modules/vote/fun/index.ts @@ -1,3 +1,7 @@ import { voting_funUpdateIsArsipById } from "./edit/fun_update_is_arsip_by_id"; +import { voting_getMasterStatus } from "./get/get_list_status_voting"; +import { vote_funGetAllByStatusId } from "./get/status/get_all_by_status_id"; export { voting_funUpdateIsArsipById }; +export { vote_funGetAllByStatusId }; +export { voting_getMasterStatus }; diff --git a/src/app_modules/vote/main/layout.tsx b/src/app_modules/vote/main/layout.tsx index 70797876..fb31f83b 100644 --- a/src/app_modules/vote/main/layout.tsx +++ b/src/app_modules/vote/main/layout.tsx @@ -37,7 +37,7 @@ export default function LayoutVote_Main({ { id: 2, name: "Status", - path: RouterVote.status, + path: RouterVote.status({ id: "1" }), icon: , }, { @@ -49,7 +49,7 @@ export default function LayoutVote_Main({ { id: 4, name: "Riwayat", - path: RouterVote.riwayat, + path: RouterVote.riwayat({ id: "1" }), icon: , }, ]; @@ -91,7 +91,6 @@ export default function LayoutVote_Main({ } > - {children} diff --git a/src/app_modules/vote/main/riwayat/index.tsx b/src/app_modules/vote/main/riwayat/index.tsx index e8c4e1ac..89f4506f 100644 --- a/src/app_modules/vote/main/riwayat/index.tsx +++ b/src/app_modules/vote/main/riwayat/index.tsx @@ -7,40 +7,53 @@ import Vote_RiwayatSaya from "./saya"; import { useAtom } from "jotai"; import { gs_vote_riwayat } from "../../global_state"; import { MODEL_VOTING } from "../../model/interface"; -import { AccentColor, MainColor } from "@/app_modules/_global/color/color_pallet"; +import { + AccentColor, + MainColor, +} from "@/app_modules/_global/color/color_pallet"; +import { useRouter } from "next/navigation"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; export default function Vote_Riwayat({ + riwayatId, listRiwayat, listRiwayatSaya, }: { - listRiwayat: MODEL_VOTING[]; - listRiwayatSaya: MODEL_VOTING[]; + riwayatId: string; + listRiwayat?: MODEL_VOTING[]; + listRiwayatSaya?: MODEL_VOTING[]; }) { - const [tabsRiwayat, setTabsRiwayat] = useAtom(gs_vote_riwayat); + const router = useRouter(); + const [changeStatus, setChangeStatus] = useState(riwayatId); + const listTabs = [ { - id: 1, - path: , + id: "1", value: "Semua", label: "Semua Riwayat", }, { - id: 2, - path: , + id: "2", value: "Saya", label: "Riwayat Saya", }, ]; + async function onChangeStatus({ statusId }: { statusId: string }) { + router.push(RouterVote.riwayat({ id: statusId })); + } + return ( <> { + setChangeStatus(val); + onChangeStatus({ statusId: val }); + }} styles={{ tabsList: { backgroundColor: MainColor.darkblue, @@ -58,15 +71,15 @@ export default function Vote_Riwayat({ {listTabs.map((e, i) => ( ))} - {listTabs.map((e) => ( - - {e.path} - - ))} + + {riwayatId === "1" && ( + + )} + + {riwayatId === "2" && ( + + )} diff --git a/src/app_modules/vote/main/riwayat/saya.tsx b/src/app_modules/vote/main/riwayat/saya.tsx index c1f46d43..f9822ff9 100644 --- a/src/app_modules/vote/main/riwayat/saya.tsx +++ b/src/app_modules/vote/main/riwayat/saya.tsx @@ -28,7 +28,7 @@ export default function Vote_RiwayatSaya({ // --- Main component --- // (
diff --git a/src/app_modules/vote/main/riwayat/semua.tsx b/src/app_modules/vote/main/riwayat/semua.tsx index 6e3a027d..d28574d8 100644 --- a/src/app_modules/vote/main/riwayat/semua.tsx +++ b/src/app_modules/vote/main/riwayat/semua.tsx @@ -26,7 +26,7 @@ export default function Vote_SemuaRiwayat({ // --- Main component --- // (
diff --git a/src/app_modules/vote/main/status/index.tsx b/src/app_modules/vote/main/status/index.tsx index d05de29d..3f55e91c 100644 --- a/src/app_modules/vote/main/status/index.tsx +++ b/src/app_modules/vote/main/status/index.tsx @@ -1,51 +1,36 @@ "use client"; +import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; import { AccentColor, MainColor, } from "@/app_modules/_global/color/color_pallet"; -import { Stack, Tabs } from "@mantine/core"; -import { useAtom } from "jotai"; -import { gs_vote_status } from "../../global_state"; +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 Vote_StatusDraft from "./draft"; import Vote_StatusPublish from "./publish"; import Vote_StatusReject from "./reject"; import Vote_StatusReview from "./review"; export default function Vote_Status({ - listPublish, - listReview, - listDraft, - listReject, + statusId, + dataVoting, + listStatus, }: { - listPublish: any[]; - listReview: any[]; - listDraft: any[]; - listReject: any[]; + statusId: string; + dataVoting: MODEL_VOTING[]; + listStatus: MODEL_NEW_DEFAULT_MASTER[]; }) { - const [tabsStatus, setTabsStatus] = useAtom(gs_vote_status); - const listTabs = [ - { - id: 1, - path: , - value: "Publish", - }, - { - id: 2, - path: , - value: "Review", - }, - { - id: 3, - path: , - value: "Draft", - }, - { - id: 4, - path: , - value: "Reject", - }, - ]; + + const router = useRouter(); + const [changeStatus, setChangeStatus] = useState(statusId); + + async function onChangeStatus({ statusId }: { statusId: string }) { + router.replace(RouterVote.status({ id: statusId })); + } return ( <> @@ -53,9 +38,11 @@ export default function Vote_Status({ mt={1} variant="pills" radius={"xl"} - defaultValue={"Publish"} - value={tabsStatus} - onTabChange={setTabsStatus} + value={changeStatus} + onTabChange={(val: any) => { + setChangeStatus(val); + onChangeStatus({ statusId: val }); + }} styles={{ tabsList: { backgroundColor: MainColor.darkblue, @@ -70,28 +57,36 @@ export default function Vote_Status({ > - {listTabs.map((e) => ( + {listStatus.map((e) => ( - {e.value} + {e.name} ))} - {listTabs.map((e) => ( - - {e.path} - - ))} + + + {statusId === "1" && ( + + )} + {statusId === "2" && } + {statusId === "3" && } + {statusId === "4" && } + diff --git a/src/app_modules/vote/main/status/review.tsx b/src/app_modules/vote/main/status/review.tsx index c59703bc..3fc866c5 100644 --- a/src/app_modules/vote/main/status/review.tsx +++ b/src/app_modules/vote/main/status/review.tsx @@ -1,17 +1,14 @@ "use client"; import { RouterVote } from "@/app/lib/router_hipmi/router_vote"; -import ComponentVote_CardViewStatus from "../../component/card_view_status"; -import { MODEL_VOTING } from "../../model/interface"; -import { Box, Center, Loader, Stack, Text } from "@mantine/core"; -import _ from "lodash"; -import ComponentVote_IsEmptyData from "../../component/is_empty_data"; 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 { Box, Center, Loader } from "@mantine/core"; +import _ from "lodash"; import { ScrollOnly } from "next-scroll-loader"; import { useState } from "react"; -import ComponentVote_CardViewPublish from "../../component/card_view_publish"; +import ComponentVote_CardViewStatus from "../../component/card_view_status"; import { vote_getAllReview } from "../../fun/get/status/get_all_review"; +import { MODEL_VOTING } from "../../model/interface"; export default function Vote_StatusReview({ listReview,