"use client"; import { MailIcon, UserIcon } from "lucide-react"; import { Dialog, DialogContent, DialogHeader, DialogTrigger, } from "../ui/dialog"; import { Button } from "../ui/button"; import { useEffect, useState } from "react"; import { useTranslations } from "next-intl"; import { Input } from "../ui/input"; import { getCookiesDecrypt } from "@/lib/utils"; import { close, error, loading } from "@/config/swal"; import { createSuggestion, deleteSuggestion, getSuggestionList, } from "@/service/curated-content/curated-content"; import { formatDateToIndonesian } from "@/utils/globals"; export default function SuggestionModal(props: { id: number; numberOfSuggestion: number; }) { const { id, numberOfSuggestion } = props; const t = useTranslations("Form"); const [suggestionValue, setSuggestionValue] = useState(""); const userId = getCookiesDecrypt("uie"); const [listData, setListData] = useState([]); const [replyId, setReplyId] = useState(0); const [replyValue, setReplyValue] = useState(""); useEffect(() => { initState(); }, [id]); async function initState() { loading(); const response = await getSuggestionList(id); setListData(response?.data?.data); close(); } const saveSuggestion = async (parentId?: number) => { console.log("suggestion vval", suggestionValue); const data = { mediaUploadId: Number(id), message: parentId ? replyValue : suggestionValue, parentId: parentId ? parentId : null, }; loading(); const response = await createSuggestion(data); if (response?.error) { error(response?.message); return false; } close(); setSuggestionValue(""); setReplyValue(""); initState(); }; const handleDeleteSuggestion = async (id: number) => { loading(); const response = await deleteSuggestion(id); if (response?.error) { error(response?.message); return false; } close(); initState(); }; return (

{t("suggestion-box", { defaultValue: "Suggestion Box" })} ({numberOfSuggestion || 0})

Suggestions
setSuggestionValue(e.target.value)} />
{listData?.length > 0 && listData?.map((data: any) => (
{replyId === data?.id && (
setReplyValue(e.target.value)} />
)}
{data?.children.length > 0 && data?.children.map((child: any) => (
{replyId === child?.id && (
setReplyValue(e.target.value) } />
)}
{child?.children.length > 0 && child?.children.map((items: any) => (
{items.suggestionFrom?.fullname}

{items.message}

))}
))}
))}
); }