fix notifikasi admin
This commit is contained in:
46
src/app/api/admin/notifikasi/count/route.tsx
Normal file
46
src/app/api/admin/notifikasi/count/route.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
const method = request.method;
|
||||
if (method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId = searchParams.get("id");
|
||||
|
||||
const data = await prisma.notifikasi.count({
|
||||
where: {
|
||||
adminId: userId,
|
||||
userRoleId: "2",
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Data fetched successfully",
|
||||
data: data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error get count notifikasi", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Failed to get count notifikasi",
|
||||
data: null,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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"}>
|
||||
|
||||
@@ -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)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
export { apiGetNotifikasiByUserId, apiPostIsReadNotifikasi };
|
||||
export {
|
||||
apiGetNotifikasiByUserId,
|
||||
apiPostIsReadNotifikasi,
|
||||
apiGetCountNotifikasiByUserId,
|
||||
};
|
||||
|
||||
const apiGetNotifikasiByUserId = async ({
|
||||
page,
|
||||
@@ -80,4 +84,38 @@ const apiPostIsReadNotifikasi = async ({
|
||||
console.error("Error get all forum", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const apiGetCountNotifikasiByUserId = async ({id}: {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 response = await fetch(`/api/admin/notifikasi/count?id=${id}`, {
|
||||
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 count notifikasi admin", response.statusText, errorData);
|
||||
throw new Error(errorData?.message || "Failed to get count notifikasi admin");
|
||||
}
|
||||
|
||||
// Return the JSON response
|
||||
const data = await response.json();
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error("Error get count notifikasi admin", error);
|
||||
throw error; // Re-throw the error to handle it in the calling function
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,16 +13,12 @@ export default async function adminNotifikasi_findRouterDonasi({
|
||||
notifikasiId,
|
||||
status,
|
||||
router,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
status: ITypeStatusNotifikasi;
|
||||
router: AppRouterInstance;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
@@ -39,13 +35,6 @@ export default async function adminNotifikasi_findRouterDonasi({
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
const path = RouterAdminDonasi_OLD.detail_publish + appId;
|
||||
router.push(path, { scroll: false });
|
||||
onChangeNavbar({
|
||||
@@ -66,14 +55,6 @@ export default async function adminNotifikasi_findRouterDonasi({
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
|
||||
const path = `/dev/admin/donasi/sub-menu/${check.statusName}`;
|
||||
|
||||
if (check.statusName == "draft") {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
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";
|
||||
|
||||
@@ -10,17 +8,11 @@ export async function adminNotifikasi_findRouterEvent({
|
||||
appId,
|
||||
notifikasiId,
|
||||
router,
|
||||
activePage,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
router: AppRouterInstance;
|
||||
activePage: number;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
@@ -34,14 +26,6 @@ export async function adminNotifikasi_findRouterEvent({
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
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") {
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
import { ITypeStatusNotifikasi } from "@/lib/global_state";
|
||||
import { RouterAdminInvestasi } from "@/lib/router_admin/router_admin_investasi";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { ComponentAdminGlobal_NotifikasiPeringatan } from "../../_admin_global/admin_notifikasi/notifikasi_peringatan";
|
||||
import adminNotifikasi_countNotifikasi from "../fun/count/count_is_read";
|
||||
import { admin_funInvestasiCheckStatus } from "../fun/get/fun_investasi_check_status";
|
||||
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 { RouterAdminInvestasi } from "@/lib/router_admin/router_admin_investasi";
|
||||
|
||||
export default async function adminNotifikasi_findRouterInvestasi({
|
||||
appId,
|
||||
notifikasiId,
|
||||
status,
|
||||
router,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
status: ITypeStatusNotifikasi;
|
||||
router: AppRouterInstance;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
@@ -38,13 +32,6 @@ export default async function adminNotifikasi_findRouterInvestasi({
|
||||
notifId: notifikasiId,
|
||||
});
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
const path = RouterAdminInvestasi.detail_publish + appId;
|
||||
router.push(path, { scroll: false });
|
||||
|
||||
@@ -67,14 +54,6 @@ export default async function adminNotifikasi_findRouterInvestasi({
|
||||
});
|
||||
|
||||
if (udpateReadNotifikasi.status == 200) {
|
||||
const loadCountNotif = await adminNotifikasi_countNotifikasi();
|
||||
onLoadCountNotif(loadCountNotif);
|
||||
|
||||
const loadListNotifikasi = await adminNotifikasi_getByUserId({
|
||||
page: 1,
|
||||
});
|
||||
onLoadDataNotifikasi(loadListNotifikasi);
|
||||
|
||||
const path = `/dev/admin/investasi/sub-menu/${check.statusName}`;
|
||||
|
||||
if (check.statusName == "draft") {
|
||||
|
||||
@@ -12,17 +12,11 @@ export async function adminNotifikasi_findRouterVoting({
|
||||
appId,
|
||||
notifikasiId,
|
||||
router,
|
||||
activePage,
|
||||
onLoadCountNotif,
|
||||
onLoadDataNotifikasi,
|
||||
onChangeNavbar,
|
||||
}: {
|
||||
appId: string;
|
||||
notifikasiId: string;
|
||||
router: AppRouterInstance;
|
||||
activePage: number;
|
||||
onLoadCountNotif: (val: any) => void;
|
||||
onLoadDataNotifikasi: (val: any) => void;
|
||||
onChangeNavbar: (val: {
|
||||
id: IAdmin_ActivePage;
|
||||
childId: IAdmin_ActiveChildId;
|
||||
@@ -36,13 +30,6 @@ export async function adminNotifikasi_findRouterVoting({
|
||||
});
|
||||
|
||||
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}`;
|
||||
|
||||
|
||||
@@ -100,143 +100,143 @@ export default function AdminNotifikasi_ViewCardDrawer({
|
||||
|
||||
// ========================== 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,
|
||||
// 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);
|
||||
}
|
||||
// if (checkEvent) {
|
||||
// setIsAdminEvent_TriggerReview(false);
|
||||
// setVisible(false);
|
||||
// setDataId("");
|
||||
// onToggleNavbar(false);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
// ========================== EVENT ========================== //
|
||||
// return;
|
||||
// }
|
||||
// // ========================== EVENT ========================== //
|
||||
|
||||
// ========================== VOTING ========================== //
|
||||
// // ========================== 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,
|
||||
// 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);
|
||||
}
|
||||
// if (checkVoting) {
|
||||
// setIsAdminVoting_TriggerReview(false);
|
||||
// setVisible(false);
|
||||
// setDataId("");
|
||||
// onToggleNavbar(false);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
// ========================== VOTING ========================== //
|
||||
// return;
|
||||
// }
|
||||
// // ========================== VOTING ========================== //
|
||||
|
||||
// ========================== DONASI ========================== //
|
||||
// // ========================== 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,
|
||||
// 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);
|
||||
}
|
||||
// if (checkDonasi) {
|
||||
// setIsAdminDonasi_TriggerReview(false);
|
||||
// setVisible(false);
|
||||
// setDataId("");
|
||||
// onToggleNavbar(false);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
// return;
|
||||
// }
|
||||
|
||||
// ========================== DONASI ========================== //
|
||||
// // ========================== DONASI ========================== //
|
||||
|
||||
// ========================== INVESTASI ========================== //
|
||||
// // ========================== 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,
|
||||
// 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);
|
||||
}
|
||||
// if (checkInvestasi) {
|
||||
// setIsAdminDonasi_TriggerReview(false);
|
||||
// setVisible(false);
|
||||
// setDataId("");
|
||||
// onToggleNavbar(false);
|
||||
// }
|
||||
|
||||
return;
|
||||
}
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // FORUM
|
||||
// e?.kategoriApp === "FORUM" &&
|
||||
|
||||
Reference in New Issue
Block a user