upd: document
Deskripsi: - pindah item No Issues
This commit is contained in:
@@ -3,12 +3,16 @@ import { Box, Button, Divider, Flex, Grid, Group, Modal, Text, TextInput } from
|
||||
import React, { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc';
|
||||
import { funCreateFolder, funGetAllDocument } from '../lib/api_document';
|
||||
import { funCreateFolder, funGetAllDocument, funMoveDocument } from '../lib/api_document';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { IDataDocument } from '../lib/type_document';
|
||||
import { IDataDocument, IFormDetailMoreItem } from '../lib/type_document';
|
||||
import { useShallowEffect } from '@mantine/hooks';
|
||||
import { FaFolder } from 'react-icons/fa6';
|
||||
import { IoMdFolder } from 'react-icons/io';
|
||||
import { MdFolder } from 'react-icons/md';
|
||||
|
||||
export default function DrawerCutDocuments() {
|
||||
|
||||
export default function DrawerCutDocuments({ onChoosePath, data }: { data: IFormDetailMoreItem[], onChoosePath: (val: string) => void }) {
|
||||
const [opened, setOpened] = useState(false);
|
||||
const param = useParams<{ id: string }>()
|
||||
const [path, setPath] = useState('home')
|
||||
@@ -36,10 +40,9 @@ export default function DrawerCutDocuments() {
|
||||
setOpened(false)
|
||||
}
|
||||
|
||||
|
||||
async function getOneData() {
|
||||
try {
|
||||
const respon = await funGetAllDocument("?division=" + param.id + "&path=" + path);
|
||||
const respon = await funGetAllDocument("?division=" + param.id + "&path=" + path + "&category=folder");
|
||||
if (respon.success) {
|
||||
setDataDocument(respon.data);
|
||||
} else {
|
||||
@@ -66,29 +69,35 @@ export default function DrawerCutDocuments() {
|
||||
<Button variant="subtle" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => setOpened(true)}>BUAT FOLDER BARU</Button>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={6}>
|
||||
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"}>PINDAH</Button>
|
||||
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => onChoosePath(path)}>PINDAH</Button>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
</Box>
|
||||
<Box p={10} pb={60}>
|
||||
{dataDocument.map((v, i) => {
|
||||
const found = data.some((i: any) => i.id == v.id)
|
||||
return (
|
||||
<Box key={i}>
|
||||
<Box mt={10} mb={10} onClick={() => setPath(v.id)}>
|
||||
<Box mt={10} mb={10} onClick={() => {
|
||||
if (!found) {
|
||||
setPath(v.id)
|
||||
}
|
||||
}}>
|
||||
<Grid align='center'>
|
||||
<Grid.Col span={12}>
|
||||
<Group gap={20}>
|
||||
<Box>
|
||||
{
|
||||
(v.category == "FOLDER") ?
|
||||
<FcFolder size={60} /> :
|
||||
(v.extension == "pdf" || v.extension == "csv") ?
|
||||
<FcDocument size={60} /> :
|
||||
<FcImageFile size={60} />
|
||||
(found) ?
|
||||
<MdFolder size={60} color='grey' /> :
|
||||
<FcFolder size={60} />
|
||||
}
|
||||
</Box>
|
||||
<Flex direction={'column'}>
|
||||
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>
|
||||
{
|
||||
(found) && <Text c={'dimmed'} fz={13} fs={'italic'}>Tidak bisa memilih folder ini</Text>
|
||||
}
|
||||
</Flex>
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
|
||||
@@ -4,10 +4,36 @@ import React, { useState } from "react";
|
||||
import { LuFolders, LuFolderSymlink } from "react-icons/lu";
|
||||
import DrawerCutDocuments from "./drawer_cut_documents";
|
||||
import DrawerCopyDocuments from "./drawer_copy_documents";
|
||||
import { IFormDetailMoreItem } from "../lib/type_document";
|
||||
import toast from "react-hot-toast";
|
||||
import { funMoveDocument } from "../lib/api_document";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { globalRefreshDocument } from "../lib/val_document";
|
||||
|
||||
export default function DrawerMore() {
|
||||
export default function DrawerMore({ data }: { data: IFormDetailMoreItem[] }) {
|
||||
const [isCut, setIsCut] = useState(false)
|
||||
const [isCopy, setIsCopy] = useState(false)
|
||||
const refresh = useHookstate(globalRefreshDocument)
|
||||
|
||||
|
||||
async function onMoveItem(path: string) {
|
||||
try {
|
||||
const res = await funMoveDocument({ path, dataItem: data })
|
||||
if (res.success) {
|
||||
toast.success(res.message)
|
||||
refresh.set(true)
|
||||
} else {
|
||||
toast.error(res.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.error("Gagal memindahkan item, coba lagi nanti")
|
||||
}
|
||||
setIsCut(false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Stack p={10} >
|
||||
@@ -35,11 +61,9 @@ export default function DrawerMore() {
|
||||
|
||||
|
||||
<LayoutDrawer opened={isCut} onClose={() => setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg">
|
||||
<DrawerCutDocuments />
|
||||
<DrawerCutDocuments data={data} onChoosePath={(val) => { onMoveItem(val) }} />
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
|
||||
<LayoutDrawer opened={isCopy} onClose={() => setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg">
|
||||
<DrawerCopyDocuments />
|
||||
</LayoutDrawer>
|
||||
|
||||
@@ -166,6 +166,8 @@ export default function NavbarDocumentDivision() {
|
||||
function resetRefresh() {
|
||||
refresh.set(false)
|
||||
setOpen(false)
|
||||
setMore(false)
|
||||
handleBatal()
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
@@ -397,8 +399,11 @@ export default function NavbarDocumentDivision() {
|
||||
</Box>
|
||||
</Box>
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
|
||||
<LayoutDrawer opened={more} title={''} onClose={() => setMore(false)}>
|
||||
<DrawerMore />
|
||||
<DrawerMore data={selectedFiles} />
|
||||
</LayoutDrawer>
|
||||
</Box>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user