Fix: Voting

Deskripsi:
- Fix notifikasi admin to user
- Fix notifikasi user to admin
## No Issue
This commit is contained in:
2024-11-20 16:23:05 +08:00
parent 6b8ace772c
commit e65a8d30a2
36 changed files with 1077 additions and 547 deletions

View File

@@ -0,0 +1,23 @@
"use server";
import { prisma } from "@/app/lib";
import _ from "lodash";
export async function admin_funVotingCheckStatus({ id }: { id: string }) {
const data = await prisma.voting.findUnique({
where: {
id: id,
},
select: {
Voting_Status: true,
},
});
if (!data)
return { status: 400, message: "Id tidak ditemukan", statusName: "" };
return {
status: 200,
message: "Id ditemukan",
statusName: _.lowerCase(data.Voting_Status?.name),
};
}

View File

@@ -1,37 +1,82 @@
import { RouterAdminEvent } from "@/app/lib/router_admin/router_admin_event";
import { RouterAdminVote } from "@/app/lib/router_admin/router_admin_vote";
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { admin_funEventCheckStatus } from "../fun/get";
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
import { admin_funEventCheckStatus } from "../fun/get";
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "./type_of_select_page";
export async function adminNotifikasi_findRouterEvent({
data,
appId,
notifikasiId,
router,
activePage,
onLoadCountNotif,
onLoadDataNotifikasi,
onChangeNavbar,
}: {
data: MODEL_NOTIFIKASI;
appId: string;
notifikasiId: string;
router: AppRouterInstance;
activePage: number;
onLoadCountNotif: (val: any) => void;
onLoadDataNotifikasi: (val: any) => void;
onChangeNavbar: (val: {
id: IAdmin_ActivePage;
childId: IAdmin_ActiveChildId;
}) => void;
}) {
const check = await admin_funEventCheckStatus({id: data.appId})
const check = await admin_funEventCheckStatus({ id: appId });
if (check.status == 200) {
const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
notifId: data?.id,
notifId: notifikasiId,
});
if (udpateReadNotifikasi.status == 200) {
return {
success: true,
statusName: check.statusName,
};
} else {
return {
success: false,
statusName: "",
};
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId({
page: 1,
});
onLoadDataNotifikasi(loadListNotifikasi);
const path = `/dev/admin/event/table/${check.statusName}`;
if (check.statusName == "draft") {
ComponentAdminGlobal_NotifikasiPeringatan(
"Status telah dirubah oleh user"
);
} else {
if (check.statusName == "publish") {
onChangeNavbar({
id: "Event",
childId: "Event_2",
});
}
if (check.statusName == "review") {
onChangeNavbar({
id: "Event",
childId: "Event_3",
});
}
if (check.statusName == "reject") {
onChangeNavbar({
id: "Event",
childId: "Event_4",
});
}
router.push(path, { scroll: false });
}
}
return true;
} else {
ComponentAdminGlobal_NotifikasiPeringatan("Status telah dirubah oleh user");
return false;
}
}

View File

@@ -2,31 +2,82 @@ import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
import { admin_funCheckStatusJob } from "../fun/get/fun_check_status_job";
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
import { IAdmin_ActivePage, IAdmin_ActiveChildId } from "./type_of_select_page";
export async function adminNotifikasi_findRouterJob({
data,
appId,
notifikasiId,
router,
activePage,
onLoadCountNotif,
onLoadDataNotifikasi,
onChangeNavbar,
}: {
data: MODEL_NOTIFIKASI;
appId: string;
notifikasiId: string;
router: AppRouterInstance;
activePage: number;
onLoadCountNotif: (val: any) => void;
onLoadDataNotifikasi: (val: any) => void;
onChangeNavbar: (val: {
id: IAdmin_ActivePage;
childId: IAdmin_ActiveChildId;
}) => void;
}) {
const check = await admin_funCheckStatusJob({ id: data.appId });
const check = await admin_funCheckStatusJob({ id: appId });
if (check.status == 200) {
const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
notifId: data?.id,
notifId: notifikasiId,
});
if (udpateReadNotifikasi.status == 200) {
return {
success: true,
statusName: check.statusName,
};
} else {
return {
success: false,
statusName: ""
};
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId({
page: 1,
});
onLoadDataNotifikasi(loadListNotifikasi);
const path = `/dev/admin/job/child/${check.statusName}`;
if (check.statusName == "draft") {
ComponentAdminGlobal_NotifikasiPeringatan(
"Status telah dirubah oleh user"
);
} else {
if (check.statusName == "publish") {
onChangeNavbar({
id: "Job",
childId: "Job_2",
});
}
if (check.statusName == "review") {
onChangeNavbar({
id: "Job",
childId: "Job_3",
});
}
if (check.statusName == "reject") {
onChangeNavbar({
id: "Job",
childId: "Job_4",
});
}
router.push(path, { scroll: false });
}
}
return true;
} else {
ComponentAdminGlobal_NotifikasiPeringatan("Status telah dirubah oleh user");
return false;
}
}

