"use client"; // ============================================================================ // Create Creative Page // ============================================================================ import { useState } from "react"; import { useParams, useRouter } from "next/navigation"; import { Loader2, ArrowLeft, Info } from "lucide-react"; import { DashboardHeader } from "@/components/layout/dashboard-header"; import { useWorkspace } from "@/components/providers/workspace-provider"; import { creativesApi } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; // ============================================================================ // Component // ============================================================================ export default function NewCreativePage() { const params = useParams(); const router = useRouter(); const workspaceId = params?.workspaceId as string; const { currentProject } = useWorkspace(); const [name, setName] = useState(""); const [text, setText] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!name.trim() || !text.trim()) { setError("Заполните все обязательные поля"); return; } if (!text.includes("{invite_link}")) { setError("Текст должен содержать {invite_link} для вставки ссылки"); return; } if (!currentProject) { setError("Выберите проект в верхнем меню"); return; } try { setIsSubmitting(true); setError(null); const creative = await creativesApi.create( workspaceId, currentProject.id, { name: name.trim(), text: text.trim(), } ); router.push(`/dashboard/${workspaceId}/creatives/${creative.id}`); } catch (err: any) { setError(err?.detail || "Не удалось создать креатив"); } finally { setIsSubmitting(false); } }; const insertInviteLink = () => { if (!text.includes("{invite_link}")) { setText((prev) => prev + "{invite_link}"); } }; return ( <>

Новый креатив

Создайте рекламный материал для размещений

{!currentProject && ( Выберите проект в верхнем меню для создания креатива )}
Информация о креативе Креатив — это текст рекламного сообщения с пригласительной ссылкой
setName(e.target.value)} disabled={isSubmitting} />

Внутреннее название для удобства поиска