upd: document
Deskripsi: - persiapan pindah item No Issues
This commit is contained in:
17
src/app/api/document/more/route.ts
Normal file
17
src/app/api/document/more/route.ts
Normal file
@@ -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 });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -2,39 +2,63 @@ import { WARNA } from '@/module/_global';
|
|||||||
import { Box, Button, Divider, Flex, Grid, Group, Modal, Text, TextInput } from '@mantine/core';
|
import { Box, Button, Divider, Flex, Grid, Group, Modal, Text, TextInput } from '@mantine/core';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { FcFolder } from 'react-icons/fc';
|
import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc';
|
||||||
const dataDocuments = [
|
import { funCreateFolder, funGetAllDocument } from '../lib/api_document';
|
||||||
{
|
import { useParams } from 'next/navigation';
|
||||||
id: 1,
|
import { IDataDocument } from '../lib/type_document';
|
||||||
name: 'Administrasi',
|
import { useShallowEffect } from '@mantine/hooks';
|
||||||
date: '18/06/2024 14.00 PM',
|
|
||||||
icon: <FcFolder size={40} />
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: 'Administrasi',
|
|
||||||
date: '18/06/2024 14.00 PM',
|
|
||||||
icon: <FcFolder size={40} />
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: 'Administrasi',
|
|
||||||
date: '18/06/2024 14.00 PM',
|
|
||||||
icon: <FcFolder size={40} />
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function DrawerCutDocuments() {
|
export default function DrawerCutDocuments() {
|
||||||
const [opened, setOpened] = useState(false);
|
const [opened, setOpened] = useState(false);
|
||||||
function onCreate(val: boolean) {
|
const param = useParams<{ id: string }>()
|
||||||
if (val) {
|
const [path, setPath] = useState('home')
|
||||||
toast.success("Sukses! Membuat Folder");
|
const [dataDocument, setDataDocument] = useState<IDataDocument[]>([])
|
||||||
|
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)
|
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 (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Box h={60} pos={"fixed"} bottom={0} w={{base: "92%", md: "94%"}} style={{
|
<Box h={60} pos={"fixed"} bottom={0} w={{ base: "92%", md: "94%" }} style={{
|
||||||
zIndex: 999
|
zIndex: 999
|
||||||
}}>
|
}}>
|
||||||
<Grid justify='center'>
|
<Grid justify='center'>
|
||||||
@@ -42,34 +66,42 @@ export default function DrawerCutDocuments() {
|
|||||||
<Button variant="subtle" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => setOpened(true)}>BUAT FOLDER BARU</Button>
|
<Button variant="subtle" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => setOpened(true)}>BUAT FOLDER BARU</Button>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"}>PIDAH</Button>
|
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"}>PINDAH</Button>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
<Box p={10} pb={60}>
|
<Box p={10} pb={60}>
|
||||||
{dataDocuments.map((v, i) => {
|
{dataDocument.map((v, i) => {
|
||||||
return (
|
return (
|
||||||
<Box key={i}>
|
<Box key={i}>
|
||||||
<Box mt={10} mb={10}>
|
<Box mt={10} mb={10} onClick={() => setPath(v.id)}>
|
||||||
<Grid align='center'>
|
<Grid align='center'>
|
||||||
<Grid.Col span={12}>
|
<Grid.Col span={12}>
|
||||||
<Group gap={20}>
|
<Group gap={20}>
|
||||||
<Box>
|
<Box>
|
||||||
{v.icon}
|
{
|
||||||
</Box>
|
(v.category == "FOLDER") ?
|
||||||
<Flex direction={'column'}>
|
<FcFolder size={60} /> :
|
||||||
<Text>{v.name}</Text>
|
(v.extension == "pdf" || v.extension == "csv") ?
|
||||||
<Text fz={10}>{v.date}</Text>
|
<FcDocument size={60} /> :
|
||||||
</Flex>
|
<FcImageFile size={60} />
|
||||||
</Group>
|
}
|
||||||
</Grid.Col>
|
</Box>
|
||||||
</Grid>
|
<Flex direction={'column'}>
|
||||||
</Box>
|
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>
|
||||||
<Divider size="xs" />
|
</Flex>
|
||||||
|
</Group>
|
||||||
|
</Grid.Col>
|
||||||
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
<Divider size="xs" />
|
||||||
})}
|
</Box>
|
||||||
|
)
|
||||||
|
})}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<Modal styles={{
|
<Modal styles={{
|
||||||
body: {
|
body: {
|
||||||
borderRadius: 20
|
borderRadius: 20
|
||||||
@@ -92,7 +124,9 @@ export default function DrawerCutDocuments() {
|
|||||||
}}
|
}}
|
||||||
size="md"
|
size="md"
|
||||||
radius={10}
|
radius={10}
|
||||||
placeholder="Buat Folder Baru"
|
placeholder="Nama folder"
|
||||||
|
value={valName}
|
||||||
|
onChange={(e) => setValName(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Grid mt={40}>
|
<Grid mt={40}>
|
||||||
@@ -100,7 +134,7 @@ export default function DrawerCutDocuments() {
|
|||||||
<Button variant="subtle" fullWidth color='#969494' onClick={() => setOpened(false)}>Batalkan</Button>
|
<Button variant="subtle" fullWidth color='#969494' onClick={() => setOpened(false)}>Batalkan</Button>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<Button variant="subtle" fullWidth color={WARNA.biruTua} onClick={(val) => onCreate(true)}>Membuat</Button>
|
<Button variant="subtle" fullWidth color={WARNA.biruTua} onClick={() => onCreateFolder()}>Membuat</Button>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -32,9 +32,14 @@ export default function DrawerMore() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</SimpleGrid>
|
</SimpleGrid>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
|
||||||
<LayoutDrawer opened={isCut} onClose={() => setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg">
|
<LayoutDrawer opened={isCut} onClose={() => setIsCut(false)} title={'Pilih Lokasi Pemindahan'} size="lg">
|
||||||
<DrawerCutDocuments />
|
<DrawerCutDocuments />
|
||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LayoutDrawer opened={isCopy} onClose={() => setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg">
|
<LayoutDrawer opened={isCopy} onClose={() => setIsCopy(false)} title={'Pilih Lokasi Salin'} size="lg">
|
||||||
<DrawerCopyDocuments />
|
<DrawerCopyDocuments />
|
||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Gagal mendapatkan divisi, coba lagi nanti");
|
toast.error("Gagal mendapatkan item, coba lagi nanti");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user