"use client"; import Link from "next/link"; import * as React from "react"; import type { Project } from "@agy/contracts"; import { Button, Card, CardHint, CardTitle, EmptyState, ErrorState, Field, LoadingState, } from "@agy/ui"; import { ApiError, api } from "@/lib/api"; import { useSession } from "@/lib/session"; export default function ProjectsPage() { const { activeOrganization } = useSession(); const [projects, setProjects] = React.useState([]); const [loading, setLoading] = React.useState(true); const [error, setError] = React.useState(null); const [name, setName] = React.useState(""); const [description, setDescription] = React.useState(""); const [creating, setCreating] = React.useState(false); const [formError, setFormError] = React.useState(null); const load = React.useCallback(async () => { if (!activeOrganization) { setLoading(false); return; } setLoading(true); setError(null); try { setProjects(await api.listProjects(activeOrganization.id)); } catch (err) { setError(err instanceof ApiError ? err.message : "دریافت پروژه‌ها ناموفق بود."); } finally { setLoading(false); } }, [activeOrganization]); React.useEffect(() => { void load(); }, [load]); const onCreate = async (event: React.FormEvent) => { event.preventDefault(); if (!activeOrganization) return; setFormError(null); setCreating(true); try { const created = await api.createProject(activeOrganization.id, { name: name.trim(), description: description.trim(), }); setProjects((current) => [created, ...current]); setName(""); setDescription(""); } catch (err) { setFormError(err instanceof ApiError ? err.message : "ساخت پروژه ناموفق بود."); } finally { setCreating(false); } }; if (!activeOrganization) { return ( ); } return (

پروژه‌ها

هر پروژه می‌تواند یک مخزن خصوصی، یک محیط اجرای ایزوله و یک دامنهٔ تست داشته باشد.

ساخت پروژه نام پروژه به یک slug یکتا در سازمان تبدیل می‌شود.
setName(e.target.value)} placeholder="مثلاً فروشگاه آنلاین" />
setDescription(e.target.value)} />
{formError && (
)}
{loading ? ( ) : error ? ( ) : projects.length === 0 ? ( ) : (
{projects.map((project) => (

{project.name}

{project.slug}

{project.description && (

{project.description}

)}
))}
)}
); }