feat: some fixes
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
// Create Creative Page
|
||||
// ============================================================================
|
||||
|
||||
import { useState } from "react";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useParams, useRouter, useSearchParams } from "next/navigation";
|
||||
import { Loader2, ArrowLeft, Info } from "lucide-react";
|
||||
import { DashboardHeader } from "@/components/layout/dashboard-header";
|
||||
import { useWorkspace } from "@/components/providers/workspace-provider";
|
||||
@@ -30,14 +30,27 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
export default function NewCreativePage() {
|
||||
const params = useParams();
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const workspaceId = params?.workspaceId as string;
|
||||
const { currentProject } = useWorkspace();
|
||||
const { currentProject, setSelectedProjects, projects } = useWorkspace();
|
||||
|
||||
const prefilledProjectId = searchParams.get("project_id");
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [text, setText] = useState("");
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
// Auto-select project if prefilled from URL
|
||||
useEffect(() => {
|
||||
if (prefilledProjectId && projects.length > 0) {
|
||||
const project = projects.find(p => p.id === prefilledProjectId);
|
||||
if (project) {
|
||||
setSelectedProjects([project]);
|
||||
}
|
||||
}
|
||||
}, [prefilledProjectId, projects, setSelectedProjects]);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
@@ -69,7 +82,8 @@ export default function NewCreativePage() {
|
||||
}
|
||||
);
|
||||
|
||||
router.push(`/dashboard/${workspaceId}/creatives/${creative.id}`);
|
||||
// Redirect to creatives list with project filter
|
||||
router.push(`/dashboard/${workspaceId}/creatives?project_id=${currentProject.id}`);
|
||||
} catch (err: any) {
|
||||
setError(err?.detail || "Не удалось создать креатив");
|
||||
} finally {
|
||||
@@ -239,4 +253,3 @@ export default function NewCreativePage() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user