Skip to content

Commit

Permalink
Merge pull request #821 from cultuurnet/bugfix/III-5865
Browse files Browse the repository at this point in the history
  • Loading branch information
Anahkiasen authored Oct 24, 2023
2 parents 6b4e01e + 4096d28 commit 57c8147
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/pages/organizers/create/OrganizerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Page } from '@/ui/Page';
import { Text } from '@/ui/Text';
import { getValueFromTheme } from '@/ui/theme';
import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback';
import { getUniqueLabels } from '@/utils/getUniqueLabels';

import { NameAndUrlStep } from './steps/NameAndUrlStep';

Expand Down Expand Up @@ -110,13 +111,7 @@ const OrganizerForm = () => {

// @ts-expect-error
const organizer = getOrganizerByIdQuery?.data;

const organizerLabelsSet = new Set([
...(organizer?.labels ?? []),
...(organizer?.hiddenLabels ?? []),
]);

const organizerLabels = [...organizerLabelsSet];
const organizerLabels = getUniqueLabels(organizer);

const createOrganizerMutation = useCreateOrganizerMutation();
const updateOrganizerMutation = useUpdateOrganizerMutation();
Expand Down
3 changes: 2 additions & 1 deletion src/pages/steps/AdditionalInformationStep/LabelsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { getStackProps, Stack, StackProps } from '@/ui/Stack';
import { Text, TextVariants } from '@/ui/Text';
import { getGlobalBorderRadius } from '@/ui/theme';
import { Typeahead } from '@/ui/Typeahead';
import { getUniqueLabels } from '@/utils/getUniqueLabels';

type LabelsStepProps = StackProps & TabContentProps;

Expand All @@ -50,7 +51,7 @@ function LabelsStep({
});

const options = labelsQuery.data?.member ?? [];
const [labels, setLabels] = useState<string[]>(entity?.labels ?? []);
const [labels, setLabels] = useState<string[]>(getUniqueLabels(entity) ?? []);
const addLabelMutation = useAddOfferLabelMutation();
const removeLabelMutation = useRemoveOfferLabelMutation();

Expand Down
13 changes: 13 additions & 0 deletions src/utils/getUniqueLabels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Offer } from '@/types/Offer';
import { Organizer } from '@/types/Organizer';

const getUniqueLabels = (entity: Organizer | Offer) => {
const organizerLabelsSet = new Set([
...(entity?.labels ?? []),
...(entity?.hiddenLabels ?? []),
]);

return [...organizerLabelsSet];
};

export { getUniqueLabels };

0 comments on commit 57c8147

Please sign in to comment.