upd: dokumen divisi
Deskripsi: - move dokumen divisi - copy dokumen divisi - share dokumen divisi NO issues
This commit is contained in:
@@ -8,9 +8,15 @@ import DrawerBottom from "@/components/drawerBottom";
|
||||
import { InputForm } from "@/components/inputForm";
|
||||
import MenuItemRow from "@/components/menuItemRow";
|
||||
import ModalFloat from "@/components/modalFloat";
|
||||
import ModalSelectMultiple from "@/components/modalSelectMultiple";
|
||||
import { ColorsStatus } from "@/constants/ColorsStatus";
|
||||
import Styles from "@/constants/Styles";
|
||||
import { apiDocumentDelete, apiDocumentRename, apiGetDocument } from "@/lib/api";
|
||||
import {
|
||||
apiDocumentDelete,
|
||||
apiDocumentRename,
|
||||
apiGetDocument,
|
||||
apiShareDocument,
|
||||
} from "@/lib/api";
|
||||
import { setUpdateDokumen } from "@/lib/dokumenUpdate";
|
||||
import { useAuthSession } from "@/providers/AuthProvider";
|
||||
import {
|
||||
@@ -49,6 +55,7 @@ type PropsPath = {
|
||||
};
|
||||
|
||||
export default function DocumentDivision() {
|
||||
const [isShare, setShare] = useState(false);
|
||||
const { token, decryptToken } = useAuthSession();
|
||||
const { id } = useLocalSearchParams<{ id: string }>();
|
||||
const [path, setPath] = useState("home");
|
||||
@@ -61,7 +68,7 @@ export default function DocumentDivision() {
|
||||
const [copyAllowed, setCopyAllowed] = useState(true);
|
||||
const [modalMore, setModalMore] = useState(false);
|
||||
const [isRename, setRename] = useState(false);
|
||||
const dispatch = useDispatch()
|
||||
const dispatch = useDispatch();
|
||||
const update = useSelector((state: any) => state.dokumenUpdate);
|
||||
const [bodyRename, setBodyRename] = useState({
|
||||
id: "",
|
||||
@@ -181,37 +188,67 @@ export default function DocumentDivision() {
|
||||
|
||||
async function handleRename() {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const response = await apiDocumentRename({ user: hasil, ...bodyRename })
|
||||
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()
|
||||
ToastAndroid.show("Berhasil mengubah nama", ToastAndroid.SHORT);
|
||||
dispatch(setUpdateDokumen(!update));
|
||||
handleBatal();
|
||||
} 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 {
|
||||
setRename(false)
|
||||
setRename(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current))
|
||||
const response = await apiDocumentDelete({ user: hasil, data: selectedFiles })
|
||||
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()
|
||||
ToastAndroid.show("Berhasil menghapus", ToastAndroid.SHORT);
|
||||
dispatch(setUpdateDokumen(!update));
|
||||
handleBatal();
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
handleBatal();
|
||||
}, [update]);
|
||||
|
||||
async function handleShare(selectedDivision: any[]) {
|
||||
try {
|
||||
const hasil = await decryptToken(String(token?.current));
|
||||
const response = await apiShareDocument({
|
||||
user: hasil,
|
||||
dataDivision: selectedDivision,
|
||||
dataItem: selectedFiles,
|
||||
});
|
||||
if (response.success) {
|
||||
ToastAndroid.show("Berhasil membagikan item", 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 {
|
||||
setShare(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +389,7 @@ export default function DocumentDivision() {
|
||||
title: "Konfirmasi",
|
||||
desc: "Apakah anda yakin ingin menghapus dokumen?",
|
||||
onPress: () => {
|
||||
handleDelete()
|
||||
handleDelete();
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -385,7 +422,9 @@ export default function DocumentDivision() {
|
||||
/>
|
||||
}
|
||||
title="Bagikan"
|
||||
onPress={() => { }}
|
||||
onPress={() => {
|
||||
setShare(true);
|
||||
}}
|
||||
column="many"
|
||||
color="white"
|
||||
disabled={selectedFiles.length != 1 || shareSelected}
|
||||
@@ -434,7 +473,9 @@ export default function DocumentDivision() {
|
||||
title="Ganti Nama"
|
||||
isVisible={isRename}
|
||||
setVisible={setRename}
|
||||
onSubmit={() => { handleRename() }}
|
||||
onSubmit={() => {
|
||||
handleRename();
|
||||
}}
|
||||
disableSubmit={bodyRename.name == ""}
|
||||
>
|
||||
<View>
|
||||
@@ -448,6 +489,19 @@ export default function DocumentDivision() {
|
||||
/>
|
||||
</View>
|
||||
</ModalFloat>
|
||||
|
||||
<ModalSelectMultiple
|
||||
choose="dinas"
|
||||
title="Bagikan"
|
||||
category="share-division"
|
||||
open={isShare}
|
||||
close={setShare}
|
||||
onSelect={(value) => {
|
||||
handleShare(value)
|
||||
}}
|
||||
value={id}
|
||||
item={selectedFiles[0]?.id}
|
||||
/>
|
||||
</SafeAreaView>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user