diff --git a/apps/editor/features/community/components/project-settings-dialog.tsx b/apps/editor/features/community/components/project-settings-dialog.tsx index d8574e01..e5ab9b92 100644 --- a/apps/editor/features/community/components/project-settings-dialog.tsx +++ b/apps/editor/features/community/components/project-settings-dialog.tsx @@ -10,7 +10,7 @@ import { DialogTitle, } from '@/components/ui/primitives/dialog' import { Switch } from '@/components/ui/primitives/switch' -import { updateProjectAddress, updateProjectPrivacy, deleteProject } from '../lib/projects/actions' +import { updateProjectName, updateProjectPrivacy, deleteProject } from '../lib/projects/actions' import type { Project } from '../lib/projects/types' interface ProjectSettingsDialogProps { @@ -30,19 +30,23 @@ export function ProjectSettingsDialog({ }: ProjectSettingsDialogProps) { const [loading, setLoading] = useState(false) const [isDeleting, setIsDeleting] = useState(false) + const [name, setName] = useState(project.name || '') const [isPrivate, setIsPrivate] = useState(project.is_private) - const [address, setAddress] = useState({ - street_number: project.address?.street_number || '', - route: project.address?.route || '', - city: project.address?.city || '', - state: project.address?.state || '', - postal_code: project.address?.postal_code || '', - country: project.address?.country || 'US', - }) const handleSave = async () => { setLoading(true) try { + // Update name if changed + const trimmedName = name.trim() + if (trimmedName && trimmedName !== (project.name || '')) { + const nameResult = await updateProjectName(project.id, trimmedName) + if (!nameResult.success) { + alert(`Failed to update name: ${nameResult.error}`) + setLoading(false) + return + } + } + // Update privacy if changed if (isPrivate !== project.is_private) { const privacyResult = await updateProjectPrivacy(project.id, isPrivate) @@ -53,26 +57,6 @@ export function ProjectSettingsDialog({ } } - // Update address if changed and project has an address - if (project.address) { - const addressChanged = - address.street_number !== (project.address.street_number || '') || - address.route !== (project.address.route || '') || - address.city !== (project.address.city || '') || - address.state !== (project.address.state || '') || - address.postal_code !== (project.address.postal_code || '') || - address.country !== (project.address.country || 'US') - - if (addressChanged) { - const addressResult = await updateProjectAddress(project.id, address) - if (!addressResult.success) { - alert(`Failed to update address: ${addressResult.error}`) - setLoading(false) - return - } - } - } - onUpdate?.() onOpenChange(false) } catch (error) { @@ -108,10 +92,26 @@ export function ProjectSettingsDialog({ Project Settings - Update project address and privacy settings + Update project name and privacy settings
+ {/* Project Name */} +
+ + setName(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" + disabled={loading} + /> +
+ {/* Privacy Toggle */}
@@ -126,83 +126,6 @@ export function ProjectSettingsDialog({
- {/* Address Fields */} -
-

Address

- -
-
- - setAddress({ ...address, street_number: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="123" - /> -
- -
- - setAddress({ ...address, route: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="Main St" - /> -
-
- -
-
- - setAddress({ ...address, city: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="San Francisco" - /> -
- -
- - setAddress({ ...address, state: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="CA" - /> -
-
- -
-
- - setAddress({ ...address, postal_code: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="94102" - /> -
- -
- - setAddress({ ...address, country: e.target.value })} - className="mt-1 w-full rounded-md border border-border bg-background px-3 py-2 text-sm" - placeholder="US" - /> -
-
-
- {/* Danger Zone */}

Danger Zone

diff --git a/apps/editor/features/community/lib/projects/actions.ts b/apps/editor/features/community/lib/projects/actions.ts index 5a62a380..e83fa881 100644 --- a/apps/editor/features/community/lib/projects/actions.ts +++ b/apps/editor/features/community/lib/projects/actions.ts @@ -574,6 +574,71 @@ export async function updateProjectPrivacy( } } +/** + * Update project name + */ +export async function updateProjectName( + projectId: string, + name: string, +): Promise { + try { + const session = await getSession() + + if (!session?.user) { + return { + success: false, + error: 'Not authenticated', + } + } + + if (!name.trim()) { + return { + success: false, + error: 'Project name cannot be empty', + } + } + + const supabase = await createServerSupabaseClient() + + // Verify ownership + const { data: project } = await supabase + .from('projects') + .select('owner_id') + .eq('id', projectId) + .single() + + if ((project as any)?.owner_id !== session.user.id) { + return { + success: false, + error: 'Unauthorized', + } + } + + // Update name + const { error } = await (supabase + .from('projects') as any) + .update({ name: name.trim() }) + .eq('id', projectId) + + if (error) { + return { + success: false, + error: error.message, + } + } + + return { + success: true, + message: 'Project name updated', + } + } catch (error) { + return { + success: false, + error: error instanceof Error ? error.message : 'Failed to update project name', + } + } +} + /** * Update project address */