| import { createContext, useContext } from "react"; | |
| import type { FieldSpec } from "./types"; | |
| // The checklist definition is fetched from GET /api/fields, which serves | |
| // endopath.fields.FIELDS (issue #37). This file used to be a hand-mirrored copy | |
| // of the nine field names and their labels, one of five places the list was | |
| // written out; a rename cost five edits and nothing asserted they agreed. | |
| // | |
| // The context and hook live here; ChecklistFieldsProvider.tsx holds the | |
| // component that fills them. Kept apart so neither file exports both a | |
| // component and a non-component (react-refresh/only-export-components). | |
| export interface ChecklistFields { | |
| fields: FieldSpec[]; | |
| /** Field names in render order. Case Review lays out its cards in this order. */ | |
| names: string[]; | |
| labels: Record<string, string>; | |
| loading: boolean; | |
| error: string | null; | |
| } | |
| export const EMPTY_CHECKLIST_FIELDS: ChecklistFields = { | |
| fields: [], | |
| names: [], | |
| labels: {}, | |
| loading: true, | |
| error: null, | |
| }; | |
| export const ChecklistFieldsContext = createContext<ChecklistFields>(EMPTY_CHECKLIST_FIELDS); | |
| export function useChecklistFields(): ChecklistFields { | |
| return useContext(ChecklistFieldsContext); | |
| } | |