'use client';
import { useState, useEffect } from 'react';
import { useRouter } from 'next/navigation';
import Link from 'next/link';
import { ArrowLeft, Loader2, Globe, Lock, UserPlus, Trash2, AlertTriangle, Settings, Save } 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 {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
type Visibility = 'PRIVATE' | 'INVITE' | 'PUBLIC';
const visibilityOptions: { value: Visibility; label: string; description: string; icon: React.ReactNode }[] = [
{
value: 'PRIVATE',
label: 'Private',
description: 'Only you can access this project',
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: ,
},
];
interface ProjectSettingsPageProps {
params: Promise<{ projectId: string }>;
}
export default function ProjectSettingsPage({ params }: ProjectSettingsPageProps) {
const router = useRouter();
const [projectId, setProjectId] = useState('');
const [isLoading, setIsLoading] = useState(true);
const [isSaving, setIsSaving] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [error, setError] = useState('');
const [success, setSuccess] = useState('');
const [deleteConfirmation, setDeleteConfirmation] = useState('');
const [formData, setFormData] = useState({
name: '',
description: '',
visibility: 'PRIVATE' as Visibility,
});
useEffect(() => {
params.then(({ projectId: id }) => {
setProjectId(id);
fetch(`/api/projects/${id}`)
.then((res) => res.json())
.then((data) => {
if (data.error) {
setError(data.error);
} else {
setFormData({
name: data.name || '',
description: data.description || '',
visibility: data.visibility || 'PRIVATE',
});
}
})
.catch(() => setError('Failed to load project'))
.finally(() => setIsLoading(false));
});
}, [params]);
const handleSave = async (e: React.FormEvent) => {
e.preventDefault();
setIsSaving(true);
setError('');
setSuccess('');
try {
const response = await fetch(`/api/projects/${projectId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
const data = await response.json();
if (!response.ok) {
setError(data.error || 'Failed to update project');
return;
}
setSuccess('Project settings saved successfully');
setTimeout(() => setSuccess(''), 3000);
} catch {
setError('Something went wrong. Please try again.');
} finally {
setIsSaving(false);
}
};
const handleDelete = async () => {
if (deleteConfirmation !== formData.name) {
setError('Project name does not match');
return;
}
setIsDeleting(true);
setError('');
try {
const response = await fetch(`/api/projects/${projectId}`, {
method: 'DELETE',
});
if (!response.ok) {
const data = await response.json();
setError(data.error || 'Failed to delete project');
return;
}
router.push('/dashboard');
} catch {
setError('Something went wrong. Please try again.');
} finally {
setIsDeleting(false);
}
};
if (isLoading) {
return (
);
}
return (
Back to Project
{/* General Settings */}
Project Settings
Update your project details and access settings
{/* Danger Zone */}
Danger Zone
Irreversible actions that will permanently affect your project
Delete this project
This action cannot be undone
Delete "{formData.name}"?
This will permanently delete this project and all of its
videos, versions, and comments. This action cannot be undone.