'use client' import { WARNA } from "@/module/_global"; import { Box, Grid, ActionIcon, Progress, Text, Skeleton } from "@mantine/core"; import { useShallowEffect } from "@mantine/hooks"; import { useParams } from "next/navigation"; import toast from "react-hot-toast"; import { HiMiniPresentationChartBar } from "react-icons/hi2"; import { funGetTaskDivisionById } from "../lib/api_task"; import { useState } from "react"; import { globalRefreshTask } from "../lib/val_task"; import { useHookstate } from "@hookstate/core"; export default function ProgressDetailTask() { const [valProgress, setValProgress] = useState(0) const [valLastUpdate, setValLastUpdate] = useState('') const param = useParams<{ id: string, detail: string }>() const refresh = useHookstate(globalRefreshTask) const [loading, setLoading] = useState(true) async function getOneData() { try { setLoading(true) const res = await funGetTaskDivisionById(param.detail, 'progress'); if (res.success) { setValProgress(res.data.progress); setValLastUpdate(res.data.lastUpdate); } else { toast.error(res.message); } setLoading(false) } catch (error) { console.error(error); toast.error("Gagal mendapatkan progress tugas divisi, coba lagi nanti"); } finally { setLoading(false) } } function onRefresh() { if (refresh.get()) { getOneData() refresh.set(false) } } useShallowEffect(() => { onRefresh() }, [refresh.get()]) useShallowEffect(() => { getOneData(); }, [param.detail]) return ( {loading ? : Kemajuan Kegiatan {valProgress}% } ) }