POLISH-1: gridify emits canonical '='; localize litter InvalidParentGender 400 (ApiError body) + de strings
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useMemo, useState, type FormEvent } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import { de } from '../strings/de'
|
||||
import { errorCode } from '../api/client'
|
||||
import { createLitter, getLitter, updateLitter } from '../api/litters'
|
||||
import { listGerbils } from '../api/gerbils'
|
||||
import type { CreateLitter } from '../api/types'
|
||||
@@ -49,6 +50,7 @@ export default function WurfFormPage() {
|
||||
|
||||
const [form, setForm] = useState<FormState>(EMPTY)
|
||||
const [errors, setErrors] = useState<Partial<Record<keyof FormState, string>>>({})
|
||||
const [submitError, setSubmitError] = useState<string | null>(null)
|
||||
const [goHomeTouched, setGoHomeTouched] = useState(false)
|
||||
const [initializedFor, setInitializedFor] = useState<string | null>(null)
|
||||
|
||||
@@ -116,9 +118,18 @@ export default function WurfFormPage() {
|
||||
expectedGoHomeDate: nn(form.expectedGoHomeDate),
|
||||
notes: nn(form.notes),
|
||||
}
|
||||
setSubmitError(null)
|
||||
const result = await mutation.run(body)
|
||||
if (result.ok) navigate(`/wuerfe/${result.value.id}`)
|
||||
// On failure mutation.error drives the inline alert; run() never throws.
|
||||
if (result.ok) {
|
||||
navigate(`/wuerfe/${result.value.id}`)
|
||||
return
|
||||
}
|
||||
// Localize the backend's parent-gender 400 by its code; else generic message.
|
||||
setSubmitError(
|
||||
errorCode(result.cause) === 'InvalidParentGender'
|
||||
? t.validation.invalidParentGender
|
||||
: result.error,
|
||||
)
|
||||
}
|
||||
|
||||
if (isEdit && existing.loading) return <p className="muted">{de.common.loading}</p>
|
||||
@@ -223,7 +234,7 @@ export default function WurfFormPage() {
|
||||
<textarea value={form.notes} onChange={(e) => set('notes', e.target.value)} />
|
||||
</label>
|
||||
|
||||
{mutation.error && <div className="alert alert--error">{mutation.error}</div>}
|
||||
{submitError && <div className="alert alert--error">{submitError}</div>}
|
||||
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn--primary" disabled={mutation.pending}>
|
||||
|
||||
Reference in New Issue
Block a user