fix(sites): fix site CRUD crashes and silent form errors

- Fix AttributeError in sites router: CurrentUser has `user_id` not `id`
  (create/update/delete all crashed with 500)
- Add onError handlers with toast notifications to SiteFormDialog

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jason Staack
2026-03-19 17:42:58 -05:00
parent 4e917ac819
commit dffea763f6
2 changed files with 14 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { useState } from 'react'
import { useMutation, useQueryClient } from '@tanstack/react-query'
import { sitesApi, type SiteResponse, type SiteCreate, type SiteUpdate } from '@/lib/api'
import { toast } from '@/components/ui/toast'
import {
Dialog,
DialogContent,
@@ -36,6 +37,11 @@ export function SiteFormDialog({ open, onOpenChange, tenantId, site }: SiteFormD
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ['sites', tenantId] })
onOpenChange(false)
toast({ title: 'Site created' })
},
onError: (err: unknown) => {
const e = err as { response?: { data?: { detail?: string } } }
toast({ title: 'Failed to create site', description: e.response?.data?.detail || 'Unknown error', variant: 'destructive' })
},
})
@@ -44,6 +50,11 @@ export function SiteFormDialog({ open, onOpenChange, tenantId, site }: SiteFormD
onSuccess: () => {
void queryClient.invalidateQueries({ queryKey: ['sites', tenantId] })
onOpenChange(false)
toast({ title: 'Site updated' })
},
onError: (err: unknown) => {
const e = err as { response?: { data?: { detail?: string } } }
toast({ title: 'Failed to update site', description: e.response?.data?.detail || 'Unknown error', variant: 'destructive' })
},
})