fix: dokumen divisi
Deskripsi: - update order by - loading rename - loading create - loading hapus - loading move - loading copy - realtime move di asal itemnya No Issues
This commit is contained in:
@@ -2,15 +2,15 @@ import { keyWibu, LayoutDrawer, TEMA } from "@/module/_global";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { Box, Flex, SimpleGrid, Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useParams, useSearchParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { LuFolders, LuFolderSymlink } from "react-icons/lu";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import { funCopyDocument, funMoveDocument } from "../lib/api_document";
|
||||
import { IDataDocument } from "../lib/type_document";
|
||||
import { globalRefreshDocument } from "../lib/val_document";
|
||||
import DrawerCutDocuments from "./drawer_cut_documents";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
|
||||
export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||
const [isCut, setIsCut] = useState(false)
|
||||
@@ -19,20 +19,31 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||
const param = useParams<{ id: string }>()
|
||||
const [forbidCopy, setForbidCopy] = useState(true)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [loadingMove, setLoadingMove] = useState(false)
|
||||
const [loadingCopy, setLoadingCopy] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
})
|
||||
const searchParams = useSearchParams()
|
||||
const pathAwal = searchParams.get('path')
|
||||
|
||||
|
||||
async function onMoveItem(path: string) {
|
||||
try {
|
||||
setLoadingMove(true)
|
||||
const res = await funMoveDocument({ path, dataItem: data })
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
category: "division-document",
|
||||
id: path,
|
||||
}])
|
||||
setDataRealtime([
|
||||
{
|
||||
category: "division-document",
|
||||
id: path,
|
||||
},
|
||||
{
|
||||
category: "division-document",
|
||||
id: pathAwal,
|
||||
}
|
||||
])
|
||||
toast.success(res.message)
|
||||
refresh.set(true)
|
||||
} else {
|
||||
@@ -41,13 +52,16 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal memindahkan item, coba lagi nanti")
|
||||
} finally {
|
||||
setLoadingMove(false)
|
||||
setIsCut(false)
|
||||
}
|
||||
setIsCut(false)
|
||||
}
|
||||
|
||||
|
||||
async function onCopyItem(path: string) {
|
||||
try {
|
||||
setLoadingCopy(true)
|
||||
const res = await funCopyDocument({ idDivision: param.id, path, dataItem: data })
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
@@ -62,8 +76,10 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal memindahkan item, coba lagi nanti")
|
||||
} finally {
|
||||
setLoadingCopy(false)
|
||||
setIsCopy(false)
|
||||
}
|
||||
setIsCopy(false)
|
||||
}
|
||||
|
||||
|
||||
@@ -108,11 +124,11 @@ export default function DrawerMore({ data }: { data: IDataDocument[] }) {
|
||||
|
||||
|
||||
<LayoutDrawer opened={isCut} onClose={() => setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg">
|
||||
<DrawerCutDocuments data={data} onChoosePath={(val) => { onMoveItem(val) }} category="move" />
|
||||
<DrawerCutDocuments data={data} loadingAction={loadingMove} onChoosePath={(val) => { onMoveItem(val) }} category="move" />
|
||||
</LayoutDrawer>
|
||||
|
||||
<LayoutDrawer opened={isCopy} onClose={() => setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg">
|
||||
<DrawerCutDocuments data={data} onChoosePath={(val) => { onCopyItem(val) }} category="copy" />
|
||||
<DrawerCutDocuments data={data} loadingAction={loadingCopy} onChoosePath={(val) => { onCopyItem(val) }} category="copy" />
|
||||
</LayoutDrawer>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user