Merge pull request #422 from bipproduction/amalia/16-apr-25
Amalia/16 apr 25
This commit is contained in:
@@ -93,3 +93,33 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// UPDATE READ ALL NOTIFICATION
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const user = await funGetUserByCookies()
|
||||||
|
if (user.id == undefined) {
|
||||||
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
|
}
|
||||||
|
|
||||||
|
const upd = await prisma.notifications.updateMany({
|
||||||
|
where: {
|
||||||
|
idUserTo: user.id,
|
||||||
|
isRead: false
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isRead: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUser({ act: 'UPDATE', desc: 'User menandai semua notifikasi', table: 'notifications', data: '' })
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mengupdate notifikasi", }, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mengupdate notifikasi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "1.3.2", tahap: "beta", update: "- update baru : menampilkan notifikasi pengumuman setelah login (fixed tampilan); - fix random nomer kode otp 4 digit" }, { status: 200 });
|
return NextResponse.json({ success: true, version: "1.3.3", tahap: "beta", update: "- update baru : menampilkan notifikasi pengumuman setelah login (fixed tampilan); - rich text di pengumuman (tambah dan edit); - fitur tandai dibaca semua notifikasi" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ export default function EditAnnouncement() {
|
|||||||
))
|
))
|
||||||
|
|
||||||
:
|
:
|
||||||
<>
|
<Box pb={50}>
|
||||||
<Text c={tema.get().utama} mb={10}>Divisi Terpilih</Text>
|
<Text c={tema.get().utama} mb={10}>Divisi Terpilih</Text>
|
||||||
{
|
{
|
||||||
memberGroup.get().length == 0 ? <Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada divisi yang dipilih</Text> :
|
memberGroup.get().length == 0 ? <Text c="dimmed" ta={"center"} fs={"italic"}>Belum ada divisi yang dipilih</Text> :
|
||||||
@@ -343,7 +343,7 @@ export default function EditAnnouncement() {
|
|||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</>
|
</Box>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { funGetHome } from "./lib/api_home";
|
import { funGetHome } from "./lib/api_home";
|
||||||
import { globalParamJumlahNotif } from "./lib/val_home";
|
import { globalParamJumlahNotif } from "./lib/val_home";
|
||||||
|
import DrawerNotification from "./ui/drawer_notification";
|
||||||
import NotificationAnnouncement from "./ui/notification_announcement";
|
import NotificationAnnouncement from "./ui/notification_announcement";
|
||||||
import ViewDetailFeature from "./ui/view_detail_feature";
|
import ViewDetailFeature from "./ui/view_detail_feature";
|
||||||
import ViewHome from "./ui/view_home";
|
import ViewHome from "./ui/view_home";
|
||||||
@@ -13,3 +14,4 @@ export { ViewNotification }
|
|||||||
export { funGetHome }
|
export { funGetHome }
|
||||||
export { globalParamJumlahNotif }
|
export { globalParamJumlahNotif }
|
||||||
export { NotificationAnnouncement }
|
export { NotificationAnnouncement }
|
||||||
|
export { DrawerNotification }
|
||||||
@@ -16,3 +16,10 @@ export const funGetOneNotificationAnnouncement = async (path?: string) => {
|
|||||||
const response = await fetch(`/api/notification${(path) ? path : ''}`, { next: { tags: ['notification'] } });
|
const response = await fetch(`/api/notification${(path) ? path : ''}`, { next: { tags: ['notification'] } });
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const funReadAllNotification = async () => {
|
||||||
|
const response = await fetch(`/api/home/notification`, {
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
return await response.json().catch(() => null);
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
import { hookstate } from "@hookstate/core";
|
import { hookstate } from "@hookstate/core";
|
||||||
|
|
||||||
export const globalParamJumlahNotif = hookstate<boolean>(false)
|
export const globalParamJumlahNotif = hookstate<boolean>(false)
|
||||||
|
export const globalRefreshNotif = hookstate<boolean>(false)
|
||||||
|
|||||||
49
src/module/home/ui/drawer_notification.tsx
Normal file
49
src/module/home/ui/drawer_notification.tsx
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
"use client"
|
||||||
|
import { TEMA } from '@/module/_global';
|
||||||
|
import { useHookstate } from '@hookstate/core';
|
||||||
|
import { Box, Flex, SimpleGrid, Stack, Text } from '@mantine/core';
|
||||||
|
import toast from 'react-hot-toast';
|
||||||
|
import { LuCheckCheck } from 'react-icons/lu';
|
||||||
|
import { funReadAllNotification } from '../lib/api_notification';
|
||||||
|
import { globalRefreshNotif } from '../lib/val_home';
|
||||||
|
|
||||||
|
export default function DrawerNotification({ onDone }: { onDone: () => void }) {
|
||||||
|
const tema = useHookstate(TEMA)
|
||||||
|
const reloadNotif = useHookstate(globalRefreshNotif)
|
||||||
|
|
||||||
|
async function handleReadAll() {
|
||||||
|
try {
|
||||||
|
const res = await funReadAllNotification()
|
||||||
|
if (res.success) {
|
||||||
|
toast.success(res.message)
|
||||||
|
reloadNotif.set(!reloadNotif.get())
|
||||||
|
} else {
|
||||||
|
toast.error(res.message)
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
toast.error("Gagal mengupdate notifikasi, coba lagi nanti")
|
||||||
|
} finally {
|
||||||
|
onDone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Stack pt={10}>
|
||||||
|
<SimpleGrid
|
||||||
|
cols={{ base: 3, sm: 3, lg: 3 }}
|
||||||
|
>
|
||||||
|
<Flex onClick={() => { handleReadAll() }} justify={'center'} align={'center'} direction={'column'} >
|
||||||
|
<Box>
|
||||||
|
<LuCheckCheck size={30} color={tema.get().utama} />
|
||||||
|
</Box>
|
||||||
|
<Box>
|
||||||
|
<Text c={tema.get().utama} ta={"center"}>Tandai Dibaca Semua</Text>
|
||||||
|
</Box>
|
||||||
|
</Flex>
|
||||||
|
</SimpleGrid>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import toast from "react-hot-toast";
|
|||||||
import { FaBell } from "react-icons/fa6";
|
import { FaBell } from "react-icons/fa6";
|
||||||
import { funGetAllNotification, funReadNotification, } from "../lib/api_notification";
|
import { funGetAllNotification, funReadNotification, } from "../lib/api_notification";
|
||||||
import { IListNotification } from "../lib/type_notification";
|
import { IListNotification } from "../lib/type_notification";
|
||||||
|
import { globalRefreshNotif } from "../lib/val_home";
|
||||||
|
|
||||||
export default function ListNotification() {
|
export default function ListNotification() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -19,6 +20,7 @@ export default function ListNotification() {
|
|||||||
const { value: containerRef } = useHookstate(currentScroll);
|
const { value: containerRef } = useHookstate(currentScroll);
|
||||||
const [isPage, setPage] = useState(1);
|
const [isPage, setPage] = useState(1);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const reloadNotif = useHookstate(globalRefreshNotif)
|
||||||
|
|
||||||
async function fetchData(loading: boolean) {
|
async function fetchData(loading: boolean) {
|
||||||
try {
|
try {
|
||||||
@@ -47,7 +49,7 @@ export default function ListNotification() {
|
|||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
fetchData(false);
|
fetchData(false);
|
||||||
}, [isPage]);
|
}, [isPage, reloadNotif.get()]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleScroll = async () => {
|
const handleScroll = async () => {
|
||||||
|
|||||||
@@ -1,15 +1,32 @@
|
|||||||
import { LayoutNavbarNew } from '@/module/_global'
|
'use client'
|
||||||
import { Box, } from '@mantine/core'
|
import { LayoutDrawer, LayoutNavbarNew, TEMA } from '@/module/_global'
|
||||||
import React from 'react'
|
import { ActionIcon, Box, } from '@mantine/core'
|
||||||
|
import { useState } from 'react'
|
||||||
|
import { HiMenu } from 'react-icons/hi'
|
||||||
|
import DrawerNotification from './drawer_notification'
|
||||||
import ListNotification from './list_notification'
|
import ListNotification from './list_notification'
|
||||||
|
|
||||||
export default function ViewNotification() {
|
export default function ViewNotification() {
|
||||||
|
const [isOpen, setOpen] = useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<LayoutNavbarNew back='/home' title='Notifikasi' menu={<></>} />
|
<LayoutNavbarNew
|
||||||
|
back='/home'
|
||||||
|
title='Notifikasi'
|
||||||
|
menu={
|
||||||
|
<ActionIcon onClick={() => setOpen(true)} variant="light" bg={TEMA.get().bgIcon} size="lg" radius="lg" aria-label="Settings">
|
||||||
|
<HiMenu size={20} color='white' />
|
||||||
|
</ActionIcon>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Box p={20}>
|
<Box p={20}>
|
||||||
<ListNotification />
|
<ListNotification />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
<LayoutDrawer opened={isOpen} title={'Menu'} onClose={() => setOpen(false)}>
|
||||||
|
<DrawerNotification onDone={() => setOpen(false)} />
|
||||||
|
</LayoutDrawer>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user