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:
@@ -83,7 +83,7 @@ async def create_site(
|
||||
"""Create a new site. Requires operator role or above."""
|
||||
await _check_tenant_access(current_user, tenant_id, db)
|
||||
return await site_service.create_site(
|
||||
db=db, tenant_id=tenant_id, data=data, user_id=current_user.id
|
||||
db=db, tenant_id=tenant_id, data=data, user_id=current_user.user_id
|
||||
)
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ async def update_site(
|
||||
"""Update a site. Requires operator role or above."""
|
||||
await _check_tenant_access(current_user, tenant_id, db)
|
||||
return await site_service.update_site(
|
||||
db=db, tenant_id=tenant_id, site_id=site_id, data=data, user_id=current_user.id
|
||||
db=db, tenant_id=tenant_id, site_id=site_id, data=data, user_id=current_user.user_id
|
||||
)
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ async def delete_site(
|
||||
"""Delete a site. Requires tenant_admin or above."""
|
||||
await _check_tenant_access(current_user, tenant_id, db)
|
||||
await site_service.delete_site(
|
||||
db=db, tenant_id=tenant_id, site_id=site_id, user_id=current_user.id
|
||||
db=db, tenant_id=tenant_id, site_id=site_id, user_id=current_user.user_id
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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' })
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user