'use client' import { WARNA } from "@/module/_global" import { Box, Divider, Flex, Group, Skeleton, Text } from "@mantine/core" import { useRouter } from "next/navigation" import { useState } from "react" import { IDataHomeEvent } from "../lib/type_home" import { funGetHome } from "../lib/api_home" import toast from "react-hot-toast" import { useMediaQuery, useShallowEffect } from "@mantine/hooks" import _ from "lodash" export default function ListEventHome() { const router = useRouter() const [isData, setData] = useState([]) const [loading, setLoading] = useState(true); const isMobile = useMediaQuery('(max-width: 369px)'); const fetchData = async () => { try { setData([]); setLoading(true); const response = await funGetHome('?cat=event') if (response.success) { setData(response.data) } else { toast.error(response.message); } setLoading(false); } catch (error) { toast.error("Gagal mendapatkan data, coba lagi nanti"); console.error(error); } finally { setLoading(false); } }; useShallowEffect(() => { fetchData(); }, []); return ( Acara Hari Ini {loading ? Array(3) .fill(null) .map((_, i) => ( )) : _.isEmpty(isData) ? Tidak ada acara : isData.map((event, index) => { const bgColor = ['#D8D8F1', '#FED6C5'][index % 2] const colorDivider = ['#535FCA', '#A7A7A7'][index % 2] return ( router.push(`/division/${event.idDivision}/calender/${event.id}`)} bg={bgColor} pl={15} p={10} style={{ borderRadius: 10 }} h={113}> {event.timeStart} - {event.timeEnd} {_.startCase(event.title)} Dibuat oleh : {event.user_name} ) }) } ) }