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:
@@ -23,7 +23,8 @@ export interface IInfoDocument {
|
||||
}
|
||||
|
||||
export interface IInfoShare {
|
||||
division: string
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface IFormFolder {
|
||||
|
||||
@@ -4,17 +4,13 @@ import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
|
||||
import _ from "lodash";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { CiCalendarDate } from "react-icons/ci";
|
||||
import { FcDocument, FcFolder, FcImageFile } from "react-icons/fc";
|
||||
import { GrLocationPin } from "react-icons/gr";
|
||||
import { HiOutlineDocumentText } from "react-icons/hi2";
|
||||
import { MdOutlineCategory } from "react-icons/md";
|
||||
import { PiUsersThree } from "react-icons/pi";
|
||||
import { TbLockAccess } from "react-icons/tb";
|
||||
import { PiCalendarBlankLight, PiMapPinSimpleLight, PiShapesLight, PiShareNetworkLight, PiUsersThreeLight } from "react-icons/pi";
|
||||
import { funGetInfoDocument } from "../lib/api_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 [dataShare, setDataShare] = useState<IInfoShare[]>([])
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -24,16 +20,17 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
async function getOneData(loading: boolean) {
|
||||
try {
|
||||
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) {
|
||||
setDataInfo(respon.data);
|
||||
setDataShare(respon.share)
|
||||
setDataShare(responShare.data)
|
||||
} else {
|
||||
toast.error(respon.message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
toast.error("Gagal mendapatkan item, coba lagi nanti");
|
||||
toast.error("Gagal mendapatkan data, coba lagi nanti");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -61,7 +58,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
}
|
||||
</Stack>
|
||||
</Box>
|
||||
<ScrollArea
|
||||
{/* <ScrollArea
|
||||
h={{
|
||||
base: "55vh",
|
||||
xl: "56vh",
|
||||
@@ -72,7 +69,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
scrollbarSize={2}
|
||||
scrollHideDelay={0}
|
||||
scrollbars="y"
|
||||
>
|
||||
> */}
|
||||
{loading ? (
|
||||
<SkeletonDetailProfile />
|
||||
) : (
|
||||
@@ -89,7 +86,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
<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>
|
||||
<Divider size="xs" />
|
||||
@@ -98,7 +95,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
<Group>
|
||||
{
|
||||
!isMobile ?
|
||||
<MdOutlineCategory size={25} />
|
||||
<PiShapesLight size={25} />
|
||||
: ''
|
||||
}
|
||||
<Text fz={15}>Tipe</Text>
|
||||
@@ -114,14 +111,14 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
<Group>
|
||||
{
|
||||
!isMobile ?
|
||||
<GrLocationPin size={25} />
|
||||
<PiMapPinSimpleLight size={25} />
|
||||
: ''
|
||||
}
|
||||
<Text fz={15}>Lokasi</Text>
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
<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>
|
||||
<Divider size="xs" />
|
||||
@@ -130,14 +127,14 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
<Group>
|
||||
{
|
||||
!isMobile ?
|
||||
<PiUsersThree size={25} />
|
||||
<PiUsersThreeLight size={25} />
|
||||
: ''
|
||||
}
|
||||
<Text fz={15}>Pemilik</Text>
|
||||
</Group>
|
||||
</Grid.Col>
|
||||
<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>
|
||||
<Divider size="xs" />
|
||||
@@ -146,7 +143,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
<Group>
|
||||
{
|
||||
!isMobile ?
|
||||
<CiCalendarDate size={25} />
|
||||
<PiCalendarBlankLight size={25} />
|
||||
: ''
|
||||
}
|
||||
<Text fz={15}>Tanggal Dibuat</Text>
|
||||
@@ -163,25 +160,23 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
<Accordion.Item value="share" p={0}>
|
||||
<Accordion.Control p={0} icon={
|
||||
!isMobile ?
|
||||
<TbLockAccess size={25} />
|
||||
<PiShareNetworkLight size={25} />
|
||||
: ''
|
||||
} fz={15}>Yang Memiliki Akses</Accordion.Control>
|
||||
} fz={15}>Telah dibagikan ke divisi</Accordion.Control>
|
||||
<Accordion.Panel>
|
||||
<List
|
||||
spacing="xs"
|
||||
size="sm"
|
||||
center
|
||||
icon={
|
||||
<PiUsersThree size={20} />
|
||||
}
|
||||
icon={dataShare.length > 0 ? <PiUsersThreeLight size={20} /> : <></>}
|
||||
>
|
||||
<List.Item>{dataInfo?.division}</List.Item>
|
||||
{
|
||||
dataShare.map((i: any) => {
|
||||
return (
|
||||
<List.Item key={i.id}>{i.division}</List.Item>
|
||||
)
|
||||
})
|
||||
dataShare.length === 0 ? <List.Item ta={"center"}>Tidak ada data</List.Item> :
|
||||
dataShare.map((i: any) => {
|
||||
return (
|
||||
<List.Item key={i.id}>{i.name}</List.Item>
|
||||
)
|
||||
})
|
||||
}
|
||||
</List>
|
||||
</Accordion.Panel>
|
||||
@@ -189,7 +184,7 @@ export default function DrawerInfoDocument({ data }: { data: IFormDetailMoreItem
|
||||
</Accordion>
|
||||
</Stack>
|
||||
)}
|
||||
</ScrollArea>
|
||||
{/* </ScrollArea> */}
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -150,7 +150,7 @@ export default function DrawerMore({ data, share }: { data: IDataDocument[], sha
|
||||
</LayoutDrawer>
|
||||
|
||||
<LayoutDrawer opened={isInfo} onClose={() => setIsInfo(false)} title={'Informasi Dokumen'} size="lg">
|
||||
<DrawerInfoDocument data={data} />
|
||||
<DrawerInfoDocument data={data[0]} />
|
||||
</LayoutDrawer>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -7,24 +7,23 @@ import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
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 { 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 [isData, setData] = useState<IDataDivison[]>([]);
|
||||
const param = useParams<{ id: string }>();
|
||||
const refresh = useHookstate(globalRefreshDocument);
|
||||
const tema = useHookstate(TEMA);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadingBtn, setLoadingBtn] = useState(false)
|
||||
const isMobile2 = useMediaQuery("(max-width: 438px)");
|
||||
|
||||
async function onShare() {
|
||||
try {
|
||||
if (selectedFiles.length == 0) {
|
||||
return toast.error("Pilih divisi terlebih dahulu");
|
||||
}
|
||||
setLoadingBtn(true)
|
||||
|
||||
const respon = await funShareDocument({
|
||||
dataDivision: selectedFiles,
|
||||
@@ -39,6 +38,8 @@ export default function DrawerShareDocument({ data, }: { data: IShareDivision[];
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
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(
|
||||
"?division=" + param.id
|
||||
);
|
||||
const shared = await funGetInfoDocument(`?item=${data[0].id}&cat=share`);
|
||||
if (response.success) {
|
||||
setData(response.data.filter((i: any) => i.id != param.id));
|
||||
setSelectedFiles(shared.data)
|
||||
} else {
|
||||
toast.error(response.message);
|
||||
}
|
||||
@@ -202,6 +205,7 @@ export default function DrawerShareDocument({ data, }: { data: IShareDivision[];
|
||||
radius={30}
|
||||
fullWidth
|
||||
onClick={() => onShare()}
|
||||
loading={loadingBtn}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
|
||||
@@ -434,16 +434,16 @@ export default function NavbarDocumentDivision() {
|
||||
</Flex>
|
||||
<Flex justify={"center"} align={"center"} direction={"column"}
|
||||
onClick={
|
||||
selectedFiles.length > 0 && !shareSelected
|
||||
selectedFiles.length == 1 && !shareSelected
|
||||
? () => setShare(true)
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<ActionIcon variant="subtle" aria-label="share" >
|
||||
<ActionIcon variant="subtle" aria-label="share">
|
||||
<LuShare2
|
||||
size={20}
|
||||
color={
|
||||
selectedFiles.length > 0 && !shareSelected
|
||||
selectedFiles.length == 1 && !shareSelected
|
||||
? "white"
|
||||
: "#656060"
|
||||
}
|
||||
@@ -453,7 +453,7 @@ export default function NavbarDocumentDivision() {
|
||||
fz={12}
|
||||
ta={"center"}
|
||||
c={
|
||||
selectedFiles.length > 0 && !shareSelected
|
||||
selectedFiles.length == 1 && !shareSelected
|
||||
? "white"
|
||||
: "#656060"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user