import { AlertDefaultSystem, ButtonCustom, Grid } from "@/components"; import { apiVotingDelete, apiVotingUpdateStatus, } from "@/service/api-client/api-voting"; import { router } from "expo-router"; import Toast from "react-native-toast-message"; export default function Voting_ButtonStatusSection({ id, status, isLoading, onSetLoading, }: { id: string; status: string; isLoading: boolean; onSetLoading: (value: boolean) => void; }) { const handleBatalkanReview = () => { AlertDefaultSystem({ title: "Batalkan Review", message: "Apakah Anda yakin ingin batalkan review ini?", textLeft: "Batal", textRight: "Ya", onPressRight: async () => { try { onSetLoading(true); const response = await apiVotingUpdateStatus({ id: id as string, status: "draft", }); if (response?.success) { Toast.show({ type: "success", text1: response.message, }); router.back(); } else { Toast.show({ type: "info", text1: "Info", text2: response.message, }); router.back(); } } catch (error) { console.log("[ERROR]", error); } finally { onSetLoading(false); } }, }); }; const handleAjukanReview = () => { AlertDefaultSystem({ title: "Ajukan Review", message: "Apakah Anda yakin ingin ajukan review ini?", textLeft: "Batal", textRight: "Ya", onPressRight: async () => { try { onSetLoading(true); const response = await apiVotingUpdateStatus({ id: id as string, status: "review", }); if (response?.success) { Toast.show({ type: "success", text1: response.message, }); router.back(); } else { Toast.show({ type: "info", text1: "Info", text2: response.message, }); router.back(); } } catch (error) { console.log("[ERROR]", error); } finally { onSetLoading(false); } }, }); }; const handleEditKembali = () => { AlertDefaultSystem({ title: "Edit Kembali", message: "Apakah Anda yakin ingin edit kembali ini?", textLeft: "Batal", textRight: "Ya", onPressRight: async () => { try { onSetLoading(true); const response = await apiVotingUpdateStatus({ id: id as string, status: "draft", }); if (response?.success) { Toast.show({ type: "success", text1: response.message, }); router.back(); } else { Toast.show({ type: "info", text1: "Info", text2: response.message, }); router.back(); } } catch (error) { console.log("[ERROR]", error); } finally { onSetLoading(false); } }, }); }; const handleOpenDeleteAlert = () => { AlertDefaultSystem({ title: "Hapus", message: "Apakah Anda yakin ingin menghapus data ini?", textLeft: "Batal", textRight: "Hapus", onPressRight: async () => { try { onSetLoading(true); const response = await apiVotingDelete({ id: id as string, }); if (response?.success) { Toast.show({ type: "success", text1: response.message, }); router.back(); } else { Toast.show({ type: "info", text1: "Info", text2: response.message, }); router.back(); } } catch (error) { console.log("[ERROR]", error); } finally { onSetLoading(false); } }, }); }; const DeleteButton = () => { return ( <> Hapus ); }; switch (status) { case "publish": return <>; case "review": return ( Batalkan Review ); case "draft": return ( <> Ajukan Review {DeleteButton()} ); case "reject": return ( <> Edit Kembali {DeleteButton()} ); default: return Status Undifined; } }