import ButtonBackHeader from "@/components/buttonBackHeader"; import HeaderRightCalendarList from "@/components/calendar/headerCalendarList"; import ItemDateCalendar from "@/components/calendar/itemDateCalendar"; import EventItem from "@/components/eventItem"; import Skeleton from "@/components/skeleton"; import Styles from "@/constants/Styles"; import { apiGetCalendarByDateDivision, apiGetIndicatorCalendar } from "@/lib/api"; import { useAuthSession } from "@/providers/AuthProvider"; import { Feather } from "@expo/vector-icons"; import dayjs from "dayjs"; import { router, Stack, useLocalSearchParams } from "expo-router"; import moment from "moment"; import { useEffect, useState } from "react"; import { Pressable, SafeAreaView, ScrollView, Text, View } from "react-native"; import Datepicker, { CalendarComponents, CalendarDay } from "react-native-ui-datepicker"; import { useSelector } from "react-redux"; type Props = { id: string; idCalendar: string; timeStart: string; timeEnd: string; dateStart: string; dateEnd: string; status: number; title: string; desc: string; user_name: string; }; export default function CalendarDivision() { const [selected, setSelected] = useState(new Date()); const [data, setData] = useState([]); const { token, decryptToken } = useAuthSession(); const { id } = useLocalSearchParams<{ id: string }>(); const [dataIndicator, setDataIndicator] = useState([]); const [month, setMonth] = useState(new Date().getMonth()); const update = useSelector((state: any) => state.calendarUpdate) const [loading, setLoading] = useState(true) async function handleLoad(loading: boolean) { try { setLoading(loading) const hasil = await decryptToken(String(token?.current)); const response = await apiGetCalendarByDateDivision({ user: hasil, date: dayjs(selected).format("YYYY-MM-DD"), division: id, }); setData(response.data); } catch (error) { console.error(error); } finally { setLoading(false) } } async function handleLoadIndicator() { try { const newDate = new Date(selected?.getFullYear(), month, 1); const hasil = await decryptToken(String(token?.current)); const response = await apiGetIndicatorCalendar({ user: hasil, date: dayjs(newDate).format("YYYY-MM-DD"), division: id, }); setDataIndicator(response.data); } catch (error) { console.error(error); } } useEffect(() => { handleLoad(true) }, [selected]) useEffect(() => { handleLoad(false); }, [update.data]); useEffect(() => { handleLoadIndicator(); }, [month, update.data]); const components: CalendarComponents = { Day: (day: CalendarDay) => { const now = String(day.date); const today = moment(now).format("YYYY-MM-DD"); const sign = dataIndicator.includes(today); return ( ); }, IconNext: setMonth(month + 1)}> , IconPrev: setMonth(month - 1)}> , }; return ( ( { router.back(); }} /> ), headerTitle: "Kalender", headerTitleAlign: "center", headerRight: () => , }} /> setSelected(date)} styles={{ selected: Styles.selectedDate, }} /> Acara { loading ? <> : data.length > 0 ? ( data.map((item, index) => ( { router.push(`./calendar/${item.id}`); }} /> )) ) : ( Tidak ada acara ) } ); }