Deskripsi: -get all dokumen - select dokumen - tambah folder - upload file - rename dokumen - hapus dokumen - informasi dokumen - move blm selsai NO Issues
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import Styles from "@/constants/Styles";
|
|
import { apiMoveDocument } from "@/lib/api";
|
|
import { setUpdateDokumen } from "@/lib/dokumenUpdate";
|
|
import { useAuthSession } from "@/providers/AuthProvider";
|
|
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
|
import { useEffect, useState } from "react";
|
|
import { ToastAndroid, View } from "react-native";
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
import DrawerBottom from "../drawerBottom";
|
|
import MenuItemRow from "../menuItemRow";
|
|
import ModalInformasi from "./modalInformasi";
|
|
import ModalSalinMove from "./modalSalinMove";
|
|
|
|
type Props = {
|
|
idStorage: string;
|
|
id: string;
|
|
name: string;
|
|
extension: string;
|
|
category: string;
|
|
path: string;
|
|
share: boolean;
|
|
createdBy: string;
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
}
|
|
|
|
export default function ModalMore({ onClose, data, share }: { onClose: () => void, data: Props[], share: boolean }) {
|
|
const [isInformasi, setInformasi] = useState(false)
|
|
const [isCut, setIsCut] = useState(false)
|
|
const [isCopy, setIsCopy] = useState(false)
|
|
const [forbidCopy, setForbidCopy] = useState(true)
|
|
const [nFileSelected, setNFileSelected] = useState(0)
|
|
const { token, decryptToken } = useAuthSession()
|
|
const dispatch = useDispatch()
|
|
const update = useSelector((state: any) => state.dokumenUpdate)
|
|
const [isMoveCopy, setMoveCopy] = useState(false)
|
|
|
|
function cekFileSelected() {
|
|
const cek = data.some((i: any) => i.category == "FOLDER")
|
|
setForbidCopy(cek)
|
|
setNFileSelected(data.length)
|
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
cekFileSelected()
|
|
}, [data])
|
|
|
|
async function handleMove(path: string) {
|
|
try {
|
|
const hasil = await decryptToken(String(token?.current))
|
|
const response = await apiMoveDocument({ user: hasil, dataItem: data, path })
|
|
if (response.success) {
|
|
ToastAndroid.show("Berhasil memindahkan file", ToastAndroid.SHORT)
|
|
dispatch(setUpdateDokumen(!update))
|
|
} else {
|
|
ToastAndroid.show(response.message, ToastAndroid.SHORT)
|
|
}
|
|
} catch (error) {
|
|
console.error(error)
|
|
ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT)
|
|
} finally {
|
|
setMoveCopy(false)
|
|
onClose()
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<View style={Styles.rowItemsCenter}>
|
|
{
|
|
!share &&
|
|
<MenuItemRow
|
|
icon={<MaterialCommunityIcons name="folder-move-outline" color="black" size={25} />}
|
|
title="Pindah"
|
|
onPress={() => {
|
|
setMoveCopy(true)
|
|
}}
|
|
/>
|
|
}
|
|
{
|
|
!forbidCopy &&
|
|
<MenuItemRow
|
|
icon={<MaterialCommunityIcons name="folder-multiple-outline" color="black" size={25} />}
|
|
title="Salin"
|
|
onPress={() => {
|
|
// handleMoveCopy('copy')
|
|
}}
|
|
/>
|
|
}
|
|
{
|
|
nFileSelected == 1 &&
|
|
<MenuItemRow
|
|
icon={<MaterialCommunityIcons name="information-variant" color="black" size={25} />}
|
|
title="Informasi"
|
|
onPress={() => {
|
|
// onClose()
|
|
setInformasi(true)
|
|
}}
|
|
/>
|
|
}
|
|
</View>
|
|
|
|
<DrawerBottom animation="slide" isVisible={isInformasi} setVisible={setInformasi} title="Informasi Dokumen" height={80}>
|
|
<ModalInformasi data={data[0]} />
|
|
</DrawerBottom>
|
|
|
|
<ModalSalinMove open={isMoveCopy} close={() => setMoveCopy(false)} category={'move'} onConfirm={(value: string) => handleMove(value)} />
|
|
</>
|
|
)
|
|
} |