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,