clean all
This commit is contained in:
1 parent
f57d6ec3d3
commit
27afb719f5
101 files changed
+45
-14426
No files matched your search
@@ -1,119 +0,0 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist, createJSONStorage } from 'zustand/middleware';
|
||||
|
||||
import { newId } from '../lib/id';
|
||||
import type { Finding } from '../schema/finding';
|
||||
import type { Report } from '../schema/report';
|
||||
import { SCHEMA_VERSION } from '../schema/report';
|
||||
|
||||
interface ReportState {
|
||||
report: Report | null;
|
||||
selection: string[];
|
||||
|
||||
hydrate: (r: Report) => void;
|
||||
reset: () => void;
|
||||
|
||||
toggleZone: (zoneId: string) => void;
|
||||
clearSelection: () => void;
|
||||
setSelection: (zones: string[]) => void;
|
||||
|
||||
addFinding: (input: Omit<Finding, 'id'>) => Finding;
|
||||
updateFinding: (id: string, patch: Partial<Finding>) => void;
|
||||
removeFinding: (id: string) => void;
|
||||
|
||||
setConclusion: (text: string) => void;
|
||||
setRecommendations: (text: string) => void;
|
||||
setNextAppointment: (date: string | undefined) => void;
|
||||
}
|
||||
|
||||
function emptyReport(overrides: Partial<Report> = {}): Report {
|
||||
return {
|
||||
version: SCHEMA_VERSION,
|
||||
id: newId('report'),
|
||||
createdAt: new Date().toISOString(),
|
||||
species: 'equine',
|
||||
practitioner: { fullName: '' },
|
||||
animal: { name: '', owner: '' },
|
||||
sessionDate: new Date().toISOString().slice(0, 10),
|
||||
findings: [],
|
||||
conclusion: '',
|
||||
recommendations: '',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export const useReportStore = create<ReportState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
report: null,
|
||||
selection: [],
|
||||
|
||||
hydrate: (r) => set({ report: r, selection: [] }),
|
||||
reset: () => set({ report: null, selection: [] }),
|
||||
|
||||
toggleZone: (zoneId) =>
|
||||
set((s) => {
|
||||
const has = s.selection.includes(zoneId);
|
||||
return {
|
||||
selection: has ? s.selection.filter((z) => z !== zoneId) : [...s.selection, zoneId],
|
||||
};
|
||||
}),
|
||||
clearSelection: () => set({ selection: [] }),
|
||||
setSelection: (zones) => set({ selection: zones }),
|
||||
|
||||
addFinding: (input) => {
|
||||
const finding: Finding = { ...input, id: newId('finding') };
|
||||
const r = get().report;
|
||||
if (!r) return finding;
|
||||
set({
|
||||
report: { ...r, findings: [...r.findings, finding] },
|
||||
selection: [],
|
||||
});
|
||||
return finding;
|
||||
},
|
||||
|
||||
updateFinding: (id, patch) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
return {
|
||||
report: {
|
||||
...s.report,
|
||||
findings: s.report.findings.map((f) => (f.id === id ? { ...f, ...patch } : f)),
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
removeFinding: (id) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
return {
|
||||
report: {
|
||||
...s.report,
|
||||
findings: s.report.findings.filter((f) => f.id !== id),
|
||||
},
|
||||
};
|
||||
}),
|
||||
|
||||
setConclusion: (text) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, conclusion: text } } : s)),
|
||||
setRecommendations: (text) =>
|
||||
set((s) => (s.report ? { report: { ...s.report, recommendations: text } } : s)),
|
||||
setNextAppointment: (date) =>
|
||||
set((s) => {
|
||||
if (!s.report) return s;
|
||||
const next: Report =
|
||||
date === undefined
|
||||
? { ...s.report, nextAppointment: undefined }
|
||||
: { ...s.report, nextAppointment: date };
|
||||
return { report: next };
|
||||
}),
|
||||
}),
|
||||
{
|
||||
name: 'osteo-report-draft',
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
partialize: (s) => ({ report: s.report }),
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
export { emptyReport };
|
||||
Reference in new issue
Block a user