upd: dokumen divisi

Deskripsi:
- move dokumen divisi
- copy dokumen divisi
- share dokumen divisi

NO issues
This commit is contained in:
amel
2025-06-02 14:32:32 +08:00
parent 572db6f5d1
commit d9a9c821ea
7 changed files with 308 additions and 119 deletions

View File

@@ -208,7 +208,7 @@ export default function MenuBottomSelectDocument({ onDone }: Props) {
setShare(false)
}}
/>
<ModalSalinMove open={isMoveCopy} close={setMoveCopy} category={valMoveCopy} onConfirm={(value: string) => { }} />
<ModalSalinMove open={isMoveCopy} close={setMoveCopy} category={valMoveCopy} onConfirm={(value: string) => { }} dataChoose={[]} />
</>
)
}

View File

@@ -1,8 +1,9 @@
import Styles from "@/constants/Styles";
import { apiMoveDocument } from "@/lib/api";
import { apiCopyDocument, apiMoveDocument } from "@/lib/api";
import { setUpdateDokumen } from "@/lib/dokumenUpdate";
import { useAuthSession } from "@/providers/AuthProvider";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { useLocalSearchParams } from "expo-router";
import { useEffect, useState } from "react";
import { ToastAndroid, View } from "react-native";
import { useDispatch, useSelector } from "react-redux";
@@ -22,90 +23,159 @@ type Props = {
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)
export default function ModalMore({
onClose,
data,
share,
}: {
onClose: () => void;
data: Props[];
share: boolean;
}) {
const { id } = useLocalSearchParams<{ id: string }>();
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);
function cekFileSelected() {
const cek = data.some((i: any) => i.category == "FOLDER")
setForbidCopy(cek)
setNFileSelected(data.length)
const cek = data.some((i: any) => i.category == "FOLDER");
setForbidCopy(cek);
setNFileSelected(data.length);
}
useEffect(() => {
cekFileSelected()
}, [data])
cekFileSelected();
}, [data]);
async function handleMove(path: string) {
try {
const hasil = await decryptToken(String(token?.current))
const response = await apiMoveDocument({ user: hasil, dataItem: data, path })
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))
ToastAndroid.show("Berhasil memindahkan file", ToastAndroid.SHORT);
dispatch(setUpdateDokumen(!update));
} else {
ToastAndroid.show(response.message, ToastAndroid.SHORT)
ToastAndroid.show(response.message, ToastAndroid.SHORT);
}
} catch (error) {
console.error(error)
ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT)
console.error(error);
ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT);
} finally {
setMoveCopy(false)
onClose()
setIsCut(false);
onClose();
}
}
async function handleCopy(path: string) {
try {
const hasil = await decryptToken(String(token?.current));
const response = await apiCopyDocument({
user: hasil,
dataItem: data,
path,
idDivision: id
});
if (response.success) {
ToastAndroid.show("Berhasil menyalin 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 {
setIsCopy(false);
onClose();
}
}
return (
<>
<View style={Styles.rowItemsCenter}>
{
!share &&
{!share && (
<MenuItemRow
icon={<MaterialCommunityIcons name="folder-move-outline" color="black" size={25} />}
icon={
<MaterialCommunityIcons
name="folder-move-outline"
color="black"
size={25}
/>
}
title="Pindah"
onPress={() => {
setMoveCopy(true)
setIsCut(true);
}}
/>
}
{
!forbidCopy &&
)}
{!forbidCopy && (
<MenuItemRow
icon={<MaterialCommunityIcons name="folder-multiple-outline" color="black" size={25} />}
icon={
<MaterialCommunityIcons
name="folder-multiple-outline"
color="black"
size={25}
/>
}
title="Salin"
onPress={() => {
// handleMoveCopy('copy')
setIsCopy(true);
}}
/>
}
{
nFileSelected == 1 &&
)}
{nFileSelected == 1 && (
<MenuItemRow
icon={<MaterialCommunityIcons name="information-variant" color="black" size={25} />}
icon={
<MaterialCommunityIcons
name="information-variant"
color="black"
size={25}
/>
}
title="Informasi"
onPress={() => {
// onClose()
setInformasi(true)
setInformasi(true);
}}
/>
}
)}
</View>
<DrawerBottom animation="slide" isVisible={isInformasi} setVisible={setInformasi} title="Informasi Dokumen" height={80}>
<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)} />
<ModalSalinMove
open={isCut}
close={() => setIsCut(false)}
category={"move"}
onConfirm={(value: string) => handleMove(value)}
dataChoose={data}
/>
<ModalSalinMove
open={isCopy}
close={() => setIsCopy(false)}
category={"copy"}
onConfirm={(value: string) => handleCopy(value)}
dataChoose={data}
/>
</>
)
}
);
}

View File

@@ -13,6 +13,7 @@ type Props = {
close: (value: boolean) => void
category: 'copy' | 'move'
onConfirm: (value: string) => void
dataChoose: any[]
}
type DataProps = {
@@ -33,7 +34,7 @@ type PropsPath = {
name: string;
};
export default function ModalSalinMove({ open, close, category, onConfirm }: Props) {
export default function ModalSalinMove({ open, close, category, onConfirm, dataChoose }: Props) {
const [data, setData] = useState<DataProps[]>([])
const { token, decryptToken } = useAuthSession()
const [path, setPath] = useState('home')
@@ -79,18 +80,28 @@ export default function ModalSalinMove({ open, close, category, onConfirm }: Pro
</View>
<View>
{
data.map((item, index) => (
<BorderBottomItem
key={index}
borderType="bottom"
icon={<Ionicons name="folder-open-sharp" color={'#f9cc40'} size={30} />}
title={item.name}
titleWeight="normal"
onPress={() => {
setPath(item.id);
}}
/>
))
data.length > 0 ?
data.map((item, index) => {
const found = dataChoose.some((i: any) => i.id == item.id);
return (
<BorderBottomItem
key={index}
borderType="bottom"
icon={<Ionicons name="folder-open-sharp" style={[found ? Styles.cGray : Styles.cFolder]} size={30} />}
title={item.name}
titleWeight="normal"
onPress={() => {
if (found) return;
setPath(item.id);
}}
subtitle={found ? <Text style={[Styles.textInformation, Styles.cGray]}>Tidak dapat memilih folder ini</Text> : ''}
/>
)
}
)
:
<Text style={[Styles.textDefault, Styles.cGray, Styles.mt15, { textAlign: 'center' }]}>Tidak ada data</Text>
}
</View>
<View style={[Styles.rowOnly, Styles.mt15, Styles.absolute0]}>