diff --git a/src/app/(protected)/page.tsx b/src/app/(protected)/page.tsx index 9705b0f..02c1ffb 100644 --- a/src/app/(protected)/page.tsx +++ b/src/app/(protected)/page.tsx @@ -2,12 +2,16 @@ import { useEffect, useState } from "react"; import Link from "next/link"; +import { useRouter } from "next/navigation"; import { getProjects, Project } from "@/lib/api"; import { logout } from "@/lib/auth-client"; +import CreateProjectModal from "@/components/CreateProjectModal"; export default function Home() { const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); + const [showCreate, setShowCreate] = useState(false); + const router = useRouter(); useEffect(() => { getProjects() @@ -19,38 +23,60 @@ export default function Home() { return (
-
+

Team Board

AI Agent Collaboration Platform

{loading ? (

Загрузка...

- ) : projects.length > 0 ? ( -
- {projects.map((p) => ( - -
{p.name}
- {p.description &&
{p.description}
} - - ))} -
) : ( -

Нет проектов. Создайте первый через API.

+ <> + {projects.length > 0 && ( +
+ {projects.map((p) => ( + +
{p.name}
+ {p.description && ( +
{p.description}
+ )} + + ))} +
+ )} + + + )}
+ + {showCreate && ( + setShowCreate(false)} + onCreated={(project) => { + setShowCreate(false); + router.push(`/projects/${project.slug}`); + }} + /> + )}
); } diff --git a/src/components/CreateProjectModal.tsx b/src/components/CreateProjectModal.tsx new file mode 100644 index 0000000..928dc77 --- /dev/null +++ b/src/components/CreateProjectModal.tsx @@ -0,0 +1,99 @@ +"use client"; + +import { useState } from "react"; +import { createProject, Project } from "@/lib/api"; + +interface Props { + onCreated: (project: Project) => void; + onClose: () => void; +} + +export default function CreateProjectModal({ onCreated, onClose }: Props) { + const [name, setName] = useState(""); + const [description, setDescription] = useState(""); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(""); + + const slug = name + .toLowerCase() + .replace(/[^a-zа-яё0-9\s-]/gi, "") + .replace(/\s+/g, "-") + .replace(/-+/g, "-") + .slice(0, 50); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!name.trim() || !slug) return; + setLoading(true); + setError(""); + try { + const project = await createProject({ + name: name.trim(), + slug, + description: description.trim() || null, + }); + onCreated(project); + } catch (err) { + setError("Ошибка создания проекта"); + } finally { + setLoading(false); + } + }; + + return ( +
+
e.stopPropagation()} + onSubmit={handleSubmit} + className="bg-[var(--card)] border border-[var(--border)] rounded-xl p-6 w-96" + > +

Новый проект

+ + {error && ( +
+ {error} +
+ )} + + + setName(e.target.value)} + className="w-full mb-1 px-3 py-2 bg-[var(--bg)] border border-[var(--border)] rounded-lg + outline-none focus:border-[var(--accent)] text-sm" + placeholder="Мой проект" + /> + {slug &&
Slug: {slug}
} + + +