import { ButtonCustom, SelectCustom, Spacing, StackCustom, TextAreaCustom, TextCustom, TextInputCustom, ViewWrapper, } from "@/components"; import DateTimePickerCustom from "@/components/DateInput/DateTimePickerCustom"; import { useAuth } from "@/hooks/use-auth"; import { apiEventCreate } from "@/service/api-client/api-event"; import { apiMasterEventType } from "@/service/api-client/api-master"; import { DateTimePickerEvent } from "@react-native-community/datetimepicker"; import { router } from "expo-router"; import React, { useEffect, useState } from "react"; import Toast from "react-native-toast-message"; interface EventCreateProps { title?: string; lokasi?: string; deskripsi?: string; eventMaster_TipeAcaraId?: string; tanggal?: string; tanggalSelesai?: string; authorId?: string; } export default function EventCreate() { const [data, setData] = useState(); const [listTypeEvent, setListTypeEvent] = useState([]); const [isLoading, setIsLoading] = useState(false); const { user } = useAuth(); useEffect(() => { onLoadMasterEventType(); }, []); const onLoadMasterEventType = async () => { try { const response = await apiMasterEventType(); setListTypeEvent(response.data); } catch (error) { console.log("Error onLoadMasterEventType", error); } }; const [selectedDate, setSelectedDate] = useState< Date | DateTimePickerEvent | null >(null); const [selectedEndDate, setSelectedEndDate] = useState< Date | DateTimePickerEvent | null >(null); const handlerSubmit = async () => { if ( !data?.title || !data?.lokasi || !data?.deskripsi || !data?.eventMaster_TipeAcaraId ) { Toast.show({ type: "info", text1: "Info", text2: "Lengkapi semua data", }); return; } if (!selectedDate || !selectedEndDate) { Toast.show({ type: "info", text1: "Info", text2: "Pilih tanggal mulai dan berakhir", }); return; } // if (selectedDate) { // console.log("Tanggal yang dipilih:", selectedDate); // console.log(`ISO Format ${Platform.OS}:`, selectedDate.toString()); // // Kirim ke API atau proses lanjutan // } else { // console.log("Tanggal belum dipilih"); // } // if (selectedEndDate) { // console.log("Tanggal yang dipilih:", selectedEndDate); // console.log(`ISO Format ${Platform.OS}:`, selectedEndDate.toString()); // // Kirim ke API atau proses lanjutan // } else { // console.log("Tanggal berakhir belum dipilih"); // } try { setIsLoading(true); const newData = { ...data, tanggal: new Date(selectedDate as any).toISOString(), tanggalSelesai: new Date(selectedEndDate as any).toISOString(), authorId: user?.id, }; console.log("Data berhasil disimpan", JSON.stringify(newData, null, 2)); const response = await apiEventCreate(newData); console.log("Response", JSON.stringify(response, null, 2)); router.replace("/event/status"); } catch (error) { console.log(error); } finally { setIsLoading(false); } }; const buttonSubmit = ( ); return ( <> setData({ ...data, title: value })} /> ({ label: item.name, value: item.id, }))} value={data?.eventMaster_TipeAcaraId || ""} onChange={(value: any) => setData({ ...data, eventMaster_TipeAcaraId: value }) } /> setData({ ...data, lokasi: value })} /> { setSelectedDate(date as any); }} value={selectedDate as any} minimumDate={new Date(Date.now())} /> { setSelectedEndDate(date as any); }} value={selectedEndDate as any} minimumDate={new Date(selectedDate as any)} /> {!selectedDate && ( Note: Pilih tanggal mulai terlebih dahulu )} setData({ ...data, deskripsi: value }) } /> {buttonSubmit} ); }