All files / src/lib homeowner-inquiries.ts

100% Statements 13/13
100% Branches 10/10
100% Functions 4/4
100% Lines 11/11

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          1x                         12x 9x   3x           3x 3x 1x                     3x 3x 1x                       6x        
// Shared helpers for the homeowner inquiry pages (list + detail). Extracted so
// the label map, project-type fallback, IST date formatters, and status-chip
// class live in one place instead of being copy-pasted between
// account/inquiries/index.astro and account/inquiries/[id].astro.
 
export const REQUIREMENT_LABELS: Record<string, string> = {
	full_home: "Full Home",
	living_room: "Living Room",
	bedroom: "Bedroom",
	kitchen: "Kitchen",
	bathroom: "Bathroom",
	office: "Office",
	other: "Interior Project",
};
 
// Human label for an inquiry's requirement type, with a safe fallback for
// unknown/absent codes.
export function projectTypeLabel(requirementType: string | null): string {
	if (requirementType && REQUIREMENT_LABELS[requirementType]) {
		return REQUIREMENT_LABELS[requirementType];
	}
	return "Interior Project";
}
 
// IST date (day + month + year) for list cards. IST per spec
// (communication_history_log): timestamps rendered in IST.
export function formatInquiryDate(iso: string): string {
	const d = new Date(iso);
	if (Number.isNaN(d.getTime())) return "";
	return d.toLocaleDateString("en-IN", {
		day: "numeric",
		month: "short",
		year: "numeric",
		timeZone: "Asia/Kolkata",
	});
}
 
// IST date + time for the activity timeline. IST per spec
// (communication_history_log): "timestamp (date + time, IST)".
export function formatInquiryDateTime(iso: string): string {
	const d = new Date(iso);
	if (Number.isNaN(d.getTime())) return "";
	return d.toLocaleString("en-IN", {
		day: "numeric",
		month: "short",
		hour: "numeric",
		minute: "2-digit",
		timeZone: "Asia/Kolkata",
	});
}
 
// Status chip colours. Amber (warning) for on_hold per spec; everything else
// uses the neutral primary chip. Tokenized so dark mode resolves correctly.
export function statusChipClass(status: string): string {
	return status === "on_hold"
		? "bg-warning-light text-warning"
		: "bg-primary-50 text-primary-700";
}