"use client"; "use client"; import React, { useEffect, useState } from "react"; import { useForm, Controller } from "react-hook-form"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Card } from "@/components/ui/card"; import { zodResolver } from "@hookform/resolvers/zod"; import * as z from "zod"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { useParams } from "next/navigation"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Avatar, AvatarImage } from "@/components/ui/avatar"; import { deleteEscalationDiscussion, getEscalationDiscussion, getTicketingDetail, getTicketingInternalDetail, getTicketingInternalDiscussion, saveEscalationDiscussion, saveTicketInternalReply, } from "@/service/communication/communication"; import { Textarea } from "@/components/ui/textarea"; import { Icon } from "@iconify/react/dist/iconify.js"; import { Link } from "@/i18n/routing"; import { loading } from "@/lib/swal"; import { id } from "date-fns/locale"; import { htmlToString } from "@/utils/globals"; import InfoLainnyaModal from "../ticketing/info-lainnya"; import { PlusIcon } from "lucide-react"; const taskSchema = z.object({ title: z.string().min(1, { message: "Judul diperlukan" }), naration: z.string().min(2, { message: "Narasi Penugasan harus lebih dari 2 karakter.", }), }); export type replyDetail = { id: number; message: string; createdAt: string; messageFrom: { id: number; fullname: string; }; messageTo: { id: number; fullname: string; }; }; export default function FormDetailEscalation() { const MySwal = withReactContent(Swal); const { id } = useParams() as { id: string }; const [detail, setDetail] = useState(); const [ticketReply, setTicketReply] = useState([]); const [replyVisible, setReplyVisible] = useState(false); const [activeReplyId, setActiveReplyId] = useState(null); const [selectedPriority, setSelectedPriority] = useState(""); const [openEmergencyModal, setOpenEmergencyModal] = useState(false); const [replyMessage, setReplyMessage] = useState(""); const [listDiscussion, setListDiscussion] = useState([]); const [message, setMessage] = useState(""); const { control, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(taskSchema), }); useEffect(() => { async function initState() { if (id) { const response = await getTicketingDetail(id); setDetail(response?.data?.data); } } initState(); getTicketReply(); }, [id]); async function getTicketReply() { const res = await getTicketingInternalDiscussion(id); if (res?.data !== null) { setTicketReply(res?.data?.data); } } const handleReply = () => { setReplyVisible((prev) => !prev); }; useEffect(() => { const fetchDiscussion = async () => { const response = await getEscalationDiscussion(id); setListDiscussion(response?.data?.data || []); }; fetchDiscussion(); }, []); const postData = async () => { if (!message.trim()) return; const payload = { ticketId: id, message, parentId: null, }; try { await saveEscalationDiscussion(payload); setMessage(""); const response = await getEscalationDiscussion(id); setListDiscussion(response?.data?.data || []); } catch (error) { console.error("Gagal mengirim tanggapan:", error); } }; const postDataChild = async (parentId: any) => { const textarea = document.getElementById( `input-comment-${parentId}` ) as HTMLTextAreaElement | null; const replyMessage = textarea?.value; if (!replyMessage?.trim()) return; const payload = { ticketId: Number(id), parentMessageId: parentId, message: replyMessage, }; try { await saveEscalationDiscussion(payload); if (textarea) textarea.value = ""; const response = await getEscalationDiscussion(id); setListDiscussion(response?.data?.data || []); } catch (error) { console.error("Gagal mengirim balasan:", error); } }; const openEmergencyIssueDetail = () => { setOpenEmergencyModal(true); }; async function deleteDataSuggestion(dataId: any) { const response = await deleteEscalationDiscussion(dataId); console.log(response); const responseGet = await getEscalationDiscussion(id); setListDiscussion(responseGet?.data?.data); } return (
{detail !== undefined && (

Ticket #{detail.id}

{detail?.commentFromUserName} {` `} mengirimkan pesan untuk{` `} {detail?.message}

{`${new Date(detail?.createdAt).getDate()}-${ new Date(detail?.createdAt).getMonth() + 1 }-${new Date(detail?.createdAt).getFullYear()} ${new Date( detail?.createdAt ).getHours()}:${new Date(detail?.createdAt).getMinutes()}`}

{detail.message}

{detail?.typeId === 6 && detail?.emergencyIssue ? (
) : null} {detail?.emergencyIssue && ( setOpenEmergencyModal(false)} data={detail.emergencyIssue} /> )}
)}
{detail !== undefined && (
( )} /> {/* {errors.title?.message && (

{errors.title.message}

)} */}
(