import { TEMA } from "@/module/_global"; import { Box, Breadcrumbs, Button, Divider, Flex, Grid, Group, Modal, ScrollArea, Skeleton, Text, TextInput, } from "@mantine/core"; import React, { useState } from "react"; import toast from "react-hot-toast"; import { FcFolder } from "react-icons/fc"; import { funCreateFolder, funGetAllDocument, funMoveDocument, } from "../lib/api_document"; import { useParams } from "next/navigation"; import { IDataDocument, IFormDetailMoreItem, IJalurItem, } from "../lib/type_document"; import { useMediaQuery, useShallowEffect } from "@mantine/hooks"; import { MdFolder } from "react-icons/md"; import router from "next/router"; import { GoChevronRight } from "react-icons/go"; import { useHookstate } from "@hookstate/core"; export default function DrawerCutDocuments({ category, onChoosePath, data, }: { category: string; data: IFormDetailMoreItem[]; onChoosePath: (val: string) => void; }) { const [opened, setOpened] = useState(false); const param = useParams<{ id: string }>(); const [path, setPath] = useState("home"); const [dataDocument, setDataDocument] = useState([]); const [dataJalur, setDataJalur] = useState([]); const [valName, setValName] = useState(""); const tema = useHookstate(TEMA); const [loading, setLoading] = useState(true); const isMobile = useMediaQuery("(max-width: 369px)"); async function onCreateFolder() { try { const res = await funCreateFolder({ name: valName, path: path, idDivision: param.id, }); if (res.success) { getOneData(); } else { toast.error(res.message); } } catch (error) { console.error(error); toast.error("Gagal membuat folder baru, coba lagi nanti"); } setOpened(false); } async function getOneData() { try { setLoading(true); const respon = await funGetAllDocument( "?division=" + param.id + "&path=" + path + "&category=folder" ); if (respon.success) { setDataDocument(respon.data); setDataJalur(respon.jalur); } else { toast.error(respon.message); } setLoading(false); } catch (error) { console.error(error); toast.error("Gagal mendapatkan item, coba lagi nanti"); } finally { setLoading(false); } } useShallowEffect(() => { getOneData(); }, [param.id, path]); return ( } separatorMargin="md" mt="xs" > {dataJalur.map((v, i) => { return ( setPath(v.id)} key={i} style={{ cursor: "pointer" }} > {v.name} ); })} {loading ? ( ) : null} {loading ? ( Array(6) .fill(null) .map((_, i) => ( )) ) : ( {dataDocument.length == 0 ? ( Tidak ada Dokumen ) : ( {dataDocument.map((v, i) => { const found = data.some((i: any) => i.id == v.id); return ( { if (!found) { setPath(v.id); } }} > {found ? ( ) : ( )} {v.category == "FOLDER" ? v.name : v.name + "." + v.extension} {found && ( Tidak bisa memilih folder ini )} ); })} )} )} setOpened(false)} centered withCloseButton={false} > Buat Folder setValName(e.target.value)} /> ); }