upd: document
Deskripsi: - pindah item No Issues
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserByCookies } from "@/module/auth";
|
import { funGetUserByCookies } from "@/module/auth";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
|
||||||
// MOVE ITEM
|
// MOVE ITEM
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
try {
|
try {
|
||||||
@@ -9,6 +11,35 @@ export async function POST(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { path, dataItem } = (await request.json());
|
||||||
|
|
||||||
|
|
||||||
|
if (path != "home") {
|
||||||
|
const cekPath = await prisma.divisionDocumentFolderFile.count({
|
||||||
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
id: path
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cekPath == 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan path, data tidak ditemukan" }, { status: 404 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < dataItem.length; i++) {
|
||||||
|
const id = dataItem[i].id;
|
||||||
|
const cekFile = await prisma.divisionDocumentFolderFile.update({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
path: path
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil memindahkan item" }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil memindahkan item" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export async function GET(request: Request) {
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const idDivision = searchParams.get("division");
|
const idDivision = searchParams.get("division");
|
||||||
const path = searchParams.get("path");
|
const path = searchParams.get("path");
|
||||||
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
const cekDivision = await prisma.division.count({
|
const cekDivision = await prisma.division.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -43,14 +44,26 @@ export async function GET(request: Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let kondisi: any = {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(idDivision),
|
||||||
|
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
||||||
|
}
|
||||||
|
|
||||||
|
if (category == "folder") {
|
||||||
|
kondisi = {
|
||||||
|
isActive: true,
|
||||||
|
idDivision: String(idDivision),
|
||||||
|
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path,
|
||||||
|
category: "FOLDER"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const data = await prisma.divisionDocumentFolderFile.findMany({
|
const data = await prisma.divisionDocumentFolderFile.findMany({
|
||||||
where: {
|
where: kondisi,
|
||||||
isActive: true,
|
|
||||||
idDivision: String(idDivision),
|
|
||||||
path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path
|
|
||||||
},
|
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
category: true,
|
category: true,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IFormEditItem, IFormFolder } from "./type_document";
|
import { IFormEditItem, IFormFolder, IFormMoreItem } from "./type_document";
|
||||||
|
|
||||||
export const funGetAllDocument = async (path?: string) => {
|
export const funGetAllDocument = async (path?: string) => {
|
||||||
const response = await fetch(`/api/document${(path) ? path : ''}`, { next: { tags: ['document'] } });
|
const response = await fetch(`/api/document${(path) ? path : ''}`, { next: { tags: ['document'] } });
|
||||||
@@ -43,4 +43,15 @@ export const funDeleteDocument = async (data: []) => {
|
|||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
return await response.json().catch(() => null);
|
return await response.json().catch(() => null);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const funMoveDocument = async (data: IFormMoreItem) => {
|
||||||
|
const response = await fetch("/api/document/more", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
return await response.json().catch(() => null);
|
||||||
};
|
};
|
||||||
@@ -23,4 +23,14 @@ export interface IFormEditItem {
|
|||||||
path: string
|
path: string
|
||||||
idDivision: string
|
idDivision: string
|
||||||
extension: string
|
extension: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFormDetailMoreItem {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IFormMoreItem {
|
||||||
|
path: string,
|
||||||
|
dataItem: IFormDetailMoreItem[]
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,16 @@ import { Box, Button, Divider, Flex, Grid, Group, Modal, Text, TextInput } from
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc';
|
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 { useParams } from 'next/navigation';
|
||||||
import { IDataDocument } from '../lib/type_document';
|
import { IDataDocument, IFormDetailMoreItem } from '../lib/type_document';
|
||||||
import { useShallowEffect } from '@mantine/hooks';
|
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 [opened, setOpened] = useState(false);
|
||||||
const param = useParams<{ id: string }>()
|
const param = useParams<{ id: string }>()
|
||||||
const [path, setPath] = useState('home')
|
const [path, setPath] = useState('home')
|
||||||
@@ -36,10 +40,9 @@ export default function DrawerCutDocuments() {
|
|||||||
setOpened(false)
|
setOpened(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function getOneData() {
|
async function getOneData() {
|
||||||
try {
|
try {
|
||||||
const respon = await funGetAllDocument("?division=" + param.id + "&path=" + path);
|
const respon = await funGetAllDocument("?division=" + param.id + "&path=" + path + "&category=folder");
|
||||||
if (respon.success) {
|
if (respon.success) {
|
||||||
setDataDocument(respon.data);
|
setDataDocument(respon.data);
|
||||||
} else {
|
} 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>
|
<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"}>PINDAH</Button>
|
<Button variant="filled" fullWidth color={WARNA.biruTua} radius={"xl"} onClick={() => onChoosePath(path)}>PINDAH</Button>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Box>
|
</Box>
|
||||||
<Box p={10} pb={60}>
|
<Box p={10} pb={60}>
|
||||||
{dataDocument.map((v, i) => {
|
{dataDocument.map((v, i) => {
|
||||||
|
const found = data.some((i: any) => i.id == v.id)
|
||||||
return (
|
return (
|
||||||
<Box key={i}>
|
<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 align='center'>
|
||||||
<Grid.Col span={12}>
|
<Grid.Col span={12}>
|
||||||
<Group gap={20}>
|
<Group gap={20}>
|
||||||
<Box>
|
<Box>
|
||||||
{
|
{
|
||||||
(v.category == "FOLDER") ?
|
(found) ?
|
||||||
<FcFolder size={60} /> :
|
<MdFolder size={60} color='grey' /> :
|
||||||
(v.extension == "pdf" || v.extension == "csv") ?
|
<FcFolder size={60} />
|
||||||
<FcDocument size={60} /> :
|
|
||||||
<FcImageFile size={60} />
|
|
||||||
}
|
}
|
||||||
</Box>
|
</Box>
|
||||||
<Flex direction={'column'}>
|
<Flex direction={'column'}>
|
||||||
<Text>{(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}</Text>
|
<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>
|
</Flex>
|
||||||
</Group>
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
|
|||||||
@@ -4,10 +4,36 @@ import React, { useState } from "react";
|
|||||||
import { LuFolders, LuFolderSymlink } from "react-icons/lu";
|
import { LuFolders, LuFolderSymlink } from "react-icons/lu";
|
||||||
import DrawerCutDocuments from "./drawer_cut_documents";
|
import DrawerCutDocuments from "./drawer_cut_documents";
|
||||||
import DrawerCopyDocuments from "./drawer_copy_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 [isCut, setIsCut] = useState(false)
|
||||||
const [isCopy, setIsCopy] = 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 (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Stack p={10} >
|
<Stack p={10} >
|
||||||
@@ -35,11 +61,9 @@ export default function DrawerMore() {
|
|||||||
|
|
||||||
|
|
||||||
<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 data={data} onChoosePath={(val) => { onMoveItem(val) }} />
|
||||||
</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>
|
||||||
|
|||||||
@@ -166,6 +166,8 @@ export default function NavbarDocumentDivision() {
|
|||||||
function resetRefresh() {
|
function resetRefresh() {
|
||||||
refresh.set(false)
|
refresh.set(false)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
|
setMore(false)
|
||||||
|
handleBatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
@@ -397,8 +399,11 @@ export default function NavbarDocumentDivision() {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LayoutDrawer opened={more} title={''} onClose={() => setMore(false)}>
|
<LayoutDrawer opened={more} title={''} onClose={() => setMore(false)}>
|
||||||
<DrawerMore />
|
<DrawerMore data={selectedFiles} />
|
||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user