Deskripsi:
- Fix notifikasi admi to user
- Fix count notifikasi di admin dan user
## No Issue
This commit is contained in:
2024-11-11 17:02:42 +08:00
parent a6548f7b36
commit aa612d24bc
42 changed files with 1114 additions and 765 deletions

View File

@@ -0,0 +1,75 @@
import { AccentColor } from "@/app_modules/_global/color";
import { MODEL_USER } from "@/app_modules/home/model/interface";
import { Menu, ActionIcon, Stack, Grid, Center, Text } from "@mantine/core";
import { IconUserCircle, IconUser, IconPhone } from "@tabler/icons-react";
import { useState } from "react";
import Admin_Logout from "../logout";
export function Admin_ComponentButtonUserCircle({ dataUser }: { dataUser: MODEL_USER }) {
const [isOpenMenuUser, setOpenMenuUser] = useState(false);
return (
<>
<Menu
withArrow
arrowPosition="center"
opened={isOpenMenuUser}
onChange={setOpenMenuUser}
shadow="md"
width={250}
position="bottom-start"
styles={{
dropdown: {
backgroundColor: AccentColor.blue,
border: `1px solid ${AccentColor.skyblue}`,
},
item: {
color: "white",
":hover": {
backgroundColor: "gray",
},
},
arrow: {
borderTopColor: AccentColor.skyblue,
borderLeftColor: AccentColor.skyblue,
},
}}
>
<Menu.Target>
<ActionIcon variant="transparent" onClick={() => console.log("test")}>
<IconUserCircle color="white" />
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Stack spacing={5} px={"xs"}>
<Menu.Item>
<Grid>
<Grid.Col span={2}>
<IconUser />
</Grid.Col>
<Grid.Col span={"auto"}>
<Text lineClamp={1}>{dataUser.username}</Text>
</Grid.Col>
</Grid>
</Menu.Item>
<Menu.Item>
<Grid>
<Grid.Col span={2}>
<IconPhone />
</Grid.Col>
<Grid.Col span={"auto"}>
<Text lineClamp={1}>+{dataUser.nomor}</Text>
</Grid.Col>
</Grid>
</Menu.Item>
<Menu.Divider />
<Center py={"xs"}>
<Admin_Logout />
</Center>
</Stack>
</Menu.Dropdown>
</Menu>
</>
);
}

View File

