fix notifikasi admin

This commit is contained in:
2025-05-20 17:18:10 +08:00
parent 6103dbfbea
commit 923552681f
11 changed files with 395 additions and 324 deletions

View File

@@ -10,6 +10,7 @@ import {
Center,
Divider,
Group,
Indicator,
MediaQuery,
Popover,
SimpleGrid,
@@ -38,6 +39,7 @@ export function Admin_V3_ComponentButtonUserCircle({
setOpenPop,
setNavbarOpen,
setDrawerNotifikasi,
countNotifikasi,
}: {
dataUser: MODEL_USER | null;
openPop: boolean;
@@ -47,6 +49,7 @@ export function Admin_V3_ComponentButtonUserCircle({
// setNavbarOpen: (open: boolean) => void;
setDrawerNotifikasi: React.Dispatch<React.SetStateAction<boolean>>;
// setDrawerNotifikasi: (open: boolean) => void;
countNotifikasi: number;
}) {
const router = useRouter();
@@ -82,11 +85,11 @@ export function Admin_V3_ComponentButtonUserCircle({
label: "Notifikasi",
color: "",
onClick: () => {
ComponentAdminGlobal_NotifikasiPeringatan(
"Notifikasi: Masih dalam pengembangan",
2000
);
// setDrawerNotifikasi(true);
// ComponentAdminGlobal_NotifikasiPeringatan(
// "Notifikasi: Masih dalam pengembangan",
// 2000
// );
setDrawerNotifikasi(true);
},
},
{
@@ -109,11 +112,11 @@ export function Admin_V3_ComponentButtonUserCircle({
label: "Notifikasi",
color: "",
onClick: () => {
ComponentAdminGlobal_NotifikasiPeringatan(
"Notifikasi: Masih dalam pengembangan",
2000
);
// setDrawerNotifikasi(true);
// ComponentAdminGlobal_NotifikasiPeringatan(
// "Notifikasi: Masih dalam pengembangan",
// 2000
// );
setDrawerNotifikasi(true);
},
},
{
@@ -233,7 +236,23 @@ export function Admin_V3_ComponentButtonUserCircle({
key={i}
>
<Group onClick={e.onClick}>
<e.icon size={18} color={e.color || "white"} />
{e.label == "Notifikasi" ? (
countNotifikasi == 0 ||
dataUser?.masterUserRoleId == "3" ? (
<IconBell color="white" />
) : (
<Indicator
color="yellow"
processing
label={<Text c="black" fz={10}>{countNotifikasi}</Text>}
>
<IconBell color="white" />
</Indicator>
)
) : (
<e.icon size={18} color={e.color || "white"} />
)}
<Text c={e.color || "white"} lineClamp={1}>
{e.label}
</Text>
@@ -257,7 +276,22 @@ export function Admin_V3_ComponentButtonUserCircle({
cursor: "pointer",
}}
>
<e.icon size={18} color={e.color || "white"} />
{e.label == "Notifikasi" ? (
countNotifikasi == 0 ||
dataUser?.masterUserRoleId == "3" ? (
<IconBell size={18} color={e.color || "white"} />
) : (
<Indicator
color="yellow"
processing
label={<Text c="black" fz={10}>{countNotifikasi}</Text>}
>
<IconBell size={18} color={e.color || "white"} />
</Indicator>
)
) : (
<e.icon size={18} color={e.color || "white"} />
)}
<Text c={e.color || "white"} lineClamp={1}>
{e.label}
</Text>

View File

@@ -39,6 +39,7 @@ import {
import { Admin_V3_ComponentButtonUserCircle } from "./comp_button_user_circle";
import { Admin_V3_SkeletonNavbar } from "./skeleton_navbar";
import { Admin_V3_ViewDrawerNotifikasi } from "./notifikasi/view_drawer_notifikasi";
import { apiGetCountNotifikasiByUserId } from "../notifikasi/lib/api_fetch_notifikasi";
export function Admin_V3_MainLayout({
children,
@@ -60,6 +61,10 @@ export function Admin_V3_MainLayout({
// Notifikasi
const [countNtf, setCountNtf] = useState(countNotifikasi);
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
const [reloadNtf, setReloadNtf] = useState(false);
const [openPop, setOpenPop] = useState(false);
const [opened, handlers] = useDisclosure(false);
const [openedDrawer, handlersDrawer] = useDisclosure(false);
useShallowEffect(() => {
handleLoadUser();
@@ -79,9 +84,33 @@ export function Admin_V3_MainLayout({
setDataUser(null);
}
}
const [openPop, setOpenPop] = useState(false);
const [opened, handlers] = useDisclosure(false);
const [openedDrawer, handlersDrawer] = useDisclosure(false);
useShallowEffect(() => {
setCountNtf((e) => e + newAdminNtf);
setNewAdminNtf(0);
}, [newAdminNtf, setNewAdminNtf]);
useShallowEffect(() => {
handleLoadCountNotifikasi();
}, [reloadNtf]);
async function handleLoadCountNotifikasi() {
try {
const response = await apiGetCountNotifikasiByUserId({ id: userLoginId });
if (response && response.success) {
setCountNtf(response.data);
setReloadNtf(false);
} else {
console.error("Failed to fetch count notifikasi", response);
setCountNtf(0);
setReloadNtf(false);
}
} catch (error) {
console.error("Error fetching count notifikasi", error);
setCountNtf(0);
setReloadNtf(false);
}
}
return (
<>
@@ -155,6 +184,7 @@ export function Admin_V3_MainLayout({
setOpenPop={setOpenPop}
setNavbarOpen={handlers.close}
setDrawerNotifikasi={handlersDrawer.toggle}
countNotifikasi={countNtf}
/>
</Group>
</Header>
@@ -203,6 +233,9 @@ export function Admin_V3_MainLayout({
onToggleNavbar={(val: any) => {
val === false && handlersDrawer.close();
}}
onLoadCountNotif={(val: boolean) => {
setReloadNtf(val);
}}
/>
{/* <ComponentAdmin_UIDrawerNotifikasi
newAdminNtf={newAdminNtf}

View File

@@ -5,7 +5,8 @@ import {
gs_adminDonasi_triggerReview,
gs_adminEvent_triggerReview,
gs_adminJob_triggerReview,
gs_adminVoting_triggerReview
gs_adminVoting_triggerReview,
ITypeStatusNotifikasi,
} from "@/lib/global_state";
import { clientLogger } from "@/util/clientLogger";
import { Badge, Card, Divider, Group, Stack, Text } from "@mantine/core";
@@ -16,19 +17,23 @@ import "moment/locale/id";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
import adminNotifikasi_findRouterDonasi from "../../notifikasi/route_setting/donasi";
import { adminNotifikasi_findRouterEvent } from "../../notifikasi/route_setting/event";
import adminNotifikasi_findRouterForum from "../../notifikasi/route_setting/forum";
import adminNotifikasi_findRouterInvestasi from "../../notifikasi/route_setting/investasi";
import { adminNotifikasi_findRouterJob } from "../../notifikasi/route_setting/job";
import {
IAdmin_ActiveChildId,
IAdmin_ActivePage,
} from "../../notifikasi/route_setting/type_of_select_page";
import { adminNotifikasi_findRouterVoting } from "../../notifikasi/route_setting/voting";
export default function Admin_V3_ComponentCardNotifikasi({
data,
activePage,
onChangeNavbar,
onToggleNavbar,
// onLoadCountNotif,
onLoadCountNotif,
// onLoadDataNotifikasi,
}: {
data: MODEL_NOTIFIKASI;
@@ -38,7 +43,7 @@ export default function Admin_V3_ComponentCardNotifikasi({
childId: IAdmin_ActiveChildId;
}) => void;
onToggleNavbar: (val: any) => void;
// onLoadCountNotif: (val: any) => void;
onLoadCountNotif: (val: boolean) => void;
// onLoadDataNotifikasi: (val: any) => void;
}) {
const router = useRouter();
@@ -84,6 +89,7 @@ export default function Admin_V3_ComponentCardNotifikasi({
setVisible(false);
setDataId("");
onToggleNavbar(false);
onLoadCountNotif(true);
}
return;
@@ -108,6 +114,7 @@ export default function Admin_V3_ComponentCardNotifikasi({
setDataId("");
setVisible(false);
onToggleNavbar(false);
onLoadCountNotif(true);
} else {
ComponentAdminGlobal_NotifikasiPeringatan("Gagal memuat forum");
}
@@ -116,143 +123,121 @@ export default function Admin_V3_ComponentCardNotifikasi({
// ========================== EVENT ========================== //
// if (data.kategoriApp == "EVENT") {
// setDataId(data.id);
if (data.kategoriApp == "EVENT") {
setDataId(data.id);
// const checkEvent = await adminNotifikasi_findRouterEvent({
// 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,
// });
// },
// });
const checkEvent = await adminNotifikasi_findRouterEvent({
appId: data.appId,
notifikasiId: data.id,
router: router,
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
// if (checkEvent) {
// setIsAdminEvent_TriggerReview(false);
// setVisible(false);
// setDataId("");
// onToggleNavbar(false);
// }
if (checkEvent) {
setIsAdminEvent_TriggerReview(false);
setVisible(false);
setDataId("");
onToggleNavbar(false);
onLoadCountNotif(true);
}
// return;
// }
return;
}
// ========================== EVENT ========================== //
// ========================== VOTING ========================== //
// if (data.kategoriApp == "VOTING") {
// setDataId(data.id);
if (data.kategoriApp == "VOTING") {
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,
// });
// },
// });
const checkVoting = await adminNotifikasi_findRouterVoting({
router: router,
appId: data.appId,
notifikasiId: data.id,
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
// if (checkVoting) {
// setIsAdminVoting_TriggerReview(false);
// setVisible(false);
// setDataId("");
// onToggleNavbar(false);
// }
if (checkVoting) {
setIsAdminVoting_TriggerReview(false);
setVisible(false);
setDataId("");
onToggleNavbar(false);
onLoadCountNotif(true);
}
// return;
// }
return;
}
// ========================== VOTING ========================== //
// ========================== DONASI ========================== //
// if (data.kategoriApp == "DONASI") {
// setDataId(data.id);
if (data.kategoriApp == "DONASI") {
setDataId(data.id);
// const checkDonasi = await adminNotifikasi_findRouterDonasi({
// appId: data.appId,
// notifikasiId: data.id,
// router: router,
// status: data.status as ITypeStatusNotifikasi,
// onLoadCountNotif(val) {
// onLoadCountNotif(val);
// },
// onLoadDataNotifikasi(val) {
// onLoadDataNotifikasi(val);
// },
// onChangeNavbar(val) {
// onChangeNavbar({
// id: val.id,
// childId: val.childId,
// });
// },
// });
const checkDonasi = await adminNotifikasi_findRouterDonasi({
appId: data.appId,
notifikasiId: data.id,
router: router,
status: data.status as ITypeStatusNotifikasi,
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
// if (checkDonasi) {
// setIsAdminDonasi_TriggerReview(false);
// setVisible(false);
// setDataId("");
// onToggleNavbar(false);
// }
if (checkDonasi) {
setIsAdminDonasi_TriggerReview(false);
setVisible(false);
setDataId("");
onToggleNavbar(false);
onLoadCountNotif(true);
}
// return;
// }
return;
}
// ========================== DONASI ========================== //
// ========================== INVESTASI ========================== //
// if (data.kategoriApp == "INVESTASI") {
// setDataId(data.id);
if (data.kategoriApp == "INVESTASI") {
setDataId(data.id);
// const checkInvestasi = await adminNotifikasi_findRouterInvestasi({
// appId: data.appId,
// notifikasiId: data.id,
// status: data.status as ITypeStatusNotifikasi,
// router: router,
// onLoadCountNotif(val) {
// onLoadCountNotif(val);
// },
// onLoadDataNotifikasi(val) {
// onLoadDataNotifikasi(val);
// },
// onChangeNavbar(val) {
// onChangeNavbar({
// id: val.id,
// childId: val.childId,
// });
// },
// });
const checkInvestasi = await adminNotifikasi_findRouterInvestasi({
appId: data.appId,
notifikasiId: data.id,
status: data.status as ITypeStatusNotifikasi,
router: router,
onChangeNavbar(val) {
onChangeNavbar({
id: val.id,
childId: val.childId,
});
},
});
// if (checkInvestasi) {
// setIsAdminDonasi_TriggerReview(false);
// setVisible(false);
// setDataId("");
// onToggleNavbar(false);
// }
if (checkInvestasi) {
setIsAdminDonasi_TriggerReview(false);
setVisible(false);
setDataId("");
onToggleNavbar(false);
onLoadCountNotif(true);
}
// return;
// }
return;
}
// ========================== INVESTASI ========================== //
} catch (error) {
@@ -311,7 +296,7 @@ export default function Admin_V3_ComponentCardNotifikasi({
</Card.Section>
<Card.Section px={"sm"} pb={"sm"}>
<Stack spacing={0}>
<Text lineClamp={2} fw={"bold"} fz={"xs"}>
<Text lineClamp={2} fw={"bold"}>
{data.title}
</Text>
{/* <Text lineClamp={2} fz={"xs"}>

View File

@@ -31,6 +31,7 @@ export function Admin_V3_ViewDrawerNotifikasi({
openedDrawer,
onChangeNavbar,
onToggleNavbar,
onLoadCountNotif,
}: {
userLoginId: string;
openedDrawer: boolean;
@@ -39,6 +40,7 @@ export function Admin_V3_ViewDrawerNotifikasi({
childId: IAdmin_ActiveChildId;
}) => void;
onToggleNavbar: (val: any) => void;
onLoadCountNotif: (val: boolean) => void;
}) {
// newAdminNtf,
// listNotifikasi,
@@ -171,14 +173,14 @@ export function Admin_V3_ViewDrawerNotifikasi({
>
Tandai baca semua
</Button>
<Button
{/* <Button
radius={"xl"}
onClick={() => {
handleUpdateUnRead();
}}
>
Tandai belum baca
</Button>
</Button> */}
</Group>
<Divider color={MainColor.white}/>
@@ -206,7 +208,9 @@ export function Admin_V3_ViewDrawerNotifikasi({
activePage={activePage}
onChangeNavbar={(val) => onChangeNavbar(val)}
onToggleNavbar={(val) => onToggleNavbar(val)}
// onLoadCountNotif={(val) => onLoadCountNotif(val)}
onLoadCountNotif={(val) => {
onLoadCountNotif(val)
}}
// onLoadDataNotifikasi={(val) => setData(val)}
/>
)}