View File

@@ -1,4 +1,4 @@
export type IAdmin_ActivePage = "Investasi" | "Donasi" | "Event" | "Vote" | "Job" | "Forum" | "Collaboration"
export type IAdmin_ActivePage = "Main" | "Investasi" | "Donasi" | "Event" | "Voting" | "Job" | "Forum" | "Collaboration"
export type IAdmin_ActiveChildId =
| "Investasi_1"
| "Investasi_2"

View File

@@ -1,27 +1,84 @@
import { RouterAdminVote } from "@/app/lib/router_admin/router_admin_vote";
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
import { admin_funVotingCheckStatus } from "../fun/get/fun_voting_check_status";
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
import adminNotifikasi_getByUserId from "../fun/get/get_notifikasi_by_user_id";
import adminNotifikasi_funUpdateIsReadById from "../fun/update/fun_update_is_read_by_id";
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "./type_of_select_page";
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
export async function adminNotifikasi_findRouterVoting({
data,
appId,
notifikasiId,
router,
activePage,
onLoadCountNotif,
onLoadDataNotifikasi,
onChangeNavbar,
onToggleNavbar,
}: {
data: MODEL_NOTIFIKASI;
appId: string;
notifikasiId: string;
router: AppRouterInstance;
onChangeNavbar: (val: any) => void;
onToggleNavbar: (val: any) => void;
activePage: number;
onLoadCountNotif: (val: any) => void;
onLoadDataNotifikasi: (val: any) => void;
onChangeNavbar: (val: {
id: IAdmin_ActivePage;
childId: IAdmin_ActiveChildId;
}) => void;
}) {
const path = RouterAdminVote.table_review;
const check = await admin_funVotingCheckStatus({ id: appId });
if (data.status === "Review") {
router.push(path, { scroll: false });
onChangeNavbar({
id: 5,
childId: 53,
if (check.status == 200) {
const updateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
notifId: notifikasiId,
});
}
onToggleNavbar(true);
if (updateReadNotifikasi.status == 200) {
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId({
page: 1,
});
onLoadDataNotifikasi(loadListNotifikasi);
const path = `/dev/admin/vote/child/table_${check.statusName}`;
if (check.statusName == "draft") {
ComponentAdminGlobal_NotifikasiPeringatan(
"Status telah dirubah oleh user"
);
} else {
if (check.statusName == "publish") {
onChangeNavbar({
id: "Voting",
childId: "Voting_2",
});
}
if (check.statusName == "review") {
onChangeNavbar({
id: "Voting",
childId: "Voting_3",
});
}
if (check.statusName == "reject") {
onChangeNavbar({
id: "Voting",
childId: "Voting_4",
});
}
router.push(path, { scroll: false });
}
}
return true;
} else {
ComponentAdminGlobal_NotifikasiPeringatan("Status tidak ditemukan");
return false;
}
}

View File

@@ -1,19 +1,10 @@
import {
gs_adminEventTriggerReview,
gs_adminJobTriggerReview,
} from "@/app/lib/global_state";
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import { Center, Loader, Paper, Text } from "@mantine/core";
import { Box, Center, Loader, Paper, Stack, Text } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai";
import _ from "lodash";
import { ScrollOnly } from "next-scroll-loader";
import { useRouter } from "next/navigation";
import { useState } from "react";
import adminNotifikasi_countNotifikasi from "./fun/count/count_is_read";
import adminNotifikasi_getByUserId from "./fun/get/get_notifikasi_by_user_id";
import { adminNotifikasi_findRouterEvent } from "./route_setting/event";
import { adminNotifikasi_findRouterJob } from "./route_setting/job";
import {
IAdmin_ActiveChildId,
IAdmin_ActivePage,
@@ -67,42 +58,39 @@ export function ComponentAdmin_UIDrawerNotifikasi({
return (
<>
<Paper h={"100%"}>
<ScrollOnly
height="90vh"
renderLoading={() => (
<Center mt={"lg"}>
<Loader color={"yellow"} />
</Center>
)}
data={data}
setData={setData}
moreData={async () => {
const loadData = await adminNotifikasi_getByUserId({
page: activePage + 1,
});
<Stack>
{/* <Box bg={"red"}>apa ini</Box> */}
<ScrollOnly
height="90vh"
renderLoading={() => (
<Center mt={"lg"}>
<Loader color={"yellow"} />
</Center>
)}
data={data}
setData={setData}
moreData={async () => {
const loadData = await adminNotifikasi_getByUserId({
page: activePage + 1,
});
setActivePage((val) => val + 1);
setActivePage((val) => val + 1);
return loadData;
}}
>
{(item) => (
<AdminNotifikasi_ViewCardDrawer
data={item}
activePage={activePage}
onChangeNavbar={(val) => onChangeNavbar(val)}
onLoadCountNotif={(val) => onLoadCountNotif(val)}
onToggleNavbar={(val) => onToggleNavbar(val)}
onLoadDataNotifikasi={(val) => setData(val)}
/>
)}
</ScrollOnly>
{/* <Stack>
{data.map((e, i) => (
))}
</Stack> */}
return loadData;
}}
>
{(item) => (
<AdminNotifikasi_ViewCardDrawer
data={item}
activePage={activePage}
onChangeNavbar={(val) => onChangeNavbar(val)}
onLoadCountNotif={(val) => onLoadCountNotif(val)}
onToggleNavbar={(val) => onToggleNavbar(val)}
onLoadDataNotifikasi={(val) => setData(val)}
/>
)}
</ScrollOnly>
</Stack>
</Paper>
</>
);

View File

@@ -1,23 +1,26 @@
import {
gs_adminJobTriggerReview,
gs_adminEventTriggerReview,
gs_adminEvent_triggerReview,
gs_adminJob_triggerReview,
gs_adminVoting_triggerReview,
} from "@/app/lib/global_state";
import { AccentColor } from "@/app_modules/_global/color";
import { ComponentGlobal_CardLoadingOverlay } from "@/app_modules/_global/component";
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import { Card, Stack, Group, Badge, Divider, Text } from "@mantine/core";
import { IconChecks, IconCheck } from "@tabler/icons-react";
import { Badge, Card, Divider, Group, Stack, Text } from "@mantine/core";
import { IconCheck, IconChecks } from "@tabler/icons-react";
import { useAtom } from "jotai";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../_admin_global/admin_notifikasi/notifikasi_peringatan";
import adminNotifikasi_countNotifikasi from "./fun/count/count_is_read";
import adminNotifikasi_getByUserId from "./fun/get/get_notifikasi_by_user_id";
import { adminNotifikasi_findRouterEvent } from "./route_setting/event";
import { adminNotifikasi_findRouterJob } from "./route_setting/job";
import {
IAdmin_ActivePage,
IAdmin_ActiveChildId,
IAdmin_ActivePage,
} from "./route_setting/type_of_select_page";
import { adminNotifikasi_findRouterVoting } from "./route_setting/voting";
export default function AdminNotifikasi_ViewCardDrawer({
data,
@@ -43,112 +46,113 @@ export default function AdminNotifikasi_ViewCardDrawer({
// Realtime
const [isAdminJob_TriggerReview, setIsAdminJob_TriggerReview] = useAtom(
gs_adminJobTriggerReview
gs_adminJob_triggerReview
);
const [isAdminEvent_TriggerReview, setIsAdminEvent_TriggerReview] = useAtom(
gs_adminEventTriggerReview
gs_adminEvent_triggerReview
);
const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom(
gs_adminVoting_triggerReview
);
async function onRead({ data }: { data: MODEL_NOTIFIKASI }) {
// JOB
async function onRead() {
// ========================== JOB ========================== //
if (data?.kategoriApp === "JOB") {
setVisible(true);
setDataId(data.id);
const checkJob = await adminNotifikasi_findRouterJob({
data: data,
appId: data.appId,
notifikasiId: data.id,
router: router,
activePage: activePage,
onLoadCountNotif(val) {
onLoadCountNotif(val);
},
onLoadDataNotifikasi(val) {
onLoadDataNotifikasi(val);
},
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
if (checkJob?.success) {
setVisible(true);
setDataId(data.id);
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId({
page: activePage,
});
onLoadDataNotifikasi(loadListNotifikasi as any);
if (loadCountNotif && loadListNotifikasi) {
const path = `/dev/admin/job/child/${checkJob.statusName}`;
if (checkJob.statusName == "publish") {
onChangeNavbar({
id: "Job",
childId: "Job_2",
});
}
if (checkJob.statusName == "review") {
onChangeNavbar({
id: "Job",
childId: "Job_3",
});
}
if (checkJob.statusName == "reject") {
onChangeNavbar({
id: "Job",
childId: "Job_4",
});
}
setIsAdminJob_TriggerReview(false);
router.push(path);
setVisible(false);
setDataId("");
}
if (checkJob) {
setIsAdminJob_TriggerReview(false);
setVisible(false);
setDataId("");
}
}
// ========================== JOB ========================== //
// ========================== EVENT ========================== //
// EVENT
if (data.kategoriApp == "EVENT") {
setVisible(true);
setDataId(data.id);
const checkEvent = await adminNotifikasi_findRouterEvent({
data: data,
appId: data.appId,
notifikasiId: data.id,
router: router,
activePage: activePage,
onLoadCountNotif(val) {
onLoadCountNotif(val);
},
onLoadDataNotifikasi(val) {
onLoadDataNotifikasi(val);
},
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
if (checkEvent?.success) {
setVisible(true);
setDataId(data.id);
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId({
page: activePage,
});
onLoadDataNotifikasi(loadListNotifikasi as any);
if (loadCountNotif && loadListNotifikasi) {
const path = `/dev/admin/event/table/${checkEvent.statusName}`;
if (checkEvent.statusName == "publish") {
onChangeNavbar({
id: "Event",
childId: "Event_2",
});
}
if (checkEvent.statusName == "review") {
onChangeNavbar({
id: "Event",
childId: "Event_3",
});
}
if (checkEvent.statusName == "reject") {
onChangeNavbar({
id: "Event",
childId: "Event_4",
});
}
setIsAdminEvent_TriggerReview(false);
router.push(path);
setVisible(false);
setDataId("");
}
if (checkEvent) {
setIsAdminEvent_TriggerReview(false);
setVisible(false);
setDataId("");
}
}
// ========================== EVENT ========================== //
// ========================== VOTING ========================== //
if (data.kategoriApp == "VOTING") {
setVisible(true);
setDataId(data.id);
const checkVoting = await adminNotifikasi_findRouterVoting({
router: router,
appId: data.appId,
notifikasiId: data.id,
activePage: activePage,
onLoadCountNotif(val) {
onLoadCountNotif(val);
},
onLoadDataNotifikasi(val) {
onLoadDataNotifikasi(val);
},
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
if (checkVoting) {
setIsAdminVoting_TriggerReview(false);
setVisible(false);
setDataId("");
}
}
// ========================== VOTING ========================== //
// // FORUM
// e?.kategoriApp === "FORUM" &&
@@ -213,7 +217,7 @@ export default function AdminNotifikasi_ViewCardDrawer({
style={{
transition: "0.5s",
}}
mb={"md"}
mb={"15px"}
c={"white"}
key={data.id}
bg={data.isRead ? "gray" : AccentColor.darkblue}
@@ -228,9 +232,8 @@ export default function AdminNotifikasi_ViewCardDrawer({
borderWidth: "2px",
},
}}
onClick={async () => {
onRead({ data: data });
// callBackIsNotifikasi(false);
onClick={() => {
onRead();
}}
>
<Card.Section p={"sm"}>