diff --git a/src/app/api/document/more/route.ts b/src/app/api/document/more/route.ts new file mode 100644 index 0000000..f4a77c7 --- /dev/null +++ b/src/app/api/document/more/route.ts @@ -0,0 +1,17 @@ +import { funGetUserByCookies } from "@/module/auth"; +import { NextResponse } from "next/server"; + +// MOVE ITEM +export async function POST(request: Request) { + try { + const user = await funGetUserByCookies() + if (user.id == undefined) { + return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 }); + } + + return NextResponse.json({ success: true, message: "Berhasil memindahkan item" }, { status: 200 }); + } catch (error) { + console.log(error); + return NextResponse.json({ success: false, message: "Gagal memindahkan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 }); + } +}; \ No newline at end of file diff --git a/src/module/document/ui/drawer_cut_documents.tsx b/src/module/document/ui/drawer_cut_documents.tsx index 96c0728..7677160 100644 --- a/src/module/document/ui/drawer_cut_documents.tsx +++ b/src/module/document/ui/drawer_cut_documents.tsx @@ -2,39 +2,63 @@ import { WARNA } from '@/module/_global'; import { Box, Button, Divider, Flex, Grid, Group, Modal, Text, TextInput } from '@mantine/core'; import React, { useState } from 'react'; import toast from 'react-hot-toast'; -import { FcFolder } from 'react-icons/fc'; -const dataDocuments = [ - { - id: 1, - name: 'Administrasi', - date: '18/06/2024 14.00 PM', - icon: - }, - { - id: 2, - name: 'Administrasi', - date: '18/06/2024 14.00 PM', - icon: - }, - { - id: 3, - name: 'Administrasi', - date: '18/06/2024 14.00 PM', - icon: - }, -] +import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc'; +import { funCreateFolder, funGetAllDocument } from '../lib/api_document'; +import { useParams } from 'next/navigation'; +import { IDataDocument } from '../lib/type_document'; +import { useShallowEffect } from '@mantine/hooks'; export default function DrawerCutDocuments() { const [opened, setOpened] = useState(false); - function onCreate(val: boolean) { - if (val) { - toast.success("Sukses! Membuat Folder"); + const param = useParams<{ id: string }>() + const [path, setPath] = useState('home') + const [dataDocument, setDataDocument] = useState([]) + const [valName, setValName] = useState('') + + + 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 { + const respon = await funGetAllDocument("?division=" + param.id + "&path=" + path); + if (respon.success) { + setDataDocument(respon.data); + } else { + toast.error(respon.message); + } + + } catch (error) { + console.error(error); + toast.error("Gagal mendapatkan item, coba lagi nanti"); + } + } + + useShallowEffect(() => { + getOneData() + }, [param.id, path]) + return ( - @@ -42,34 +66,42 @@ export default function DrawerCutDocuments() { - + - {dataDocuments.map((v, i) => { - return ( - - - - - - - {v.icon} - - - {v.name} - {v.date} - - - - - - + {dataDocument.map((v, i) => { + return ( + + setPath(v.id)}> + + + + + { + (v.category == "FOLDER") ? + : + (v.extension == "pdf" || v.extension == "csv") ? + : + + } + + + {(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension} + + + + - ) - })} + + + ) + })} + + + setValName(e.target.value)} /> @@ -100,7 +134,7 @@ export default function DrawerCutDocuments() { - + diff --git a/src/module/document/ui/drawer_more.tsx b/src/module/document/ui/drawer_more.tsx index 67a02e5..9db2302 100644 --- a/src/module/document/ui/drawer_more.tsx +++ b/src/module/document/ui/drawer_more.tsx @@ -32,9 +32,14 @@ export default function DrawerMore() { + + setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg"> + + + setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg"> diff --git a/src/module/document/ui/navbar_document_division.tsx b/src/module/document/ui/navbar_document_division.tsx index 1f35cbe..0f0a319 100644 --- a/src/module/document/ui/navbar_document_division.tsx +++ b/src/module/document/ui/navbar_document_division.tsx @@ -159,7 +159,7 @@ export default function NavbarDocumentDivision() { } catch (error) { console.error(error); - toast.error("Gagal mendapatkan divisi, coba lagi nanti"); + toast.error("Gagal mendapatkan item, coba lagi nanti"); } }