Merge pull request #140 from bipproduction/amalia/22-agustus-24
upd: document
This commit is contained in:
50
src/app/api/division/more/route.ts
Normal file
50
src/app/api/division/more/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// GET LIST DIVISI BY ID DIVISI (CONTOH : UNTUK SHARE DOKUMEN)
|
||||
export async function GET(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 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const idDivision = searchParams.get("division");
|
||||
const name = searchParams.get('search');
|
||||
|
||||
const dataDivision = await prisma.division.findUnique({
|
||||
where: {
|
||||
id: String(idDivision),
|
||||
isActive: true
|
||||
}
|
||||
})
|
||||
|
||||
if (!dataDivision) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan", }, { status: 404 });
|
||||
}
|
||||
|
||||
const data = await prisma.division.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
idGroup: dataDivision.idGroup,
|
||||
name: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
}
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
@@ -184,4 +185,43 @@ export async function PUT(request: Request) {
|
||||
console.log(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal salin item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// SHARE ITEM
|
||||
export async function DELETE(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 });
|
||||
}
|
||||
|
||||
const { dataDivision, dataItem } = (await request.json());
|
||||
|
||||
|
||||
for (let i = 0; i < dataItem.length; i++) {
|
||||
const del = await prisma.divisionDocumentShare.deleteMany({
|
||||
where: {
|
||||
idDocument: dataItem[i].id
|
||||
}
|
||||
})
|
||||
|
||||
const omitData = dataDivision.map((v: any) => ({
|
||||
..._.omit(v, ["name", "id"]),
|
||||
idDivision: v.id,
|
||||
idDocument: dataItem[i].id
|
||||
}))
|
||||
|
||||
const insert = await prisma.divisionDocumentShare.createMany({
|
||||
data: omitData
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil membagikan item" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal membagikan item, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
};
|
||||
@@ -22,7 +22,7 @@ import CreateAnggotaDivision from './ui/create_anggota_division';
|
||||
import EditDivision from './ui/edit_division';
|
||||
import CreateReport from './ui/create_report';
|
||||
import ReportDivisionId from './ui/report_division_id';
|
||||
import { funGetDivisionById } from './lib/api_division';
|
||||
import { funGetDivisionById, funGetListDivisionByIdDivision } from './lib/api_division';
|
||||
|
||||
export { CreateUsers };
|
||||
export { CreateAdminDivision };
|
||||
@@ -49,3 +49,4 @@ export { EditDivision }
|
||||
export { CreateReport }
|
||||
export { ReportDivisionId }
|
||||
export { funGetDivisionById }
|
||||
export { funGetListDivisionByIdDivision }
|
||||
|
||||
@@ -70,4 +70,11 @@ export const funAddDivisionMember = async (path: string, data: IFormMemberDivisi
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const funGetListDivisionByIdDivision = async (path: string) => {
|
||||
const response = await fetch(`/api/division/more${path}`);
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IFormEditItem, IFormFolder, IFormMoreCopyItem, IFormMoreItem } from "./type_document";
|
||||
import { IFormEditItem, IFormFolder, IFormMoreCopyItem, IFormMoreItem, IShareDocument } from "./type_document";
|
||||
|
||||
export const funGetAllDocument = async (path?: string) => {
|
||||
const response = await fetch(`/api/document${(path) ? path : ''}`, { next: { tags: ['document'] } });
|
||||
@@ -65,4 +65,16 @@ export const funCopyDocument = async (data: IFormMoreCopyItem) => {
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
|
||||
export const funShareDocument = async (data: IShareDocument) => {
|
||||
const response = await fetch("/api/document/more", {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -44,4 +44,15 @@ export interface IFormMoreCopyItem {
|
||||
idDivision: string,
|
||||
path: string,
|
||||
dataItem: IDataDocument[]
|
||||
}
|
||||
|
||||
|
||||
export interface IShareDivision {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface IShareDocument {
|
||||
dataDivision: IShareDivision[],
|
||||
dataItem: IShareDivision[]
|
||||
}
|
||||
127
src/module/document/ui/drawer_share_document.tsx
Normal file
127
src/module/document/ui/drawer_share_document.tsx
Normal file
@@ -0,0 +1,127 @@
|
||||
import { WARNA } from "@/module/_global";
|
||||
import { funGetListDivisionByIdDivision, IDataDivison } from "@/module/division_new";
|
||||
import { IDataMemberTaskDivision } from "@/module/task/lib/type_task";
|
||||
import { Box, Select, Button, Avatar, Divider, Flex, Group, Stack, Text, ActionIcon } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FaCheck, FaUsers } from "react-icons/fa6";
|
||||
import { IShareDivision } from "../lib/type_document";
|
||||
import { funShareDocument } from "../lib/api_document";
|
||||
import { useHookstate } from "@hookstate/core";
|
||||
import { globalRefreshDocument } from "../lib/val_document";
|
||||
|
||||
export default function DrawerShareDocument({ data }: { data: IShareDivision[]}) {
|
||||
const [selectedFiles, setSelectedFiles] = useState<any>([])
|
||||
const [isData, setData] = useState<IDataDivison[]>([])
|
||||
const param = useParams<{ id: string }>()
|
||||
const refresh = useHookstate(globalRefreshDocument)
|
||||
|
||||
|
||||
|
||||
async function onShare() {
|
||||
try {
|
||||
if (selectedFiles.length == 0) {
|
||||
return toast.error('Pilih divisi terlebih dahulu')
|
||||
}
|
||||
|
||||
|
||||
const respon = await funShareDocument({ dataDivision: selectedFiles, dataItem: data })
|
||||
if (respon.success) {
|
||||
toast.success(respon.message)
|
||||
refresh.set(true)
|
||||
} else {
|
||||
toast.error(respon.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.error("Gagal membagikan item, coba lagi nanti");
|
||||
}
|
||||
}
|
||||
|
||||
async function getData() {
|
||||
try {
|
||||
const response = await funGetListDivisionByIdDivision('?division=' + param.id)
|
||||
if (response.success) {
|
||||
setData(response.data.filter((i: any) => i.id != param.id))
|
||||
} else {
|
||||
toast.error(response.message);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
toast.error("Gagal mendapatkan divisi, coba lagi nanti");
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
getData()
|
||||
}, []);
|
||||
|
||||
const handleFileClick = (index: number) => {
|
||||
if (selectedFiles.some((i: any) => i.id == isData[index].id)) {
|
||||
setSelectedFiles(selectedFiles.filter((i: any) => i.id != isData[index].id))
|
||||
} else {
|
||||
setSelectedFiles([...selectedFiles, { id: isData[index].id, name: isData[index].name }])
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Box pt={10}>
|
||||
<Box mt={10}>
|
||||
{isData.map((v, i) => {
|
||||
const isSelected = selectedFiles.some((i: any) => i?.id == v.id);
|
||||
return (
|
||||
<Box mb={15} key={i} onClick={() => handleFileClick(i)} >
|
||||
<Flex justify={"space-between"} align={"center"}>
|
||||
<Group>
|
||||
<ActionIcon variant="light" color="gray" radius="xl" size={42} p={10}>
|
||||
<FaUsers fontSize={40} />
|
||||
</ActionIcon>
|
||||
<Stack align="flex-start" justify="flex-start">
|
||||
<Text style={{
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
}}>
|
||||
{v.name}
|
||||
</Text>
|
||||
</Stack>
|
||||
</Group>
|
||||
<Text
|
||||
style={{
|
||||
cursor: 'pointer',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
paddingLeft: 20,
|
||||
}}
|
||||
>
|
||||
{isSelected ? <FaCheck style={{ marginRight: 10 }} /> : ""}
|
||||
</Text>
|
||||
</Flex>
|
||||
<Divider my={"md"} />
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
<Box h={90} pos={"fixed"} bottom={0} w={{ base: "92%", md: "94%" }} style={{
|
||||
zIndex: 999
|
||||
}}>
|
||||
<Box>
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => onShare()}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { useHookstate } from '@hookstate/core';
|
||||
import { globalRefreshDocument } from '../lib/val_document';
|
||||
import { RiListCheck } from 'react-icons/ri';
|
||||
import { GoChevronRight } from 'react-icons/go';
|
||||
import DrawerShareDocument from './drawer_share_document';
|
||||
|
||||
export default function NavbarDocumentDivision() {
|
||||
const router = useRouter()
|
||||
@@ -172,6 +173,7 @@ export default function NavbarDocumentDivision() {
|
||||
refresh.set(false)
|
||||
setOpen(false)
|
||||
setMore(false)
|
||||
setShare(false)
|
||||
handleBatal()
|
||||
}
|
||||
|
||||
@@ -266,11 +268,11 @@ export default function NavbarDocumentDivision() {
|
||||
<Box>
|
||||
<Box p={20} pb={60}>
|
||||
<Box>
|
||||
<Breadcrumbs separator={<GoChevronRight />} separatorMargin="md" mt="xs">
|
||||
<Breadcrumbs separator={<GoChevronRight />} separatorMargin="md" mt="xs" style={{ cursor: 'pointer' }}>
|
||||
{
|
||||
dataJalur.map((v, i) => {
|
||||
return (
|
||||
<Text onClick={() => router.push('?path=' + v.id)} key={i} style={{ cursor: 'pointer' }}>
|
||||
<Text onClick={() => router.push('?path=' + v.id)} key={i}>
|
||||
{v.name}
|
||||
</Text>
|
||||
)
|
||||
@@ -386,36 +388,7 @@ export default function NavbarDocumentDivision() {
|
||||
|
||||
|
||||
<LayoutDrawer opened={share} title={'Bagikan'} onClose={() => setShare(false)} size='lg'>
|
||||
<Box pt={10}>
|
||||
<Select
|
||||
styles={{
|
||||
input: {
|
||||
color: WARNA.biruTua,
|
||||
borderRadius: WARNA.biruTua,
|
||||
borderColor: WARNA.biruTua,
|
||||
},
|
||||
}}
|
||||
size="lg"
|
||||
radius={10}
|
||||
placeholder="Pilih Divisi"
|
||||
/>
|
||||
<Box h={90} pos={"fixed"} bottom={0} w={{ base: "92%", md: "94%" }} style={{
|
||||
zIndex: 999
|
||||
}}>
|
||||
<Box>
|
||||
<Button
|
||||
c={"white"}
|
||||
bg={WARNA.biruTua}
|
||||
size="lg"
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => ''}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<DrawerShareDocument data={selectedFiles} />
|
||||
</LayoutDrawer>
|
||||
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ export default function AddMemberDetailTask() {
|
||||
<Box>
|
||||
<LayoutNavbarNew
|
||||
back=""
|
||||
title="Pilih Anggotak"
|
||||
title="Pilih Anggota"
|
||||
menu
|
||||
/>
|
||||
<pre>{JSON.stringify(isData, null, 1)}</pre>
|
||||
@@ -142,7 +142,7 @@ export default function AddMemberDetailTask() {
|
||||
</Text>
|
||||
{selectAll ? <FaCheck style={{ marginRight: 10 }} /> : ""}
|
||||
</Group>
|
||||
<Box mt={15}>
|
||||
{/* <Box mt={15}>
|
||||
{isData.map((v, i) => {
|
||||
const isSelected = selectedFiles.some((i: any) => i?.idUser == v.idUser);
|
||||
const found = isDataMember.some((i: any) => i.idUser == v.idUser)
|
||||
@@ -177,7 +177,7 @@ export default function AddMemberDetailTask() {
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</Box>
|
||||
</Box> */}
|
||||
<Box mt={"xl"}>
|
||||
<Button
|
||||
c={"white"}
|
||||
|
||||
Reference in New Issue
Block a user