: document

Deskripsi:
- copy item

nb : baru setengah selesai, aku nyerah aja lahh

nanti aja pikirin nya

No Issues
This commit is contained in:
amel
2024-08-22 14:30:46 +08:00
parent 92a4c06bff
commit 3d513c0d08
6 changed files with 196 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
import { IFormEditItem, IFormFolder, IFormMoreItem } from "./type_document";
import { IFormEditItem, IFormFolder, IFormMoreCopyItem, IFormMoreItem } from "./type_document";
export const funGetAllDocument = async (path?: string) => {
const response = await fetch(`/api/document${(path) ? path : ''}`, { next: { tags: ['document'] } });
@@ -54,4 +54,15 @@ export const funMoveDocument = async (data: IFormMoreItem) => {
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
};
export const funCopyDocument = async (data: IFormMoreCopyItem) => {
const response = await fetch("/api/document/more", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
return await response.json().catch(() => null);
};

View File

@@ -33,4 +33,10 @@ export interface IFormDetailMoreItem {
export interface IFormMoreItem {
path: string,
dataItem: IFormDetailMoreItem[]
}
export interface IFormMoreCopyItem {
idDivision: string,
path: string,
dataItem: IDataDocument[]
}

View File

@@ -12,7 +12,7 @@ import { IoMdFolder } from 'react-icons/io';
import { MdFolder } from 'react-icons/md';
export default function DrawerCutDocuments({ onChoosePath, data }: { data: IFormDetailMoreItem[], onChoosePath: (val: string) => void }) {
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')
@@ -69,7 +69,13 @@ export default function DrawerCutDocuments({ onChoosePath, data }: { data: IForm
<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"} onClick={() => onChoosePath(path)}>PINDAH</Button>
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => onChoosePath(path)}>
{
(category == "move") ?
"PINDAH" : "SALIN"
}
</Button>
</Grid.Col>
</Grid>
</Box>

View File

@@ -4,16 +4,18 @@ 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 { IDataDocument, IFormDetailMoreItem } from "../lib/type_document";
import toast from "react-hot-toast";
import { funMoveDocument } from "../lib/api_document";
import { funCopyDocument, funMoveDocument } from "../lib/api_document";
import { useHookstate } from "@hookstate/core";
import { globalRefreshDocument } from "../lib/val_document";
import { useParams } from "next/navigation";
export default function DrawerMore({ data }: { data: IFormDetailMoreItem[] }) {
export default function DrawerMore({ data }: { data: IDataDocument[] }) {
const [isCut, setIsCut] = useState(false)
const [isCopy, setIsCopy] = useState(false)
const refresh = useHookstate(globalRefreshDocument)
const param = useParams<{ id: string }>()
async function onMoveItem(path: string) {
@@ -33,6 +35,23 @@ export default function DrawerMore({ data }: { data: IFormDetailMoreItem[] }) {
}
async function onCopyItem(path: string) {
try {
const res = await funCopyDocument({ idDivision: param.id, 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")
}
setIsCopy(false)
}
return (
<Box>
@@ -61,11 +80,11 @@ export default function DrawerMore({ data }: { data: IFormDetailMoreItem[] }) {
<LayoutDrawer opened={isCut} onClose={() => setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg">
<DrawerCutDocuments data={data} onChoosePath={(val) => { onMoveItem(val) }} />
<DrawerCutDocuments data={data} onChoosePath={(val) => { onMoveItem(val) }} category="move" />
</LayoutDrawer>
<LayoutDrawer opened={isCopy} onClose={() => setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg">
<DrawerCopyDocuments />
<DrawerCutDocuments data={data} onChoosePath={(val) => { onCopyItem(val) }} category="copy" />
</LayoutDrawer>
</Box>
);

View File

@@ -57,7 +57,8 @@ export default function NavbarDocumentDivision() {
id: dataDocument[index].id,
name: dataDocument[index].name,
path: dataDocument[index].path,
extension: dataDocument[index].extension
extension: dataDocument[index].extension,
category: dataDocument[index].category,
}
])
}
@@ -81,7 +82,8 @@ export default function NavbarDocumentDivision() {
id: dataDocument[index].id,
name: dataDocument[index].name,
path: dataDocument[index].path,
extension: dataDocument[index].extension
extension: dataDocument[index].extension,
category: dataDocument[index].category,
}
setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr])
}