feature: notifikasi pengumuman setelah login
Deskripsi: - ui notification announcement - api findmany notification announcement - nb : masih setiap reload home tampil (seharusnya setelah login aja) No Issues
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { funGetHome } from "./lib/api_home";
|
||||
import { globalParamJumlahNotif } from "./lib/val_home";
|
||||
import NotificationAnnouncement from "./ui/notification_announcement";
|
||||
import ViewDetailFeature from "./ui/view_detail_feature";
|
||||
import ViewHome from "./ui/view_home";
|
||||
import ViewNotification from "./ui/view_notification";
|
||||
@@ -10,4 +11,5 @@ export { ViewDetailFeature }
|
||||
export { ViewSearch }
|
||||
export { ViewNotification }
|
||||
export { funGetHome }
|
||||
export { globalParamJumlahNotif }
|
||||
export { globalParamJumlahNotif }
|
||||
export { NotificationAnnouncement }
|
||||
@@ -10,4 +10,9 @@ export const funReadNotification = async (data: { id: string }) => {
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funGetOneNotificationAnnouncement = async (path?: string) => {
|
||||
const response = await fetch(`/api/notification${(path) ? path : ''}`, { next: { tags: ['notification'] } });
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
65
src/module/home/ui/notification_announcement.tsx
Normal file
65
src/module/home/ui/notification_announcement.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
'use client'
|
||||
import { NotificationCustome } from "@/module/_global";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { funGetOneNotificationAnnouncement, funReadNotification } from "../lib/api_notification";
|
||||
import { IListNotification } from "../lib/type_notification";
|
||||
|
||||
export default function NotificationAnnouncement() {
|
||||
const router = useRouter()
|
||||
const [tampilNotif, setTampilNotif] = useState(false)
|
||||
const [isData, setData] = useState<IListNotification[]>([]);
|
||||
|
||||
async function fetchData() {
|
||||
try {
|
||||
const res = await funGetOneNotificationAnnouncement();
|
||||
if (res.success) {
|
||||
setTampilNotif(true)
|
||||
setData(res.data);
|
||||
} else {
|
||||
toast.error(res.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal memuat data, coba lagi nanti");
|
||||
} finally {
|
||||
setTimeout(() => {
|
||||
setTampilNotif(false);
|
||||
}, 6000);
|
||||
}
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
async function onClickNotif(category: string, idContent: string, idData: string) {
|
||||
try {
|
||||
const response = await funReadNotification({ id: idData });
|
||||
if (response.success) {
|
||||
router.push(`/${category}/${idContent}`);
|
||||
} else {
|
||||
toast.error(response.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal memuat data, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{
|
||||
tampilNotif &&
|
||||
<NotificationCustome
|
||||
title={isData[0]?.title}
|
||||
desc={isData[0]?.desc}
|
||||
onClick={() => { onClickNotif(isData[0]?.category, isData[0]?.idContent, isData[0]?.id) }}
|
||||
onClose={() => { '' }}
|
||||
/>
|
||||
}
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import ListDiscussion from './list_discussion';
|
||||
import ListDivisi from './list_divisi';
|
||||
import ListEventHome from './list_event';
|
||||
import ListProjects from './list_project';
|
||||
import NotificationAnnouncement from './notification_announcement';
|
||||
|
||||
|
||||
export default function ViewHome() {
|
||||
@@ -18,6 +19,7 @@ export default function ViewHome() {
|
||||
<HeaderHome />
|
||||
<Box p={20}>
|
||||
<Stack >
|
||||
<NotificationAnnouncement />
|
||||
<Carosole />
|
||||
<Features />
|
||||
<ListProjects />
|
||||
|
||||
Reference in New Issue
Block a user