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
Changes from 1 commit
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
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>(
trulshj marked this conversation as resolved.
Show resolved Hide resolved
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
Loading