"use client" import { globalRole, keyWibu, LayoutDrawer, LayoutNavbarNew, TEMA } from "@/module/_global"; import { globalIsAdminDivision, globalIsMemberDivision } from "@/module/division_new"; import { useHookstate } from "@hookstate/core"; import { ActionIcon, Avatar, Badge, Box, Center, Divider, Flex, Grid, Group, rem, Skeleton, Spoiler, Text, TextInput } from "@mantine/core"; import { useMediaQuery, useShallowEffect } from "@mantine/hooks"; import moment from "moment"; import "moment/locale/id"; import { useParams, useRouter } from "next/navigation"; import { useState } from "react"; import toast from "react-hot-toast"; import { GrChatOption } from "react-icons/gr"; import { HiMenu } from "react-icons/hi"; import { VscSend } from "react-icons/vsc"; import { useWibuRealtime } from "wibu-realtime"; import { funGetOneDiscussionGeneral } from "../lib/api_discussion_general"; import { IComentsDisscussionGeneral, IDetailDiscussionGeneral } from "../lib/type_discussion_general"; import { globalRefreshDiscussionGeneral } from "../lib/val_discussion_general"; import DrawerDetailDiscussionGeneral from "./drawer_detail_discussion_general"; import { BiSolidCommentDetail } from "react-icons/bi"; export default function DetailDiscussionGeneral() { const [isData, setData] = useState() const [isDataKomentar, setDataKomentar] = useState([]) const [isComent, setIsComent] = useState("") const param = useParams<{ id: string }>() const [isLoad, setIsLoad] = useState(true) const [loadingKomentar, setLoadingKomentar] = useState(false) const refresh = useHookstate(globalRefreshDiscussionGeneral) const roleLogin = useHookstate(globalRole) const [isCreator, setCreator] = useState(false) const [isUser, setUser] = useState('') const adminLogin = useHookstate(globalIsAdminDivision) const memberDivision = useHookstate(globalIsMemberDivision) const tema = useHookstate(TEMA) const router = useRouter() const [openDrawer, setOpenDrawer] = useState(false) const isMobile = useMediaQuery('(max-width: 369px)') const isMobile2 = useMediaQuery("(max-width: 438px)") const [dataRealTime, setDataRealtime] = useWibuRealtime({ WIBU_REALTIME_TOKEN: keyWibu, project: "sdm" }) const getData = async (loading: boolean) => { try { setIsLoad(loading) const response = await funGetOneDiscussionGeneral(param.id, "?cat=detail") if (response.success) { setData(response.data) } else { toast.error(response.message) } } catch (error) { console.error(error) toast.error("Gagal mendapatkan data, coba lagi nanti") } finally { setIsLoad(false) } } useShallowEffect(() => { getData(true) }, [refresh.get()]) // useShallowEffect(() => { // if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-detail' && i.id == param.id)) { // getData(false) // } // if (dataRealTime && dataRealTime.some((i: any) => i.category == 'discussion-delete' && i.id == param.id && i.user != isUser)) { // toast.error("Data telah di hapus, anda akan beralih ke halaman list diskusi") // setTimeout(() => { // router.push(`/division/${param.id}/discussion`) // }, 1000) // } // }, [dataRealTime]) async function getKomentar(loading: boolean) { try { setLoadingKomentar(loading) const response = await funGetOneDiscussionGeneral(param.id, "?cat=komentar") if (response.success) { setData(response.data) } else { toast.error(response.message) } } catch (error) { console.error(error) } finally { setLoadingKomentar(false) } } // const sendComent = async () => { // try { // if (isComent.trim() == "") { // return toast.error("Masukkan Komentar Anda") // } // const response = await funCreateComent(id, { comment: isComent, idDiscussion: param.detail }) // if (response.success) { // setIsComent("") // setDataRealtime([{ // category: "discussion-detail", // id: id, // }]) // reloadData() // } else { // toast.error(response.message) // } // } catch (error) { // console.error(error) // } // } return ( setOpenDrawer(true)} bg={tema.get().bgIcon} size="lg" radius="lg" aria-label="Settings"> : <> } /> setOpenDrawer(false)}> setOpenDrawer(false)} id={param.id} status={Number(isData?.status)} /> {isLoad ? Array(1) .fill(null) .map((_, i) => ( )) : <> {isDataKomentar?.length == 0 ? {isData?.title} {isData?.status === 1 ? "BUKA" : "TUTUP"} {isData?.createdAt} {isData?.desc} {isDataKomentar?.length ? {isDataKomentar?.length} Komentar : ""} : {isData?.title} {isData?.status === 1 ? "BUKA" : "TUTUP"} {isData?.createdAt} {isData?.desc} {isDataKomentar?.length ? {isDataKomentar.length} Komentar : ""} } } {isLoad ? Array(2) .fill(0) .map((_, i) => ( )) : isDataKomentar.map((v, i) => { return ( {v.username} {moment(v.createdAt).format("ll")} {v.comment} ); }) } {isLoad ? : {300 - isComent.length} karakter tersisa setIsComent(e.target.value)} value={isComent} maxLength={300} />
}
) }