From 52acdca9cf415b1cea6eb401add9960c90bd34ef Mon Sep 17 00:00:00 2001 From: Truls Henrik Jakobsen Date: Mon, 16 Dec 2024 12:51:19 +0100 Subject: [PATCH 1/2] refactor: filter out locations with no benefit data --- .../compensations/CompensationSelector.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/compensations/CompensationSelector.tsx b/src/components/compensations/CompensationSelector.tsx index d1b2bd4a1..e29114601 100644 --- a/src/components/compensations/CompensationSelector.tsx +++ b/src/components/compensations/CompensationSelector.tsx @@ -27,18 +27,23 @@ export default function CompensationSelector({ }: CompensationsProps) { const t = useTranslations("compensation_calculator"); + const hasBenefits = (id: string) => + compensations.benefitsByLocation.some((b) => b.location._ref === id); + + const locationOptions: IOption[] = locations + .map((companyLocation) => ({ + id: companyLocation._id, + label: companyLocation.companyLocationName, + })) + .filter((l) => hasBenefits(l.id)); + const [selectedLocation, setSelectedLocation] = useState( - locations[0]._id, + locationOptions[0]?.id, ); const [selectedLocationLabel, setSelectedLocationLabel] = useState( - locations[0].companyLocationName, + locationOptions[0]?.label, ); - const locationOptions: IOption[] = locations.map((companyLocation) => ({ - id: companyLocation._id, - label: companyLocation.companyLocationName, - })); - const benefitsFilteredByLocation = compensations.benefitsByLocation.find( (benefit) => benefit.location._ref === selectedLocation, From b4415d5bfd143914021aab96c10321e2c488838b Mon Sep 17 00:00:00 2001 From: Truls Henrik Jakobsen Date: Mon, 16 Dec 2024 12:57:52 +0100 Subject: [PATCH 2/2] chore: remove "no_compensation_data" We filter it now, so this shouldn't occur --- messages/en.json | 3 +-- messages/no.json | 3 +-- messages/se.json | 3 +-- .../compensations/CompensationSelector.tsx | 15 +-------------- 4 files changed, 4 insertions(+), 20 deletions(-) diff --git a/messages/en.json b/messages/en.json index 946a1d472..8ce9cc52f 100644 --- a/messages/en.json +++ b/messages/en.json @@ -47,8 +47,7 @@ "degreeOptions": { "bachelor": "Bachelor", "master": "Master" - }, - "no_compensation_data": "Whoops, the accounts seem to be on holiday. {city}, huh..." + } }, "employee_card": { "show": "Showing", diff --git a/messages/no.json b/messages/no.json index 803a181e7..45652d68d 100644 --- a/messages/no.json +++ b/messages/no.json @@ -44,8 +44,7 @@ "bachelor": "Bachelor", "master": "Master" }, - "test": "test", - "no_compensation_data": "Woops, regnskapet er på avveie. {city} altså..." + "test": "test" }, "custom_link": { "visit_cv": "Gå til mini-CV", diff --git a/messages/se.json b/messages/se.json index 3b5342ea5..d784bbc9a 100644 --- a/messages/se.json +++ b/messages/se.json @@ -43,8 +43,7 @@ "degreeOptions": { "bachelor": "Bachelor", "master": "Master" - }, - "no_compensation_data": "Hoppsan, bokföringen är på villovägar. {city} alltså..." + } }, "custom_link": { "visit_cv": "Besök mini-CV", diff --git a/src/components/compensations/CompensationSelector.tsx b/src/components/compensations/CompensationSelector.tsx index e29114601..4174bd11c 100644 --- a/src/components/compensations/CompensationSelector.tsx +++ b/src/components/compensations/CompensationSelector.tsx @@ -1,5 +1,4 @@ "use client"; -import { useTranslations } from "next-intl"; import { useState } from "react"; import { @@ -25,8 +24,6 @@ export default function CompensationSelector({ locations, locale, }: CompensationsProps) { - const t = useTranslations("compensation_calculator"); - const hasBenefits = (id: string) => compensations.benefitsByLocation.some((b) => b.location._ref === id); @@ -40,9 +37,6 @@ export default function CompensationSelector({ const [selectedLocation, setSelectedLocation] = useState( locationOptions[0]?.id, ); - const [selectedLocationLabel, setSelectedLocationLabel] = useState( - locationOptions[0]?.label, - ); const benefitsFilteredByLocation = compensations.benefitsByLocation.find( @@ -62,20 +56,13 @@ export default function CompensationSelector({ selectedId={selectedLocation} onValueChange={(option) => { setSelectedLocation(option.id); - setSelectedLocationLabel(option.label); }} /> {yearlyBonusesForLocation && ( )} - {benefitsFilteredByLocation.length > 0 ? ( - - ) : ( - - {t("no_compensation_data", { city: selectedLocationLabel })} - - )} + ); }