"use client"; import { useState } from "react"; import Link from "next/link"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { toast } from "sonner"; import { Button, Card, CardContent, Dialog, Input, PageHeader, Textarea } from "@/components/ds"; import { useCurrentHub } from "@/modules/workspace/hooks/useCurrentHub"; import { workspaceApi } from "@/modules/workspace/services/workspace-api"; import { TEAM_STATUS, labelOf } from "@/modules/workspace/labels"; import { WorkspaceEmptyState, WorkspacePageError, WorkspacePageLoader } from "@/modules/workspace/pages/shared"; export const WorkspaceTeams = function WorkspaceTeamsPage() { const queryClient = useQueryClient(); const { tenantId, hubId, loading: hubLoading } = useCurrentHub(); const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const teams = useQuery({ queryKey: ["workspace", tenantId, "teams", hubId], queryFn: () => workspaceApi.teams.list(tenantId!, hubId || undefined), enabled: !!tenantId, }); const create = useMutation({ mutationFn: () => workspaceApi.teams.create(tenantId!, { work_hub_id: hubId, name, description }), onSuccess: () => { toast.success("تیم ایجاد شد"); setOpen(false); setName(""); setDescription(""); void queryClient.invalidateQueries({ queryKey: ["workspace", tenantId, "teams"] }); }, onError: (err) => toast.error(err instanceof Error ? err.message : "ایجاد تیم ناموفق بود"), }); if (!tenantId || hubLoading || teams.isLoading) return ; if (!hubId) { return ; } if (teams.error) return teams.refetch()} />; return ( setOpen(true)}>تیم جدید} /> {(teams.data ?? []).length === 0 ? ( setOpen(true)}>ایجاد تیم} /> ) : ( {(teams.data ?? []).map((team) => ( {String(team.name || "تیم")} {labelOf(TEAM_STATUS, String(team.status || ""))} {String(team.description || "بدون توضیح")} اعضای تیم ))} )} setOpen(false)} title="تیم جدید"> setName(event.target.value)} placeholder="نام تیم" /> setDescription(event.target.value)} placeholder="توضیح" /> create.mutate()}> ایجاد ); }; export default WorkspaceTeams;
{String(team.description || "بدون توضیح")}