'use client' import { useRef, useState } from 'react' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/primitives/dialog' import { Switch } from '@/components/ui/primitives/switch' import { updateProjectName, updateProjectVisibility, deleteProject } from '../lib/projects/actions' import type { Project } from '../lib/projects/types' interface ProjectSettingsDialogProps { project: Project open: boolean onOpenChange: (open: boolean) => void onUpdate?: () => void onDelete?: () => void } export function ProjectSettingsDialog({ project, open, onOpenChange, onUpdate, onDelete, }: ProjectSettingsDialogProps) { const [isDeleting, setIsDeleting] = useState(false) const [name, setName] = useState(project.name || '') const [isPrivate, setIsPrivate] = useState(project.is_private) const [showScansPublic, setShowScansPublic] = useState(project.show_scans_public ?? true) const [showGuidesPublic, setShowGuidesPublic] = useState(project.show_guides_public ?? true) const nameTimerRef = useRef>(null) const handleNameChange = (value: string) => { setName(value) if (nameTimerRef.current) clearTimeout(nameTimerRef.current) nameTimerRef.current = setTimeout(async () => { const trimmed = value.trim() if (trimmed && trimmed !== (project.name || '')) { await updateProjectName(project.id, trimmed) onUpdate?.() } }, 500) } const handleVisibilityChange = async ( field: 'isPrivate' | 'showScansPublic' | 'showGuidesPublic', value: boolean, ) => { if (field === 'isPrivate') setIsPrivate(value) if (field === 'showScansPublic') setShowScansPublic(value) if (field === 'showGuidesPublic') setShowGuidesPublic(value) await updateProjectVisibility(project.id, { [field]: value }) onUpdate?.() } const handleDelete = async () => { if (!confirm('Are you sure you want to delete this project? This action cannot be undone.')) { return } setIsDeleting(true) try { const result = await deleteProject(project.id) if (result.success) { onDelete?.() onOpenChange(false) } else { alert(`Failed to delete project: ${result.error}`) } } catch (error) { alert('Failed to delete project') } finally { setIsDeleting(false) } } return ( Project Settings Changes are saved automatically
{/* Project Name */}
handleNameChange(e.target.value)} placeholder="My Project" className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary" />
{/* Privacy Toggle */}
Privacy
{isPrivate ? 'Only you can view this project' : 'Anyone can view this project'}
Public handleVisibilityChange('isPrivate', !checked)} />
{/* Public Visibility Toggles */}
Show 3D Scans
Visible to public viewers
handleVisibilityChange('showScansPublic', checked)} />
Show Floorplans
Visible to public viewers
handleVisibilityChange('showGuidesPublic', checked)} />
{/* Danger Zone */}

Danger Zone

Once you delete a project, there is no going back. Please be certain.

) }