'use client'; import { useState, useEffect } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import Link from 'next/link'; import { ArrowLeft, Loader2, Globe, Lock, UserPlus, FolderPlus, Building2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Textarea } from '@/components/ui/textarea'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; type Visibility = 'PRIVATE' | 'INVITE' | 'PUBLIC'; interface Workspace { id: string; name: string; } const visibilityOptions: { value: Visibility; label: string; description: string; icon: React.ReactNode; }[] = [ { value: 'PRIVATE', label: 'Private', description: 'Only workspace members and project members can access', icon: , }, { value: 'INVITE', label: 'Invite Only', description: 'Share with specific people via email', icon: , }, { value: 'PUBLIC', label: 'Public', description: 'Anyone with the link can view', icon: , }, ]; export default function NewProjectPage() { const router = useRouter(); const searchParams = useSearchParams(); const preselectedWorkspace = searchParams.get('workspace'); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const [workspaces, setWorkspaces] = useState([]); const [isLoadingWorkspaces, setIsLoadingWorkspaces] = useState(true); const [formData, setFormData] = useState({ name: '', description: '', visibility: 'PRIVATE' as Visibility, workspaceId: preselectedWorkspace || '', }); useEffect(() => { async function fetchWorkspaces() { try { const res = await fetch('/api/workspaces'); if (res.ok) { const data = await res.json(); const workspacesData = data.data.workspaces || []; setWorkspaces(workspacesData); // Auto-select if only one workspace and none preselected if (!preselectedWorkspace && workspacesData.length === 1) { setFormData((prev) => ({ ...prev, workspaceId: workspacesData[0].id })); } } } catch { // ignore } finally { setIsLoadingWorkspaces(false); } } fetchWorkspaces(); }, [preselectedWorkspace]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!formData.workspaceId) { setError('Please select a workspace'); return; } setIsLoading(true); setError(''); try { const response = await fetch('/api/projects', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData), }); const data = await response.json(); if (!response.ok) { setError(data.error || 'Failed to create project'); return; } router.push(`/projects/${data.data.id}`); } catch { setError('Something went wrong. Please try again.'); } finally { setIsLoading(false); } }; return (
Back to Projects
Create New Project Set up a new project to organize your videos and collect feedback
{/* Workspace selector */}
{isLoadingWorkspaces ? (
Loading workspaces...
) : workspaces.length === 0 ? (

You need a workspace first. Every project belongs to a workspace.

) : ( )}
setFormData((prev) => ({ ...prev, name: e.target.value }))} required disabled={isLoading} className="h-11" />