import { BackButton, BaseBox, NewWrapper, ScrollableCustom, StackCustom, TextCustom, } from "@/components"; import { IconPlus } from "@/components/_Icon"; import { AccentColor, MainColor } from "@/constants/color-palet"; import { useAuth } from "@/hooks/use-auth"; import { useNotificationStore } from "@/hooks/use-notification-store"; import { apiGetNotificationsById } from "@/service/api-notifications"; import { listOfcategoriesAppNotification } from "@/types/type-notification-category"; import { formatChatTime } from "@/utils/formatChatTime"; import { router, Stack, useFocusEffect } from "expo-router"; import { useCallback, useState } from "react"; import { RefreshControl, View } from "react-native"; const selectedCategory = (value: string) => { const category = listOfcategoriesAppNotification.find( (c) => c.value === value ); return category?.label; }; const BoxNotification = ({ data, activeCategory, }: { data: any; activeCategory: string | null; }) => { const { markAsRead } = useNotificationStore(); return ( <> { console.log( "Notification >", selectedCategory(activeCategory as string) ); router.push(data.deepLink); markAsRead(data.id); }} > {data.title} {data.pesan} {formatChatTime(data.createdAt)} ); }; export default function AdminNotification() { const { user } = useAuth(); const [activeCategory, setActiveCategory] = useState("event"); const [listData, setListData] = useState([]); const [refreshing, setRefreshing] = useState(false); const handlePress = (item: any) => { setActiveCategory(item.value); // tambahkan logika lain seperti filter dsb. }; useFocusEffect( useCallback(() => { fecthData(); }, [activeCategory]) ); const fecthData = async () => { try { const response = await apiGetNotificationsById({ id: user?.id as any, category: activeCategory as any, }); // console.log("Response Notification", JSON.stringify(response, null, 2)); if (response.success) { setListData(response.data); } else { setListData([]); } } catch (error) { console.log("Error Notification", error); } }; const onRefresh = () => { setRefreshing(true); fecthData(); setRefreshing(false); }; return ( <> , headerRight: () => ( router.push("/test-notifications")} /> ), }} /> ({ id: i, label: e.label, value: e.value, }))} onButtonPress={handlePress} activeId={activeCategory as string} /> } refreshControl={ } > {listData.map((e, i) => ( ))} ); }