From 999ce52e76a6c189f549be689b6677750ea4b2c1 Mon Sep 17 00:00:00 2001 From: amel Date: Fri, 23 Aug 2024 12:31:17 +0800 Subject: [PATCH] upd: document Deskripsi: - jalur share - action document yg di share No Issues --- src/app/api/document/route.ts | 107 +++++++++++++++++- src/module/document/lib/type_document.ts | 1 + .../document/ui/navbar_document_division.tsx | 58 +++++++--- 3 files changed, 146 insertions(+), 20 deletions(-) diff --git a/src/app/api/document/route.ts b/src/app/api/document/route.ts index 6c21827..440b187 100644 --- a/src/app/api/document/route.ts +++ b/src/app/api/document/route.ts @@ -30,16 +30,56 @@ export async function GET(request: Request) { return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 }); } + let statusAkses = false + let aksesPath = String(path) if (path != "home" && path != "null" && path != "undefined" && path != "") { const cekPath = await prisma.divisionDocumentFolderFile.count({ where: { isActive: true, - id: String(path) + id: String(path), + idDivision: String(idDivision) } }) - if (cekPath == 0) { - return NextResponse.json({ success: false, message: "Gagal mendapatkan item, data tidak ditemukan" }, { status: 404 }); + const cekSharePath = await prisma.divisionDocumentShare.count({ + where: { + isActive: true, + idDivision: String(idDivision), + idDocument: String(path) + } + }) + + if (cekPath == 0 && cekSharePath == 0) { + do { + const dataPath = await prisma.divisionDocumentFolderFile.findUnique({ + where: { + id: String(aksesPath) + } + }) + + if (dataPath) { + const cekShare = await prisma.divisionDocumentShare.count({ + where: { + isActive: true, + idDivision: String(idDivision), + idDocument: String(aksesPath) + } + }) + if (cekShare == 0) { + statusAkses = false + aksesPath = dataPath.path + } else { + statusAkses = true + } + + } else { + aksesPath = "home" + } + } while (aksesPath != "home" && statusAkses == false); + + if (statusAkses == false) { + return NextResponse.json({ success: false, message: "Data tidak ditemukan / tidak memilik hak akses" }, { status: 404 }); + } } } @@ -50,6 +90,8 @@ export async function GET(request: Request) { path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path } + let formatDataShare: any[] = []; + if (category == "folder") { kondisi = { isActive: true, @@ -57,6 +99,52 @@ export async function GET(request: Request) { path: (path == "undefined" || path == "null" || path == "" || path == null) ? "home" : path, category: "FOLDER" } + } else { + if (path == "home" || path == "null" || path == "undefined") { + const dataShare = await prisma.divisionDocumentShare.findMany({ + where: { + isActive: true, + idDivision: String(idDivision), + }, + select: { + DivisionDocumentFolderFile: { + select: { + id: true, + category: true, + name: true, + extension: true, + path: true, + User: { + select: { + name: true + } + }, + createdAt: true, + updatedAt: true + } + } + } + }) + + formatDataShare = dataShare.map((v: any) => ({ + ..._.omit(v, ["DivisionDocumentFolderFile"]), + id: v.DivisionDocumentFolderFile.id, + category: v.DivisionDocumentFolderFile.category, + name: v.DivisionDocumentFolderFile.name, + extension: v.DivisionDocumentFolderFile.extension, + path: v.DivisionDocumentFolderFile.path, + createdBy: v.DivisionDocumentFolderFile.User.name, + createdAt: moment(v.DivisionDocumentFolderFile.createdAt).format("DD-MM-YYYY HH:mm"), + updatedAt: moment(v.DivisionDocumentFolderFile.updatedAt).format("DD-MM-YYYY HH:mm"), + share: true + })) + + } else { + kondisi = { + isActive: true, + path: (path == "undefined" || path == "null" || path == null) ? "home" : path + } + } } @@ -85,9 +173,15 @@ export async function GET(request: Request) { ..._.omit(v, ["User", "createdAt", "updatedAt"]), createdBy: v.User.name, createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"), - updatedAt: moment(v.updatedAt).format("DD-MM-YYYY HH:mm") + updatedAt: moment(v.updatedAt).format("DD-MM-YYYY HH:mm"), + share: false })) + if (formatDataShare.length > 0) { + allData.push(...formatDataShare) + } + + const formatData = _.orderBy(allData, ['category', 'name']) let pathNow = path let jalur = [] @@ -100,13 +194,14 @@ export async function GET(request: Request) { } }) - if (dataPath) { + if (dataPath && (dataPath.idDivision == idDivision || path == pathNow || pathNow == aksesPath)) { const fix = { id: String(pathNow), name: dataPath.name, } jalur.push(fix) pathNow = dataPath.path + } else { pathNow = "home" } @@ -117,7 +212,7 @@ export async function GET(request: Request) { jalur.push({ id: 'home', name: 'home' }) jalur = [...jalur].reverse() - return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: allData, jalur }, { status: 200 }); + return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: formatData, jalur }, { status: 200 }); } catch (error) { console.log(error); diff --git a/src/module/document/lib/type_document.ts b/src/module/document/lib/type_document.ts index d29e46c..14992f9 100644 --- a/src/module/document/lib/type_document.ts +++ b/src/module/document/lib/type_document.ts @@ -4,6 +4,7 @@ export interface IDataDocument { extension: string; category: string; path: string; + share: boolean; createdBy: string; createdAt: string; updatedAt: string; diff --git a/src/module/document/ui/navbar_document_division.tsx b/src/module/document/ui/navbar_document_division.tsx index 3237717..8a30364 100644 --- a/src/module/document/ui/navbar_document_division.tsx +++ b/src/module/document/ui/navbar_document_division.tsx @@ -1,6 +1,6 @@ 'use client' import { LayoutDrawer, LayoutNavbarNew, WARNA } from '@/module/_global'; -import { ActionIcon, Anchor, Box, Breadcrumbs, Button, Checkbox, Divider, Flex, Grid, Group, Modal, Select, SimpleGrid, Text, TextInput } from '@mantine/core'; +import { ActionIcon, Anchor, Box, Breadcrumbs, Button, Checkbox, Divider, Flex, Grid, Group, Indicator, Modal, Select, SimpleGrid, Text, TextInput } from '@mantine/core'; import React, { useState } from 'react'; import { HiMenu } from 'react-icons/hi'; import { FcDocument, FcFolder, FcImageFile } from 'react-icons/fc'; @@ -23,6 +23,7 @@ import { globalRefreshDocument } from '../lib/val_document'; import { RiListCheck } from 'react-icons/ri'; import { GoChevronRight } from 'react-icons/go'; import DrawerShareDocument from './drawer_share_document'; +import { FaSlideshare } from 'react-icons/fa6'; export default function NavbarDocumentDivision() { const router = useRouter() @@ -33,6 +34,7 @@ export default function NavbarDocumentDivision() { const [rename, setRename] = useState(false) const [share, setShare] = useState(false) const [more, setMore] = useState(false) + const [shareSelected, setShareSelected] = useState(false) const searchParams = useSearchParams() const path = searchParams.get('path') const [dataDocument, setDataDocument] = useState([]) @@ -62,6 +64,7 @@ export default function NavbarDocumentDivision() { path: dataDocument[index].path, extension: dataDocument[index].extension, category: dataDocument[index].category, + share: dataDocument[index].share, } ]) } @@ -74,6 +77,13 @@ export default function NavbarDocumentDivision() { } else { setSelectAll(false) } + + const shareSelected = selectedFiles.some((i: any) => i?.share == true) + if (shareSelected) { + setShareSelected(true) + } else { + setShareSelected(false) + } } const handleSelectAll = () => { @@ -87,6 +97,7 @@ export default function NavbarDocumentDivision() { path: dataDocument[index].path, extension: dataDocument[index].extension, category: dataDocument[index].category, + share: dataDocument[index].share, } setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr]) } @@ -154,6 +165,8 @@ export default function NavbarDocumentDivision() { setDataJalur(respon.jalur); } else { toast.error(respon.message); + setDataDocument([]); + setDataJalur([]); } const res = await funGetDivisionById(param.id); @@ -231,24 +244,24 @@ export default function NavbarDocumentDivision() { 0) ? 'white' : 'grey'}>Unduh setIsDelete(true)} justify={'center'} align={'center'} direction={'column'}> - 0) ? 'white' : 'grey'} /> - 0) ? 'white' : 'grey'}>Hapus + 0 && !shareSelected) ? 'white' : 'grey'} /> + 0 && !shareSelected) ? 'white' : 'grey'}>Hapus { if (selectedFiles.length == 1) { onChooseRename() } }} justify={'center'} align={'center'} direction={'column'}> - - Ganti Nama + + Ganti Nama setShare(true)} justify={'center'} align={'center'} direction={'column'}> - 0) ? 'white' : 'grey'} /> - 0) ? 'white' : 'grey'}>Bagikan + 0 && !shareSelected) ? 'white' : 'grey'} /> + 0 && !shareSelected) ? 'white' : 'grey'}>Bagikan setMore(true)} justify={'center'} align={'center'} direction={'column'}> - 0) ? 'white' : 'grey'} /> - 0) ? 'white' : 'grey'}>Lainnya + 0 && !shareSelected) ? 'white' : 'grey'} /> + 0 && !shareSelected) ? 'white' : 'grey'}>Lainnya @@ -295,12 +308,29 @@ export default function NavbarDocumentDivision() { { - (v.category == "FOLDER") ? - : - (v.extension == "pdf" || v.extension == "csv") ? - : - + (v.share) ? + } size={25}> + { + (v.category == "FOLDER") ? + : + (v.extension == "pdf" || v.extension == "csv") ? + : + + } + + : + <> + { + (v.category == "FOLDER") ? + : + (v.extension == "pdf" || v.extension == "csv") ? + : + + } + + } + {(v.category == "FOLDER") ? v.name : v.name + '.' + v.extension}