feat(new): NewReportRoute wires forms + practitioner cache
This commit is contained in:
1 parent
9271a79067
commit
2b2a7db63c
1 file changed
+63
-1
@@ -1,3 +1,65 @@
|
|||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
import { useNavigate } from 'react-router-dom'
|
||||||
|
import PractitionerForm from '@/components/report/PractitionerForm'
|
||||||
|
import AnimalForm from '@/components/report/AnimalForm'
|
||||||
|
import Brand from '@/components/brand/Brand'
|
||||||
|
import Button from '@/components/ui/Button'
|
||||||
|
import Input from '@/components/ui/Input'
|
||||||
|
import Label from '@/components/ui/Label'
|
||||||
|
import { todayIso } from '@/lib/dates'
|
||||||
|
import { readCachedPractitioner, writeCachedPractitioner } from '@/state/practitionerCache'
|
||||||
|
import { useReportStore } from '@/state/reportStore'
|
||||||
|
|
||||||
export default function NewReportRoute() {
|
export default function NewReportRoute() {
|
||||||
return <div>NewReportRoute placeholder</div>
|
const navigate = useNavigate()
|
||||||
|
const initReport = useReportStore((s) => s.initReport)
|
||||||
|
|
||||||
|
const [practitioner, setPractitioner] = useState({ name: '' })
|
||||||
|
const [animal, setAnimal] = useState({ speciesId: 'equine', name: '' })
|
||||||
|
const [owner, setOwner] = useState({ name: '' })
|
||||||
|
const [date, setDate] = useState(todayIso())
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const cached = readCachedPractitioner()
|
||||||
|
if (cached) setPractitioner(cached)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const canSubmit = practitioner.name.trim() && animal.name.trim() && owner.name.trim()
|
||||||
|
|
||||||
|
function submit() {
|
||||||
|
if (!canSubmit) return
|
||||||
|
writeCachedPractitioner(practitioner)
|
||||||
|
initReport({
|
||||||
|
date,
|
||||||
|
practitioner,
|
||||||
|
animal,
|
||||||
|
owner,
|
||||||
|
observations: [],
|
||||||
|
conclusion: '',
|
||||||
|
recommendations: '',
|
||||||
|
})
|
||||||
|
navigate('/editor')
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<main className="min-h-screen">
|
||||||
|
<header className="px-6 py-4 border-b border-[var(--color-border)] flex items-center justify-between">
|
||||||
|
<Brand />
|
||||||
|
<Button variant="ghost" onClick={() => navigate('/')}>← Accueil</Button>
|
||||||
|
</header>
|
||||||
|
<div className="max-w-3xl mx-auto px-6 py-8 space-y-8">
|
||||||
|
<h1 className="font-serif text-3xl">Nouveau bilan</h1>
|
||||||
|
<div>
|
||||||
|
<Label htmlFor="date">Date du bilan</Label>
|
||||||
|
<Input id="date" type="date" value={date} onChange={(e) => setDate(e.target.value)} />
|
||||||
|
</div>
|
||||||
|
<PractitionerForm value={practitioner} onChange={setPractitioner} />
|
||||||
|
<AnimalForm animal={animal} owner={owner} onChangeAnimal={setAnimal} onChangeOwner={setOwner} />
|
||||||
|
<div className="flex gap-3 justify-end">
|
||||||
|
<Button variant="ghost" onClick={() => navigate('/')}>Annuler</Button>
|
||||||
|
<Button disabled={!canSubmit} onClick={submit}>Démarrer le bilan</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user