diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index a3e7a7a9e..d07e36d3f 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -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'; @@ -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(); diff --git a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx index 895d1453b..9ea5fc944 100644 --- a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx @@ -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; @@ -50,7 +51,7 @@ function LabelsStep({ }); const options = labelsQuery.data?.member ?? []; - const [labels, setLabels] = useState(entity?.labels ?? []); + const [labels, setLabels] = useState(getUniqueLabels(entity) ?? []); const addLabelMutation = useAddOfferLabelMutation(); const removeLabelMutation = useRemoveOfferLabelMutation(); diff --git a/src/utils/getUniqueLabels.ts b/src/utils/getUniqueLabels.ts new file mode 100644 index 000000000..893a72f8a --- /dev/null +++ b/src/utils/getUniqueLabels.ts @@ -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 };