Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: filter out locations with no benefit data #1068

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions messages/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions messages/se.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 11 additions & 19 deletions src/components/compensations/CompensationSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"use client";
import { useTranslations } from "next-intl";
import { useState } from "react";

import {
Expand All @@ -25,20 +24,20 @@ export default function CompensationSelector({
locations,
locale,
}: 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<string>(
locations[0]._id,
);
const [selectedLocationLabel, setSelectedLocationLabel] = useState<string>(
locations[0].companyLocationName,
locationOptions[0]?.id,
);

const locationOptions: IOption[] = locations.map((companyLocation) => ({
id: companyLocation._id,
label: companyLocation.companyLocationName,
}));

const benefitsFilteredByLocation =
compensations.benefitsByLocation.find(
(benefit) => benefit.location._ref === selectedLocation,
Expand All @@ -57,20 +56,13 @@ export default function CompensationSelector({
selectedId={selectedLocation}
onValueChange={(option) => {
setSelectedLocation(option.id);
setSelectedLocationLabel(option.label);
}}
/>

{yearlyBonusesForLocation && (
<YearlyBonuses bonuses={yearlyBonusesForLocation} locale={locale} />
)}
{benefitsFilteredByLocation.length > 0 ? (
<BenefitsByLocation benefits={benefitsFilteredByLocation} />
) : (
<span>
{t("no_compensation_data", { city: selectedLocationLabel })}
</span>
)}
<BenefitsByLocation benefits={benefitsFilteredByLocation} />
</div>
);
}
Loading