'use client' import { WARNA } from "@/module/_global"; import LayoutModal from "@/module/_global/layout/layout_modal"; import { Avatar, Box, Button, Center, Grid, Group, rem, Text, Textarea } from "@mantine/core"; import { useState } from "react"; import toast from "react-hot-toast"; import { funCreateDiscussion, funGetDiscussionById } from "../lib/api_discussion"; import { useParams, useRouter } from "next/navigation"; import { useShallowEffect } from "@mantine/hooks"; import { funGetProfileByCookies } from "@/module/user/profile/lib/api_profile"; export default function FormCreateDiscussion({ id }: { id: string }) { const [isValModal, setValModal] = useState(false) const router = useRouter() const [isImg, setImg] = useState("") const param = useParams<{ id: string, detail: string }>() const [loading, setLoading] = useState(true) const [img, setIMG] = useState() const [touched, setTouched] = useState({ desc: false, }); const [isData, setData] = useState({ desc: "", idDivision: id }) async function getData() { try { setLoading(true) const res = await funGetProfileByCookies() setIMG(`/api/file/img?jenis=image&cat=user&file=${res.data.img}`) setLoading(false) } catch (error) { console.error(error); } finally { setLoading(false) } } useShallowEffect(() => { getData() }, []) async function createDiscussion(val: boolean) { try { if (val) { const response = await funCreateDiscussion({ desc: isData.desc, idDivision: id }) if (response.success) { toast.success(response.message) router.push(`/division/${param.id}/discussion/`) setValModal(false) router.back() } else { toast.error(response.message) } } } catch (error) { console.error(error); toast.error("Gagal menambahkan diskusi, coba lagi nanti"); } finally { setValModal(false) } } return (