/* eslint-disable react-hooks/exhaustive-deps */ import { AlertDefaultSystem, BackButton, BaseBox, DotButton, DrawerCustom, LoaderCustom, MenuDrawerDynamicGrid, Spacing, StackCustom, TextCustom, ViewWrapper, } from "@/components"; import { IconArchive, IconContribution, IconEdit } from "@/components/_Icon"; import { IMenuDrawerItem } from "@/components/_Interface/types"; import ReportBox from "@/components/Box/ReportBox"; import Voting_BoxDetailHasilVotingSection from "@/screens/Voting/BoxDetailHasilVotingSection"; import { Voting_BoxDetailSection } from "@/screens/Voting/BoxDetailSection"; import Voting_ButtonStatusSection from "@/screens/Voting/ButtonStatusSection"; import { apiVotingGetOne, apiVotingUpdateData, } from "@/service/api-client/api-voting"; import { router, Stack, useFocusEffect, useLocalSearchParams, } from "expo-router"; import { useCallback, useState } from "react"; import Toast from "react-native-toast-message"; export default function VotingDetailStatus() { const { id, status } = useLocalSearchParams(); const [openDrawerDraft, setOpenDrawerDraft] = useState(false); const [openDrawerPublish, setOpenDrawerPublish] = useState(false); const [isLoading, setIsLoading] = useState(false); const [loadingGetData, setLoadingGetData] = useState(false); const [data, setData] = useState(null); useFocusEffect( useCallback(() => { onLoadData(); }, [id]) ); const onLoadData = async () => { try { setLoadingGetData(true); const response = await apiVotingGetOne({ id: id as string }); console.log("[DATA BY ID]", JSON.stringify(response, null, 2)); if (response.success) { setData(response.data); } } catch (error) { console.log("[ERROR]", error); } finally { setLoadingGetData(false); } }; const handlePressDraft = (item: IMenuDrawerItem) => { console.log("PATH >> ", item.path); router.navigate(item.path as any); setOpenDrawerDraft(false); }; const handlePressPublish = (item: IMenuDrawerItem) => { if (item.path === "") { AlertDefaultSystem({ title: "Update Arsip", message: "Apakah Anda yakin ingin mengarsipkan voting ini?", textLeft: "Batal", textRight: "Ya", onPressRight: async () => { try { const response = await apiVotingUpdateData({ id: id as string, data: data.isArsip ? false : true, category: "archive", }); if (response.success) { Toast.show({ type: "success", text1: response.message, }); router.back(); } } catch (error) { console.log("[ERROR]", error); } }, }); } router.navigate(item.path as any); setOpenDrawerPublish(false); }; return ( <> , headerRight: () => status === "draft" ? ( setOpenDrawerDraft(true)} /> ) : status === "publish" ? ( setOpenDrawerPublish(true)} /> ) : null, }} /> {loadingGetData ? ( ) : ( <> {status === "publish" && ( Status:{" "} {data?.isArsip ? "Arsip" : "Publish"} )} {data && data?.catatan && (status === "draft" || status === "reject") && ( )} {status === "publish" ? ( ) : ( )} )} {/* ========= Draft Drawer ========= */} setOpenDrawerDraft(false)} height={"auto"} > , label: "Edit", path: `/voting/${id}/edit`, }, ]} columns={4} onPressItem={handlePressDraft as any} /> {/* ========= Publish Drawer ========= */} setOpenDrawerPublish(false)} height={"auto"} > , label: "Daftar Kontributor", path: `/voting/${id}/list-of-contributor`, }, { icon: , label: "Update Arsip", path: "" as any, }, ]} onPressItem={handlePressPublish as any} /> ); }