"use client"; import React from "react"; import { convertFullTime } from "@/lib/utils"; import { BsTrash3 } from "react-icons/bs"; import ph from "@/assets/images/ph.png"; import Image from "next/image"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { deleteComment, postCommentViolation } from "@/utils/CitizenReport"; import { toast } from "sonner"; import RequestViolations from "./RequestViolations"; interface RequestCommentProps { id: string; comment: string; dateTime: string; user: any; canDelete: boolean; onDeleteCommentSuccess: any; commentsCount: () => void; } // Define the post violation function type type PostViolationArgs = { id: string; payload: { instanceId: number; violationTypeId: number; description: string; }; }; 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, commentsCount, }) => { const queryClient = useQueryClient(); const DeleteComment = useMutation({ mutationKey: ["deleteComment"], mutationFn: deleteComment, onSuccess: (res) => { queryClient.invalidateQueries({ queryKey: ["Comments"] }); commentsCount(); toast(<>{res.message}, { className: "!bg-green !text-black flex justify-end", }); }, onError: (error: any | string) => { toast(<>{error.message}, { className: "!bg-red-500 !text-white", }); onDeleteCommentSuccess(); }, }); const handelDelete = () => { DeleteComment.mutate(id); }; // Correctly wrapped function const wrappedPostCommentViolation = async ({ id, payload, }: PostViolationArgs) => { return postCommentViolation(id, payload); }; return (
picture

{getUserTitle(user)}

{convertFullTime(dateTime)}

{comment}

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