'use client' import { useState } from 'react' import { createClient } from '@/lib/supabase/client' import { toast } from 'sonner' import type { TablesInsert } from '@/types/database' import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog' import type { Secret } from '../types' // ─── Add Secret Modal ────────────────────────────────────────────────────────── export function AddSecretModal({ onClose, onSaved, spaceId, }: { onClose: () => void onSaved: (s: Secret) => void spaceId: string }) { const [title, setTitle] = useState('') const [area, setArea] = useState('') const [value, setValue] = useState('') const [saving, setSaving] = useState(false) async function handleSave(e: React.FormEvent) { e.preventDefault() if (!title.trim() || !value.trim()) return setSaving(true) const supabase = createClient() const { data, error } = await supabase.from('secrets').insert({ space_id: spaceId, title: title.trim(), label: title.trim(), area: area.trim() || null, value: value.trim(), // `satisfies` keeps the payload type-checked; the trailing `as never` // only bridges the typed browser client whose .insert() generic collapses // to `never`. // TODO(types): remove after regenerating types/database.ts (missing FK relationship metadata) } satisfies TablesInsert<'secrets'> as never).select('id, title, area, created_at').single() setSaving(false) if (error) { toast.error(error.message); return } toast.success('Secret saved') onSaved(data as Secret) onClose() } return ( { if (!o) onClose() }}> Add Secret / Credential
setTitle(e.target.value)} className="w-full bg-background border border-border rounded px-3 py-2 font-sans text-sm text-foreground focus:outline-none focus:border-primary transition" placeholder="e.g. WiFi Password" required />
setArea(e.target.value)} className="w-full bg-background border border-border rounded px-3 py-2 font-sans text-sm text-foreground focus:outline-none focus:border-primary transition" placeholder="e.g. Network" />