All files / src/components/crm lead-vocabulary.ts

100% Statements 12/12
100% Branches 8/8
100% Functions 4/4
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68                                            17x                     17x                                 578x 560x         6x 4x         221x     17x 17x  
/**
 * The words the Leads screens print for a lead's scope and budget — once.
 *
 * These two maps existed in three places with three spellings: the long form
 * in `LeadOverview.tsx` ("Modular Kitchen"), a hand-abbreviated form in
 * `LeadCard.tsx` ("Kitchen", "Kitchen Reno"), and a third copy in
 * `add-lead-modal.config.ts` that the Add-lead form's `<Select>` reads. A pro
 * who created a lead as "Kitchen Renovation" then saw "Kitchen Reno" on the
 * board and "Kitchen Renovation" on the detail page was reading three
 * vocabularies for one field.
 *
 * The Job Book prints ONE label per code. Rows are dense enough to carry the
 * real word, and the mockup's lead cards print the full thing ("Modular
 * kitchen", "3BHK full home interior"), so the long form wins and the
 * abbreviations are gone.
 *
 * NO NEW VOCABULARY: the codes are the API's (`lead.projectType`,
 * `lead.budgetRange`) and the budget labels keep the ₹-and-lakhs spelling
 * already shipped. This file only stops there being three of them.
 */
 
/** `lead.projectType` code → the one label for it. */
export const PROJECT_TYPE_LABELS: Record<string, string> = {
	modular_kitchen: "Modular kitchen",
	full_interior: "Full home interior",
	wardrobe: "Wardrobe",
	tv_unit: "TV unit",
	pooja_unit: "Pooja unit",
	kitchen_renovation: "Kitchen renovation",
	other: "Other",
};
 
/** `lead.budgetRange` code → the one label for it. */
export const BUDGET_RANGE_LABELS: Record<string, string> = {
	under_1l: "Under ₹1 lakh",
	"1_3l": "₹1–3 lakhs",
	"3_5l": "₹3–5 lakhs",
	"5_10l": "₹5–10 lakhs",
	"10_20l": "₹10–20 lakhs",
	above_20l: "Above ₹20 lakhs",
};
 
/**
 * A lead's scope as one printed phrase, or null when it has none.
 *
 * Falls back to the raw code rather than hiding the field: an unmapped code
 * means the API grew a project type this build does not know, and showing it
 * is more useful than showing nothing.
 */
export function scopeLabel(projectType: string | null | undefined): string | null {
	if (!projectType) return null;
	return PROJECT_TYPE_LABELS[projectType] ?? projectType;
}
 
/** A lead's budget band as one printed phrase, or null when it has none. */
export function budgetLabel(budgetRange: string | null | undefined): string | null {
	if (!budgetRange) return null;
	return BUDGET_RANGE_LABELS[budgetRange] ?? budgetRange;
}
 
/** `{ value, label }` option lists for a `<Select>`, derived from the maps. */
function toOptions(labels: Record<string, string>) {
	return Object.entries(labels).map(([value, label]) => ({ value, label }));
}
 
export const PROJECT_TYPE_OPTIONS = toOptions(PROJECT_TYPE_LABELS);
export const BUDGET_RANGE_OPTIONS = toOptions(BUDGET_RANGE_LABELS);