extract MEASURE_NAMES catalogue and MeasureName type

This commit is contained in:
Khalim Conn-Kowlessar 2026-05-05 11:25:45 +00:00
parent b100c15052
commit dc3bfa73d3

View file

@ -4,6 +4,40 @@
* Used to compute per-measure upload completion and guide contractors in the upload modal.
*/
/**
* Canonical list of measure names recognised by the application.
*
* This is the single source of truth: document-requirement lookups, UI dropdowns
* and validation should reference this tuple rather than maintaining their own
* copies. Names match the values produced by the upstream HubSpot pull pipeline.
*/
export const MEASURE_NAMES = [
"ASHP",
"Solar PV",
"DMevs",
"Loft insulation",
"CWI",
"EWI",
"IWI",
"Flat roof",
"RIR",
"UFI",
"HW",
"Windows",
"Ext. doors",
"TRVs",
"Heating controls",
"New boiler",
"HHRSH",
"Battery",
"LEL",
"Listed building",
"Removal 2nd heating",
"Others",
] as const;
export type MeasureName = (typeof MEASURE_NAMES)[number];
// Required for every measure
const BASE_DOCS = [
"pre_photo",
@ -18,7 +52,9 @@ const BASE_DOCS = [
// MCS-accredited measures require MCS certification in addition to base docs
const MCS_EXTRA = ["mcs_compliance_certificate"] as const;
export const MEASURE_DOC_REQUIREMENTS: Record<string, string[]> = {
export { BASE_DOCS };
export const MEASURE_DOC_REQUIREMENTS: Partial<Record<MeasureName, string[]>> = {
ASHP: [...BASE_DOCS, ...MCS_EXTRA, "commissioning_records"],
"Solar PV": [...BASE_DOCS, ...MCS_EXTRA, "g98_notification"],
DMevs: [
@ -41,10 +77,11 @@ export const MEASURE_DOC_REQUIREMENTS: Record<string, string[]> = {
/**
* Returns the required document types for a given measure name.
* Falls back to BASE_DOCS for any measure not explicitly listed.
* Falls back to BASE_DOCS for any measure not explicitly listed (including
* unknown measures from upstream).
*/
export function getRequiredDocs(measureName: string): string[] {
return MEASURE_DOC_REQUIREMENTS[measureName] ?? [...BASE_DOCS];
return MEASURE_DOC_REQUIREMENTS[measureName as MeasureName] ?? [...BASE_DOCS];
}
/**