AdminSettings: show error message when location fetch fails
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
f902e87e25
commit
28e470433a
1 changed files with 13 additions and 1 deletions
|
|
@ -110,6 +110,7 @@ function IntegrationCard({ integration, onSaved }: { integration: Integration; o
|
|||
const [enabled, setEnabled] = useState(integration.enabled)
|
||||
const [wfLocations, setWfLocations] = useState<{ id: string; name: string; short_name: string | null }[]>([])
|
||||
const [fetchingLocs, setFetchingLocs] = useState(false)
|
||||
const [locError, setLocError] = useState<string | null>(null)
|
||||
|
||||
function openForm() {
|
||||
const initial: Record<string, string> = {}
|
||||
|
|
@ -212,9 +213,17 @@ function IntegrationCard({ integration, onSaved }: { integration: Integration; o
|
|||
<button
|
||||
onClick={async () => {
|
||||
setFetchingLocs(true)
|
||||
setLocError(null)
|
||||
try {
|
||||
const res = await fetch('/settings/api/integrations/workforce/locations', { credentials: 'include' })
|
||||
if (res.ok) setWfLocations(await res.json())
|
||||
if (res.ok) {
|
||||
setWfLocations(await res.json())
|
||||
} else {
|
||||
const data = await res.json().catch(() => ({}))
|
||||
setLocError(data.error || `Error ${res.status}`)
|
||||
}
|
||||
} catch {
|
||||
setLocError('Network error')
|
||||
} finally { setFetchingLocs(false) }
|
||||
}}
|
||||
disabled={fetchingLocs}
|
||||
|
|
@ -229,6 +238,9 @@ function IntegrationCard({ integration, onSaved }: { integration: Integration; o
|
|||
{fetchingLocs ? 'Fetching…' : 'Fetch locations'}
|
||||
</button>
|
||||
</div>
|
||||
{locError && (
|
||||
<div style={{ fontSize: '0.78rem', color: '#dc2626', marginTop: '0.35rem' }}>{locError}</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue