'use client' import { keyWibu, TEMA } from "@/module/_global"; import { useHookstate } from "@hookstate/core"; import { ActionIcon, Box, Grid, Group, Progress, Skeleton, Text } from "@mantine/core"; import { useMediaQuery, useShallowEffect } from "@mantine/hooks"; import { useParams } from "next/navigation"; import { useState } from "react"; import toast from "react-hot-toast"; import { HiMiniPresentationChartBar } from "react-icons/hi2"; import { IoIosWarning } from "react-icons/io"; import { useWibuRealtime } from "wibu-realtime"; import { funGetTaskDivisionById } from "../lib/api_task"; import { globalRefreshTask } from "../lib/val_task"; 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) const isMobile = useMediaQuery('(max-width: 369px)'); const tema = useHookstate(TEMA) const [reason, setReason] = useState("") const [dataRealTime, setDataRealtime] = useWibuRealtime({ WIBU_REALTIME_TOKEN: keyWibu, project: "sdm" }) async function getOneDataCancel() { try { const res = await funGetTaskDivisionById(param.detail, 'data'); if (res.success) { setReason(res.data.reason); } else { toast.error(res.message); } } catch (error) { console.error(error); toast.error("Gagal mendapatkan data tugas divisi, coba lagi nanti"); } } useShallowEffect(() => { getOneDataCancel(); }, [param.detail]) async function getOneData(loading: boolean) { try { setLoading(loading) const res = await funGetTaskDivisionById(param.detail, 'progress'); if (res.success) { setValProgress(res.data.progress); setValLastUpdate(res.data.lastUpdate); } else { toast.error(res.message); } } catch (error) { console.error(error); toast.error("Gagal mendapatkan progress tugas divisi, coba lagi nanti"); } finally { setLoading(false) } } function onRefresh() { if (refresh.get()) { getOneData(false) refresh.set(false) } } useShallowEffect(() => { onRefresh() }, [refresh.get()]) useShallowEffect(() => { getOneData(true); }, [param.detail]) useShallowEffect(() => { if (dataRealTime && dataRealTime.some((i: any) => i.category == 'tugas-detail-status' && i.id == param.detail)) { getOneDataCancel() getOneData(false) } }, [dataRealTime]) return ( {loading ? "" : reason !== null ? ( Tugas dibatalkan {reason} ) : null } {loading ? : Kemajuan Tugas {valProgress}% } ) }