Merge pull request #332 from bipproduction/amalia/08-nov-24

Amalia/08 nov 24
This commit is contained in:
Amalia
2024-11-08 17:06:04 +08:00
committed by GitHub
8 changed files with 56 additions and 37 deletions

View File

@@ -87,7 +87,7 @@ export async function GET(request: Request, context: { params: { id: string } })
totalComments: comments.length,
};
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: response }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: response, user: user.id }, { status: 200 });
} catch (error) {
console.error(error);
@@ -175,7 +175,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
// create log user
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus data diskusi', table: 'divisionDisscussion', data: id })
return NextResponse.json({ success: true, message: "Berhasil menghapus diskusi" }, { status: 200 });
return NextResponse.json({ success: true, message: "Berhasil menghapus diskusi", user: user.id }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });

View File

@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) {
try {
return NextResponse.json({ success: true, version: "0.1.9", mode: "staging" }, { status: 200 });
return NextResponse.json({ success: true, version: "0.2.0", mode: "staging" }, { status: 200 });
} catch (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 });

View File

@@ -22,6 +22,7 @@ export default function DateEventDivision() {
const [isMonth, setMonth] = useState<any>(moment().month() + 1)
const [loading, setLoading] = useState(true)
const isMobile = useMediaQuery('(max-width: 369px)');
const [isDateChoose, setDataChoose] = useState<any>(moment().format('YYYY-MM-DD'))
const [dataRealTime, setDataRealtime] = useWibuRealtime({
WIBU_REALTIME_TOKEN: keyWibu,
project: "sdm"
@@ -37,7 +38,6 @@ export default function DateEventDivision() {
} else {
toast.error(response.message)
}
setLoading(false)
} catch (error) {
console.error(error)
toast.error("Gagal mendapatkan list acara")
@@ -63,6 +63,7 @@ export default function DateEventDivision() {
async function changeMonth(value: any) {
const monthKlik = moment(value).format('MM')
setDataChoose(value)
if (monthKlik != isMonth) {
setMonth(monthKlik)
getIndicator(value)
@@ -99,7 +100,7 @@ export default function DateEventDivision() {
getIndicator(isDate)
getData(isDate, false)
} else if (dataRealTime && dataRealTime.some((i: any) => i.category == 'calendar-event' && i.division == param.id && i.date != isDate)) {
getIndicator(isDate)
getIndicator(isDateChoose)
}
}, [dataRealTime])

View File

@@ -72,7 +72,7 @@ export default function DetailEventDivision() {
toast.error("Data telah di hapus, anda akan beralih ke halaman list acara")
setTimeout(() => {
router.push(`/division/${param.id}/calender`)
}, 2000)
}, 1000)
}
}, [dataRealTime])

View File

@@ -11,7 +11,7 @@ import { FaUsers } from 'react-icons/fa6';
import { useHookstate } from '@hookstate/core';
import { useWibuRealtime } from 'wibu-realtime';
export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: string, close: (val:boolean) => void }) {
export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: string, close: (val: boolean) => void }) {
const router = useRouter()
const [isModal, setModal] = useState(false)
const param = useParams<{ id: string, detail: string }>()
@@ -22,29 +22,27 @@ export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: s
project: "sdm"
})
async function fetchDeleteCalender(val: boolean) {
async function fetchDeleteCalender() {
try {
if (val) {
setLoadingDelete(true)
const response = await funDeleteCalenderById(idCalendar)
if (response.success) {
setDataRealtime([
{
category: "calendar-detail-delete",
id: idCalendar,
},
{
category: "calendar-event",
division: param.id,
date: response.data.dateStart,
idUserFrom: response.user
}
])
toast.success(response.message)
router.push(`/division/${param.id}/calender`)
} else {
toast.error(response.message)
}
setLoadingDelete(true)
const response = await funDeleteCalenderById(idCalendar)
if (response.success) {
setDataRealtime([
{
category: "calendar-detail-delete",
id: idCalendar,
idUserFrom: response.user
},
{
category: "calendar-event",
division: param.id,
date: response.data.dateStart,
}
])
toast.success(response.message)
router.push(`/division/${param.id}/calender`)
} else {
toast.error(response.message)
}
} catch (error) {
console.error(error);
@@ -94,7 +92,13 @@ export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: s
</Stack>
<LayoutModal loading={loadingDelete} opened={isModal} onClose={() => setModal(false)}
description="Apakah Anda yakin ingin menghapus data acara ini? Data ini akan mempengaruhi semua data yang terkait"
onYes={(val) => { fetchDeleteCalender(val) }} />
onYes={(val) => {
if (val) {
fetchDeleteCalender()
} else {
setModal(false)
}
}} />
</Box>
);
}

View File

@@ -6,7 +6,7 @@ import { ActionIcon, Avatar, Badge, Box, Center, Divider, Flex, Grid, Group, rem
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
import moment from "moment";
import "moment/locale/id";
import { useParams } from "next/navigation";
import { useParams, useRouter } from "next/navigation";
import { useState } from "react";
import toast from "react-hot-toast";
import { GrChatOption } from "react-icons/gr";
@@ -26,8 +26,10 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
const refresh = useHookstate(globalRefreshDiscussion)
const roleLogin = useHookstate(globalRole)
const [isCreator, setCreator] = useState(false)
const [isUser, setUser] = useState('')
const adminLogin = useHookstate(globalIsAdminDivision)
const tema = useHookstate(TEMA)
const router = useRouter()
const isMobile = useMediaQuery('(max-width: 369px)');
const isMobile2 = useMediaQuery("(max-width: 438px)");
const [dataRealTime, setDataRealtime] = useWibuRealtime({
@@ -42,6 +44,7 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
setData(response.data)
setIsLoad(false)
setCreator(response.data.isCreator)
setUser(response.user)
} catch (error) {
console.error(error)
} finally {
@@ -57,6 +60,13 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-detail' && i.id == id)) {
getData(false)
}
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-delete' && i.id == id && i.user != isUser)) {
toast.error("Data telah di hapus, anda akan beralih ke halaman list diskusi")
setTimeout(() => {
router.push(`/division/${param.id}/discussion`)
}, 1000)
}
}, [dataRealTime])
async function reloadData() {

View File

@@ -55,10 +55,15 @@ export default function DrawerDetailDiscussion({ onSuccess, id, status, idDivisi
async function fetchDeleteDiscussion(val: boolean) {
try {
setLoadingDelete(true)
if (val) {
setLoadingDelete(true)
const response = await funDeleteDiscussion(id)
if (response.success) {
setDataRealtime([{
category: "discussion-delete",
id: id,
user: response.user
}])
toast.success(response.message)
onSuccess(false)
router.push(`/division/${param.id}/discussion`)

View File

@@ -45,15 +45,15 @@ export default function ListDiscussion({ id }: { id: string }) {
}
}
useShallowEffect(() => {
getData(false)
}, [isPage])
useShallowEffect(() => {
setPage(1)
getData(true)
}, [searchQuery])
useShallowEffect(() => {
getData(false)
}, [isPage])
useEffect(() => {
const handleScroll = async () => {
if (containerRef && containerRef.current) {
@@ -78,7 +78,6 @@ export default function ListDiscussion({ id }: { id: string }) {
useShallowEffect(() => {
console.log(notifLoadPage.get())
if (notifLoadPage.get().category == 'division/' + param.id + '/discussion' && notifLoadPage.get().load == true) {
setRefresh(true)
}