Skip to content

Commit

Permalink
refactor: filter out locations with no benefit data
Browse files Browse the repository at this point in the history
  • Loading branch information
trulshj committed Dec 16, 2024
1 parent 8ed7a30 commit 52acdca
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/components/compensations/CompensationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>(
locations[0]._id,
locationOptions[0]?.id,
);
const [selectedLocationLabel, setSelectedLocationLabel] = useState<string>(
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,
Expand Down

0 comments on commit 52acdca

Please sign in to comment.