feat(store): add practitioner/animal/owner setters
Enables in-place edit of report identity blocks from the editor. Mirrors existing setConclusion/setRecommendations pattern; no-op when no report is loaded. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
15a3ef2890
commit
1280f9feb8
2 files changed
+70
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { create } from 'zustand'
|
||||
import { ReportSchema, type Report } from '@/domain/schema/report'
|
||||
import type { Observation } from '@/domain/schema/observation'
|
||||
import type { Practitioner } from '@/domain/schema/practitioner'
|
||||
import type { Animal, Owner } from '@/domain/schema/animal'
|
||||
import { generateId } from '@/lib/id'
|
||||
import { nowIso } from '@/lib/dates'
|
||||
|
||||
@@ -15,6 +17,9 @@ export interface ReportStore {
|
||||
moveObservationDown: (index: number) => void
|
||||
updateObservation: (index: number, obs: Observation) => void
|
||||
setActiveObservation: (index: number) => void
|
||||
setPractitioner: (next: Practitioner) => void
|
||||
setAnimal: (next: Animal) => void
|
||||
setOwner: (next: Owner) => void
|
||||
setConclusion: (text: string) => void
|
||||
setRecommendations: (text: string) => void
|
||||
setNextAppointment: (next: Report['nextAppointment']) => void
|
||||
@@ -110,6 +115,15 @@ export const useReportStore = create<ReportStore>((set) => ({
|
||||
|
||||
setActiveObservation: (index) => set({ activeObservationIndex: index }),
|
||||
|
||||
setPractitioner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, practitioner: next } } : s)),
|
||||
|
||||
setAnimal: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, animal: next } } : s)),
|
||||
|
||||
setOwner: (next) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, owner: next } } : s)),
|
||||
|
||||
setConclusion: (text) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, conclusion: text } } : s)),
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { useReportStore } from '@/state/reportStore'
|
||||
|
||||
const draft = {
|
||||
date: '2026-05-18',
|
||||
practitioner: { name: 'Dr. Dupont' },
|
||||
animal: { speciesId: 'equine', name: 'Mistral' },
|
||||
owner: { name: 'Jean Martin' },
|
||||
observations: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useReportStore.getState().reset()
|
||||
})
|
||||
|
||||
describe('reportStore identity setters', () => {
|
||||
it('setPractitioner replaces the practitioner block', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
useReportStore.getState().setPractitioner({
|
||||
name: 'Dr. Curie',
|
||||
cabinet: 'Clinique du Pré',
|
||||
contact: 'contact@example.test',
|
||||
})
|
||||
const p = useReportStore.getState().report!.practitioner
|
||||
expect(p.name).toBe('Dr. Curie')
|
||||
expect(p.cabinet).toBe('Clinique du Pré')
|
||||
expect(p.contact).toBe('contact@example.test')
|
||||
})
|
||||
|
||||
it('setAnimal replaces the animal block', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
useReportStore.getState().setAnimal({
|
||||
speciesId: 'equine',
|
||||
name: 'Tempête',
|
||||
breed: 'Pur-sang',
|
||||
})
|
||||
const a = useReportStore.getState().report!.animal
|
||||
expect(a.name).toBe('Tempête')
|
||||
expect(a.breed).toBe('Pur-sang')
|
||||
})
|
||||
|
||||
it('setOwner replaces the owner block', () => {
|
||||
useReportStore.getState().initReport(draft)
|
||||
useReportStore.getState().setOwner({ name: 'Marie Petit' })
|
||||
expect(useReportStore.getState().report!.owner.name).toBe('Marie Petit')
|
||||
})
|
||||
|
||||
it('setters are no-ops when no report is loaded', () => {
|
||||
useReportStore.getState().setPractitioner({ name: 'Ghost' })
|
||||
useReportStore.getState().setAnimal({ speciesId: 'equine', name: 'Ghost' })
|
||||
useReportStore.getState().setOwner({ name: 'Ghost' })
|
||||
expect(useReportStore.getState().report).toBeNull()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user