@@ -0,0 +1,203 @@
import { MainColor } from "@/app_modules/_global/color";
import { Box, NavLink, Text } from "@mantine/core";
import { IconCircleDot, IconCircleDotFilled } from "@tabler/icons-react";
import { useAtom } from "jotai";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { newListAdminPage } from "../../new_list_page";
import { gs_admin_navbar_isActive_dropdown } from "../new_global_state";
export default function Admin_UiNavbar({
userRoleId,
activeId,
activeChildId,
setActiveId,
setActiveChildId,
}: {
userRoleId: string;
activeId: string;
activeChildId: string;
setActiveId: (val: any) => void;
setActiveChildId: (val: any) => void;
}) {
const router = useRouter();
// global state
const [openDropdown, setOpenDropdown] = useAtom(
gs_admin_navbar_isActive_dropdown
);
// const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu);
// const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu);
// Kalau fix developer navbar, fix juga navbar admin, dan berlaku sebaliknya
const developerNavbar = newListAdminPage.map((parent) => (
<Box key={parent.id}>
<NavLink
opened={openDropdown && activeId === parent.id}
styles={{
icon: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
label: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeId === parent.id ? "bold" : "normal"}
label={<Text>{parent.name}</Text>}
icon={parent.icon}
onClick={() => {
setActiveId(parent.id);
setActiveChildId("");
parent.path == "" ? setActiveChildId(parent.child[0].id) : "";
parent.path == ""
? router.push(parent.child[0].path)
: router.push(parent.path);
openDropdown && activeId === parent.id
? setOpenDropdown(false)
: setOpenDropdown(true);
}}
// active={activeId === parent.id}
>
{/* Navlink Children */}
{!_.isEmpty(parent.child) &&
parent.child.map((child) => (
<Box key={child.id}>
<NavLink
styles={{
icon: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
label: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeChildId === child.id ? "bold" : "normal"}
label={<Text>{child.name}</Text>}
icon={
activeChildId === child.id ? (
<IconCircleDotFilled size={10} />
) : (
<IconCircleDot size={10} />
)
}
onClick={() => {
setActiveChildId(child.id);
router.push(child.path);
}}
active={activeId === child.id}
/>
</Box>
))}
</NavLink>
</Box>
));
const bukanDeveloper = newListAdminPage.slice(0, -1);
const adminNavbar = bukanDeveloper.map((parent) => (
<Box key={parent.id}>
<NavLink
opened={openDropdown && activeId === parent.id}
styles={{
icon: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
label: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeId === parent.id ? "bold" : "normal"}
label={<Text>{parent.name}</Text>}
icon={parent.icon}
onClick={() => {
setActiveId(parent.id);
setActiveChildId("");
parent.path == "" ? setActiveChildId(parent.child[0].id) : "";
parent.path == ""
? router.push(parent.child[0].path)
: router.push(parent.path);
openDropdown && activeId === parent.id
? setOpenDropdown(false)
: setOpenDropdown(true);
}}
// active={activeId === parent.id}
>
{/* Navlink Children */}
{!_.isEmpty(parent.child) &&
parent.child.map((child) => (
<Box key={child.id}>
<NavLink
styles={{
icon: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
label: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeChildId === child.id ? "bold" : "normal"}
label={<Text>{child.name}</Text>}
icon={
activeChildId === child.id ? (
<IconCircleDotFilled size={10} />
) : (
<IconCircleDot size={10} />
)
}
onClick={() => {
setActiveChildId(child.id);
router.push(child.path);
}}
active={activeId === child.id}
/>
</Box>
))}
</NavLink>
</Box>
));
return userRoleId == "2" ? adminNavbar : developerNavbar;
}

View File

@@ -1,5 +1,8 @@
import { Admin_ComponentLoadImageLandscape } from "./_component/comp_admin_load_image";
import { Admin_ComponentSkeletonNavbar } from "./_component/comp_admin_skeleton_navbar";
import { Admin_ComponentButtonUserCircle } from "./_component/comp_button_user_on_navbar";
import Admin_UiNavbar from "./_ui/ui_navbar_admin";
export { Admin_ComponentLoadImageLandscape, Admin_ComponentSkeletonNavbar };
export { Admin_UiNavbar };
export {Admin_ComponentButtonUserCircle}

View File

@@ -36,6 +36,8 @@ import { useState } from "react";
import { AdminJob_funEditCatatanById } from "../../fun/edit/fun_edit_catatan_by_id";
import { AdminJob_funEditStatusPublishById } from "../../fun/edit/fun_edit_status_publish_by_id";
import adminJob_getListReview from "../../fun/get/get_list_review";
import { IRealtimeData } from "@/app/lib/global_state";
import { WibuRealtime } from "wibu-pkg";
export default function AdminJob_TableReview({
dataReview,
@@ -334,7 +336,7 @@ async function onPublish({
const loadData = await adminJob_getListReview({ page: 1 });
onLoadData(loadData);
const dataNotif = {
const dataNotifikasi: IRealtimeData = {
appId: publish.data?.id as any,
status: publish.data?.MasterStatus?.name as any,
userId: publish.data?.authorId as any,
@@ -343,20 +345,16 @@ async function onPublish({
title: "Job publish",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
const createNotifikasi = await adminNotifikasi_funCreateToUser({
data: dataNotifikasi as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: publish?.data?.authorId, count: 1 })
);
mqtt_client.publish(
"Job_new_post",
JSON.stringify({ isNewPost: true, count: 1 })
);
if (createNotifikasi.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
ComponentGlobal_NotifikasiBerhasil(publish.message);
@@ -382,24 +380,34 @@ async function onReject({
ComponentGlobal_NotifikasiBerhasil(reject.message);
const dataNotif = {
// const dataNotif = {
// appId: reject.data?.id as any,
// status: reject.data?.MasterStatus?.name as any,
// userId: reject.data?.authorId as any,
// pesan: reject.data?.title as any,
// kategoriApp: "JOB",
// title: "Job anda ditolak !",
// };
const dataNotifikasi: IRealtimeData = {
appId: reject.data?.id as any,
status: reject.data?.MasterStatus?.name as any,
userId: reject.data?.authorId as any,
pesan: reject.data?.title as any,
kategoriApp: "JOB",
title: "Job anda ditolak !",
title: "Job reject",
};
const notif = await adminNotifikasi_funCreateToUser({
data: dataNotif as any,
const createRejectNotifikasi = await adminNotifikasi_funCreateToUser({
data: dataNotifikasi as any,
});
if (notif.status === 201) {
mqtt_client.publish(
"USER",
JSON.stringify({ userId: dataNotif.userId, count: 1 })
);
if (createRejectNotifikasi.status === 201) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
}
} else {
ComponentGlobal_NotifikasiGagal(reject.message);

View File

@@ -326,7 +326,7 @@ export default function AdminLayout({
position="right"
size={"xs"}
>
<ComponentAdmin_UIDrawerNotifikasi
{/* <ComponentAdmin_UIDrawerNotifikasi
data={dataNotif}
onLoadReadNotif={(val: any) => {
setDataNotif(val);
@@ -339,7 +339,7 @@ export default function AdminLayout({
onLoadCountNotif={(val: any) => {
setCountNotif(val);
}}
/>
/> */}
</Drawer>
</>
);

View File

@@ -1,62 +1,74 @@
"use client";
import { gs_admin_ntf } from "@/app/lib/global_state";
import {
ActionIcon,
AppShell,
Box,
Center,
Divider,
Drawer,
Grid,
Group,
Menu,
Indicator,
Navbar,
NavLink,
ScrollArea,
Stack,
Text,
Title,
} from "@mantine/core";
import { useMediaQuery } from "@mantine/hooks";
import {
IconBell,
IconCircleDot,
IconCircleDotFilled,
IconPhone,
IconUser,
IconUserCircle,
} from "@tabler/icons-react";
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
import { IconBell } from "@tabler/icons-react";
import { useAtom } from "jotai";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { AccentColor, MainColor } from "../_global/color";
import { AccentColor } from "../_global/color";
import { MODEL_USER } from "../home/model/interface";
import Admin_Logout from "./_admin_global/logout";
import { MODEL_NOTIFIKASI } from "../notifikasi/model/interface";
import {
Admin_ComponentButtonUserCircle,
Admin_ComponentSkeletonNavbar,
Admin_UiNavbar,
} from "./_admin_global";
import {
gs_admin_navbar_isActive_dropdown,
gs_admin_navbar_menu,
gs_admin_navbar_subMenu,
} from "./_admin_global/new_global_state";
import { newListAdminPage } from "./new_list_page";
import adminNotifikasi_getByUserId from "./notifikasi/fun/get/get_notifikasi_by_user_id";
import { ComponentAdmin_UIDrawerNotifikasi } from "./notifikasi/ui_drawer_notifikasi";
import { Admin_ComponentSkeletonNavbar } from "./_admin_global";
export function Admin_NewLayout({
children,
user,
countNotifikasi,
listNotifikasi,
}: {
children: React.ReactNode;
user: MODEL_USER;
countNotifikasi: number;
listNotifikasi: MODEL_NOTIFIKASI[];
}) {
const matches = useMediaQuery("(min-width: 1024px)");
const [dataUser, setDataUser] = useState(user);
const userRoleId = dataUser.masterUserRoleId;
const [opened, setOpened] = useState(false);
const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu);
const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu);
const [dataNotifikasi, setDataNotifikasi] =
useState<MODEL_NOTIFIKASI[]>(listNotifikasi);
// Notifikasi
const [isDrawerNotifikasi, setDrawerNotifikasi] = useState(false);
const [isNavbarOpen, setIsNavbarOpen] = useState(false);
const [countNtf, setCountNtf] = useState(countNotifikasi);
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
useShallowEffect(() => {
setCountNtf((e) => e + newAdminNtf), setNewAdminNtf(0);
}, [newAdminNtf, setNewAdminNtf]);
async function onLoadListNotifikasi() {
const loadNotifikasi = await adminNotifikasi_getByUserId();
setDataNotifikasi(loadNotifikasi as []);
setDrawerNotifikasi(true);
}
return (
<>
@@ -65,7 +77,7 @@ export function Admin_NewLayout({
navbarOffsetBreakpoint={1024}
navbar={
<Navbar
height={"100vh"}
height={"100%"}
width={{ base: 250 }}
hiddenBreakpoint={1024}
hidden={!opened}
@@ -88,13 +100,26 @@ export function Admin_NewLayout({
<Grid.Col span={5}>
<Stack h={"100%"} justify="center">
<Group position="right" spacing={5}>
<ButtonUserCircle dataUser={dataUser} />
<Admin_ComponentButtonUserCircle
dataUser={dataUser}
/>
<ActionIcon
variant="transparent"
onClick={() => setDrawerNotifikasi(true)}
onClick={() => {
onLoadListNotifikasi();
}}
>
<IconBell color="white" />
{countNtf == 0 ? (
<IconBell color="white" />
) : (
<Indicator
processing
label={<Text fz={10}>{countNtf}</Text>}
>
<IconBell color="white" />
</Indicator>
)}
</ActionIcon>
</Group>
</Stack>
@@ -110,7 +135,13 @@ export function Admin_NewLayout({
style={{ color: "white", transition: "0.5s" }}
>
<Stack style={{ color: "white" }}>
<NavbarAdmin userRoleId={userRoleId} />
<Admin_UiNavbar
userRoleId={userRoleId}
activeId={activeId}
activeChildId={activeChildId as any}
setActiveId={setActiveId}
setActiveChildId={setActiveChildId}
/>
</Stack>
</Navbar.Section>
@@ -156,272 +187,20 @@ export function Admin_NewLayout({
size={"xs"}
>
<ComponentAdmin_UIDrawerNotifikasi
data={[]}
onLoadReadNotif={(val: any) => {
// setDataNotif(val);
listNotifikasi={dataNotifikasi}
onChangeNavbar={(val: { id: string; childId: string }) => {
setActiveId(val.id);
setActiveChildId(val.childId);
}}
onChangeNavbar={(val: any) => {
// setActiveId(val.id);
// setActiveChild(val.childId);
onToggleNavbar={(val: any) => {
// console.log(val, "toggle navbar");
// setDrawerNotifikasi(val);
}}
onToggleNavbar={setIsNavbarOpen}
onLoadCountNotif={(val: any) => {
// setCountNotif(val);
setCountNtf(val);
}}
/>
</Drawer>
</>
);
}
function NavbarAdmin({ userRoleId }: { userRoleId: string }) {
const router = useRouter();
// global state
const [openDropdown, setOpenDropdown] = useAtom(
gs_admin_navbar_isActive_dropdown
);
const [activeId, setActiveId] = useAtom(gs_admin_navbar_menu);
const [activeChildId, setActiveChildId] = useAtom(gs_admin_navbar_subMenu);
// Kalau fix developer navbar, fix juga navbar admin, dan berlaku sebaliknya
const developerNavbar = newListAdminPage.map((parent) => (
<Box key={parent.id}>
<NavLink
opened={openDropdown && activeId === parent.id}
styles={{
icon: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
label: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeId === parent.id ? "bold" : "normal"}
label={<Text>{parent.name}</Text>}
icon={parent.icon}
onClick={() => {
setActiveId(parent.id);
setActiveChildId("");
parent.path == "" ? setActiveChildId(parent.child[0].id) : "";
parent.path == ""
? router.push(parent.child[0].path)
: router.push(parent.path);
openDropdown && activeId === parent.id
? setOpenDropdown(false)
: setOpenDropdown(true);
}}
// active={activeId === parent.id}
>
{/* Navlink Children */}
{!_.isEmpty(parent.child) &&
parent.child.map((child) => (
<Box key={child.id}>
<NavLink
styles={{
icon: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
label: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeChildId === child.id ? "bold" : "normal"}
label={<Text>{child.name}</Text>}
icon={
activeChildId === child.id ? (
<IconCircleDotFilled size={10} />
) : (
<IconCircleDot size={10} />
)
}
onClick={() => {
setActiveChildId(child.id);
router.push(child.path);
}}
active={activeId === child.id}
/>
</Box>
))}
</NavLink>
</Box>
));
const bukanDeveloper = newListAdminPage.slice(0, -1);
const adminNavbar = bukanDeveloper.map((parent) => (
<Box key={parent.id}>
<NavLink
opened={openDropdown && activeId === parent.id}
styles={{
icon: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
label: {
color: activeId === parent.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeId === parent.id ? "bold" : "normal"}
label={<Text>{parent.name}</Text>}
icon={parent.icon}
onClick={() => {
setActiveId(parent.id);
setActiveChildId("");
parent.path == "" ? setActiveChildId(parent.child[0].id) : "";
parent.path == ""
? router.push(parent.child[0].path)
: router.push(parent.path);
openDropdown && activeId === parent.id
? setOpenDropdown(false)
: setOpenDropdown(true);
}}
// active={activeId === parent.id}
>
{/* Navlink Children */}
{!_.isEmpty(parent.child) &&
parent.child.map((child) => (
<Box key={child.id}>
<NavLink
styles={{
icon: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
label: {
color:
activeChildId === child.id ? MainColor.yellow : "white",
},
}}
style={{
color: "white",
transition: "0.5s",
}}
sx={{
":hover": {
backgroundColor: "transparent",
},
}}
fw={activeChildId === child.id ? "bold" : "normal"}
label={<Text>{child.name}</Text>}
icon={
activeChildId === child.id ? (
<IconCircleDotFilled size={10} />
) : (
<IconCircleDot size={10} />
)
}
onClick={() => {
setActiveChildId(child.id);
router.push(child.path);
}}
active={activeId === child.id}
/>
</Box>
))}
</NavLink>
</Box>
));
return userRoleId == "2" ? adminNavbar : developerNavbar;
}
function ButtonUserCircle({ dataUser }: { dataUser: MODEL_USER }) {
const [isOpenMenuUser, setOpenMenuUser] = useState(false);
return (
<>
<Menu
withArrow
arrowPosition="center"
opened={isOpenMenuUser}
onChange={setOpenMenuUser}
shadow="md"
width={250}
position="bottom-start"
styles={{
dropdown: {
backgroundColor: AccentColor.blue,
border: `1px solid ${AccentColor.skyblue}`,
},
item: {
color: "white",
":hover": {
backgroundColor: "gray",
},
},
arrow: {
borderTopColor: AccentColor.skyblue,
borderLeftColor: AccentColor.skyblue,
},
}}
>
<Menu.Target>
<ActionIcon variant="transparent" onClick={() => console.log("test")}>
<IconUserCircle color="white" />
</ActionIcon>
</Menu.Target>
<Menu.Dropdown>
<Stack spacing={5} px={"xs"}>
<Menu.Item>
<Grid>
<Grid.Col span={2}>
<IconUser />
</Grid.Col>
<Grid.Col span={"auto"}>
<Text lineClamp={1}>{dataUser.username}</Text>
</Grid.Col>
</Grid>
</Menu.Item>
<Menu.Item>
<Grid>
<Grid.Col span={2}>
<IconPhone />
</Grid.Col>
<Grid.Col span={"auto"}>
<Text lineClamp={1}>+{dataUser.nomor}</Text>
</Grid.Col>
</Grid>
</Menu.Item>
<Menu.Divider />
<Center py={"xs"}>
<Admin_Logout />
</Center>
</Stack>
</Menu.Dropdown>
</Menu>
</>
);
}

View File

@@ -67,33 +67,33 @@ export const newListAdminPage = [
//Donasi
{
id: "Donaasi",
id: "Donasi",
name: "Donasi",
path: "",
icon: <IconHeartHandshake />,
child: [
{
id: "Donaasi_1",
id: "Donasi_1",
name: "Dashboard",
path: RouterAdminDonasi.main,
},
{
id: "Donaasi_2",
id: "Donasi_2",
name: "Table Publish",
path: RouterAdminDonasi.table_publish,
},
{
id: "Donaasi_3",
id: "Donasi_3",
name: "Table Review",
path: RouterAdminDonasi.table_review,
},
{
id: "Donaasi_4",
id: "Donasi_4",
name: "Table Reject",
path: RouterAdminDonasi.table_reject,
},
{
id: "Donaasi_5",
id: "Donasi_5",
name: "Table Kategori",
path: RouterAdminDonasi.table_kategori,
},

View File

@@ -23,6 +23,7 @@ export default async function adminNotifikasi_funCreateToUser({
userRoleId: "1",
},
});
if (!create) return { status: 400, message: "Gagal mengirim notifikasi" };
return { status: 201, message: "Berhasil mengirim notifikasi" };
}

View File

@@ -0,0 +1,20 @@
"use server";
import { prisma } from "@/app/lib";
export async function admin_funCheckStatusJob({ id }: { id: string }) {
const data = await prisma.job.findUnique({
where: {
id: id,
},
select: {
MasterStatus: true,
},
});
if (data?.MasterStatus?.name === "Review") {
return true;
} else {
return false;
}
}

View File

@@ -20,5 +20,6 @@ export default async function adminNotifikasi_getByUserId() {
userRoleId: "2",
},
});
return data;
}

View File

@@ -1,35 +1,26 @@
import { MODEL_NOTIFIKASI } from "@/app_modules/notifikasi/model/interface";
import _ from "lodash";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
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";
export default async function adminNotifikasi_findRouterJob({
export async function adminNotifikasi_findRouterJob({
data,
router,
onChangeNavbar,
onToggleNavbar,
}: {
data: MODEL_NOTIFIKASI;
router: AppRouterInstance;
onChangeNavbar: (val: any) => void;
onToggleNavbar: (val: any) => void;
}) {
const routeName = "/dev/admin/job/child/";
const check = await admin_funCheckStatusJob({ id: data.appId });
if (data.status === "Review") {
router.push(routeName + _.lowerCase(data.status));
onChangeNavbar({
id: 6,
childId: 63,
if (check) {
const udpateReadNotifikasi = await adminNotifikasi_funUpdateIsReadById({
notifId: data?.id,
});
}
if (data.status === "Draft") {
router.push(routeName + "review");
onChangeNavbar({
id: 6,
childId: 63,
});
if (udpateReadNotifikasi.status == 200) {
return true;
} else {
return false;
}
} else {
ComponentAdminGlobal_NotifikasiPeringatan("Status telah dirubah oleh user");
}
onToggleNavbar(true);
}

View File

@@ -0,0 +1,36 @@
export type IAdmin_ActivePage = "Investasi" | "Donasi" | "Event" | "Vote" | "Job" | "Forum" | "Collaboration"
export type IAdmin_ActiveChildId =
| "Investasi_1"
| "Investasi_2"
| "Investasi_3"
| "Investasi_4"
| "Donasi_1"
| "Donasi_2"
| "Donasi_3"
| "Donasi_4"
| "Donasi_5"
| "Event_1"
| "Event_2"
| "Event_3"
| "Event_4"
| "Event_5"
| "Event_6"
| "Voting_1"
| "Voting_2"
| "Voting_3"
| "Voting_4"
| "Voting_5"
| "Job_1"
| "Job_2"
| "Job_3"
| "Job_4"
| "Forum_1"
| "Forum_2"
| "Forum_3"
| "Forum_4"
| "Collaboration_1"
| "Collaboration_2"
| "Collaboration_3"
| "Collaboration_4";

View File

@@ -1,41 +1,142 @@
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 {
Badge,
Card,
Center,
Divider,
Group,
Paper,
Stack,
Card,
Group,
Badge,
Divider,
Text,
} from "@mantine/core";
import { IconChecks, IconCheck } from "@tabler/icons-react";
import { IconCheck, IconChecks } from "@tabler/icons-react";
import _ from "lodash";
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_funUpdateIsReadById from "./fun/update/fun_update_is_read_by_id";
import adminNotifikasi_findRouterDonasi from "./route_setting/donasi";
import { adminNotifikasi_findRouterEvent } from "./route_setting/event";
import adminNotifikasi_findRouterForum from "./route_setting/forum";
import adminNotifikasi_findRouterJob from "./route_setting/job";
import { adminNotifikasi_findRouterVoting } from "./route_setting/voting";
import adminNotifikasi_findRouterInvestasi from "./route_setting/investasi";
import { adminNotifikasi_findRouterJob } from "./route_setting/job";
import {
IAdmin_ActiveChildId,
IAdmin_ActivePage,
} from "./route_setting/type_of_select_page";
export function ComponentAdmin_UIDrawerNotifikasi({
data,
onLoadReadNotif,
listNotifikasi,
onChangeNavbar,
onToggleNavbar,
onLoadCountNotif,
}: {
data: MODEL_NOTIFIKASI[];
onLoadReadNotif: (val: any) => void;
onChangeNavbar: (val: any) => void;
listNotifikasi: MODEL_NOTIFIKASI[];
onChangeNavbar: (val: {
id: IAdmin_ActivePage;
childId: IAdmin_ActiveChildId;
}) => void;
onToggleNavbar: (val: any) => void;
onLoadCountNotif: (val: any) => void;
}) {
const router = useRouter();
const [data, setData] = useState<MODEL_NOTIFIKASI[]>(listNotifikasi);
const [visible, setVisible] = useState(false);
const [dataId, setDataId] = useState<string>("");
async function onRead({ data }: { data: MODEL_NOTIFIKASI }) {
// JOB
if (data?.kategoriApp === "JOB") {
const checkJob = await adminNotifikasi_findRouterJob({
data: data,
});
if (checkJob) {
setVisible(true);
setDataId(data.id);
const loadCountNotif = await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadListNotifikasi = await adminNotifikasi_getByUserId();
setData(loadListNotifikasi as any);
if (loadCountNotif && loadListNotifikasi) {
onChangeNavbar({
id: "Job",
childId: "Job_3",
});
router.push("/dev/admin/job/child/review");
setVisible(false);
setDataId("");
}
}
}
// // FORUM
// e?.kategoriApp === "FORUM" &&
// adminNotifikasi_findRouterForum({
// data: e,
// router: router,
// onChangeNavbar(val) {
// onChangeNavbar(val);
// },
// onToggleNavbar(val) {
// onToggleNavbar(val);
// },
// });
// // VOTE
// e?.kategoriApp === "VOTING" &&
// adminNotifikasi_findRouterVoting({
// data: e,
// router: router,
// onChangeNavbar(val) {
// onChangeNavbar(val);
// },
// onToggleNavbar(val) {
// onToggleNavbar(val);
// },
// });
// // EVENT
// e?.kategoriApp === "EVENT" &&
// adminNotifikasi_findRouterEvent({
// data: e,
// router: router,
// onChangeNavbar(val) {
// onChangeNavbar(val);
// },
// onToggleNavbar(val) {
// onToggleNavbar(val);
// },
// });
// // DONASI
// e.kategoriApp === "DONASI" &&
// adminNotifikasi_findRouterDonasi({
// data: e,
// router: router,
// onChangeNavbar(val) {
// onChangeNavbar(val);
// },
// onToggleNavbar(val) {
// onToggleNavbar(val);
// },
// });
// // INVESTASI
// e.kategoriApp === "INVESTASI" &&
// adminNotifikasi_findRouterInvestasi({
// data: e,
// router: router,
// onChangeNavbar(val) {
// onChangeNavbar(val);
// },
// onToggleNavbar(val) {
// onToggleNavbar(val);
// },
// });
}
if (_.isEmpty(data)) {
return (
@@ -58,109 +159,22 @@ export function ComponentAdmin_UIDrawerNotifikasi({
style={{
transition: "0.5s",
}}
c={"white"}
key={e?.id}
// withBorder
bg={e?.isRead ? "gray.1" : "gray.4"}
bg={e?.isRead ? "gray" : AccentColor.darkblue}
sx={{
borderColor: "gray",
borderColor: AccentColor.blue,
borderStyle: "solid",
borderWidth: "0.5px",
borderWidth: "2px",
":hover": {
backgroundColor: "#C1C2C5",
backgroundColor: AccentColor.blue,
borderColor: AccentColor.softblue,
borderStyle: "solid",
borderWidth: "2px",
},
}}
onClick={async () => {
// JOB
e?.kategoriApp === "JOB" &&
adminNotifikasi_findRouterJob({
data: e,
router: router,
onChangeNavbar: (val: any) => {
onChangeNavbar(val);
},
onToggleNavbar: onToggleNavbar,
});
// FORUM
e?.kategoriApp === "FORUM" &&
adminNotifikasi_findRouterForum({
data: e,
router: router,
onChangeNavbar(val) {
onChangeNavbar(val);
},
onToggleNavbar(val) {
onToggleNavbar(val);
},
});
// VOTE
e?.kategoriApp === "VOTING" &&
adminNotifikasi_findRouterVoting({
data: e,
router: router,
onChangeNavbar(val) {
onChangeNavbar(val);
},
onToggleNavbar(val) {
onToggleNavbar(val);
},
});
// EVENT
e?.kategoriApp === "EVENT" &&
adminNotifikasi_findRouterEvent({
data: e,
router: router,
onChangeNavbar(val) {
onChangeNavbar(val);
},
onToggleNavbar(val) {
onToggleNavbar(val);
},
});
// DONASI
e.kategoriApp === "DONASI" &&
adminNotifikasi_findRouterDonasi({
data: e,
router: router,
onChangeNavbar(val) {
onChangeNavbar(val);
},
onToggleNavbar(val) {
onToggleNavbar(val);
},
});
// INVESTASI
e.kategoriApp === "INVESTASI" &&
adminNotifikasi_findRouterInvestasi({
data: e,
router: router,
onChangeNavbar(val) {
onChangeNavbar(val);
},
onToggleNavbar(val) {
onToggleNavbar(val);
},
});
const updateIsRead = await adminNotifikasi_funUpdateIsReadById({
notifId: e?.id,
});
if (updateIsRead) {
const loadCountNotif =
await adminNotifikasi_countNotifikasi();
onLoadCountNotif(loadCountNotif);
const loadDataNotif = await adminNotifikasi_getByUserId();
onLoadReadNotif(loadDataNotif);
} else {
return null;
}
onRead({ data: e });
// callBackIsNotifikasi(false);
}}
>
@@ -193,12 +207,12 @@ export function ComponentAdmin_UIDrawerNotifikasi({
</Card.Section>
<Card.Section p={"sm"}>
<Group position="apart">
<Text fz={10} color="gray">
<Text fz={10}>
{new Intl.DateTimeFormat("id-ID", {
dateStyle: "long",
}).format(e?.createdAt)}
<Text span inherit fz={10} color="gray">
<Text span inherit fz={10}>
{", "}
{new Intl.DateTimeFormat("id-ID", {
timeStyle: "short",
@@ -207,20 +221,19 @@ export function ComponentAdmin_UIDrawerNotifikasi({
</Text>
{e?.isRead ? (
<Group spacing={5}>
<IconChecks color="gray" size={10} />
<Text fz={10} color="gray">
Sudah dilihat
</Text>
<IconChecks size={10} />
<Text fz={10}>Sudah dilihat</Text>
</Group>
) : (
<Group spacing={5}>
<IconCheck color="gray" size={10} />
<Text fz={10} color="gray">
Belum dilihat
</Text>
<IconCheck size={10} />
<Text fz={10}>Belum dilihat</Text>
</Group>
)}
</Group>
{visible && dataId === e?.id && (
<ComponentGlobal_CardLoadingOverlay />
)}
</Card.Section>
</Card>
))}