From 572db6f5d1c5bdf68850673ce71d3911f9709212 Mon Sep 17 00:00:00 2001 From: amel Date: Fri, 30 May 2025 17:42:13 +0800 Subject: [PATCH] upd: dokumen divisi Deskripsi: -get all dokumen - select dokumen - tambah folder - upload file - rename dokumen - hapus dokumen - informasi dokumen - move blm selsai NO Issues --- .../[id]/(fitur-division)/document/index.tsx | 467 ++++++++++++++++-- components/document/headerDocument.tsx | 158 ++++-- components/document/itemFile.tsx | 4 +- .../document/menuBottomSelectDocument.tsx | 2 +- components/document/modalInformasi.tsx | 96 ++++ components/document/modalMore.tsx | 111 +++++ components/document/modalSalinMove.tsx | 103 +++- components/itemDetailMember.tsx | 4 +- components/modalFloat.tsx | 7 +- lib/api.ts | 46 +- lib/dokumenUpdate.ts | 14 + lib/store.ts | 2 + 12 files changed, 916 insertions(+), 98 deletions(-) create mode 100644 components/document/modalInformasi.tsx create mode 100644 components/document/modalMore.tsx create mode 100644 lib/dokumenUpdate.ts diff --git a/app/(application)/division/[id]/(fitur-division)/document/index.tsx b/app/(application)/division/[id]/(fitur-division)/document/index.tsx index 2da7037..8ea284c 100644 --- a/app/(application)/division/[id]/(fitur-division)/document/index.tsx +++ b/app/(application)/division/[id]/(fitur-division)/document/index.tsx @@ -1,52 +1,453 @@ -import ButtonBackHeader from "@/components/buttonBackHeader" -import { ButtonHeader } from "@/components/buttonHeader" -import HeaderRightDocument from "@/components/document/headerDocument" -import ItemFile from "@/components/document/itemFile" -import MenuBottomSelectDocument from "@/components/document/menuBottomSelectDocument" -import Styles from "@/constants/Styles" -import { AntDesign, MaterialIcons } from "@expo/vector-icons" -import { router, Stack, useLocalSearchParams } from "expo-router" -import { useState } from "react" -import { SafeAreaView, ScrollView, Text, View } from "react-native" +import AlertKonfirmasi from "@/components/alertKonfirmasi"; +import ButtonBackHeader from "@/components/buttonBackHeader"; +import { ButtonHeader } from "@/components/buttonHeader"; +import HeaderRightDocument from "@/components/document/headerDocument"; +import ItemFile from "@/components/document/itemFile"; +import ModalMore from "@/components/document/modalMore"; +import DrawerBottom from "@/components/drawerBottom"; +import { InputForm } from "@/components/inputForm"; +import MenuItemRow from "@/components/menuItemRow"; +import ModalFloat from "@/components/modalFloat"; +import { ColorsStatus } from "@/constants/ColorsStatus"; +import Styles from "@/constants/Styles"; +import { apiDocumentDelete, apiDocumentRename, apiGetDocument } from "@/lib/api"; +import { setUpdateDokumen } from "@/lib/dokumenUpdate"; +import { useAuthSession } from "@/providers/AuthProvider"; +import { + AntDesign, + MaterialCommunityIcons, + MaterialIcons, +} from "@expo/vector-icons"; +import { router, Stack, useLocalSearchParams } from "expo-router"; +import { useEffect, useState } from "react"; +import { + Pressable, + SafeAreaView, + ScrollView, + Text, + ToastAndroid, + View, +} from "react-native"; +import { useDispatch, useSelector } from "react-redux"; + +type Props = { + id: string; + category: string; + name: string; + extension: string; + idStorage: string; + path: string; + createdBy: string; + share: boolean; + createdAt: string; + updatedAt: string; +}; + +type PropsPath = { + id: string; + name: string; +}; export default function DocumentDivision() { - const { path } = useLocalSearchParams<{ path?: string }>() - const [isChecked, setIsChecked] = useState(false) + const { token, decryptToken } = useAuthSession(); + const { id } = useLocalSearchParams<{ id: string }>(); + const [path, setPath] = useState("home"); + const [data, setData] = useState([]); + const [dataJalur, setDataJalur] = useState([]); + const [dariSelectAll, setDariSelectAll] = useState(false); + const [selectedFiles, setSelectedFiles] = useState([]); + const [selectAll, setSelectAll] = useState(false); + const [shareSelected, setShareSelected] = useState(false); + const [copyAllowed, setCopyAllowed] = useState(true); + const [modalMore, setModalMore] = useState(false); + const [isRename, setRename] = useState(false); + const dispatch = useDispatch() + const update = useSelector((state: any) => state.dokumenUpdate); + const [bodyRename, setBodyRename] = useState({ + id: "", + name: "", + path: "", + idDivision: id, + extension: "", + }); + + async function handleLoad() { + try { + const hasil = await decryptToken(String(token?.current)); + const response = await apiGetDocument({ + user: hasil, + path, + division: id, + category: "all", + }); + setData(response.data); + setDataJalur(response.jalur); + } catch (error) { + console.error(error); + } + } + + useEffect(() => { + handleLoad(); + }, [path, update]); + + const handleCheckboxChange = (index: number) => { + setDariSelectAll(false); + if (selectedFiles.some((i: any) => i.id == data[index].id)) { + setSelectedFiles( + selectedFiles.filter((i: any) => i.id != data[index].id) + ); + } else { + setSelectedFiles([ + ...selectedFiles, + { + id: data[index].id, + name: data[index].name, + path: data[index].path, + extension: data[index].extension, + category: data[index].category, + share: data[index].share, + idStorage: data[index].idStorage, + }, + ]); + } + }; + + function cek() { + if (selectedFiles.length == data.length) { + setSelectAll(true); + } else { + setSelectAll(false); + } + + const shareSelected = selectedFiles.some((i: any) => i?.share == true); + if (shareSelected) { + setShareSelected(true); + } else { + setShareSelected(false); + } + + const cek = selectedFiles.some((i: any) => i?.category == "FOLDER"); + if (cek || selectedFiles.length > 1) { + setCopyAllowed(false); + } else { + setCopyAllowed(true); + } + } + + useEffect(() => { + cek(); + }, [selectedFiles]); + + const handleSelectAll = () => { + if (!selectAll) { + setDariSelectAll(false); + for (let index = 0; index < data.length; index++) { + if (!selectedFiles.some((i: any) => i.id == data[index].id)) { + const newArr = { + id: data[index].id, + name: data[index].name, + path: data[index].path, + extension: data[index].extension, + category: data[index].category, + share: data[index].share, + idStorage: data[index].idStorage, + }; + setSelectedFiles((selectedFiles: any) => [...selectedFiles, newArr]); + } + } + } else { + setDariSelectAll(true); + setSelectedFiles([]); + } + }; + + const handleBatal = () => { + setSelectedFiles([]); + setSelectAll(false); + setDariSelectAll(false); + }; + + function onChooseRename() { + setBodyRename({ + ...bodyRename, + id: selectedFiles[0].id, + name: selectedFiles[0].name, + path: selectedFiles[0].path, + extension: selectedFiles[0].extension, + }); + setRename(true); + } + + async function handleRename() { + try { + const hasil = await decryptToken(String(token?.current)) + const response = await apiDocumentRename({ user: hasil, ...bodyRename }) + if (response.success) { + ToastAndroid.show("Berhasil mengubah nama", ToastAndroid.SHORT) + dispatch(setUpdateDokumen(!update)) + handleBatal() + } else { + ToastAndroid.show(response.message, ToastAndroid.SHORT) + } + } catch (error) { + console.error(error) + ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT) + } finally { + setRename(false) + } + } + + async function handleDelete() { + try { + const hasil = await decryptToken(String(token?.current)) + const response = await apiDocumentDelete({ user: hasil, data: selectedFiles }) + if (response.success) { + ToastAndroid.show("Berhasil menghapus", ToastAndroid.SHORT) + dispatch(setUpdateDokumen(!update)) + handleBatal() + } else { + ToastAndroid.show(response.message, ToastAndroid.SHORT) + } + } catch (error) { + console.error(error) + ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT) + } + } return ( - isChecked - ? } onPress={() => { setIsChecked(false) }} /> - : { router.back() }} />, - headerTitle: isChecked ? '1 item terpilih' : 'Dokumen Divisi', - headerTitleAlign: 'center', + selectedFiles.length > 0 || dariSelectAll ? ( + } + onPress={() => { + handleBatal(); + }} + /> + ) : ( + { + router.back(); + }} + /> + ), + headerTitle: + selectedFiles.length > 0 || dariSelectAll + ? `${selectedFiles.length} item terpilih` + : "Dokumen Divisi", + headerTitleAlign: "center", headerRight: () => - isChecked - ? } onPress={() => { }} /> - : + selectedFiles.length > 0 || dariSelectAll ? ( + + } + onPress={() => { + handleSelectAll(); + }} + /> + ) : ( + + ), }} /> - + - home - - folder 1 + {dataJalur.map((item, index) => ( + { + setPath(item.id); + }} + > + {item.id != "home" && ( + + )} + {item.name} + + ))} - { setIsChecked(!isChecked) }} checked={isChecked} /> - - - + {data.length > 0 ? ( + data.map((item, index) => { + const isSelected = selectedFiles.some( + (i: any) => i?.id == item.id + ); + return ( + { + handleCheckboxChange(index); + }} + checked={isSelected} + onPress={() => { + setPath(item.id); + }} + /> + ); + }) + ) : ( + + Tidak ada dokumen + + )} - { - isChecked && { setIsChecked(false) }} /> - } + {(selectedFiles.length > 0 || dariSelectAll) && ( + + + + } + title="Unduh" + onPress={() => { }} + column="many" + color="white" + disabled={selectedFiles.length == 0 || !copyAllowed} + /> + + } + title="Hapus" + onPress={() => { + AlertKonfirmasi({ + title: "Konfirmasi", + desc: "Apakah anda yakin ingin menghapus dokumen?", + onPress: () => { + handleDelete() + }, + }); + }} + column="many" + color="white" + disabled={selectedFiles.length == 0 || shareSelected} + /> + + } + title="Ganti Nama" + onPress={() => { + onChooseRename(); + }} + column="many" + color="white" + disabled={selectedFiles.length != 1 || shareSelected} + /> + + } + title="Bagikan" + onPress={() => { }} + column="many" + color="white" + disabled={selectedFiles.length != 1 || shareSelected} + /> + + } + title="Lainnya" + onPress={() => { + setModalMore(true); + }} + column="many" + color="white" + disabled={ + selectedFiles.length == 1 || + (selectedFiles.length > 0 && !shareSelected) + ? false + : true + } + /> + + + )} + + + { + setModalMore(false); + }} + data={selectedFiles} + share={shareSelected} + /> + + + { handleRename() }} + disableSubmit={bodyRename.name == ""} + > + + { + setBodyRename({ ...bodyRename, name: text }); + }} + /> + + - ) -} \ No newline at end of file + ); +} diff --git a/components/document/headerDocument.tsx b/components/document/headerDocument.tsx index 0916722..4013375 100644 --- a/components/document/headerDocument.tsx +++ b/components/document/headerDocument.tsx @@ -1,54 +1,150 @@ -import Styles from "@/constants/Styles" -import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons" -import { useState } from "react" -import { ToastAndroid, View } from "react-native" -import ButtonMenuHeader from "../buttonMenuHeader" -import DrawerBottom from "../drawerBottom" -import { InputForm } from "../inputForm" -import MenuItemRow from "../menuItemRow" -import ModalFloat from "../modalFloat" +import Styles from "@/constants/Styles"; +import { apiCreateFolderDocument, apiUploadFileDocument } from "@/lib/api"; +import { setUpdateDokumen } from "@/lib/dokumenUpdate"; +import { useAuthSession } from "@/providers/AuthProvider"; +import { MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons"; +import * as DocumentPicker from "expo-document-picker"; +import { useLocalSearchParams } from "expo-router"; +import { useState } from "react"; +import { ToastAndroid, View } from "react-native"; +import { useDispatch, useSelector } from "react-redux"; +import ButtonMenuHeader from "../buttonMenuHeader"; +import DrawerBottom from "../drawerBottom"; +import { InputForm } from "../inputForm"; +import MenuItemRow from "../menuItemRow"; +import ModalFloat from "../modalFloat"; -type Props = { - id: string | string[] | undefined | null -} +export default function HeaderRightDocument({ path }: { path: string }) { + const [isVisible, setVisible] = useState(false); + const [newFolder, setNewFolder] = useState(false); + const { id } = useLocalSearchParams<{ id: string }>(); + const [name, setName] = useState(""); + const { token, decryptToken } = useAuthSession() + const dispatch = useDispatch() + const update = useSelector((state: any) => state.dokumenUpdate) + + async function handleCreateFolder() { + try { + const hasil = await decryptToken(String(token?.current)) + const response = await apiCreateFolderDocument({ user: hasil, name, path, idDivision: id }) + if (response.success) { + ToastAndroid.show("Berhasil membuat folder baru", ToastAndroid.SHORT) + dispatch(setUpdateDokumen(!update)) + } else { + ToastAndroid.show(response.message, ToastAndroid.SHORT) + } + } catch (error) { + console.error(error) + ToastAndroid.show("Terjadi kesalahan", ToastAndroid.SHORT) + } finally { + setNewFolder(false) + } + } + + const pickDocumentAsync = async () => { + let result = await DocumentPicker.getDocumentAsync({ + type: ["*/*"], + multiple: false, + }); + if (!result.canceled) { + if (result.assets?.[0].uri) { + handleUploadFile(result.assets?.[0]) + } + } + }; + + async function handleUploadFile(file: any) { + try { + const hasil = await decryptToken(String(token?.current)) + const fd = new FormData() + fd.append("file", { + uri: file.uri, + type: "application/octet-stream", + name: file.name, + } as any); + + fd.append( + "data", + JSON.stringify({ + idPath: path, + idDivision: id, + user: hasil, + }) + ); + + const response = await apiUploadFileDocument({ data: fd }) + if (response.success) { + ToastAndroid.show("Berhasil mengunggah 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 { + setVisible(false) + } + } -export default function HeaderRightDocument({ id }: Props) { - const [isVisible, setVisible] = useState(false) - const [newFolder, setNewFolder] = useState(false) return ( <> - { setVisible(true) }} /> - + { + setVisible(true); + }} + /> + } + icon={ + + } title="Tambah Dokumen" onPress={() => { - setVisible(false) - setNewFolder(true) + setVisible(false); + setNewFolder(true); }} /> } title="Upload File" - onPress={() => { - setVisible(false) - }} + onPress={pickDocumentAsync} /> - { - setNewFolder(false) - ToastAndroid.show('Berhasil membuat folder baru', ToastAndroid.SHORT) - }}> + handleCreateFolder() + }} + > - + { + setName(value); + }} + /> - ) - -} \ No newline at end of file + ); +} diff --git a/components/document/itemFile.tsx b/components/document/itemFile.tsx index cf18488..4691c76 100644 --- a/components/document/itemFile.tsx +++ b/components/document/itemFile.tsx @@ -42,8 +42,8 @@ export default function ItemFile({ category, checked, dateTime, title, onChecked - - {title} + + {title} {dateTime} diff --git a/components/document/menuBottomSelectDocument.tsx b/components/document/menuBottomSelectDocument.tsx index 8bd3dcd..eff8d38 100644 --- a/components/document/menuBottomSelectDocument.tsx +++ b/components/document/menuBottomSelectDocument.tsx @@ -208,7 +208,7 @@ export default function MenuBottomSelectDocument({ onDone }: Props) { setShare(false) }} /> - + { }} /> ) } \ No newline at end of file diff --git a/components/document/modalInformasi.tsx b/components/document/modalInformasi.tsx new file mode 100644 index 0000000..09e7334 --- /dev/null +++ b/components/document/modalInformasi.tsx @@ -0,0 +1,96 @@ +import Styles from "@/constants/Styles"; +import { apiGetDocumentInformasi } from "@/lib/api"; +import { useAuthSession } from "@/providers/AuthProvider"; +import { Ionicons, MaterialCommunityIcons } from "@expo/vector-icons"; +import { useEffect, useState } from "react"; +import { Pressable, ScrollView, Text, View } from "react-native"; +import { useSharedValue } from "react-native-reanimated"; +import ItemAccordion from "../itemAccordion"; +import ItemDetailMember from "../itemDetailMember"; + +type Props = { + category: string, + name: string, + extension: string, + createdAt: string, + path: string, + division: string, + createdBy: string +} + +type PropsShare = { + id: string + name: string +} + +export default function ModalInformasi({ data }: { data: any }) { + const open = useSharedValue(false) + const [dataInformasi, setDataInformasi] = useState() + const { token, decryptToken } = useAuthSession() + const [dataShare, setDataShare] = useState([]) + + async function handleInformasi() { + try { + const hasil = await decryptToken(String(token?.current)) + const response = await apiGetDocumentInformasi({ user: hasil, item: data.id, cat: 'lainnya' }) + setDataInformasi(response.data) + + const responseShare = await apiGetDocumentInformasi({ user: hasil, item: data.id, cat: 'share' }) + setDataShare(responseShare.data) + } catch (error) { + console.error(error) + } + } + + useEffect(() => { + handleInformasi() + }, []) + + return ( + <> + + { + dataInformasi?.extension == 'folder' + ? + + : + + } + + + + + + + + + { open.value = !open.value; }}> + + + Telah dibagikan ke divisi + + + + + + { + dataShare.length > 0 ? ( + dataShare.map((item, index) => ( + + + {item.name} + + )) + ) + : ( + + Tidak ada data + + ) + } + + + + + ) +} \ No newline at end of file diff --git a/components/document/modalMore.tsx b/components/document/modalMore.tsx new file mode 100644 index 0000000..9d4bdee --- /dev/null +++ b/components/document/modalMore.tsx @@ -0,0 +1,111 @@ +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 ( + <> + + { + !share && + } + title="Pindah" + onPress={() => { + setMoveCopy(true) + }} + /> + } + { + !forbidCopy && + } + title="Salin" + onPress={() => { + // handleMoveCopy('copy') + }} + /> + } + { + nFileSelected == 1 && + } + title="Informasi" + onPress={() => { + // onClose() + setInformasi(true) + }} + /> + } + + + + + + + setMoveCopy(false)} category={'move'} onConfirm={(value: string) => handleMove(value)} /> + + ) +} \ No newline at end of file diff --git a/components/document/modalSalinMove.tsx b/components/document/modalSalinMove.tsx index e6b32dc..bd328cc 100644 --- a/components/document/modalSalinMove.tsx +++ b/components/document/modalSalinMove.tsx @@ -1,5 +1,9 @@ import Styles from "@/constants/Styles" +import { apiGetDocument } from "@/lib/api" +import { useAuthSession } from "@/providers/AuthProvider" import { AntDesign, Ionicons } from "@expo/vector-icons" +import { useLocalSearchParams } from "expo-router" +import { useEffect, useState } from "react" import { Pressable, Text, View } from "react-native" import BorderBottomItem from "../borderBottomItem" import DrawerBottom from "../drawerBottom" @@ -8,41 +12,92 @@ type Props = { open: boolean close: (value: boolean) => void category: 'copy' | 'move' + onConfirm: (value: string) => void } -export default function ModalSalinMove({ open, close, category, }: Props) { +type DataProps = { + id: string; + category: string; + name: string; + extension: string; + idStorage: string; + path: string; + createdBy: string; + share: boolean; + createdAt: string; + updatedAt: string; +} + +type PropsPath = { + id: string; + name: string; +}; + +export default function ModalSalinMove({ open, close, category, onConfirm }: Props) { + const [data, setData] = useState([]) + const { token, decryptToken } = useAuthSession() + const [path, setPath] = useState('home') + const { id } = useLocalSearchParams<{ id: string }>(); + const [dataJalur, setDataJalur] = useState([]) + + async function getData() { + try { + const hasil = await decryptToken(String(token?.current)) + const response = await apiGetDocument({ user: hasil, path, division: id, category: 'folder' }) + if (response.success) { + setData(response.data) + setDataJalur(response.jalur) + } + } catch (error) { + console.error(error) + } + } + + useEffect(() => { + getData() + }, [path]) + return ( - home - - folder 1 + { + dataJalur.map((item, index) => ( + { + setPath(item.id); + }} + > + {item.id != "home" && ( + + )} + {item.name} + + )) + } - } - title="Folder 1" - titleWeight="normal" - /> - } - title="Folder 2" - titleWeight="normal" - /> - } - title="Folder 3" - titleWeight="normal" - /> + { + data.map((item, index) => ( + } + title={item.name} + titleWeight="normal" + onPress={() => { + setPath(item.id); + }} + /> + )) + } - { close }}> + close(false)}> BATAL - { }}> + onConfirm(path)}> {category == 'copy' ? 'SALIN' : 'PINDAH'} diff --git a/components/itemDetailMember.tsx b/components/itemDetailMember.tsx index e30ad64..9651847 100644 --- a/components/itemDetailMember.tsx +++ b/components/itemDetailMember.tsx @@ -35,7 +35,7 @@ const data = { icon: }, dokumen: { - label: 'Nama Dokumen', + label: 'Dokumen', icon: }, type: { @@ -68,7 +68,7 @@ export default function ItemDetailMember({ category, value, border }: Props) { {data[category].icon} {data[category].label} - {value} + {value} ) } \ No newline at end of file diff --git a/components/modalFloat.tsx b/components/modalFloat.tsx index 6280470..d0f087e 100644 --- a/components/modalFloat.tsx +++ b/components/modalFloat.tsx @@ -8,9 +8,10 @@ type Props = { title?: string children: React.ReactNode onSubmit: () => void + disableSubmit?: boolean } -export default function ModalFloat({ isVisible, setVisible, title, children, onSubmit }: Props) { +export default function ModalFloat({ isVisible, setVisible, title, children, onSubmit, disableSubmit }: Props) { return ( { setVisible(false) }}> Batal - - Simpan + + Simpan diff --git a/lib/api.ts b/lib/api.ts index 523089e..7cc131c 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -399,7 +399,7 @@ export const apiGetDivisionMember = async ({ user, id, search }: { user: string, return response.data; }; -export const apiCreateDivision = async (data: { data: { idGroup: string, name: string, desc: string }, member: [], admin: string[], user:string }) => { +export const apiCreateDivision = async (data: { data: { idGroup: string, name: string, desc: string }, member: [], admin: string[], user: string }) => { const response = await api.post(`/mobile/division`, data) return response.data; }; @@ -569,4 +569,46 @@ export const apiCreateTask = async (data: FormData) => { export const apiDeleteTask = async (data: { user: string }, id: string) => { const response = await api.delete(`/mobile/task/${id}/lainnya`, { data }) return response.data; -}; \ No newline at end of file +}; + +export const apiGetDocument = async ({ user, path, division, category }: { user: string, path: string, division: string, category: 'all' | 'folder' }) => { + const response = await api.get(`mobile/document?user=${user}&path=${path}&division=${division}&category=${category}`); + return response.data; +}; + +export const apiGetDocumentInformasi = async ({ user, item, cat }: { user: string, item: string, cat: 'share' | 'lainnya' }) => { + const response = await api.get(`mobile/document/more?user=${user}&item=${item}&cat=${cat}`); + return response.data; +}; + +export const apiDocumentRename = async (data: { name: string, user: string, id: string, path: string, idDivision: string, extension: string }) => { + const response = await api.put(`/mobile/document/`, data) + return response.data; +}; + +export const apiDocumentDelete = async (data: { user: string, data: any[] }) => { + const response = await api.delete(`/mobile/document`, { data }) + return response.data +}; + +export const apiCreateFolderDocument = async (data: { name: string, path: string, idDivision: string, user: string }) => { + const response = await api.post(`/mobile/document/`, data) + return response.data; +}; + +export const apiUploadFileDocument = async ({ data }: { data: FormData }) => { + console.log(data) + const response = await api.post(`/mobile/document/upload`, data, + { + headers: { + 'Content-Type': 'multipart/form-data', + }, + } + ) + return response.data; +}; + +export const apiMoveDocument = async (data: { path: string, dataItem: any[], user: string }) => { + const response = await api.post(`/mobile/document/more`, data) + return response.data; +}; diff --git a/lib/dokumenUpdate.ts b/lib/dokumenUpdate.ts new file mode 100644 index 0000000..2e534c4 --- /dev/null +++ b/lib/dokumenUpdate.ts @@ -0,0 +1,14 @@ +import { createSlice } from '@reduxjs/toolkit'; + +const dokumenUpdate = createSlice({ + name: 'dokumenUpdate', + initialState: false, + reducers: { + setUpdateDokumen: (state, action) => { + return action.payload; + }, + }, +}); + +export const { setUpdateDokumen } = dokumenUpdate.actions; +export default dokumenUpdate.reducer; \ No newline at end of file diff --git a/lib/store.ts b/lib/store.ts index a535137..04607c6 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -6,6 +6,7 @@ import discussionGeneralDetailUpdate from './discussionGeneralDetail'; import discussionUpdate from './discussionUpdate'; import divisionCreate from './divisionCreate'; import divisionUpdate from './divisionUpdate'; +import dokumenUpdate from './dokumenUpdate'; import entitiesReducer from './entitiesSlice'; import filterSlice from './filterSlice'; import groupUpdate from './groupSlice'; @@ -36,6 +37,7 @@ const store = configureStore({ calendarUpdate: calendarUpdate, taskUpdate: taskUpdate, divisionCreate: divisionCreate, + dokumenUpdate: dokumenUpdate, } });