mirror of
https://github.com/Hestia-Homes/assessment-model.git
synced 2026-06-08 11:37:25 +00:00
commit
ff482bfbaa
1 changed files with 26 additions and 10 deletions
|
|
@ -237,7 +237,11 @@ function CriterionContent({
|
|||
function ReplacementsContent({
|
||||
items,
|
||||
}: {
|
||||
items: { sub_variable: string; expiry_date: string | null }[];
|
||||
items: {
|
||||
sub_variable: string;
|
||||
expiry_date: string | null;
|
||||
install_date: string | null;
|
||||
}[];
|
||||
}) {
|
||||
const today = new Date();
|
||||
const groups: Record<
|
||||
|
|
@ -245,6 +249,7 @@ function ReplacementsContent({
|
|||
{
|
||||
sub_variable: string;
|
||||
expiry: Date;
|
||||
install: Date;
|
||||
remaining: string;
|
||||
overdue: boolean;
|
||||
}[]
|
||||
|
|
@ -256,8 +261,9 @@ function ReplacementsContent({
|
|||
};
|
||||
|
||||
items.forEach((item) => {
|
||||
if (!item.expiry_date) return;
|
||||
if (!item.expiry_date || !item.install_date) return;
|
||||
const expiry = new Date(item.expiry_date);
|
||||
const install = new Date(item.install_date);
|
||||
const diffMs = expiry.getTime() - today.getTime();
|
||||
const diffMonths = diffMs / (1000 * 60 * 60 * 24 * 30);
|
||||
|
||||
|
|
@ -276,6 +282,7 @@ function ReplacementsContent({
|
|||
const entry = {
|
||||
sub_variable: SUB_ITEMS_TEXT[item.sub_variable] ?? item.sub_variable,
|
||||
expiry,
|
||||
install,
|
||||
remaining,
|
||||
overdue,
|
||||
};
|
||||
|
|
@ -351,9 +358,14 @@ function ReplacementsContent({
|
|||
</div>
|
||||
<div className="text-sm text-gray-600 flex justify-between">
|
||||
<span>{comp.remaining}</span>
|
||||
<span className={comp.overdue ? "text-red-600" : ""}>
|
||||
{comp.expiry.toLocaleDateString("en-GB")}
|
||||
</span>
|
||||
<div className="flex flex-col text-right">
|
||||
<span className={comp.overdue ? "text-red-600" : ""}>
|
||||
{`Installed: ${comp.install.toLocaleDateString("en-GB")}`}
|
||||
</span>
|
||||
<span className={comp.overdue ? "text-red-600" : ""}>
|
||||
{`Expired: ${comp.expiry.toLocaleDateString("en-GB")}`}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
|
@ -385,6 +397,7 @@ function DecentHomesSummary({
|
|||
sub_variable: string;
|
||||
result: string;
|
||||
expiry_date?: string | null;
|
||||
install_date?: string | null;
|
||||
}[];
|
||||
}) {
|
||||
const overallPass = decentHomes.decent_homes === "pass";
|
||||
|
|
@ -407,8 +420,11 @@ function DecentHomesSummary({
|
|||
D: [],
|
||||
};
|
||||
|
||||
const replacements: { sub_variable: string; expiry_date: string | null }[] =
|
||||
[];
|
||||
const replacements: {
|
||||
sub_variable: string;
|
||||
expiry_date: string | null;
|
||||
install_date: string | null;
|
||||
}[] = [];
|
||||
|
||||
decentHomesMeta.forEach((item) => {
|
||||
if (criteriaGroups[item.criteria]) {
|
||||
|
|
@ -421,6 +437,7 @@ function DecentHomesSummary({
|
|||
replacements.push({
|
||||
sub_variable: item.sub_variable,
|
||||
expiry_date: item.expiry_date,
|
||||
install_date: item.install_date ?? null,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
@ -428,8 +445,7 @@ function DecentHomesSummary({
|
|||
const soonCount = replacements.filter((r) => {
|
||||
if (!r.expiry_date) return false;
|
||||
const expiry = new Date(r.expiry_date);
|
||||
const diffMs = expiry.getTime() - new Date().getTime();
|
||||
return diffMs < 1000 * 60 * 60 * 24 * 365;
|
||||
return expiry.getTime() < Date.now(); // strictly overdue
|
||||
}).length;
|
||||
|
||||
return (
|
||||
|
|
@ -463,7 +479,7 @@ function DecentHomesSummary({
|
|||
<TabsTrigger
|
||||
value="replacements"
|
||||
className="relative flex items-center space-x-2 text-orange-700 font-medium
|
||||
data-[state=active]:bg-brandbrown data-[state=active]:rounded-md data-[state=active]:text-gray-100"
|
||||
data-[state=active]:bg-brandbrown data-[state=active]:rounded-md data-[state=active]:text-gray-100"
|
||||
>
|
||||
<Wrench className="w-4 h-4" />
|
||||
<span>Replacements</span>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue