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

@@ -1,13 +1,14 @@
import { atomWithStorage } from "jotai/utils";
import { IAdmin_ActiveChildId, IAdmin_ActivePage } from "../notifikasi/route_setting/type_of_select_page";
export const gs_admin_navbar_menu = atomWithStorage<string>(
export const gs_admin_navbar_menu = atomWithStorage<IAdmin_ActivePage | null>(
"gs_admin_navbar_menu",
"Main"
);
export const gs_admin_navbar_subMenu = atomWithStorage<string | null>(
export const gs_admin_navbar_subMenu = atomWithStorage<IAdmin_ActiveChildId | string>(
"gs_admin_navbar_submenu",
null
""
);
export const gs_admin_navbar_isActive_dropdown = atomWithStorage<boolean>(

View File

@@ -1,5 +1,5 @@
import {
gs_adminEventTriggerReview,
gs_adminEvent_triggerReview,
IRealtimeData,
} from "@/app/lib/global_state";
import { AccentColor } from "@/app_modules/_global/color";
@@ -63,7 +63,7 @@ export default function AdminEvent_ComponentTableReview({
// Realtime state
const [isAdminTriggerReview, setIsAdminTriggerReview] = useAtom(
gs_adminEventTriggerReview
gs_adminEvent_triggerReview
);
const [isShowReload, setIsShowReload] = useState(false);
@@ -289,27 +289,25 @@ export default function AdminEvent_ComponentTableReview({
<Paper p={"md"} withBorder shadow="lg" h={"80vh"}>
{isShowReload && (
<Paper bg={"red"} w={"50%"}>
<Affix position={{ top: rem(200) }} w={"100%"}>
<Center>
<Button
style={{
transition: "0.5s",
border: `1px solid ${AccentColor.skyblue}`,
}}
bg={AccentColor.blue}
loaderPosition="center"
loading={isLoading}
radius={"xl"}
opacity={0.8}
onClick={() => onLoadData()}
leftIcon={<IconRefresh />}
>
Update Data
</Button>
</Center>
</Affix>
</Paper>
<Affix position={{ top: rem(200) }} w={"100%"}>
<Center>
<Button
style={{
transition: "0.5s",
border: `1px solid ${AccentColor.skyblue}`,
}}
bg={AccentColor.blue}
loaderPosition="center"
loading={isLoading}
radius={"xl"}
opacity={0.8}
onClick={() => onLoadData()}
leftIcon={<IconRefresh />}
>
Update Data
</Button>
</Center>
</Affix>
)}
<ScrollArea w={"100%"} h={"90%"}>

View File

@@ -1,6 +1,6 @@
import { RouterAdminGlobal } from "@/app/lib";
import {
gs_adminJobTriggerReview,
gs_adminJob_triggerReview,
IRealtimeData,
} from "@/app/lib/global_state";
import { ComponentGlobal_InputCountDown } from "@/app_modules/_global/component";
@@ -63,7 +63,7 @@ export default function AdminJob_ViewTavleReview({
// Realtime
const [isAdminJob_TriggerReview, setIsAdminJob_TriggerReview] = useAtom(
gs_adminJobTriggerReview
gs_adminJob_triggerReview
);
const [isShowReload, setIsShowReload] = useState(false);

View File

@@ -29,7 +29,7 @@ export const listAdminPage = [
// Main Dashboard
{
id: 1,
name: "Main Dashboard",
name: "Dashboard",
path: RouterAdminDashboard.main_admin,
icon: <IconHome />,
child: [],

View File

@@ -139,7 +139,7 @@ export function Admin_NewLayout({
<Stack style={{ color: "white" }}>
<Admin_UiNavbar
userRoleId={userRoleId}
activeId={activeId}
activeId={activeId as any}
activeChildId={activeChildId as any}
setActiveId={setActiveId}
setActiveChildId={setActiveChildId}
@@ -186,13 +186,13 @@ export function Admin_NewLayout({
opened={isDrawerNotifikasi}
onClose={() => setDrawerNotifikasi(false)}
position="right"
size={"xs"}
size={"sm"}
>
<ComponentAdmin_UIDrawerNotifikasi
newAdminNtf={newAdminNtf}
listNotifikasi={dataNotifikasi}
onChangeNavbar={(val: { id: string; childId: string }) => {
setActiveId(val.id);
setActiveId(val.id as any);
setActiveChildId(val.childId);
}}
onToggleNavbar={(val: any) => {

View File

@@ -29,7 +29,7 @@ export const newListAdminPage = [
// Main Dashboard
{
id: "Main",
name: "Main Dashboard",
name: "Dashboard",
path: RouterAdminDashboard.main_admin,
icon: <IconHome />,
child: [],

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"}>

View File

@@ -6,28 +6,35 @@ import { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai";
import { useRouter } from "next/navigation";
import { gs_admin_hotMenu } from "../global_state";
import {
gs_admin_navbar_menu,
gs_admin_navbar_subMenu,
} from "../_admin_global/new_global_state";
import { IAdmin_ActivePage } from "../notifikasi/route_setting/type_of_select_page";
export default function SplashDashboardAdmin() {
const router = useRouter();
const [active, setActive] = useAtom(gs_admin_hotMenu);
const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu);
const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu);
useShallowEffect(() => {
setTimeout(() => {
router.push(RouterAdminDashboard.main_admin);
setActive(1);
setActiveId("Main");
setActiveChildId("");
}, 2000);
}, []);
return (
<>
<Center h={"100vh"}>
<Stack spacing={0} >
<Title>Welcome Admin</Title>
<Center h={"100vh"}>
<Stack spacing={0}>
<Title>Welcome Admin</Title>
<AspectRatio ratio={1 / 1} mah={700} maw={700}>
<Image src={"/aset/logo/logo-hipmi.png"} alt="Logo" />
</AspectRatio>
</Stack>
</Center>
<AspectRatio ratio={1 / 1} mah={700} maw={700}>
<Image src={"/aset/logo/logo-hipmi.png"} alt="Logo" />
</AspectRatio>
</Stack>
</Center>
</>
);
}

View File

@@ -3,6 +3,7 @@
import ComponentAdminGlobal_HeaderTamplate from "@/app_modules/admin/_admin_global/header_tamplate";
import { MODEL_VOTING } from "@/app_modules/vote/model/interface";
import {
Affix,
Box,
Button,
Center,
@@ -10,6 +11,7 @@ import {
Modal,
Pagination,
Paper,
rem,
ScrollArea,
Spoiler,
Stack,
@@ -19,21 +21,31 @@ import {
TextInput,
Title,
} from "@mantine/core";
import { useDisclosure } from "@mantine/hooks";
import { IconBan, IconCircleCheck, IconSearch } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useDisclosure, useShallowEffect } from "@mantine/hooks";
import {
IconBan,
IconCircleCheck,
IconRefresh,
IconSearch,
} from "@tabler/icons-react";
import {
gs_adminVoting_triggerReview,
IRealtimeData,
} from "@/app/lib/global_state";
import { AccentColor } from "@/app_modules/_global/color";
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 adminNotifikasi_funCreateToUser from "@/app_modules/admin/notifikasi/fun/create/fun_create_notif_user";
import mqtt_client from "@/util/mqtt_client";
import { useAtom } from "jotai";
import moment from "moment";
import { useState } from "react";
import { WibuRealtime } from "wibu-pkg";
import { adminVote_funGetListReview } from "../../fun";
import { AdminVote_funEditStatusPublishById } from "../../fun/edit/fun_edit_status_publish_by_id";
import { AdminEvent_funEditCatatanById } from "../../fun/edit/fun_edit_status_reject_by_id";
import { AdminVote_getListTableByStatusId } from "../../fun/get/get_list_table_by_status_id";
export default function AdminVote_TableReview({
listVote,
@@ -51,18 +63,40 @@ export default function AdminVote_TableReview({
}
function TableStatus({ listData }: { listData: any }) {
const router = useRouter();
const [opened, { open, close }] = useDisclosure(false);
const [data, setData] = useState<MODEL_VOTING[]>(listData.data);
const [isNPage, setNPage] = useState(listData.nPage);
const [votingId, setVotingId] = useState("");
const [catatan, setCatatan] = useState("");
const [isLoadingPublish, setLoadingPublish] = useState(false);
const [isSaveLoading, setSaveLoading] = useState(false);
const [isNPage, setNPage] = useState(listData.nPage);
const [isActivePage, setActivePage] = useState(1);
const [isSearch, setSearch] = useState("");
// Realtine
const [isLoading, setIsLoading] = useState(false);
const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom(
gs_adminVoting_triggerReview
);
const [isShowReload, setIsShowReload] = useState(false);
useShallowEffect(() => {
if (isAdminVoting_TriggerReview) {
setIsShowReload(true);
}
}, [isAdminVoting_TriggerReview, setIsShowReload]);
async function onLoadData() {
const loadData = await adminVote_funGetListReview({ page: 1 });
setData(loadData.data as any);
setNPage(loadData.nPage);
setIsLoading(false);
setIsShowReload(false);
setIsAdminVoting_TriggerReview(false);
}
async function onSearch(s: string) {
setSearch(s);
const loadData = await adminVote_funGetListReview({
@@ -135,13 +169,16 @@ function TableStatus({ listData }: { listData: any }) {
leftIcon={<IconCircleCheck />}
radius={"xl"}
onClick={() =>
onPublish(
e.id,
setData,
e.awalVote,
setLoadingPublish,
setVotingId
)
onPublish({
voteId: e.id,
awalVote: e.awalVote,
setLoadingPublish: setLoadingPublish,
setVotingId: setVotingId,
setData(val) {
setData(val.data);
setNPage(val.nPage);
},
})
}
>
Publish
@@ -185,6 +222,28 @@ function TableStatus({ listData }: { listData: any }) {
</Group>
<Paper p={"md"} withBorder shadow="lg" h={"80vh"}>
{isShowReload && (
<Affix position={{ top: rem(200) }} w={"100%"}>
<Center>
<Button
style={{
transition: "0.5s",
border: `1px solid ${AccentColor.skyblue}`,
}}
bg={AccentColor.blue}
loaderPosition="center"
loading={isLoading}
radius={"xl"}
opacity={0.8}
onClick={() => onLoadData()}
leftIcon={<IconRefresh />}
>
Update Data
</Button>
</Center>
</Affix>
)}
<ScrollArea w={"100%"} h={"90%"}>
<Table
verticalSpacing={"md"}
@@ -264,7 +323,20 @@ function TableStatus({ listData }: { listData: any }) {
loading={isSaveLoading ? true : false}
radius={"xl"}
onClick={() => {
onReject(votingId, setData, catatan, close, setSaveLoading);
onReject({
catatan: catatan,
voteId: votingId,
setData(val) {
setData(val.data);
setNPage(val.nPage);
},
close: () => {
close();
},
setSaveLoading(val) {
setSaveLoading(val);
},
});
}}
>
Simpan
@@ -276,13 +348,19 @@ function TableStatus({ listData }: { listData: any }) {
);
}
async function onPublish(
voteId: string,
setData: any,
awalVote: Date,
setLoadingPublish: any,
setVotingId: any
) {
async function onPublish({
voteId,
setData,
awalVote,
setLoadingPublish,
setVotingId,
}: {
voteId: string;
setData: (val: { data: any[]; nPage: number }) => void;
awalVote: Date;
setLoadingPublish: (val: boolean) => void;
setVotingId: (val: string) => void;
}) {
const hariIni = new Date();
const cekHari = moment(awalVote).diff(hariIni, "days");
@@ -292,8 +370,10 @@ async function onPublish(
setVotingId(voteId);
const res = await AdminVote_funEditStatusPublishById(voteId);
if (res.status === 200) {
const dataNotif = {
appId: res.data?.id,
setLoadingPublish(true);
const dataNotifikasi: IRealtimeData = {
appId: res.data?.id as string,
status: res.data?.Voting_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
@@ -302,33 +382,48 @@ async function onPublish(
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
data: dataNotifikasi as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
}
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
await AdminVote_getListTableByStatusId("2").then((val) => {
setData(val);
ComponentGlobal_NotifikasiBerhasil(res.message);
setLoadingPublish(true);
WibuRealtime.setData({
type: "trigger",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
const loadData = await adminVote_funGetListReview({ page: 1 });
setData({
data: loadData.data,
nPage: loadData.nPage,
});
ComponentGlobal_NotifikasiBerhasil(res.message);
setLoadingPublish(false);
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}
}
async function onReject(
voteId: string,
setData: any,
catatan: string,
close: any,
setSaveLoading: any
) {
async function onReject({
voteId,
catatan,
close,
setSaveLoading,
setData,
}: {
voteId: string;
catatan: string;
close: any;
setSaveLoading: (val: boolean) => void;
setData: (val: { data: any[]; nPage: number }) => void;
}) {
const data = {
id: voteId,
catatan: catatan,
@@ -337,8 +432,17 @@ async function onReject(
const res = await AdminEvent_funEditCatatanById(data as any);
if (res.status === 200) {
setSaveLoading(true);
const dataNotif = {
appId: res.data?.id,
// const dataNotif = {
// appId: res.data?.id,
// status: res.data?.Voting_Status?.name as any,
// userId: res.data?.authorId as any,
// pesan: res.data?.title as any,
// kategoriApp: "VOTING",
// title: "Voting anda di tolak !",
// };
const dataNotifikasi: IRealtimeData = {
appId: res.data?.id as string,
status: res.data?.Voting_Status?.name as any,
userId: res.data?.authorId as any,
pesan: res.data?.title as any,
@@ -347,22 +451,25 @@ async function onReject(
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
data: dataNotifikasi as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: res?.data?.authorId, count: 1 })
);
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
await AdminVote_getListTableByStatusId("2").then((val) => {
setData(val);
setSaveLoading(false);
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
const loadData = await adminVote_funGetListReview({ page: 1 });
setData({
data: loadData.data,
nPage: loadData.nPage,
});
setSaveLoading(false);
ComponentGlobal_NotifikasiBerhasil(res.message);
close();
} else {
ComponentGlobal_NotifikasiGagal(res.message);
}