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:
@@ -125,6 +125,11 @@ export async function GET(request: Request) {
|
||||
updatedAt: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
DivisionDocumentFolderFile: {
|
||||
createdAt: 'desc'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -169,7 +174,7 @@ export async function GET(request: Request) {
|
||||
updatedAt: true
|
||||
},
|
||||
orderBy: {
|
||||
name: 'asc'
|
||||
createdAt: 'desc'
|
||||
}
|
||||
})
|
||||
|
||||
@@ -185,7 +190,7 @@ export async function GET(request: Request) {
|
||||
allData.push(...formatDataShare)
|
||||
}
|
||||
|
||||
const formatData = _.orderBy(allData, ['category', 'name'], ['desc', 'asc']);
|
||||
const formatData = _.orderBy(allData, ['category', 'createdAt'], ['desc', 'asc']);
|
||||
|
||||
let pathNow = path
|
||||
let jalur = []
|
||||
|
||||
@@ -8,11 +8,11 @@ import toast from "react-hot-toast";
|
||||
import { FcFolder } from "react-icons/fc";
|
||||
import { GoChevronRight } from "react-icons/go";
|
||||
import { MdFolder } from "react-icons/md";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import { funCreateFolder, funGetAllDocument } from "../lib/api_document";
|
||||
import { IDataDocument, IFormDetailMoreItem, IJalurItem, } from "../lib/type_document";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
|
||||
export default function DrawerCutDocuments({ category, onChoosePath, data, }: { category: string; data: IFormDetailMoreItem[]; onChoosePath: (val: string) => void; }) {
|
||||
export default function DrawerCutDocuments({ category, loadingAction, onChoosePath, data, }: { category: string; loadingAction: boolean; data: IFormDetailMoreItem[]; onChoosePath: (val: string) => void; }) {
|
||||
const [opened, setOpened] = useState(false);
|
||||
const param = useParams<{ id: string }>();
|
||||
const [path, setPath] = useState("home");
|
||||
@@ -100,6 +100,7 @@ export default function DrawerCutDocuments({ category, onChoosePath, data, }: {
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button
|
||||
loading={loadingAction}
|
||||
variant="filled"
|
||||
fullWidth
|
||||
color={tema.get().utama}
|
||||
|
||||
@@ -24,6 +24,7 @@ export default function DrawerMenuDocumentDivision() {
|
||||
const openRef = useRef<() => void>(null)
|
||||
const tema = useHookstate(TEMA)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [loadingCreate, setLoadingCreate] = useState(false)
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -36,6 +37,7 @@ export default function DrawerMenuDocumentDivision() {
|
||||
|
||||
async function onCreateFolder() {
|
||||
try {
|
||||
setLoadingCreate(true)
|
||||
const res = await funCreateFolder(bodyFolder)
|
||||
if (!res.success) {
|
||||
toast.error(res.message)
|
||||
@@ -48,11 +50,13 @@ export default function DrawerMenuDocumentDivision() {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal membuat folder baru, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingCreate(false)
|
||||
refresh.set(true)
|
||||
setOpenModal(false)
|
||||
setOpenDrawerDocument(false)
|
||||
}
|
||||
|
||||
refresh.set(true)
|
||||
setOpenModal(false)
|
||||
setOpenDrawerDocument(false)
|
||||
}
|
||||
|
||||
async function onUploadFile(data: any) {
|
||||
@@ -204,7 +208,7 @@ export default function DrawerMenuDocumentDivision() {
|
||||
<Button variant="subtle" fullWidth color='#969494' onClick={() => setOpenModal(false)}>Batalkan</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="subtle" fullWidth color={tema.get().utama} onClick={() => onCreateFolder()}>Membuat</Button>
|
||||
<Button loading={loadingCreate} variant="subtle" fullWidth color={tema.get().utama} onClick={() => onCreateFolder()}>Membuat</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Box>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -18,13 +18,13 @@ import { HiMenu } from "react-icons/hi";
|
||||
import { LuShare2 } from "react-icons/lu";
|
||||
import { MdClose, MdOutlineMoreHoriz } from "react-icons/md";
|
||||
import { RiListCheck } from "react-icons/ri";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
import { funDeleteDocument, funGetAllDocument, funRenameDocument, } from "../lib/api_document";
|
||||
import { IDataDocument, IJalurItem } from "../lib/type_document";
|
||||
import { globalRefreshDocument } from "../lib/val_document";
|
||||
import DrawerMenuDocumentDivision from "./drawer_menu_document_division";
|
||||
import DrawerMore from "./drawer_more";
|
||||
import DrawerShareDocument from "./drawer_share_document";
|
||||
import { useWibuRealtime } from "wibu-realtime";
|
||||
|
||||
export default function NavbarDocumentDivision() {
|
||||
const router = useRouter();
|
||||
@@ -52,6 +52,8 @@ export default function NavbarDocumentDivision() {
|
||||
const isMobile2 = useMediaQuery("(max-width: 496px)");
|
||||
const tema = useHookstate(TEMA);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadingRename, setLoadingRename] = useState(false);
|
||||
const [loadingDelete, setLoadingDelete] = useState(false);
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -138,8 +140,9 @@ export default function NavbarDocumentDivision() {
|
||||
};
|
||||
|
||||
async function onConfirmDelete(val: boolean) {
|
||||
if (val) {
|
||||
try {
|
||||
try {
|
||||
if (val) {
|
||||
setLoadingDelete(true)
|
||||
const respon = await funDeleteDocument(selectedFiles);
|
||||
if (respon.success) {
|
||||
getOneData(false);
|
||||
@@ -150,19 +153,20 @@ export default function NavbarDocumentDivision() {
|
||||
} else {
|
||||
toast.error(respon.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus item, coba lagi nanti");
|
||||
handleBatal();
|
||||
}
|
||||
|
||||
handleBatal();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal menghapus item, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingDelete(false)
|
||||
setIsDelete(false);
|
||||
}
|
||||
|
||||
setIsDelete(false);
|
||||
}
|
||||
|
||||
async function onRenameSubmit() {
|
||||
try {
|
||||
setLoadingRename(true);
|
||||
const res = await funRenameDocument(bodyRename);
|
||||
if (res.success) {
|
||||
setDataRealtime([{
|
||||
@@ -176,11 +180,13 @@ export default function NavbarDocumentDivision() {
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mengganti nama item, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingRename(false)
|
||||
setSelectedFiles([]);
|
||||
setDariSelectAll(false);
|
||||
setRename(false);
|
||||
}
|
||||
|
||||
setSelectedFiles([]);
|
||||
setDariSelectAll(false);
|
||||
setRename(false);
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
@@ -802,6 +808,7 @@ export default function NavbarDocumentDivision() {
|
||||
|
||||
{/* MODAL KONFIRMASI DELETE */}
|
||||
<LayoutModal
|
||||
loading={loadingDelete}
|
||||
opened={isDelete}
|
||||
onClose={() => setIsDelete(false)}
|
||||
description="Apakah Anda yakin ingin menghapus item?"
|
||||
@@ -861,6 +868,7 @@ export default function NavbarDocumentDivision() {
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button
|
||||
loading={loadingRename}
|
||||
variant="subtle"
|
||||
fullWidth
|
||||
color={tema.get().utama}
|
||||
|
||||
Reference in New Issue
Block a user