/* eslint-disable react-hooks/exhaustive-deps */ import { BackButton, BaseBox, DotButton, DrawerCustom, Grid, LoaderCustom, MenuDrawerDynamicGrid, TextCustom, ViewWrapper, } from "@/components"; import { IconPlus } from "@/components/_Icon"; import { apiDonationGetNewsById } from "@/service/api-client/api-donation"; import { formatChatTime } from "@/utils/formatChatTime"; import dayjs from "dayjs"; import { router, Stack, useFocusEffect, useLocalSearchParams, } from "expo-router"; import _ from "lodash"; import { useCallback, useState } from "react"; export default function DonationRecapOfNews() { const { id } = useLocalSearchParams(); console.log("[ID]", id); const [openDrawer, setOpenDrawer] = useState(false); const [list, setList] = useState(null); const [loadList, setLoadList] = useState(false); useFocusEffect( useCallback(() => { onLoadList(); }, [id]) ); const onLoadList = async () => { try { setLoadList(true); const response = await apiDonationGetNewsById({ id: id as string, category: "get-all", }); console.log("[RESPONSE LIST]", JSON.stringify(response, null, 2)); setList(response.data); } catch (error) { console.log("[ERROR]", error); setList([]); } finally { setLoadList(false); } }; return ( <> , headerRight: () => setOpenDrawer(true)} />, }} /> {loadList ? ( ) : _.isEmpty(list) ? ( Tidak ada kabar ) : ( list?.map((item: any, index: number) => ( {item?.title || "-"} {formatChatTime(item?.createdAt)} )) )} setOpenDrawer(false)} height={"auto"} > , label: "Tambah Berita", path: `/donation/${id}/(news)/add-news`, }, ]} onPressItem={(item) => { console.log("PATH ", item.path); router.navigate(item.path as any); setOpenDrawer(false); }} /> ); }