"use client" import { Box, Flex, Grid, Group, List, Skeleton, Spoiler, Stack, Text } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { useState } from "react"; import { BsCardText } from "react-icons/bs"; import { TfiAnnouncement } from "react-icons/tfi"; import { IAnnouncement } from "../lib/type_announcement"; import { funGetAnnouncementById } from "../lib/api_announcement"; import toast from "react-hot-toast"; export default function DetailAnnouncement({ id }: { id: string }) { const [isData, setIsData] = useState() const [isMember, setIsMember] = useState({}) const [loading, setLoading] = useState(false) async function fetchOneAnnouncement() { try { setLoading(true) const res = await funGetAnnouncementById(id) if (res.success) { setIsData(res.data) setIsMember(res.member) } else { toast.error(res.message) } } catch (error) { console.error(error) toast.error("Gagal mendapatkan pengumuman, coba lagi nanti") } finally { setLoading(false) } } useShallowEffect(() => { fetchOneAnnouncement() }, []) return ( { loading ? : {isData?.title} } { loading ? Array(3) .fill(null) .map((_, i) => ( )) : {isData?.desc} } { loading ? Array(6) .fill(null) .map((_, i) => ( )) : Object.keys(isMember).map((v: any, i: any) => { return ( {isMember[v]?.[0].group} { isMember[v].map((item: any, x: any) => { return {item.division} }) } ) }) } ) }