"use client"; import React from "react"; import { convertFullTime } from "@/lib/utils"; import RequestViolation from "./RequestViolation"; import { BsTrash3 } from "react-icons/bs"; import ph from "@/assets/images/ph.png"; import Image from "next/image"; import { useMutation } from "@tanstack/react-query"; import { deleteComment } from "@/utils/CitizenReport"; import { toast } from "sonner"; interface RequestCommentProps { id: string; comment: string; dateTime: string; user: any; canDelete: boolean; onDeleteCommentSuccess:any } const getUserTitle = (user: any) => { if (user.firstName || user.lastName) return `${user.firstName || ""} ${user.lastName || ""}`; else if (user.title) return user.title; else return "شهروند"; }; const RequestComment: React.FC = ({ id, comment, dateTime, user, canDelete, onDeleteCommentSuccess, }) => { const DeleteComment = useMutation({ mutationKey: ["deleteComment"], mutationFn: deleteComment, onSuccess: (res) => { toast(<>{res.message}, { className: "!bg-green !text-black", }); }, onError: (error: any | string) => { toast(<>{error.message}, { className: "!bg-red-500 !text-white", }); onDeleteCommentSuccess(); }, }); const handelDelete = () => { DeleteComment.mutate(id); }; return (
picture

{getUserTitle(user)}

{convertFullTime(dateTime)}

{comment}

{canDelete && ( )}
); }; export default RequestComment;