fix: diskusi
deskripsi: -pencarian - loading pada update status dan hapus diskusi No Issues
This commit is contained in:
@@ -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, useRouter } from "next/navigation";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { GrChatOption } from "react-icons/gr";
|
||||
@@ -23,7 +23,6 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
|
||||
const [isComent, setIsComent] = useState("")
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const [isLoad, setIsLoad] = useState(true)
|
||||
const router = useRouter()
|
||||
const refresh = useHookstate(globalRefreshDiscussion)
|
||||
const roleLogin = useHookstate(globalRole)
|
||||
const [isCreator, setCreator] = useState(false)
|
||||
|
||||
@@ -23,13 +23,15 @@ export default function DrawerDetailDiscussion({ onSuccess, id, status, idDivisi
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
const [loadingUpdate, setLoadingUpdate] = useState(false)
|
||||
const [loadingDelete, setLoadingDelete] = useState(false)
|
||||
|
||||
|
||||
async function fetchStatusDiscussion(val: boolean) {
|
||||
try {
|
||||
setLoadingUpdate(true)
|
||||
if (val) {
|
||||
const response = await funEditStatusDiscussion(id, { status: status })
|
||||
|
||||
if (response.success) {
|
||||
toast.success(response.message)
|
||||
refresh.set(!refresh.get())
|
||||
@@ -38,40 +40,37 @@ export default function DrawerDetailDiscussion({ onSuccess, id, status, idDivisi
|
||||
id: id,
|
||||
}])
|
||||
onSuccess(false)
|
||||
setValModalStatus(false)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
}
|
||||
setValModalStatus(false)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
setValModalStatus(false)
|
||||
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingUpdate(false)
|
||||
setValModalStatus(false)
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchDeleteDiscussion(val: boolean) {
|
||||
try {
|
||||
setLoadingDelete(true)
|
||||
if (val) {
|
||||
const response = await funDeleteDiscussion(id)
|
||||
if (response.success) {
|
||||
toast.success(response.message)
|
||||
setValModal(false)
|
||||
onSuccess(false)
|
||||
router.push(`/division/${param.id}/discussion`)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
}
|
||||
setValModal(false)
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
setValModal(false)
|
||||
toast.error("Gagal hapus diskusi, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingDelete(false)
|
||||
setValModal(false)
|
||||
}
|
||||
}
|
||||
@@ -130,12 +129,12 @@ export default function DrawerDetailDiscussion({ onSuccess, id, status, idDivisi
|
||||
</SimpleGrid>
|
||||
</Stack>
|
||||
|
||||
<LayoutModal opened={isValModal} onClose={() => setValModal(false)}
|
||||
<LayoutModal loading={loadingDelete} opened={isValModal} onClose={() => setValModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus diskusi ini?"
|
||||
onYes={(val) => { fetchDeleteDiscussion(val) }} />
|
||||
|
||||
|
||||
<LayoutModal opened={isValModalStatus} onClose={() => setValModalStatus(false)}
|
||||
<LayoutModal loading={loadingUpdate} opened={isValModalStatus} onClose={() => setValModalStatus(false)}
|
||||
description="Apakah Anda yakin ingin mengubah status diskusi ini?"
|
||||
onYes={(val) => { fetchStatusDiscussion(val) }} />
|
||||
</Box>
|
||||
|
||||
@@ -15,7 +15,6 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
||||
const [isValModal, setValModal] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const router = useRouter()
|
||||
const [isImg, setImg] = useState("")
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [img, setIMG] = useState<any | null>()
|
||||
@@ -51,25 +50,27 @@ export default function FormCreateDiscussion({ id }: { id: string }) {
|
||||
|
||||
async function createDiscussion(val: boolean) {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const response = await funCreateDiscussion({
|
||||
desc: isData.desc,
|
||||
idDivision: id
|
||||
})
|
||||
if (val) {
|
||||
setLoadingModal(true)
|
||||
const response = await funCreateDiscussion({
|
||||
desc: isData.desc,
|
||||
idDivision: id
|
||||
})
|
||||
|
||||
if (response.success) {
|
||||
setDataRealtime(response.notif)
|
||||
toast.success(response.message)
|
||||
router.push(`/division/${param.id}/discussion/`)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
if (response.success) {
|
||||
setDataRealtime(response.notif)
|
||||
toast.success(response.message)
|
||||
router.push(`/division/${param.id}/discussion/`)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menambahkan diskusi, coba lagi nanti");
|
||||
} finally {
|
||||
setValModal(false)
|
||||
setLoadingModal(false)
|
||||
setValModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
'use client'
|
||||
import { currentScroll, TEMA } from "@/module/_global";
|
||||
import { currentScroll, globalNotifPage, ReloadButtonTop, TEMA } from "@/module/_global";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { Avatar, Badge, Box, Divider, Flex, Grid, Group, Skeleton, Spoiler, Text, TextInput } from "@mantine/core";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import _ from "lodash";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { GrChatOption } from "react-icons/gr";
|
||||
import { HiMagnifyingGlass } from "react-icons/hi2";
|
||||
import { funGetAllDiscussion } from "../lib/api_discussion";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IDataDiscussion } from "../lib/type_discussion";
|
||||
import toast from "react-hot-toast";
|
||||
import _ from "lodash";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
|
||||
|
||||
export default function ListDiscussion({ id }: { id: string }) {
|
||||
const [isData, setData] = useState<IDataDiscussion[]>([])
|
||||
@@ -21,11 +22,12 @@ export default function ListDiscussion({ id }: { id: string }) {
|
||||
const router = useRouter()
|
||||
const { value: containerRef } = useHookstate(currentScroll);
|
||||
const [isPage, setPage] = useState(1)
|
||||
const notifLoadPage = useHookstate(globalNotifPage)
|
||||
const [isRefresh, setRefresh] = useState(false)
|
||||
|
||||
const getData = async (loading: boolean) => {
|
||||
try {
|
||||
if (loading)
|
||||
setLoading(true)
|
||||
setLoading(loading)
|
||||
const response = await funGetAllDiscussion('?division=' + id + '&search=' + searchQuery + '&page=' + isPage)
|
||||
if (response.success) {
|
||||
if (isPage == 1) {
|
||||
@@ -36,7 +38,6 @@ export default function ListDiscussion({ id }: { id: string }) {
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
} finally {
|
||||
@@ -75,8 +76,37 @@ export default function ListDiscussion({ id }: { id: string }) {
|
||||
}, [containerRef, isPage]);
|
||||
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
console.log(notifLoadPage.get())
|
||||
if (notifLoadPage.get().category == 'division/' + param.id + '/discussion' && notifLoadPage.get().load == true) {
|
||||
setRefresh(true)
|
||||
}
|
||||
}, [notifLoadPage.get().load])
|
||||
|
||||
function onRefresh() {
|
||||
notifLoadPage.set({
|
||||
category: '',
|
||||
load: false
|
||||
})
|
||||
setRefresh(false)
|
||||
setPage(1)
|
||||
setTimeout(() => {
|
||||
getData(false)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Box p={20}>
|
||||
{
|
||||
isRefresh &&
|
||||
<ReloadButtonTop
|
||||
onReload={() => { onRefresh() }}
|
||||
title='UPDATE'
|
||||
/>
|
||||
|
||||
}
|
||||
<TextInput
|
||||
styles={{
|
||||
input: {
|
||||
|
||||
Reference in New Issue
Block a user