rev: fitur unshare dokumen divisi
Deskripsi: - unshare dokumen - modal drawer dokumen - update api - cuma bisa share 1 dokumen terpilih No Issues
This commit is contained in:
@@ -214,6 +214,7 @@ export async function GET(request: Request) {
|
|||||||
|
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const idItem = searchParams.get("item");
|
const idItem = searchParams.get("item");
|
||||||
|
const category = searchParams.get("cat");
|
||||||
|
|
||||||
const cekItem = await prisma.divisionDocumentFolderFile.count({
|
const cekItem = await prisma.divisionDocumentFolderFile.count({
|
||||||
where: {
|
where: {
|
||||||
@@ -225,66 +226,72 @@ export async function GET(request: Request) {
|
|||||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan dokumen, data tidak ditemukan" }, { status: 404 });
|
return NextResponse.json({ success: false, message: "Gagal mendapatkan dokumen, data tidak ditemukan" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await prisma.divisionDocumentFolderFile.findUnique({
|
let fixData
|
||||||
where: {
|
if (category == 'share') {
|
||||||
id: String(idItem),
|
const share = await prisma.divisionDocumentShare.findMany({
|
||||||
},
|
where: {
|
||||||
select: {
|
idDocument: String(idItem),
|
||||||
category: true,
|
isActive: true
|
||||||
name: true,
|
|
||||||
extension: true,
|
|
||||||
createdAt: true,
|
|
||||||
path: true,
|
|
||||||
Division: {
|
|
||||||
select: {
|
|
||||||
name: true
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
User: {
|
select: {
|
||||||
select: {
|
idDivision: true,
|
||||||
name: true
|
Division: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const dataPath = await prisma.divisionDocumentFolderFile.findUnique({
|
fixData = share.map((v: any) => ({
|
||||||
where: {
|
..._.omit(v, ["idDivision", "Division"]),
|
||||||
id: data?.path
|
id: v.idDivision,
|
||||||
}
|
name: v.Division.name
|
||||||
})
|
}))
|
||||||
|
|
||||||
const share = await prisma.divisionDocumentShare.findMany({
|
} else {
|
||||||
where: {
|
const data = await prisma.divisionDocumentFolderFile.findUnique({
|
||||||
idDocument: String(idItem),
|
where: {
|
||||||
isActive: true
|
id: String(idItem),
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
Division: {
|
category: true,
|
||||||
select: {
|
name: true,
|
||||||
name: true
|
extension: true,
|
||||||
|
createdAt: true,
|
||||||
|
path: true,
|
||||||
|
Division: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
User: {
|
||||||
|
select: {
|
||||||
|
name: true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const dataPath = await prisma.divisionDocumentFolderFile.findUnique({
|
||||||
|
where: {
|
||||||
|
id: data?.path
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
fixData = {
|
||||||
|
category: data?.category,
|
||||||
|
name: data?.name,
|
||||||
|
extension: data?.extension,
|
||||||
|
createdAt: moment(data?.createdAt).format('DD MMMM YYYY'),
|
||||||
|
path: (dataPath?.name !== undefined && dataPath?.name !== null && dataPath?.name !== '') ? dataPath.name : "home",
|
||||||
|
division: data?.Division?.name,
|
||||||
|
createdBy: data?.User?.name
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const dataUtama = {
|
|
||||||
category: data?.category,
|
|
||||||
name: data?.name,
|
|
||||||
extension: data?.extension,
|
|
||||||
createdAt: moment(data?.createdAt).format('DD MMMM YYYY'),
|
|
||||||
path: (dataPath?.name !== undefined && dataPath?.name !== null && dataPath?.name !== '') ? dataPath.name : "home",
|
|
||||||
division: data?.Division?.name,
|
|
||||||
createdBy: data?.User?.name
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataShare = share.map((v: any) => ({
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: fixData }, { status: 200 });
|
||||||
..._.omit(v, ["Division"]),
|
|
||||||
division: v.Division.name
|
|
||||||
}))
|
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan item", data: dataUtama, share: dataShare }, { status: 200 });
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ export interface IInfoDocument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IInfoShare {
|
export interface IInfoShare {
|
||||||
division: string
|
id: string
|
||||||
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IFormFolder {
|
export interface IFormFolder {
|
||||||
|
|||||||
@@ -4,17 +4,13 @@ import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
|||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { CiCalendarDate } from "react-icons/ci";
|
|
||||||
import { FcDocument, FcFolder, FcImageFile } from "react-icons/fc";
|
import { FcDocument, FcFolder, FcImageFile } from "react-icons/fc";
|
||||||
import { GrLocationPin } from "react-icons/gr";
|
|
||||||
import { HiOutlineDocumentText } from "react-icons/hi2";
|
import { HiOutlineDocumentText } from "react-icons/hi2";
|
||||||
import { MdOutlineCategory } from "react-icons/md";
|
import { PiCalendarBlankLight, PiMapPinSimpleLight, PiShapesLight, PiShareNetworkLight, PiUsersThreeLight } from "react-icons/pi";
|
||||||
import { PiUsersThree } from "react-icons/pi";
|
|
||||||
import { TbLockAccess } from "react-icons/tb";
|
|
||||||
import { funGetInfoDocument } from "../lib/api_document";
|
import { funGetInfoDocument } from "../lib/api_document";
|
||||||
import { IFormDetailMoreItem, IInfoDocument, IInfoShare } from "../lib/type_document";
|
import { IFormDetailMoreItem, IInfoDocument, IInfoShare } from "../lib/type_document";
|
||||||
|
|
||||||
export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem[] }) {
|
export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem }) {
|
||||||
const [dataInfo, setDataInfo] = useState<IInfoDocument>();
|
const [dataInfo, setDataInfo] = useState<IInfoDocument>();
|
||||||
const [dataShare, setDataShare] = useState<IInfoShare[]>([])
|
const [dataShare, setDataShare] = useState<IInfoShare[]>([])
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -24,16 +20,17 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
async function getOneData(loading: boolean) {
|
async function getOneData(loading: boolean) {
|
||||||
try {
|
try {
|
||||||
setLoading(loading);
|
setLoading(loading);
|
||||||
const respon = await funGetInfoDocument("?item=" + data[0].id);
|
const respon = await funGetInfoDocument(`?item=${data.id}&cat=utama`);
|
||||||
|
const responShare = await funGetInfoDocument(`?item=${data.id}&cat=share`);
|
||||||
if (respon.success) {
|
if (respon.success) {
|
||||||
setDataInfo(respon.data);
|
setDataInfo(respon.data);
|
||||||
setDataShare(respon.share)
|
setDataShare(responShare.data)
|
||||||
} else {
|
} else {
|
||||||
toast.error(respon.message);
|
toast.error(respon.message);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Gagal mendapatkan item, coba lagi nanti");
|
toast.error("Gagal mendapatkan data, coba lagi nanti");
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -61,7 +58,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
}
|
}
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<ScrollArea
|
{/* <ScrollArea
|
||||||
h={{
|
h={{
|
||||||
base: "55vh",
|
base: "55vh",
|
||||||
xl: "56vh",
|
xl: "56vh",
|
||||||
@@ -72,7 +69,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
scrollbarSize={2}
|
scrollbarSize={2}
|
||||||
scrollHideDelay={0}
|
scrollHideDelay={0}
|
||||||
scrollbars="y"
|
scrollbars="y"
|
||||||
>
|
> */}
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<SkeletonDetailProfile />
|
<SkeletonDetailProfile />
|
||||||
) : (
|
) : (
|
||||||
@@ -89,7 +86,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
</Group>
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={6}>
|
<Grid.Col span={6}>
|
||||||
<Text lineClamp={1} fz={15} ta={"right"}>{dataInfo?.category == "FOLDER" ? dataInfo?.name : dataInfo?.name + '.' + dataInfo?.extension}</Text>
|
<Text truncate="end" ta={"right"} fz={15}>{dataInfo?.category == "FOLDER" ? dataInfo?.name : `${dataInfo?.name}.${dataInfo?.extension}`}</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Divider size="xs" />
|
<Divider size="xs" />
|
||||||
@@ -98,7 +95,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
<Group>
|
<Group>
|
||||||
{
|
{
|
||||||
!isMobile ?
|
!isMobile ?
|
||||||
<MdOutlineCategory size={25} />
|
<PiShapesLight size={25} />
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
<Text fz={15}>Tipe</Text>
|
<Text fz={15}>Tipe</Text>
|
||||||
@@ -114,14 +111,14 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
<Group>
|
<Group>
|
||||||
{
|
{
|
||||||
!isMobile ?
|
!isMobile ?
|
||||||
<GrLocationPin size={25} />
|
<PiMapPinSimpleLight size={25} />
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
<Text fz={15}>Lokasi</Text>
|
<Text fz={15}>Lokasi</Text>
|
||||||
</Group>
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={8}>
|
<Grid.Col span={8}>
|
||||||
<Text lineClamp={1} fz={15} ta={"right"}>{dataInfo?.path}</Text>
|
<Text truncate="end" fz={15} ta={"right"}>{dataInfo?.path}</Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Divider size="xs" />
|
<Divider size="xs" />
|
||||||
@@ -130,14 +127,14 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
<Group>
|
<Group>
|
||||||
{
|
{
|
||||||
!isMobile ?
|
!isMobile ?
|
||||||
<PiUsersThree size={25} />
|
<PiUsersThreeLight size={25} />
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
<Text fz={15}>Pemilik</Text>
|
<Text fz={15}>Pemilik</Text>
|
||||||
</Group>
|
</Group>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
<Grid.Col span={8}>
|
<Grid.Col span={8}>
|
||||||
<Text lineClamp={1} fz={15} ta={"right"}> {dataInfo?.division} </Text>
|
<Text truncate="end" fz={15} ta={"right"}> {dataInfo?.division} </Text>
|
||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Divider size="xs" />
|
<Divider size="xs" />
|
||||||
@@ -146,7 +143,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
<Group>
|
<Group>
|
||||||
{
|
{
|
||||||
!isMobile ?
|
!isMobile ?
|
||||||
<CiCalendarDate size={25} />
|
<PiCalendarBlankLight size={25} />
|
||||||
: ''
|
: ''
|
||||||
}
|
}
|
||||||
<Text fz={15}>Tanggal Dibuat</Text>
|
<Text fz={15}>Tanggal Dibuat</Text>
|
||||||
@@ -163,25 +160,23 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
<Accordion.Item value="share" p={0}>
|
<Accordion.Item value="share" p={0}>
|
||||||
<Accordion.Control p={0} icon={
|
<Accordion.Control p={0} icon={
|
||||||
!isMobile ?
|
!isMobile ?
|
||||||
<TbLockAccess size={25} />
|
<PiShareNetworkLight size={25} />
|
||||||
: ''
|
: ''
|
||||||
} fz={15}>Yang Memiliki Akses</Accordion.Control>
|
} fz={15}>Telah dibagikan ke divisi</Accordion.Control>
|
||||||
<Accordion.Panel>
|
<Accordion.Panel>
|
||||||
<List
|
<List
|
||||||
spacing="xs"
|
spacing="xs"
|
||||||
size="sm"
|
size="sm"
|
||||||
center
|
center
|
||||||
icon={
|
icon={dataShare.length > 0 ? <PiUsersThreeLight size={20} /> : <></>}
|
||||||
<PiUsersThree size={20} />
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<List.Item>{dataInfo?.division}</List.Item>
|
|
||||||
{
|
{
|
||||||
dataShare.map((i: any) => {
|
dataShare.length === 0 ? <List.Item ta={"center"}>Tidak ada data</List.Item> :
|
||||||
return (
|
dataShare.map((i: any) => {
|
||||||
<List.Item key={i.id}>{i.division}</List.Item>
|
return (
|
||||||
)
|
<List.Item key={i.id}>{i.name}</List.Item>
|
||||||
})
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</List>
|
</List>
|
||||||
</Accordion.Panel>
|
</Accordion.Panel>
|
||||||
@@ -189,7 +184,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
|||||||
</Accordion>
|
</Accordion>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</ScrollArea>
|
{/* </ScrollArea> */}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ export default function DrawerMore({ data, share }: { data: IDataDocument[], sha
|
|||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
|
|
||||||
<LayoutDrawer opened={isInfo} onClose={() => setIsInfo(false)} title={'Informasi Dokumen'} size="lg">
|
<LayoutDrawer opened={isInfo} onClose={() => setIsInfo(false)} title={'Informasi Dokumen'} size="lg">
|
||||||
<DrawerInfoDocument data={data} />
|
<DrawerInfoDocument data={data[0]} />
|
||||||
</LayoutDrawer>
|
</LayoutDrawer>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,24 +7,23 @@ import { useParams } from "next/navigation";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import toast from "react-hot-toast";
|
import toast from "react-hot-toast";
|
||||||
import { FaCheck, FaUsers } from "react-icons/fa6";
|
import { FaCheck, FaUsers } from "react-icons/fa6";
|
||||||
import { funShareDocument } from "../lib/api_document";
|
import { funGetInfoDocument, funShareDocument } from "../lib/api_document";
|
||||||
import { IShareDivision } from "../lib/type_document";
|
import { IShareDivision } from "../lib/type_document";
|
||||||
import { globalRefreshDocument } from "../lib/val_document";
|
import { globalRefreshDocument } from "../lib/val_document";
|
||||||
|
|
||||||
export default function DrawerShareDocument({ data, }: { data: IShareDivision[]; }) {
|
export default function DrawerShareDocument({ data }: { data: IShareDivision[]; }) {
|
||||||
const [selectedFiles, setSelectedFiles] = useState<any>([]);
|
const [selectedFiles, setSelectedFiles] = useState<any>([]);
|
||||||
const [isData, setData] = useState<IDataDivison[]>([]);
|
const [isData, setData] = useState<IDataDivison[]>([]);
|
||||||
const param = useParams<{ id: string }>();
|
const param = useParams<{ id: string }>();
|
||||||
const refresh = useHookstate(globalRefreshDocument);
|
const refresh = useHookstate(globalRefreshDocument);
|
||||||
const tema = useHookstate(TEMA);
|
const tema = useHookstate(TEMA);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [loadingBtn, setLoadingBtn] = useState(false)
|
||||||
const isMobile2 = useMediaQuery("(max-width: 438px)");
|
const isMobile2 = useMediaQuery("(max-width: 438px)");
|
||||||
|
|
||||||
async function onShare() {
|
async function onShare() {
|
||||||
try {
|
try {
|
||||||
if (selectedFiles.length == 0) {
|
setLoadingBtn(true)
|
||||||
return toast.error("Pilih divisi terlebih dahulu");
|
|
||||||
}
|
|
||||||
|
|
||||||
const respon = await funShareDocument({
|
const respon = await funShareDocument({
|
||||||
dataDivision: selectedFiles,
|
dataDivision: selectedFiles,
|
||||||
@@ -39,6 +38,8 @@ export default function DrawerShareDocument({ data, }: { data: IShareDivision[];
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error("Gagal membagikan item, coba lagi nanti");
|
toast.error("Gagal membagikan item, coba lagi nanti");
|
||||||
|
} finally {
|
||||||
|
setLoadingBtn(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +49,10 @@ export default function DrawerShareDocument({ data, }: { data: IShareDivision[];
|
|||||||
const response = await funGetListDivisionByIdDivision(
|
const response = await funGetListDivisionByIdDivision(
|
||||||
"?division=" + param.id
|
"?division=" + param.id
|
||||||
);
|
);
|
||||||
|
const shared = await funGetInfoDocument(`?item=${data[0].id}&cat=share`);
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setData(response.data.filter((i: any) => i.id != param.id));
|
setData(response.data.filter((i: any) => i.id != param.id));
|
||||||
|
setSelectedFiles(shared.data)
|
||||||
} else {
|
} else {
|
||||||
toast.error(response.message);
|
toast.error(response.message);
|
||||||
}
|
}
|
||||||
@@ -202,6 +205,7 @@ export default function DrawerShareDocument({ data, }: { data: IShareDivision[];
|
|||||||
radius={30}
|
radius={30}
|
||||||
fullWidth
|
fullWidth
|
||||||
onClick={() => onShare()}
|
onClick={() => onShare()}
|
||||||
|
loading={loadingBtn}
|
||||||
>
|
>
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -434,16 +434,16 @@ export default function NavbarDocumentDivision() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
<Flex justify={"center"} align={"center"} direction={"column"}
|
<Flex justify={"center"} align={"center"} direction={"column"}
|
||||||
onClick={
|
onClick={
|
||||||
selectedFiles.length > 0 && !shareSelected
|
selectedFiles.length == 1 && !shareSelected
|
||||||
? () => setShare(true)
|
? () => setShare(true)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ActionIcon variant="subtle" aria-label="share" >
|
<ActionIcon variant="subtle" aria-label="share">
|
||||||
<LuShare2
|
<LuShare2
|
||||||
size={20}
|
size={20}
|
||||||
color={
|
color={
|
||||||
selectedFiles.length > 0 && !shareSelected
|
selectedFiles.length == 1 && !shareSelected
|
||||||
? "white"
|
? "white"
|
||||||
: "#656060"
|
: "#656060"
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ export default function NavbarDocumentDivision() {
|
|||||||
fz={12}
|
fz={12}
|
||||||
ta={"center"}
|
ta={"center"}
|
||||||
c={
|
c={
|
||||||
selectedFiles.length > 0 && !shareSelected
|
selectedFiles.length == 1 && !shareSelected
|
||||||
? "white"
|
? "white"
|
||||||
: "#656060"
|
: "#656060"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user