import Styles from "@/constants/Styles" import { apiAddLinkProject, apiDeleteProject } from "@/lib/api" import { setUpdateProject } from "@/lib/projectUpdate" import { useAuthSession } from "@/providers/AuthProvider" import { AntDesign, Feather, 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 { InputForm } from "../inputForm" import MenuItemRow from "../menuItemRow" import ModalFloat from "../modalFloat" type Props = { id: string | string[] status: number | undefined } export default function HeaderRightProjectDetail({ id, status }: Props) { const entityUser = useSelector((state: any) => state.user) const { token, decryptToken } = useAuthSession() const [isVisible, setVisible] = useState(false) const dispatch = useDispatch() const update = useSelector((state: any) => state.projectUpdate) const [isAddLink, setAddLink] = useState(false) const [link, setLink] = useState("") async function handleDelete() { try { const hasil = await decryptToken(String(token?.current)) const response = await apiDeleteProject({ user: hasil }, String(id)) if (response.success) { dispatch(setUpdateProject({ ...update, data: !update.data })) Toast.show({ type: 'small', text1: 'Berhasil menghapus kegiatan', }) router.back() } else { Toast.show({ type: 'small', text1: 'Gagal menghapus kegiatan', }) } } catch (error) { console.error(error) } finally { setVisible(false) } } async function handleAddLink() { try { const hasil = await decryptToken(String(token?.current)) const response = await apiAddLinkProject({ user: hasil, link }, String(id)) if (response.success) { dispatch(setUpdateProject({ ...update, link: !update.link })) Toast.show({ type: 'small', text1: 'Berhasil menambahkan link', }) } else { Toast.show({ type: 'small', text1: 'Gagal menambahkan link', }) } } catch (error) { console.error(error) } finally { setAddLink(false) } } return ( <> { setVisible(true) }} /> } title="Tambah Tugas" onPress={() => { if (status == 3) return setVisible(false) router.push(`/project/${id}/add-task`) }} disabled={status == 3} /> } title="Tambah File" onPress={() => { if (status == 3) return setVisible(false) router.push(`/project/${id}/add-file`) }} disabled={status == 3} /> } title="Tambah Link" onPress={() => { if (status == 3) return setVisible(false) setTimeout(() => { setAddLink(true) }, 600) }} disabled={status == 3} /> } title="Laporan" onPress={() => { if (status == 3) return setVisible(false) router.push(`/project/${id}/report`) }} disabled={status == 3} /> { entityUser.role != "user" && entityUser.role != "coadmin" && <> } title="Tambah Anggota" onPress={() => { if (status == 3) return setVisible(false) router.push(`/project/${id}/add-member`) }} disabled={status == 3} /> } title="Edit" onPress={() => { if (status == 3) return setVisible(false) router.push(`/project/${id}/edit`) }} disabled={status == 3} /> } { entityUser.role != "user" && entityUser.role != "coadmin" && { status == 3 ? } title="Hapus" onPress={() => { setVisible(false) AlertKonfirmasi({ title: 'Konfirmasi', desc: 'Apakah Anda yakin ingin menghapus kegiatan ini? Kegiatan yang dihapus tidak dapat dikembalikan', onPress: () => { handleDelete() } }) }} /> : } title="Batal" onPress={() => { setVisible(false) router.push(`/project/${id}/cancel`) }} /> } } { setAddLink(false) }} onSubmit={() => { handleAddLink() }} disableSubmit={link == ""} > { setLink(text) }} /> ) }