From 8e8789aa2d01dbe3efe1e85a6208cb8656acc5ad Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Mon, 14 Apr 2025 12:03:14 +0800 Subject: [PATCH] fix header dashboard --- run.env.local.dev | 1 + run.env.start.local | 1 + run.env.strat.local | 0 src/app/api/admin/notifikasi/[id]/route.ts | 106 ++++++ src/app/api/admin/notifikasi/route.ts | 8 - src/app/dev/admin/layout.tsx | 1 - .../comp_button_user_circle.tsx | 216 ++++++++--- .../admin/_components_v3/main_layout.tsx | 70 +--- .../notifikasi/comp_card_notifikasi.tsx | 350 ++++++++++++++++++ .../notifikasi/view_drawer_notifikasi.tsx | 213 +++++++++++ .../fun/get/get_notifikasi_by_user_id.ts | 9 +- .../notifikasi/lib/api_fetch_notifikasi.ts | 83 +++++ .../admin/notifikasi/route_setting/job.ts | 20 +- .../admin/notifikasi/view_card_drawer.tsx | 48 +-- 14 files changed, 977 insertions(+), 149 deletions(-) create mode 100644 run.env.local.dev create mode 100644 run.env.start.local delete mode 100644 run.env.strat.local create mode 100644 src/app/api/admin/notifikasi/[id]/route.ts delete mode 100644 src/app/api/admin/notifikasi/route.ts create mode 100644 src/app_modules/admin/_components_v3/notifikasi/comp_card_notifikasi.tsx create mode 100644 src/app_modules/admin/_components_v3/notifikasi/view_drawer_notifikasi.tsx create mode 100644 src/app_modules/admin/notifikasi/lib/api_fetch_notifikasi.ts diff --git a/run.env.local.dev b/run.env.local.dev new file mode 100644 index 00000000..c23c65af --- /dev/null +++ b/run.env.local.dev @@ -0,0 +1 @@ +bun --env-file=.env.local run --bun dev -p 3005 \ No newline at end of file diff --git a/run.env.start.local b/run.env.start.local new file mode 100644 index 00000000..1fc5c96b --- /dev/null +++ b/run.env.start.local @@ -0,0 +1 @@ +bun --env-file=.env-local run --bun start -p 3000 \ No newline at end of file diff --git a/run.env.strat.local b/run.env.strat.local deleted file mode 100644 index e69de29b..00000000 diff --git a/src/app/api/admin/notifikasi/[id]/route.ts b/src/app/api/admin/notifikasi/[id]/route.ts new file mode 100644 index 00000000..f0595242 --- /dev/null +++ b/src/app/api/admin/notifikasi/[id]/route.ts @@ -0,0 +1,106 @@ +import { NextResponse } from "next/server"; +import prisma from "@/lib/prisma"; + +export { GET, POST }; +async function GET(request: Request, { params }: { params: { id: string } }) { + try { + let fixData; + const { id } = params; + const userLoginId = id; + + if (!id) { + return NextResponse.json( + { success: false, message: "ID not provided" }, + { status: 400 } + ); + } + + const { searchParams } = new URL(request.url); + const page = searchParams.get("page"); + const takeData = 10; + const skipData = Number(page) * takeData - takeData; + + if (!page) { + fixData = await prisma.notifikasi.findMany({ + orderBy: [ + { + isRead: "asc", + }, + { + createdAt: "desc", + }, + ], + where: { + adminId: userLoginId, + userRoleId: "2", + }, + }); + } else { + fixData = await prisma.notifikasi.findMany({ + take: takeData, + skip: skipData, + orderBy: [ + { + isRead: "asc", + }, + { + createdAt: "desc", + }, + ], + where: { + adminId: id, + userRoleId: "2", + }, + }); + } + + return NextResponse.json({ + success: true, + message: "Data fetched successfully", + data: fixData, + }); + } catch (error) { + console.error("Error fetching notifications:", error); + return NextResponse.json( + { success: false, message: "Failed to fetch notifications" }, + { status: 500 } + ); + } +} + +async function POST(request: Request, { params }: { params: { id: string } }) { + try { + const { id } = params; + const userLoginId = id; + + if (!id) { + return NextResponse.json( + { success: false, message: "ID not provided" }, + { status: 400 } + ); + } + + const data = await request.json(); + + const updatedData = await prisma.notifikasi.updateMany({ + where: { + adminId: userLoginId, + }, + data: { + isRead: data.isRead, + }, + }); + + return NextResponse.json({ + success: true, + message: "Notification updated successfully", + data: updatedData, + }); + } catch (error) { + console.error("Error updating notification:", error); + return NextResponse.json( + { success: false, message: "Failed to update notification" }, + { status: 500 } + ); + } +} diff --git a/src/app/api/admin/notifikasi/route.ts b/src/app/api/admin/notifikasi/route.ts deleted file mode 100644 index 4847fb76..00000000 --- a/src/app/api/admin/notifikasi/route.ts +++ /dev/null @@ -1,8 +0,0 @@ -import adminNotifikasi_getByUserId from "@/app_modules/admin/notifikasi/fun/get/get_notifikasi_by_user_id"; -import { NextRequest, NextResponse } from "next/server"; - -export async function GET(req: NextRequest) { - - - return NextResponse.json({ success: true }); -} diff --git a/src/app/dev/admin/layout.tsx b/src/app/dev/admin/layout.tsx index d3654286..bbbd7411 100644 --- a/src/app/dev/admin/layout.tsx +++ b/src/app/dev/admin/layout.tsx @@ -38,7 +38,6 @@ export default async function Layout({ {children} diff --git a/src/app_modules/admin/_components_v3/comp_button_user_circle.tsx b/src/app_modules/admin/_components_v3/comp_button_user_circle.tsx index 30c0ab7d..a75a6191 100644 --- a/src/app_modules/admin/_components_v3/comp_button_user_circle.tsx +++ b/src/app_modules/admin/_components_v3/comp_button_user_circle.tsx @@ -10,6 +10,7 @@ import { Center, Divider, Group, + MediaQuery, Popover, SimpleGrid, Stack, @@ -18,6 +19,7 @@ import { } from "@mantine/core"; import { IconBell, + IconDotsVertical, IconHierarchy2, IconLogout, IconReplaceUser, @@ -27,6 +29,8 @@ import { import { useRouter } from "next/navigation"; import { useState } from "react"; import { Admin_ComponentModal } from "../_admin_global/_component/comp_admin_modal"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { ComponentAdminGlobal_NotifikasiPeringatan } from "../_admin_global/admin_notifikasi/notifikasi_peringatan"; export function Admin_V3_ComponentButtonUserCircle({ dataUser, @@ -43,20 +47,24 @@ export function Admin_V3_ComponentButtonUserCircle({ // setNavbarOpen: (open: boolean) => void; setDrawerNotifikasi: React.Dispatch>; // setDrawerNotifikasi: (open: boolean) => void; - }) { const router = useRouter(); - const [isOpenMenuUser, setOpenMenuUser] = useState(false); - // const [openPop, setOpenPop] = useState(false); + + // STATE DESKTOP VIEW + const [dks_opened, setDksOpened] = useState(false); + + // STATE MOBILE VIEW const [openModalLogout, setOpenModalLogout] = useState(false); const [openModalReplaceUser, setOpenModalReplaceUser] = useState(false); const [loadingLogout, setLoadingLogout] = useState(false); const [loadingReplaceUser, setLoadingReplaceUser] = useState(false); - const listMenu = [ + const listMenuMobile = [ { icon: IconUser, label: dataUser?.username, + color: "", + onClick: () => {}, }, { icon: IconHierarchy2, @@ -66,15 +74,48 @@ export function Admin_V3_ComponentButtonUserCircle({ : dataUser?.masterUserRoleId == "3" ? "Super Admin" : "", + color: "", + onClick: () => {}, }, - ]; - - const listAction = [ { icon: IconBell, label: "Notifikasi", color: "", - onClick: () => setDrawerNotifikasi(true), + onClick: () => { + ComponentAdminGlobal_NotifikasiPeringatan( + "Notifikasi: Masih dalam pengembangan", + 2000 + ); + // setDrawerNotifikasi(true); + }, + }, + { + icon: IconReplaceUser, + label: "Tampilan user", + color: "", + onClick: () => setOpenModalReplaceUser(true), + }, + { + icon: IconLogout, + label: "Logout", + color: "red", + onClick: () => setOpenModalLogout(true), + }, + ]; + + const listMenuDekstop = [ + { + icon: IconBell, + label: "Notifikasi", + color: "", + onClick: () => { + ComponentAdminGlobal_NotifikasiPeringatan( + "Notifikasi: Masih dalam pengembangan", + 2000 + ); + + // setDrawerNotifikasi(true); + }, }, { icon: IconReplaceUser, @@ -103,50 +144,129 @@ export function Admin_V3_ComponentButtonUserCircle({ } } - return ( - <> - - - { - setOpenPop((o) => !o); - setNavbarOpen(false); + const PopoverButton = () => { + return ( + <> + + +
+ + { + setOpenPop((o) => !o); + setNavbarOpen(false); + }} + > + + + + + + + + + + {!dataUser?.username ? ( + + ) : ( + dataUser?.username + )} + {" "} + + + {!dataUser?.username ? ( + + ) : dataUser?.masterUserRoleId == "2" ? ( + "Admin" + ) : dataUser?.masterUserRoleId == "3" ? ( + "Super Admin" + ) : ( + "" + )} + {" "} + + { + setOpenPop((o) => !o); + setNavbarOpen(false); + }} + > + + + + +
+
+ + - -
-
+ {/* */} + + {/* Mobile View */} + <> + {listMenuMobile.map((e, i) => ( + + + + + {e.label} + + + + ))} + + {/* Mobile View */} - - - {listMenu.map((e, i) => ( - - - {e.label} - - ))} + {/* Desktop View */} + <> + {listMenuDekstop.map((e, i) => ( + + + + + {e.label} + + + + ))} + + {/* Desktop View */} - + + + +
+ + ); + }; - - {listAction.map((e, i) => ( -
- - - -
- ))} -
- - - + return ( + <> + { router.push("/dev/home", { scroll: false }); - setLoadingReplaceUser(true) + setLoadingReplaceUser(true); }} > Ke Tampilan User diff --git a/src/app_modules/admin/_components_v3/main_layout.tsx b/src/app_modules/admin/_components_v3/main_layout.tsx index 2aa70eb2..29ca047f 100644 --- a/src/app_modules/admin/_components_v3/main_layout.tsx +++ b/src/app_modules/admin/_components_v3/main_layout.tsx @@ -38,26 +38,24 @@ import { } from "../_admin_global/new_global_state"; 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"; export function Admin_V3_MainLayout({ children, userLoginId, countNotifikasi, - listNotifikasi, + version, }: { children: React.ReactNode; userLoginId: string; countNotifikasi: number; - listNotifikasi: MODEL_NOTIFIKASI[]; version: string; }) { const [dataUser, setDataUser] = useState(null); const userRoleId = dataUser?.masterUserRoleId; const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu); const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu); - const [dataNotifikasi, setDataNotifikasi] = - useState(listNotifikasi); // Notifikasi const [countNtf, setCountNtf] = useState(countNotifikasi); @@ -78,26 +76,13 @@ export function Admin_V3_MainLayout({ } } catch (error) { console.error("Error fetching user data", error); + setDataUser(null); } } const [openPop, setOpenPop] = useState(false); const [opened, handlers] = useDisclosure(false); const [openedDrawer, handlersDrawer] = useDisclosure(false); - const pathname = usePathname(); - const navLinks = [ - { icon: IconHome, label: "Home", path: "/" }, - { icon: IconBriefcase, label: "Portfolio", path: "/portfolio" }, - { icon: IconUser, label: "About Me", path: "/about" }, - { icon: IconCoin, label: "Price List", path: "/pricing" }, - { icon: IconMessage, label: "Contact", path: "/contact" }, - ]; - - const isActive = (path: string) => { - if (path === "/" && pathname === "/") return true; - if (path !== "/" && pathname.startsWith(path)) return true; - return false; - }; return ( <> @@ -146,41 +131,6 @@ export function Admin_V3_MainLayout({ - - {/* - - {navLinks.map((link) => ( - { - // if ( - // typeof window !== "undefined" && - // window.innerWidth < theme.breakpoints.md - // ) { - // close(); - // } - // }} - > - - - {link.label} - - - ))} - - */} } header={ @@ -197,7 +147,7 @@ export function Admin_V3_MainLayout({ - HIMPI DASHBOARD + HIPMI DASHBOARD - On Maintenance . . . + { + setActiveId(val.id as any); + setActiveChildId(val.childId); + }} + onToggleNavbar={(val: any) => { + handlersDrawer.close + }} + /> {/* void; + onToggleNavbar: (val: any) => void; + // onLoadCountNotif: (val: any) => void; + // onLoadDataNotifikasi: (val: any) => void; +}) { + const router = useRouter(); + const [visible, setVisible] = useState(false); + const [dataId, setDataId] = useState(""); + + // Realtime + const [isAdminJob_TriggerReview, setIsAdminJob_TriggerReview] = useAtom( + gs_adminJob_triggerReview + ); + const [isAdminEvent_TriggerReview, setIsAdminEvent_TriggerReview] = useAtom( + gs_adminEvent_triggerReview + ); + const [isAdminVoting_TriggerReview, setIsAdminVoting_TriggerReview] = useAtom( + gs_adminVoting_triggerReview + ); + const [isAdminDonasi_TriggerReview, setIsAdminDonasi_TriggerReview] = useAtom( + gs_adminDonasi_triggerReview + ); + + async function onRead() { + // ========================== JOB ========================== // + try { + setVisible(true); + + if (data?.kategoriApp === "JOB") { + setDataId(data.id); + + const checkJob = await adminNotifikasi_findRouterJob({ + 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) { + setIsAdminJob_TriggerReview(false); + setVisible(false); + setDataId(""); + onToggleNavbar(false); + } + + return; + } + // ========================== JOB ========================== // + + // ========================== EVENT ========================== // + + // 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, + // }); + // }, + // }); + + // if (checkEvent) { + // setIsAdminEvent_TriggerReview(false); + // setVisible(false); + // setDataId(""); + // onToggleNavbar(false); + // } + + // return; + // } + // ========================== EVENT ========================== // + + // ========================== VOTING ========================== // + + // 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, + // }); + // }, + // }); + + // if (checkVoting) { + // setIsAdminVoting_TriggerReview(false); + // setVisible(false); + // setDataId(""); + // onToggleNavbar(false); + // } + + // return; + // } + // ========================== VOTING ========================== // + + // ========================== DONASI ========================== // + + // 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, + // }); + // }, + // }); + + // if (checkDonasi) { + // setIsAdminDonasi_TriggerReview(false); + // setVisible(false); + // setDataId(""); + // onToggleNavbar(false); + // } + + // return; + // } + + // ========================== DONASI ========================== // + + // ========================== INVESTASI ========================== // + + // 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, + // }); + // }, + // }); + + // if (checkInvestasi) { + // setIsAdminDonasi_TriggerReview(false); + // setVisible(false); + // setDataId(""); + // onToggleNavbar(false); + // } + + // return; + // } + + // // FORUM + // e?.kategoriApp === "FORUM" && + // adminNotifikasi_findRouterForum({ + // data: e, + // router: router, + // onChangeNavbar(val) { + // onChangeNavbar(val); + // }, + // onToggleNavbar(val) { + // onToggleNavbar(val); + // }, + // }); + } catch (error) { + clientLogger.error("Error notifikasi function", error); + } finally { + setVisible(false); + } + } + + return ( + <> + { + onRead(); + }} + > + + + + + + + {data.kategoriApp} + + + {data.status ? ( + + {data.status} + + ) : ( + "" + )} + + + + + + + + {data.title} + + + {data.pesan} + + + + + + + {moment(data.createdAt).format("LLL")} + + {/* + {new Intl.DateTimeFormat("id-ID", { + dateStyle: "long", + }).format(data.createdAt)} + + + {", "} + {new Intl.DateTimeFormat("id-ID", { + timeStyle: "short", + }).format(data.createdAt)} + + */} + {data.isRead ? ( + + + Sudah dilihat + + ) : ( + + + Belum dilihat + + )} + + {visible && dataId === data.id && ( + + )} + + + + ); +} diff --git a/src/app_modules/admin/_components_v3/notifikasi/view_drawer_notifikasi.tsx b/src/app_modules/admin/_components_v3/notifikasi/view_drawer_notifikasi.tsx new file mode 100644 index 00000000..9e3e9180 --- /dev/null +++ b/src/app_modules/admin/_components_v3/notifikasi/view_drawer_notifikasi.tsx @@ -0,0 +1,213 @@ +import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface"; +import { + Box, + Button, + Center, + Group, + Loader, + Paper, + Stack, + Text, +} from "@mantine/core"; +import { useShallowEffect } from "@mantine/hooks"; +import _ from "lodash"; +import { ScrollOnly } from "next-scroll-loader"; +import adminNotifikasi_getByUserId from "../../notifikasi/fun/get/get_notifikasi_by_user_id"; +import { useState } from "react"; +import { + apiGetNotifikasiByUserId, + apiPostIsReadNotifikasi, +} from "../../notifikasi/lib/api_fetch_notifikasi"; +import AdminNotifikasi_ViewCardDrawer from "../../notifikasi/view_card_drawer"; +import Admin_V3_ComponentCardNotifikasi from "./comp_card_notifikasi"; +import CustomSkeleton from "@/app_modules/components/CustomSkeleton"; +import { + IAdmin_ActivePage, + IAdmin_ActiveChildId, +} from "../../notifikasi/route_setting/type_of_select_page"; + +export function Admin_V3_ViewDrawerNotifikasi({ + userLoginId, + openedDrawer, + onChangeNavbar, + onToggleNavbar, +}: { + userLoginId: string; + openedDrawer: boolean; + onChangeNavbar: (val: { + id: IAdmin_ActivePage; + childId: IAdmin_ActiveChildId; + }) => void; + onToggleNavbar: (val: any) => void; +}) { + // newAdminNtf, + // listNotifikasi, + // onChangeNavbar, + + // }: { + // newAdminNtf: number; + // listNotifikasi: MODEL_NOTIFIKASI[]; + // onChangeNavbar: (val: { + // id: IAdmin_ActivePage; + // childId: IAdmin_ActiveChildId; + // }) => void; + + const [data, setData] = useState(null); + const [activePage, setActivePage] = useState(1); + + // Action Button + const [isRead, setIsRead] = useState(false); + const [isUnRead, setIsUnRead] = useState(false); + + useShallowEffect(() => { + if (openedDrawer || isRead || isUnRead) { + handleLoadtData(); + } + }, [openedDrawer, isRead, isUnRead]); + + async function handleLoadtData() { + try { + const response = await apiGetNotifikasiByUserId({ + id: userLoginId, + page: `${activePage}`, + }); + if (response && response.success) { + setData(response.data); + setIsRead(false); + setIsUnRead(false); + } else { + console.error("Failed to fetch user data", response); + setData(null); + } + } catch (error) { + console.error("Error fetching data:", error); + setData(null); + } + } + + async function handleMoreData() { + try { + const nextPage = activePage + 1; + const response = await apiGetNotifikasiByUserId({ + id: userLoginId, + page: `${nextPage}`, + }); + if (response && response.success) { + setActivePage(nextPage); + return response.data; + } else { + console.error("Failed to fetch user data", response); + return null; + } + } catch (error) { + console.error("Error fetching data:", error); + return null; + } + } + + async function handleUpdateReadAll() { + try { + const response = await apiPostIsReadNotifikasi({ + id: userLoginId, + isRead: true, + }); + if (response && response.success) { + console.log("Berhasil tandai baca semua"); + setIsRead(true); + } else { + console.error("Failed to update notification", response); + return null; + } + } catch (error) { + console.error("Error updating notification:", error); + return null; + } + } + + async function handleUpdateUnRead() { + try { + const response = await apiPostIsReadNotifikasi({ + id: userLoginId, + isRead: false, + }); + if (response && response.success) { + console.log("Berhasil tandai belum baca"); + setIsUnRead(true); + } else { + console.error("Failed to update notification", response); + return null; + } + } catch (error) { + console.error("Error updating notification:", error); + return null; + } + } + + if (!data) { + return ( + <> + + {Array.from({ length: 3 }, (_, i) => ( + + ))} + + + ); + } + + return ( + <> + + + + + + + {_.isEmpty(data) ? ( +
+ + Tidak ada notifikasi + +
+ ) : ( + ( +
+ +
+ )} + data={data} + setData={setData as any} + moreData={handleMoreData} + > + {(item) => ( + onChangeNavbar(val)} + onToggleNavbar={(val) => onToggleNavbar(val)} + // onLoadCountNotif={(val) => onLoadCountNotif(val)} + // onLoadDataNotifikasi={(val) => setData(val)} + /> + )} +
+ )} +
+ + ); +} diff --git a/src/app_modules/admin/notifikasi/fun/get/get_notifikasi_by_user_id.ts b/src/app_modules/admin/notifikasi/fun/get/get_notifikasi_by_user_id.ts index a87bd7ed..1b1f7cb3 100644 --- a/src/app_modules/admin/notifikasi/fun/get/get_notifikasi_by_user_id.ts +++ b/src/app_modules/admin/notifikasi/fun/get/get_notifikasi_by_user_id.ts @@ -3,10 +3,13 @@ import prisma from "@/lib/prisma"; import { funGetUserIdByToken } from "@/app_modules/_global/fun/get"; -export default async function adminNotifikasi_getByUserId({page}: {page: number}) { +export default async function adminNotifikasi_getByUserId({ + page, +}: { + page: number; +}) { const userLoginId = await funGetUserIdByToken(); - const takeData = 10; const skipData = page * takeData - takeData; @@ -26,6 +29,6 @@ export default async function adminNotifikasi_getByUserId({page}: {page: number} userRoleId: "2", }, }); - + return data; } diff --git a/src/app_modules/admin/notifikasi/lib/api_fetch_notifikasi.ts b/src/app_modules/admin/notifikasi/lib/api_fetch_notifikasi.ts new file mode 100644 index 00000000..28c68235 --- /dev/null +++ b/src/app_modules/admin/notifikasi/lib/api_fetch_notifikasi.ts @@ -0,0 +1,83 @@ +export { apiGetNotifikasiByUserId, apiPostIsReadNotifikasi }; + +const apiGetNotifikasiByUserId = async ({ + page, + id, +}: { + page?: string; + id: string; +}) => { + try { + // Fetch token from cookie + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) { + console.error("No token found"); + return null; + } + + const isPage = page ? `?page=${page}` : ""; + const response = await fetch(`/api/admin/notifikasi/${id}${isPage}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + }); + + // Check if the response is OK + if (!response.ok) { + const errorData = await response.json().catch(() => null); + console.error("Failed to get notifikasi admin", response.statusText, errorData); + throw new Error(errorData?.message || "Failed to get notifikasi admin"); + } + + // Return the JSON response + const data = await response.json(); + return data + } catch (error) { + console.error("Error get all forum", error); + throw error; // Re-throw the error to handle it in the calling function + } +}; + +const apiPostIsReadNotifikasi = async ({ + id, + isRead, +}: { + id: string; + isRead: boolean; +}) => { + try { + // Fetch token from cookie + const { token } = await fetch("/api/get-cookie").then((res) => res.json()); + if (!token) { + console.error("No token found"); + return null; + } + + const response = await fetch(`/api/admin/notifikasi/${id}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + Authorization: `Bearer ${token}`, + }, + body: JSON.stringify({ isRead }), + }); + + // Check if the response is OK + if (!response.ok) { + const errorData = await response.json().catch(() => null); + console.error("Failed to post notifikasi admin", response.statusText, errorData); + throw new Error(errorData?.message || "Failed to post notifikasi admin"); + } + + // Return the JSON response + const data = await response.json(); + return data + } catch (error) { + console.error("Error get all forum", error); + throw error; // Re-throw the error to handle it in the calling function + } +}; \ No newline at end of file diff --git a/src/app_modules/admin/notifikasi/route_setting/job.ts b/src/app_modules/admin/notifikasi/route_setting/job.ts index ace989d4..e601220b 100644 --- a/src/app_modules/admin/notifikasi/route_setting/job.ts +++ b/src/app_modules/admin/notifikasi/route_setting/job.ts @@ -12,16 +12,16 @@ export async function adminNotifikasi_findRouterJob({ notifikasiId, router, activePage, - onLoadCountNotif, - onLoadDataNotifikasi, + // onLoadCountNotif, + // onLoadDataNotifikasi , onChangeNavbar, }: { appId: string; notifikasiId: string; router: AppRouterInstance; activePage: number; - onLoadCountNotif: (val: any) => void; - onLoadDataNotifikasi: (val: any) => void; + // onLoadCountNotif: (val: any) => void; + // onLoadDataNotifikasi: (val: any) => void; onChangeNavbar: (val: { id: IAdmin_ActivePage; childId: IAdmin_ActiveChildId; @@ -35,13 +35,13 @@ export async function adminNotifikasi_findRouterJob({ }); if (udpateReadNotifikasi.status == 200) { - const loadCountNotif = await adminNotifikasi_countNotifikasi(); - onLoadCountNotif(loadCountNotif); + // const loadCountNotif = await adminNotifikasi_countNotifikasi(); + // onLoadCountNotif(loadCountNotif); - const loadListNotifikasi = await adminNotifikasi_getByUserId({ - page: 1, - }); - onLoadDataNotifikasi(loadListNotifikasi); + // const loadListNotifikasi = await adminNotifikasi_getByUserId({ + // page: 1, + // }); + // onLoadDataNotifikasi(loadListNotifikasi); const path = `/dev/admin/job/child/${check.statusName}`; diff --git a/src/app_modules/admin/notifikasi/view_card_drawer.tsx b/src/app_modules/admin/notifikasi/view_card_drawer.tsx index 65a8c7e0..b613f078 100644 --- a/src/app_modules/admin/notifikasi/view_card_drawer.tsx +++ b/src/app_modules/admin/notifikasi/view_card_drawer.tsx @@ -68,31 +68,31 @@ export default function AdminNotifikasi_ViewCardDrawer({ if (data?.kategoriApp === "JOB") { setDataId(data.id); - const checkJob = await adminNotifikasi_findRouterJob({ - 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 checkJob = await adminNotifikasi_findRouterJob({ + // 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) { - setIsAdminJob_TriggerReview(false); - setVisible(false); - setDataId(""); - onToggleNavbar(false); - } + // if (checkJob) { + // setIsAdminJob_TriggerReview(false); + // setVisible(false); + // setDataId(""); + // onToggleNavbar(false); + // } return; }