"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, Select, Textarea } from "@/components/ds"; import { useCurrentHub } from "@/modules/workspace/hooks/useCurrentHub"; import { workspaceApi } from "@/modules/workspace/services/workspace-api"; import { PRIORITY, labelOf } from "@/modules/workspace/labels"; import { StatusChip } from "@/modules/workspace/components/StatusChip"; import { WorkspaceEmptyState, WorkspacePageError, WorkspacePageLoader } from "@/modules/workspace/pages/shared"; export const WorkspaceProjects = function WorkspaceProjectsPage() { const queryClient = useQueryClient(); const { tenantId, hubId, loading } = useCurrentHub(); const [open, setOpen] = useState(false); const [name, setName] = useState(""); const [description, setDescription] = useState(""); const [teamId, setTeamId] = useState(""); const [priority, setPriority] = useState("medium"); const projects = useQuery({ queryKey: ["workspace", tenantId, "projects", hubId], queryFn: () => workspaceApi.projects.list(tenantId!, { work_hub_id: hubId || undefined }), enabled: !!tenantId, }); const teams = useQuery({ queryKey: ["workspace", tenantId, "teams", hubId], queryFn: () => workspaceApi.teams.list(tenantId!, hubId || undefined), enabled: !!tenantId && !!hubId, }); const create = useMutation({ mutationFn: () => workspaceApi.projects.create(tenantId!, { work_hub_id: hubId, team_id: teamId || undefined, name, description, priority, status: "planning", }), onSuccess: () => { toast.success("پروژه ایجاد شد"); setOpen(false); setName(""); setDescription(""); void queryClient.invalidateQueries({ queryKey: ["workspace", tenantId, "projects"] }); }, onError: (err) => toast.error(err instanceof Error ? err.message : "ایجاد پروژه ناموفق بود"), }); if (!tenantId || loading || projects.isLoading) return ; if (!hubId) return ; if (projects.error) return projects.refetch()} />; return (
setOpen(true)}>پروژه جدید} /> {(projects.data ?? []).length === 0 ? ( setOpen(true)}>ایجاد پروژه} /> ) : (
{(projects.data ?? []).map((project) => (

{String(project.name || "پروژه")}

{String(project.description || "بدون توضیح")}

اولویت: {labelOf(PRIORITY, String(project.priority || ""))}

))}
)} setOpen(false)} title="پروژه جدید">
setName(event.target.value)} placeholder="نام پروژه" />