"use client"; import { useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner"; import { Button, Textarea } from "@/components/ds"; import { workspaceApi } from "@/modules/workspace/services/workspace-api"; import { displayPerson, formatWhen } from "@/modules/workspace/labels"; import { WorkspacePageError, WorkspacePageLoader } from "@/modules/workspace/pages/shared"; export function CommentThread({ tenantId, workHubId, subjectType, subjectId, }: { tenantId: string; workHubId: string; subjectType: "project" | "task" | "content" | "team"; subjectId: string; }) { const queryClient = useQueryClient(); const [body, setBody] = useState(""); const comments = useQuery({ queryKey: ["workspace", tenantId, "comments", subjectType, subjectId], queryFn: () => workspaceApi.comments.list(tenantId, { work_hub_id: workHubId, subject_type: subjectType, subject_id: subjectId, }), }); const create = useMutation({ mutationFn: () => workspaceApi.comments.create(tenantId, { work_hub_id: workHubId, subject_type: subjectType, subject_id: subjectId, body, }), onSuccess: () => { setBody(""); toast.success("نظر ثبت شد"); void queryClient.invalidateQueries({ queryKey: ["workspace", tenantId, "comments"] }); void queryClient.invalidateQueries({ queryKey: ["workspace", tenantId, "activity"] }); }, onError: (error) => toast.error(error instanceof Error ? error.message : "ثبت نظر ناموفق بود"), }); if (comments.isLoading) return ; if (comments.error) return comments.refetch()} />; return (

گفتگو

{(comments.data ?? []).length === 0 ? (

هنوز نظری ثبت نشده است. برای اشاره به فرد از @نام استفاده کنید.

) : ( (comments.data ?? []).map((item) => (

{displayPerson(String(item.author_user_id || ""))} · {formatWhen(String(item.created_at || ""))}

{String(item.body || "")}

)) )}