import Styles from "@/constants/Styles" import { apiDeleteCalendar } from "@/lib/api" import { setUpdateCalendar } from "@/lib/calendarUpdate" import { useAuthSession } from "@/providers/AuthProvider" import { Ionicons, MaterialCommunityIcons, MaterialIcons } from "@expo/vector-icons" import { router } from "expo-router" import { useState } from "react" import { View } from "react-native" import Toast from "react-native-toast-message" import { useDispatch, useSelector } from "react-redux" import AlertKonfirmasi from "../alertKonfirmasi" import ButtonMenuHeader from "../buttonMenuHeader" import DrawerBottom from "../drawerBottom" import MenuItemRow from "../menuItemRow" type Props = { id: string | string[], idReminder?: string } export default function HeaderRightCalendarDetail({ id, idReminder }: Props) { const [isVisible, setVisible] = useState(false) const { token, decryptToken } = useAuthSession() const update = useSelector((state: any) => state.calendarUpdate) const dispatch = useDispatch() async function handleDeleteCalendar() { try { const hasil = await decryptToken(String(token?.current)); const response = await apiDeleteCalendar({ user: hasil }, String(id)); if (response.success) { dispatch(setUpdateCalendar({ ...update, data: !update.data })); Toast.show({ type: 'small', text1: response.message, }) router.back() } else { Toast.show({ type: 'small', text1: response.message, }) } } catch (error) { console.error(error); Toast.show({ type: 'small', text1: 'Terjadi kesalahan', }) } finally { setVisible(false) } } return ( <> { setVisible(true) }} /> } title="Tambah Anggota" onPress={() => { setVisible(false) router.push(`./${idReminder}/add-member`) }} /> } title="Edit" onPress={() => { setVisible(false) router.push(`./${idReminder}/edit`) }} /> } title="Hapus" onPress={() => { setVisible(false) AlertKonfirmasi({ title: 'Konfirmasi', desc: 'Apakah anda yakin ingin menghapus data ini? Data ini akan mempengaruhi semua data yang terkait', onPress: () => { handleDeleteCalendar() } }) }} /> ) }