fix:
discussion Deskripsi: - loading skeleton pertama pada list diskusi - realtime setelah hapus diskusi No Issues
This commit is contained in:
@@ -87,7 +87,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
totalComments: comments.length,
|
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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -175,7 +175,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
|||||||
// create log user
|
// create log user
|
||||||
const log = await createLogUser({ act: 'DELETE', desc: 'User menghapus data diskusi', table: 'divisionDisscussion', data: id })
|
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) {
|
} catch (error) {
|
||||||
console.error(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 });
|
return NextResponse.json({ success: false, message: "Gagal menghapus diskusi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default function DetailEventDivision() {
|
|||||||
toast.error("Data telah di hapus, anda akan beralih ke halaman list acara")
|
toast.error("Data telah di hapus, anda akan beralih ke halaman list acara")
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
router.push(`/division/${param.id}/calender`)
|
router.push(`/division/${param.id}/calender`)
|
||||||
}, 2000)
|
}, 1000)
|
||||||
}
|
}
|
||||||
}, [dataRealTime])
|
}, [dataRealTime])
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ActionIcon, Avatar, Badge, Box, Center, Divider, Flex, Grid, Group, rem
|
|||||||
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import "moment/locale/id";
|
import "moment/locale/id";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams, useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { GrChatOption } from "react-icons/gr";
|
import { GrChatOption } from "react-icons/gr";
|
||||||
@@ -26,8 +26,10 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
|
|||||||
const refresh = useHookstate(globalRefreshDiscussion)
|
const refresh = useHookstate(globalRefreshDiscussion)
|
||||||
const roleLogin = useHookstate(globalRole)
|
const roleLogin = useHookstate(globalRole)
|
||||||
const [isCreator, setCreator] = useState(false)
|
const [isCreator, setCreator] = useState(false)
|
||||||
|
const [isUser, setUser] = useState('')
|
||||||
const adminLogin = useHookstate(globalIsAdminDivision)
|
const adminLogin = useHookstate(globalIsAdminDivision)
|
||||||
const tema = useHookstate(TEMA)
|
const tema = useHookstate(TEMA)
|
||||||
|
const router = useRouter()
|
||||||
const isMobile = useMediaQuery('(max-width: 369px)');
|
const isMobile = useMediaQuery('(max-width: 369px)');
|
||||||
const isMobile2 = useMediaQuery("(max-width: 438px)");
|
const isMobile2 = useMediaQuery("(max-width: 438px)");
|
||||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||||
@@ -42,6 +44,7 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
|
|||||||
setData(response.data)
|
setData(response.data)
|
||||||
setIsLoad(false)
|
setIsLoad(false)
|
||||||
setCreator(response.data.isCreator)
|
setCreator(response.data.isCreator)
|
||||||
|
setUser(response.user)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
} finally {
|
} 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)) {
|
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-detail' && i.id == id)) {
|
||||||
getData(false)
|
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])
|
}, [dataRealTime])
|
||||||
|
|
||||||
async function reloadData() {
|
async function reloadData() {
|
||||||
|
|||||||
@@ -55,10 +55,15 @@ export default function DrawerDetailDiscussion({ onSuccess, id, status, idDivisi
|
|||||||
|
|
||||||
async function fetchDeleteDiscussion(val: boolean) {
|
async function fetchDeleteDiscussion(val: boolean) {
|
||||||
try {
|
try {
|
||||||
setLoadingDelete(true)
|
|
||||||
if (val) {
|
if (val) {
|
||||||
|
setLoadingDelete(true)
|
||||||
const response = await funDeleteDiscussion(id)
|
const response = await funDeleteDiscussion(id)
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
setDataRealtime([{
|
||||||
|
category: "discussion-delete",
|
||||||
|
id: id,
|
||||||
|
user: response.user
|
||||||
|
}])
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
onSuccess(false)
|
onSuccess(false)
|
||||||
router.push(`/division/${param.id}/discussion`)
|
router.push(`/division/${param.id}/discussion`)
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ export default function ListDiscussion({ id }: { id: string }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
getData(false)
|
||||||
|
}, [isPage])
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
setPage(1)
|
setPage(1)
|
||||||
getData(true)
|
getData(true)
|
||||||
}, [searchQuery])
|
}, [searchQuery])
|
||||||
|
|
||||||
useShallowEffect(() => {
|
|
||||||
getData(false)
|
|
||||||
}, [isPage])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleScroll = async () => {
|
const handleScroll = async () => {
|
||||||
if (containerRef && containerRef.current) {
|
if (containerRef && containerRef.current) {
|
||||||
@@ -78,7 +78,6 @@ export default function ListDiscussion({ id }: { id: string }) {
|
|||||||
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
console.log(notifLoadPage.get())
|
|
||||||
if (notifLoadPage.get().category == 'division/' + param.id + '/discussion' && notifLoadPage.get().load == true) {
|
if (notifLoadPage.get().category == 'division/' + param.id + '/discussion' && notifLoadPage.get().load == true) {
|
||||||
setRefresh(true)
|
setRefresh(true)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user