From f8711ccd723dc14b38a090cbff89368cf354318a Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 13:20:04 +0200 Subject: [PATCH 01/26] Add missing default value --- src/pages/organizers/create/OrganizerForm.tsx | 3 +++ src/pages/organizers/create/steps/UrlStep.tsx | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 2b6c1d121..89c9ed9de 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -22,6 +22,7 @@ import { Page } from '@/ui/Page'; import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback'; import { NameAndUrlStep } from './steps/NameAndUrlStep'; +import { locationStepConfiguration } from '@/pages/steps/LocationStep'; const typeAndThemeStepConfiguration: StepsConfiguration<'nameAndUrl'> = { Component: NameAndUrlStep, @@ -44,6 +45,8 @@ const configurations = [ ...additionalInformationStepConfiguration, shouldShowStep: () => true, variant: AdditionalInformationStepVariant.ORGANIZER, + name: 'location', + defaultValue: locationStepConfiguration.defaultValue, }, ]; diff --git a/src/pages/organizers/create/steps/UrlStep.tsx b/src/pages/organizers/create/steps/UrlStep.tsx index ce555b8c4..35727a3e6 100644 --- a/src/pages/organizers/create/steps/UrlStep.tsx +++ b/src/pages/organizers/create/steps/UrlStep.tsx @@ -46,8 +46,6 @@ const UrlStep = ({ const isUrlAlreadyTaken = errors.nameAndUrl?.url?.type === 'not_unique'; - console.log({ existingOrganizer }); - useEffect(() => { if (existingOrganizer) { console.log('should set error'); From ccdac2e787fc3f835884a93e602bf6846e277e98 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 13:20:16 +0200 Subject: [PATCH 02/26] Unify location handling in isLocationSet --- src/pages/steps/LocationStep.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/steps/LocationStep.tsx b/src/pages/steps/LocationStep.tsx index eeb08e6c2..badd1f128 100644 --- a/src/pages/steps/LocationStep.tsx +++ b/src/pages/steps/LocationStep.tsx @@ -732,7 +732,7 @@ const isLocationSet = ( location: FormDataUnion['location'], formState, ) => { - if (location.isOnline || location.place) { + if (location?.isOnline || location?.place) { return true; } @@ -740,7 +740,7 @@ const isLocationSet = ( return ( isCultuurKuur || - (location.municipality?.name && + (location?.municipality?.name && formState.touchedFields.location?.streetAndNumber) ); }; From 5ad0eedcb57bcf4c480e914072bba4d3780c1cd9 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 13:20:25 +0200 Subject: [PATCH 03/26] Add Location step --- .../AdditionalInformationStep.tsx | 10 +++++ .../PhysicalLocationStep.tsx | 44 +++++++++++++++++++ src/pages/steps/LocationStep.tsx | 1 + 3 files changed, 55 insertions(+) create mode 100644 src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx diff --git a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx index 0024cb0a6..5d5cc8223 100644 --- a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx @@ -25,6 +25,8 @@ import { MediaStep } from './MediaStep'; import { OfferScore } from './OfferScore'; import { OrganizerStep } from './OrganizerStep'; import { PriceInformation } from './PriceInformation'; +import { PhysicalLocationStep } from '@/pages/steps/AdditionalInformationStep/PhysicalLocationStep'; +import { Countries } from '@/types/Country'; const getGlobalValue = getValueFromTheme('global'); @@ -44,6 +46,7 @@ const Fields = { MEDIA: 'media', AUDIENCE: 'audience', LABELS: 'labels', + LOCATION: 'location', }; type Field = Values; @@ -111,6 +114,12 @@ const tabConfigurations: TabConfig[] = [ AdditionalInformationStepVariant.MOVIE, ], }, + { + field: Fields.LOCATION, + TabContent: PhysicalLocationStep, + shouldInvalidate: false, + shouldShowOn: [AdditionalInformationStepVariant.ORGANIZER], + }, { field: Fields.LABELS, TabContent: LabelsStep, @@ -279,6 +288,7 @@ const AdditionalInformationStep = ({ onSuccessfulChange={() => invalidateOfferQuery(field, shouldInvalidate) } + {...props} {...stepProps} /> diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx new file mode 100644 index 000000000..b2f4df7fb --- /dev/null +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -0,0 +1,44 @@ +import { uniq } from 'lodash'; +import React, { useEffect, useRef, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import { UseQueryResult } from 'react-query'; + +import { useGetLabelsByQuery } from '@/hooks/api/labels'; +import { + useAddOfferLabelMutation, + useGetOfferByIdQuery, + useRemoveOfferLabelMutation, +} from '@/hooks/api/offers'; +import { + TabContentProps, + ValidationStatus, +} from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; +import { Label, Offer } from '@/types/Offer'; +import { Alert } from '@/ui/Alert'; +import { Badge, BadgeVariants } from '@/ui/Badge'; +import { FormElement } from '@/ui/FormElement'; +import { Icon, Icons } from '@/ui/Icon'; +import { Inline } from '@/ui/Inline'; +import { getStackProps, Stack, StackProps } from '@/ui/Stack'; +import { Text, TextVariants } from '@/ui/Text'; +import { getGlobalBorderRadius } from '@/ui/theme'; +import { Typeahead } from '@/ui/Typeahead'; +import { LocationStep } from '@/pages/steps/LocationStep'; +import { useForm, useFormContext, useFormState } from 'react-hook-form'; + +type PhysicalLocationStepProps = StackProps & TabContentProps; + +const LABEL_PATTERN = /^[0-9a-zA-Z][0-9a-zA-Z-_\s]{1,49}$/; + +function PhysicalLocationStep({ + offerId, + scope, + onValidationChange, + ...props +}: PhysicalLocationStepProps) { + const { t } = useTranslation(); + + return ; +} + +export { PhysicalLocationStep }; diff --git a/src/pages/steps/LocationStep.tsx b/src/pages/steps/LocationStep.tsx index badd1f128..5d8129cdb 100644 --- a/src/pages/steps/LocationStep.tsx +++ b/src/pages/steps/LocationStep.tsx @@ -1251,6 +1251,7 @@ export { DUTCH_ZIP_REGEX, GERMAN_ZIP_REGEX, isLocationSet, + LocationStep, locationStepConfiguration, useEditLocation, }; From ed92998d5479193be2d374369ae5b8a028e1c707 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 13:38:33 +0200 Subject: [PATCH 04/26] Just pass all props for now --- .../AdditionalInformationStep/PhysicalLocationStep.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx index b2f4df7fb..1e10050d7 100644 --- a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -30,12 +30,7 @@ type PhysicalLocationStepProps = StackProps & TabContentProps; const LABEL_PATTERN = /^[0-9a-zA-Z][0-9a-zA-Z-_\s]{1,49}$/; -function PhysicalLocationStep({ - offerId, - scope, - onValidationChange, - ...props -}: PhysicalLocationStepProps) { +function PhysicalLocationStep({ ...props }: PhysicalLocationStepProps) { const { t } = useTranslation(); return ; From 79808ecc16804e98e17c76325398b0b4b6b1459e Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:07:59 +0200 Subject: [PATCH 05/26] Add update organizer mutation --- src/hooks/api/organizers.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index 088ea0d47..8e35c231c 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -251,8 +251,44 @@ const useCreateOrganizerMutation = (configuration: UseMutationOptions = {}) => ...configuration, }); +type UpdateOrganizerArguments = CreateOrganizerArguments & { + organizerId: string; +}; + +const updateOrganizer = ({ + headers, + url, + organizerId, + name, + address, + mainLanguage, + contact, +}: UpdateOrganizerArguments) => + fetchFromApi({ + path: `/organizers/${organizerId}`, + options: { + headers, + method: 'PUT', + body: JSON.stringify({ + mainLanguage, + name, + url, + address, + contact, + }), + }, + }); + +const useUpdateOrganizerMutation = (configuration: UseMutationOptions = {}) => + useAuthenticatedMutation({ + mutationFn: updateOrganizer, + mutationKey: 'organizers-update', + ...configuration, + }); + export { useCreateOrganizerMutation, + useUpdateOrganizerMutation, useDeleteOrganizerByIdMutation, useGetOrganizerByIdQuery, useGetOrganizersByCreatorQuery, From 3860543bb9df9fbef8d7687281177a7b32b960f5 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:08:17 +0200 Subject: [PATCH 06/26] Don't show non unique organizer URL error for same one as current --- src/pages/organizers/create/steps/UrlStep.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/organizers/create/steps/UrlStep.tsx b/src/pages/organizers/create/steps/UrlStep.tsx index 35727a3e6..ed7600983 100644 --- a/src/pages/organizers/create/steps/UrlStep.tsx +++ b/src/pages/organizers/create/steps/UrlStep.tsx @@ -12,6 +12,8 @@ import { Input } from '@/ui/Input'; import { getStackProps, Stack, StackProps } from '@/ui/Stack'; import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback'; import { prefixUrlWithHttps } from '@/utils/url'; +import { useRouter } from 'next/router'; +import { parseOfferId } from '@/utils/parseOfferId'; type UrlStepProps = StackProps & StepProps; @@ -26,6 +28,7 @@ const UrlStep = ({ name, ...props }: UrlStepProps) => { + const { query } = useRouter(); const { t, i18n } = useTranslation(); const [watchedUrl] = useWatch({ @@ -47,7 +50,10 @@ const UrlStep = ({ const isUrlAlreadyTaken = errors.nameAndUrl?.url?.type === 'not_unique'; useEffect(() => { - if (existingOrganizer) { + if ( + existingOrganizer && + parseOfferId(existingOrganizer['@id']) !== query.organizerId + ) { console.log('should set error'); setError('nameAndUrl.url', { type: 'not_unique' }); return; From 18243da3be3854ed1a340487f5ea711293303e9a Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:08:28 +0200 Subject: [PATCH 07/26] Cleanup component a bit --- .../PhysicalLocationStep.tsx | 44 +++++-------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx index 1e10050d7..f9dc511b8 100644 --- a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -1,39 +1,19 @@ -import { uniq } from 'lodash'; -import React, { useEffect, useRef, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { UseQueryResult } from 'react-query'; - -import { useGetLabelsByQuery } from '@/hooks/api/labels'; -import { - useAddOfferLabelMutation, - useGetOfferByIdQuery, - useRemoveOfferLabelMutation, -} from '@/hooks/api/offers'; -import { - TabContentProps, - ValidationStatus, -} from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; -import { Label, Offer } from '@/types/Offer'; -import { Alert } from '@/ui/Alert'; -import { Badge, BadgeVariants } from '@/ui/Badge'; -import { FormElement } from '@/ui/FormElement'; -import { Icon, Icons } from '@/ui/Icon'; -import { Inline } from '@/ui/Inline'; -import { getStackProps, Stack, StackProps } from '@/ui/Stack'; -import { Text, TextVariants } from '@/ui/Text'; -import { getGlobalBorderRadius } from '@/ui/theme'; -import { Typeahead } from '@/ui/Typeahead'; +import React from 'react'; +import { TabContentProps } from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; +import { StackProps } from '@/ui/Stack'; import { LocationStep } from '@/pages/steps/LocationStep'; -import { useForm, useFormContext, useFormState } from 'react-hook-form'; - -type PhysicalLocationStepProps = StackProps & TabContentProps; +import { StepProps } from '@/pages/steps/Steps'; -const LABEL_PATTERN = /^[0-9a-zA-Z][0-9a-zA-Z-_\s]{1,49}$/; +type PhysicalLocationStepProps = StackProps & TabContentProps & StepProps; function PhysicalLocationStep({ ...props }: PhysicalLocationStepProps) { - const { t } = useTranslation(); - - return ; + return ( + + ); } export { PhysicalLocationStep }; From 1a511d8d2812dcd11664e317a455c2f4c1ea883f Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:08:32 +0200 Subject: [PATCH 08/26] Do upsert on save --- src/pages/organizers/create/OrganizerForm.tsx | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 89c9ed9de..f0cd09f6f 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -1,5 +1,5 @@ import { useRouter } from 'next/router'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import * as yup from 'yup'; @@ -8,6 +8,7 @@ import { URL_REGEX } from '@/constants/Regex'; import { useCreateOrganizerMutation, useGetOrganizerByIdQuery, + useUpdateOrganizerMutation, } from '@/hooks/api/organizers'; import { SupportedLanguage, SupportedLanguages } from '@/i18n/index'; import { @@ -58,7 +59,7 @@ const OrganizerForm = (props) => { const { handleSubmit, formState, getValues, reset } = form; - const organizerId = useMemo( + const urlOrganizerId = useMemo( () => query.organizerId as string, [query.organizerId], ); @@ -79,12 +80,12 @@ const OrganizerForm = (props) => { // TODO better type query const getOrganizerByIdQuery = useGetOrganizerByIdQuery( - { id: organizerId }, + { id: urlOrganizerId }, { onSuccess: (organizer: Organizer) => { - reset(convertOrganizerToFormData(organizer), { - keepDirty: true, - }); + //reset(convertOrganizerToFormData(organizer), { + // keepDirty: true, + //}); }, }, ); @@ -93,12 +94,26 @@ const OrganizerForm = (props) => { const organizer = getOrganizerByIdQuery?.data; const createOrganizerMutation = useCreateOrganizerMutation(); + const updateOrganizerMutation = useUpdateOrganizerMutation(); - const createOrganizer = async ({ onSuccess }) => { - const { organizerId } = await createOrganizerMutation.mutateAsync({ + const upsertOrganizer = async ({ onSuccess }) => { + const mutation = urlOrganizerId + ? updateOrganizerMutation + : createOrganizerMutation; + + const { organizerId } = await mutation.mutateAsync({ + organizerId: urlOrganizerId, name: getValues('nameAndUrl.name'), url: getValues('nameAndUrl.url'), mainLanguage: i18n.language, + address: { + [i18n.language]: { + addressCountry: getValues('location.country'), + addressLocality: getValues('location.municipality'), + postalCode: getValues('location.postalCode'), + streetAddress: getValues('location.streetAndNumber'), + }, + }, }); onSuccess(organizerId); @@ -107,12 +122,18 @@ const OrganizerForm = (props) => { const hasErrors = Object.keys(formState.errors).length > 0; const onSuccess = () => { - createOrganizer({ + upsertOrganizer({ onSuccess: async (organizerId) => await push(`/organizers/${organizerId}/edit`), }); }; + const onChange = (changedFields) => { + //console.log(getValues(changedFields)); + }; + + useEffect(() => {}); + return ( @@ -121,10 +142,10 @@ const OrganizerForm = (props) => { ({})} + onChangeSuccess={onChange} form={form} /> From ecf23d20154e5ee4e63a4fb166d5f6e30c73cf88 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:27:47 +0200 Subject: [PATCH 09/26] Make standard placeholders default --- src/pages/steps/LocationStep.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/pages/steps/LocationStep.tsx b/src/pages/steps/LocationStep.tsx index 5d8129cdb..8f80b87a1 100644 --- a/src/pages/steps/LocationStep.tsx +++ b/src/pages/steps/LocationStep.tsx @@ -753,8 +753,8 @@ const LocationStep = ({ name, offerId, onChange, - chooseLabel, - placeholderLabel, + chooseLabel = (t) => t('create.location.place.choose_label'), + placeholderLabel = (t) => t('create.location.place.placeholder'), setValue, trigger, watch, @@ -1172,10 +1172,6 @@ const locationStepConfiguration: StepsConfiguration<'location'> = { name: 'location', shouldShowStep: ({ watch }) => !!watch('typeAndTheme')?.type?.id, title: ({ t, scope }) => t(`create.location.title.${scope}`), - stepProps: { - chooseLabel: (t) => t('create.location.place.choose_label'), - placeholderLabel: (t) => t('create.location.place.placeholder'), - }, defaultValue: { isOnline: false, country: Countries.BE, From 966e7853e84918356762dbb147d713179d6679f8 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:35:24 +0200 Subject: [PATCH 10/26] More adaptations to LocationStep --- .../AdditionalInformationStep.tsx | 2 +- .../PhysicalLocationStep.tsx | 8 +---- src/pages/steps/LocationStep.tsx | 29 +++++++++---------- src/pages/steps/Steps.tsx | 1 + 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx index 5d5cc8223..0e6aebf50 100644 --- a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx @@ -190,7 +190,7 @@ const AdditionalInformationStep = ({ if (shouldInvalidate) { await queryClient.invalidateQueries([scope, { id: offerId }]); } - onChangeSuccess(field); + onChangeSuccess?.(field); }, // eslint-disable-next-line react-hooks/exhaustive-deps [scope, offerId, queryClient], diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx index f9dc511b8..9d7b3c246 100644 --- a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -7,13 +7,7 @@ import { StepProps } from '@/pages/steps/Steps'; type PhysicalLocationStepProps = StackProps & TabContentProps & StepProps; function PhysicalLocationStep({ ...props }: PhysicalLocationStepProps) { - return ( - - ); + return ; } export { PhysicalLocationStep }; diff --git a/src/pages/steps/LocationStep.tsx b/src/pages/steps/LocationStep.tsx index 8f80b87a1..a67cb235f 100644 --- a/src/pages/steps/LocationStep.tsx +++ b/src/pages/steps/LocationStep.tsx @@ -7,7 +7,12 @@ import { useTranslation } from 'react-i18next'; import * as yup from 'yup'; import { EventTypes } from '@/constants/EventTypes'; -import { OfferType, OfferTypes, Scope } from '@/constants/OfferType'; +import { + OfferType, + OfferTypes, + Scope, + ScopeTypes, +} from '@/constants/OfferType'; import { useChangeAttendanceModeMutation, useChangeAudienceMutation, @@ -766,17 +771,11 @@ const LocationStep = ({ const [audienceType, setAudienceType] = useState(''); const [onlineUrl, setOnlineUrl] = useState(''); const [hasOnlineUrlError, setHasOnlineUrlError] = useState(false); - - const [scope, locationStreetAndNumber, locationOnlineUrl, location] = - useWatch({ - control, - name: [ - 'scope', - 'location.streetAndNumber', - 'location.onlineUrl', - 'location', - ], - }); + const scope = watch('scope') ?? props.scope; + const [locationStreetAndNumber, locationOnlineUrl, location] = useWatch({ + control, + name: ['location.streetAndNumber', 'location.onlineUrl', 'location'], + }); const shouldAddSpaceBelowTypeahead = useMemo(() => { if (offerId) return false; @@ -1069,7 +1068,7 @@ const LocationStep = ({ )} - {scope === OfferTypes.EVENTS && ( + {scope === ScopeTypes.EVENTS && ( )} - {scope === OfferTypes.PLACES && ( + {[ScopeTypes.PLACES, ScopeTypes.ORGANIZERS].includes(scope) && ( {isPlaceAddressComplete ? ( @@ -1114,7 +1113,7 @@ const LocationStep = ({ ) : ( - {['NL', 'DE'].includes(location.country) && ( + {['NL', 'DE'].includes(location?.country) && ( & { + scope: string; loading: boolean; name: Path; onChange: (value: any) => void; From e454a2be50f6ae42d1fcd72c4f4b0c553d3805e4 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:35:41 +0200 Subject: [PATCH 11/26] Use correct getters for location --- src/pages/organizers/create/OrganizerForm.tsx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index f0cd09f6f..bfbd45e6d 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -109,8 +109,8 @@ const OrganizerForm = (props) => { address: { [i18n.language]: { addressCountry: getValues('location.country'), - addressLocality: getValues('location.municipality'), - postalCode: getValues('location.postalCode'), + addressLocality: getValues('location.municipality.name'), + postalCode: getValues('location.municipality.zip'), streetAddress: getValues('location.streetAndNumber'), }, }, @@ -128,12 +128,6 @@ const OrganizerForm = (props) => { }); }; - const onChange = (changedFields) => { - //console.log(getValues(changedFields)); - }; - - useEffect(() => {}); - return ( @@ -145,7 +139,6 @@ const OrganizerForm = (props) => { offerId={urlOrganizerId} mainLanguage={SupportedLanguages.NL} configurations={configurations} - onChangeSuccess={onChange} form={form} /> From fabe9f77ff9d97e6f847d22453ce467c242b51e7 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:46:22 +0200 Subject: [PATCH 12/26] Add location to initial form value --- src/pages/create/OfferForm.tsx | 4 ++-- src/pages/organizers/create/OrganizerForm.tsx | 16 +++++++++++----- .../PhysicalLocationStep.tsx | 3 ++- src/pages/steps/LocationStep.tsx | 6 +++--- src/types/Address.ts | 3 ++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pages/create/OfferForm.tsx b/src/pages/create/OfferForm.tsx index 4deeec531..eec03c5c6 100644 --- a/src/pages/create/OfferForm.tsx +++ b/src/pages/create/OfferForm.tsx @@ -106,7 +106,7 @@ const getAddress = ( }; const parseLocationAttributes = ( - offer: Offer, + offer: Offer | Organizer, language: SupportedLanguage, mainLanguage: SupportedLanguage, ) => { @@ -131,7 +131,7 @@ const parseLocationAttributes = ( postalCode: postalCode, place: isEvent(offer) ? offer.location : undefined, country: addressCountry, - ...(isPlace(offer) && { streetAndNumber: streetAddress }), + ...(!isEvent(offer) && { streetAndNumber: streetAddress }), ...(isEvent(offer) && !!offer.onlineUrl && { onlineUrl: offer.onlineUrl }), }, diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index bfbd45e6d..61f7dae14 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -1,5 +1,5 @@ import { useRouter } from 'next/router'; -import React, { useEffect, useMemo } from 'react'; +import React, { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import * as yup from 'yup'; @@ -11,11 +11,13 @@ import { useUpdateOrganizerMutation, } from '@/hooks/api/organizers'; import { SupportedLanguage, SupportedLanguages } from '@/i18n/index'; +import { parseLocationAttributes } from '@/pages/create/OfferForm'; import { additionalInformationStepConfiguration, AdditionalInformationStepVariant, } from '@/pages/steps/AdditionalInformationStep'; import { useParseStepConfiguration } from '@/pages/steps/hooks/useParseStepConfiguration'; +import { locationStepConfiguration } from '@/pages/steps/LocationStep'; import { Steps, StepsConfiguration } from '@/pages/steps/Steps'; import { Organizer } from '@/types/Organizer'; import { Button, ButtonVariants } from '@/ui/Button'; @@ -23,7 +25,6 @@ import { Page } from '@/ui/Page'; import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback'; import { NameAndUrlStep } from './steps/NameAndUrlStep'; -import { locationStepConfiguration } from '@/pages/steps/LocationStep'; const typeAndThemeStepConfiguration: StepsConfiguration<'nameAndUrl'> = { Component: NameAndUrlStep, @@ -73,6 +74,11 @@ const OrganizerForm = (props) => { ) as string, url: organizer.url, }, + ...parseLocationAttributes( + organizer, + i18n.language as SupportedLanguage, + organizer.mainLanguage as SupportedLanguage, + ), }; }; @@ -83,9 +89,9 @@ const OrganizerForm = (props) => { { id: urlOrganizerId }, { onSuccess: (organizer: Organizer) => { - //reset(convertOrganizerToFormData(organizer), { - // keepDirty: true, - //}); + reset(convertOrganizerToFormData(organizer), { + keepDirty: true, + }); }, }, ); diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx index 9d7b3c246..27d535c6e 100644 --- a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -1,8 +1,9 @@ import React from 'react'; + import { TabContentProps } from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; -import { StackProps } from '@/ui/Stack'; import { LocationStep } from '@/pages/steps/LocationStep'; import { StepProps } from '@/pages/steps/Steps'; +import { StackProps } from '@/ui/Stack'; type PhysicalLocationStepProps = StackProps & TabContentProps & StepProps; diff --git a/src/pages/steps/LocationStep.tsx b/src/pages/steps/LocationStep.tsx index a67cb235f..48ad6445e 100644 --- a/src/pages/steps/LocationStep.tsx +++ b/src/pages/steps/LocationStep.tsx @@ -727,9 +727,9 @@ const useEditLocation = ({ scope, offerId }: UseEditArguments) => { type PlaceStepProps = StackProps & StepProps & { - terms: Array>; - chooseLabel: (t: TFunction) => string; - placeholderLabel: (t: TFunction) => string; + terms?: Array>; + chooseLabel?: (t: TFunction) => string; + placeholderLabel?: (t: TFunction) => string; } & { offerId?: string }; const isLocationSet = ( diff --git a/src/types/Address.ts b/src/types/Address.ts index 5a21e2b58..e05d08ff6 100644 --- a/src/types/Address.ts +++ b/src/types/Address.ts @@ -1,10 +1,11 @@ import type { SupportedLanguages } from '../i18n'; import type { Values } from './Values'; +import { Country } from '@/types/Country'; type AddressLocality = string; type AddressInternal = { - addressCountry: string; + addressCountry: Country; addressLocality: AddressLocality; postalCode: string; streetAddress: string; From d6db722b75925b8df1ab97613fb4253580fa8e4f Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:46:31 +0200 Subject: [PATCH 13/26] Add save button for once the org is created --- src/i18n/nl.json | 3 ++- src/pages/organizers/create/OrganizerForm.tsx | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/i18n/nl.json b/src/i18n/nl.json index 8b189125d..c35a7b92a 100644 --- a/src/i18n/nl.json +++ b/src/i18n/nl.json @@ -976,7 +976,8 @@ } }, "step2": { - "description_tips": "Geef een enthousiaste omschrijving van je organisatie\nTot welke doelgroep richt de organisatie zich?\nWat voor activiteiten organiseert deze organisatie?" + "description_tips": "Geef een enthousiaste omschrijving van je organisatie\nTot welke doelgroep richt de organisatie zich?\nWat voor activiteiten organiseert deze organisatie?", + "save": "Bewaren" } } }, diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 61f7dae14..12e21e95f 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -149,13 +149,23 @@ const OrganizerForm = (props) => { /> - + {urlOrganizerId ? ( + + ) : ( + + )} ); From cf933bd2342d1b17e5d816f7a74605b749c8b13b Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 14:56:08 +0200 Subject: [PATCH 14/26] Add translations --- src/i18n/de.json | 8 +++++++- src/i18n/fr.json | 7 +++++++ src/i18n/nl.json | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/i18n/de.json b/src/i18n/de.json index 7f165cf87..1c8bb0c7d 100644 --- a/src/i18n/de.json +++ b/src/i18n/de.json @@ -441,6 +441,9 @@ "not_found": "Diese Veranstaltung ist dem UiTPAS noch nicht bekannt." } }, + "location": { + "title": "Standort" + }, "place": { "add_new_label": "Ort nicht gefunden? Neuen Standort hinzufügen" }, @@ -492,7 +495,6 @@ }, "description": "Ab wann soll dies online angezeigt werden?", "title": "Wählen Sie ein Veröffentlichungsdatum", - "warning": "Achtung, dieses Datum kann nur einmalig eingestellt werden." }, "duplicate": { @@ -975,6 +977,10 @@ "url_matches": "Ungültige URL", "url_not_unique": "Diese Adresse wird bereits von der Organisation „{{organizerName}}“ verwendet." } + }, + "step2": { + "description_tips": "Beschreiben Sie Ihre Organisation mit Begeisterung\nAn welche Zielgruppe richtet sich die Organisation?\nWelche Aktivitäten organisiert diese Organisation?", + "save": "Speichern" } } }, diff --git a/src/i18n/fr.json b/src/i18n/fr.json index 7e7769976..4c037ba18 100644 --- a/src/i18n/fr.json +++ b/src/i18n/fr.json @@ -443,6 +443,9 @@ "not_found": "Cette activité n'est pas encore connue par UiTPAS." } }, + "location": { + "title": "Lieu" + }, "place": { "add_new_label": "Lieu introuvable ? Ajouter un nouveau lieu" }, @@ -975,6 +978,10 @@ "url_not_unique": "Cette adresse est déjà utilisée par l'organisation '{{organizerName}}'." } } + }, + "step2": { + "description_tips": "Décrivez avec enthousiasme votre organisation\nQuel public l'organisation cible-t-elle ?\nQuel type d'activités cette organisation organise-t-elle ?", + "save": "Enregistrer" } }, "selectionTable": { diff --git a/src/i18n/nl.json b/src/i18n/nl.json index c35a7b92a..806519b77 100644 --- a/src/i18n/nl.json +++ b/src/i18n/nl.json @@ -443,6 +443,9 @@ "not_found": "Deze activiteit is nog niet gekend bij UiTPAS." } }, + "location": { + "title": "Locatie" + }, "place": { "add_new_label": "Locatie niet gevonden? Nieuwe locatie toevoegen" }, From 3c457355311cf988933ad3b0a9ffed47d8f10787 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:08:38 +0200 Subject: [PATCH 15/26] Only pass address on updates --- src/pages/organizers/create/OrganizerForm.tsx | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 12e21e95f..d56cb0c21 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -107,20 +107,28 @@ const OrganizerForm = (props) => { ? updateOrganizerMutation : createOrganizerMutation; - const { organizerId } = await mutation.mutateAsync({ - organizerId: urlOrganizerId, + let attributes = { name: getValues('nameAndUrl.name'), url: getValues('nameAndUrl.url'), mainLanguage: i18n.language, - address: { - [i18n.language]: { - addressCountry: getValues('location.country'), - addressLocality: getValues('location.municipality.name'), - postalCode: getValues('location.municipality.zip'), - streetAddress: getValues('location.streetAndNumber'), + }; + + if (urlOrganizerId) { + attributes = { + ...attributes, + organizerId: urlOrganizerId, + address: { + [i18n.language]: { + addressCountry: getValues('location.country'), + addressLocality: getValues('location.municipality.name'), + postalCode: getValues('location.municipality.zip'), + streetAddress: getValues('location.streetAndNumber'), + }, }, - }, - }); + }; + } + + const { organizerId } = await mutation.mutateAsync(attributes); onSuccess(organizerId); }; From b600bfb823a42221bc1cc5bc46e991916dae5717 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:08:46 +0200 Subject: [PATCH 16/26] Set validation status --- .../PhysicalLocationStep.tsx | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx index 27d535c6e..1a9861ed6 100644 --- a/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/PhysicalLocationStep.tsx @@ -1,13 +1,28 @@ -import React from 'react'; +import React, { useEffect } from 'react'; -import { TabContentProps } from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; -import { LocationStep } from '@/pages/steps/LocationStep'; +import { + TabContentProps, + ValidationStatus, +} from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; +import { isLocationSet, LocationStep } from '@/pages/steps/LocationStep'; import { StepProps } from '@/pages/steps/Steps'; import { StackProps } from '@/ui/Stack'; type PhysicalLocationStepProps = StackProps & TabContentProps & StepProps; -function PhysicalLocationStep({ ...props }: PhysicalLocationStepProps) { +function PhysicalLocationStep({ + onValidationChange, + ...props +}: PhysicalLocationStepProps) { + const location = props.watch('location'); + useEffect(() => { + onValidationChange( + location?.streetAndNumber + ? ValidationStatus.SUCCESS + : ValidationStatus.WARNING, + ); + }, [onValidationChange, location]); + return ; } From ffa9f80560a60b8d93c63645c129c5a1b4db9491 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:11:45 +0200 Subject: [PATCH 17/26] Hide additional steps until after creation --- src/pages/organizers/create/OrganizerForm.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index d56cb0c21..906438532 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -45,7 +45,8 @@ const configurations = [ typeAndThemeStepConfiguration, { ...additionalInformationStepConfiguration, - shouldShowStep: () => true, + shouldShowStep: (form) => + form.getValues('nameAndUrl.name') && form.getValues('nameAndUrl.url'), variant: AdditionalInformationStepVariant.ORGANIZER, name: 'location', defaultValue: locationStepConfiguration.defaultValue, From b45cd8616c61565cd23fbe24ccac25a3679cd857 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:32:41 +0200 Subject: [PATCH 18/26] Only prefill location form attributes if done once --- src/pages/organizers/create/OrganizerForm.tsx | 14 +++++++++----- src/types/Organizer.ts | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 906438532..414b27182 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -67,6 +67,14 @@ const OrganizerForm = (props) => { ); const convertOrganizerToFormData = (organizer: Organizer) => { + const locationAttributes = !organizer?.address + ? {} + : parseLocationAttributes( + organizer, + i18n.language as SupportedLanguage, + organizer.mainLanguage as SupportedLanguage, + ); + return { nameAndUrl: { name: getLanguageObjectOrFallback( @@ -75,11 +83,7 @@ const OrganizerForm = (props) => { ) as string, url: organizer.url, }, - ...parseLocationAttributes( - organizer, - i18n.language as SupportedLanguage, - organizer.mainLanguage as SupportedLanguage, - ), + ...locationAttributes, }; }; diff --git a/src/types/Organizer.ts b/src/types/Organizer.ts index 36833b87e..0ba72a029 100644 --- a/src/types/Organizer.ts +++ b/src/types/Organizer.ts @@ -20,6 +20,7 @@ type Organizer = { latitude: number; longitude: number; }; + location?: Address; url?: string; }; From 85e64eaf5e3bbeacf48883de403ca5d40a395aca Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:34:59 +0200 Subject: [PATCH 19/26] Add section title translation --- src/i18n/de.json | 3 ++- src/i18n/fr.json | 3 ++- src/i18n/nl.json | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/i18n/de.json b/src/i18n/de.json index 1c8bb0c7d..628e908e1 100644 --- a/src/i18n/de.json +++ b/src/i18n/de.json @@ -479,7 +479,8 @@ }, "title": { "events": "Stellen Sie sicher, dass Ihr Publikum keine Informationen verpasst", - "places": "Stellen Sie sicher, dass Ihr Publikum keine Informationen verpasst" + "places": "Stellen Sie sicher, dass Ihr Publikum keine Informationen verpasst", + "organizers": "Stellen Sie sicher, dass Ihr Publikum keine Informationen verpasst" }, "title_events": "Machen Sie dieses Ereignis zu etwas Besonderem", "title_places": "Heben Sie diesen Standort hervor" diff --git a/src/i18n/fr.json b/src/i18n/fr.json index 4c037ba18..26b1a5920 100644 --- a/src/i18n/fr.json +++ b/src/i18n/fr.json @@ -481,7 +481,8 @@ }, "title": { "events": "Assurez-vous que votre public ne manque aucune information", - "places": "Assurez-vous que votre public ne manque aucune information" + "places": "Assurez-vous que votre public ne manque aucune information", + "organizers": "Assurez-vous que votre public ne manque aucune information" } }, "footer": { diff --git a/src/i18n/nl.json b/src/i18n/nl.json index 806519b77..36d695c03 100644 --- a/src/i18n/nl.json +++ b/src/i18n/nl.json @@ -481,7 +481,8 @@ }, "title": { "events": "Zorg dat je publiek geen informatie mist", - "places": "Zorg dat je publiek geen informatie mist" + "places": "Zorg dat je publiek geen informatie mist", + "organizers": "Zorg dat je publiek geen informatie mist" } }, "footer": { From 2441e260716412877321945c56c9f7c04703fa76 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:37:32 +0200 Subject: [PATCH 20/26] Rename OfferScore to FormScore to match broader usage --- .../AdditionalInformationStep/AdditionalInformationStep.tsx | 4 ++-- .../{OfferScore.tsx => FormScore.tsx} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/pages/steps/AdditionalInformationStep/{OfferScore.tsx => FormScore.tsx} (98%) diff --git a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx index 0e6aebf50..80d21968f 100644 --- a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx @@ -22,7 +22,7 @@ import { BookingInfoStep } from './BookingInfoStep'; import { ContactInfoStep } from './ContactInfoStep'; import { DescriptionStep } from './DescriptionStep'; import { MediaStep } from './MediaStep'; -import { OfferScore } from './OfferScore'; +import { FormScore } from './FormScore'; import { OrganizerStep } from './OrganizerStep'; import { PriceInformation } from './PriceInformation'; import { PhysicalLocationStep } from '@/pages/steps/AdditionalInformationStep/PhysicalLocationStep'; @@ -296,7 +296,7 @@ const AdditionalInformationStep = ({ }, )} - { const minimumScore = getMinimumScore(); -const OfferScore = ({ completedFields, offerId, scope, ...props }: Props) => { +const FormScore = ({ completedFields, offerId, scope, ...props }: Props) => { const { t } = useTranslation(); const router = useRouter(); @@ -282,4 +282,4 @@ const OfferScore = ({ completedFields, offerId, scope, ...props }: Props) => { ); }; -export { OfferScore }; +export { FormScore }; From faf1fb747be7645263df1f5992fd5219f0105aa6 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:44:22 +0200 Subject: [PATCH 21/26] Only add 10 points for completed location --- .../AdditionalInformationStep/FormScore.tsx | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/FormScore.tsx b/src/pages/steps/AdditionalInformationStep/FormScore.tsx index 0a31d7bf6..498c9addc 100644 --- a/src/pages/steps/AdditionalInformationStep/FormScore.tsx +++ b/src/pages/steps/AdditionalInformationStep/FormScore.tsx @@ -3,7 +3,7 @@ import { useMemo } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { eventTypesWithNoThemes } from '@/constants/EventTypes'; -import { OfferTypes } from '@/constants/OfferType'; +import { OfferTypes, ScopeTypes } from '@/constants/OfferType'; import { useGetOfferByIdQuery } from '@/hooks/api/offers'; import { Scope } from '@/pages/create/OfferForm'; import { Features, NewFeatureTooltip } from '@/pages/NewFeatureTooltip'; @@ -71,7 +71,9 @@ const BarometerIcon = ({ rotationValue }: { rotationValue: number }) => { ); }; -const scoreWeightMapping = { +type Weights = { [key: string]: { weight: number; mandatory: boolean } }; + +const scoreWeightMapping: Weights = { type: { weight: 12, mandatory: true, @@ -132,24 +134,33 @@ type Props = { completedFields: Record; }; -const getMinimumScore = (): number => { +const getScopeWeights = (scope: Scope): Weights => { + let weights = scoreWeightMapping; + if (scope === ScopeTypes.ORGANIZERS) { + weights.location.weight = 10; + } + + return weights; +}; + +const getMinimumScore = (weights: Weights): number => { let minimumScore = 0; - Object.values(scoreWeightMapping).forEach((scoreWeight) => { + Object.values(weights).forEach((scoreWeight) => { if (scoreWeight.mandatory) minimumScore += scoreWeight.weight; }); return minimumScore; }; -const minimumScore = getMinimumScore(); - const FormScore = ({ completedFields, offerId, scope, ...props }: Props) => { const { t } = useTranslation(); const router = useRouter(); const getOfferByIdQuery = useGetOfferByIdQuery({ id: offerId, scope }); + const weights = getScopeWeights(scope); + const minimumScore = useMemo(() => getMinimumScore(weights), [weights]); // @ts-expect-error const offer: Offer | undefined = getOfferByIdQuery.data; @@ -180,8 +191,8 @@ const FormScore = ({ completedFields, offerId, scope, ...props }: Props) => { const score = useMemo(() => { let completeScore = 0; Object.keys(fullCompletedFields).forEach((field) => { - if (fullCompletedFields[field] && scoreWeightMapping[field]) { - completeScore += scoreWeightMapping[field].weight; + if (fullCompletedFields[field] && weights[field]) { + completeScore += weights[field].weight; } }); @@ -212,11 +223,11 @@ const FormScore = ({ completedFields, offerId, scope, ...props }: Props) => { unCompletedFieldKeys.forEach((fieldKey: string) => { if ( - scoreWeightMapping[fieldKey] && - scoreWeightMapping[fieldKey].weight > highestUncompletedValue.weight + weights[fieldKey] && + weights[fieldKey].weight > highestUncompletedValue.weight ) { highestUncompletedValue = { - weight: scoreWeightMapping[fieldKey].weight, + weight: weights[fieldKey].weight, fieldName: fieldKey, }; } From 3d078d4a130b17bc2a263a92d436ee4a0dbc1275 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:45:10 +0200 Subject: [PATCH 22/26] Linting --- src/hooks/api/organizers.ts | 2 +- src/pages/organizers/create/steps/UrlStep.tsx | 4 ++-- .../AdditionalInformationStep/AdditionalInformationStep.tsx | 6 +++--- src/types/Address.ts | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hooks/api/organizers.ts b/src/hooks/api/organizers.ts index 8e35c231c..66091c60c 100644 --- a/src/hooks/api/organizers.ts +++ b/src/hooks/api/organizers.ts @@ -288,10 +288,10 @@ const useUpdateOrganizerMutation = (configuration: UseMutationOptions = {}) => export { useCreateOrganizerMutation, - useUpdateOrganizerMutation, useDeleteOrganizerByIdMutation, useGetOrganizerByIdQuery, useGetOrganizersByCreatorQuery, useGetOrganizersByQueryQuery, useGetOrganizersByWebsiteQuery, + useUpdateOrganizerMutation, }; diff --git a/src/pages/organizers/create/steps/UrlStep.tsx b/src/pages/organizers/create/steps/UrlStep.tsx index ed7600983..41358b2f5 100644 --- a/src/pages/organizers/create/steps/UrlStep.tsx +++ b/src/pages/organizers/create/steps/UrlStep.tsx @@ -1,3 +1,4 @@ +import { useRouter } from 'next/router'; import { FormEvent, useEffect, useMemo } from 'react'; import { Controller, useWatch } from 'react-hook-form'; import { Trans, useTranslation } from 'react-i18next'; @@ -11,9 +12,8 @@ import { FormElement } from '@/ui/FormElement'; import { Input } from '@/ui/Input'; import { getStackProps, Stack, StackProps } from '@/ui/Stack'; import { getLanguageObjectOrFallback } from '@/utils/getLanguageObjectOrFallback'; -import { prefixUrlWithHttps } from '@/utils/url'; -import { useRouter } from 'next/router'; import { parseOfferId } from '@/utils/parseOfferId'; +import { prefixUrlWithHttps } from '@/utils/url'; type UrlStepProps = StackProps & StepProps; diff --git a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx index 80d21968f..edd9313b4 100644 --- a/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/AdditionalInformationStep.tsx @@ -7,6 +7,8 @@ import { useQueryClient } from 'react-query'; import { OfferType, Scope } from '@/constants/OfferType'; import { useIntersectionObserver } from '@/hooks/useIntersectionObserver'; import { LabelsStep } from '@/pages/steps/AdditionalInformationStep/LabelsStep'; +import { PhysicalLocationStep } from '@/pages/steps/AdditionalInformationStep/PhysicalLocationStep'; +import { Countries } from '@/types/Country'; import type { Values } from '@/types/Values'; import { parseSpacing } from '@/ui/Box'; import { Icon, Icons } from '@/ui/Icon'; @@ -21,12 +23,10 @@ import { StepsConfiguration } from '../Steps'; import { BookingInfoStep } from './BookingInfoStep'; import { ContactInfoStep } from './ContactInfoStep'; import { DescriptionStep } from './DescriptionStep'; -import { MediaStep } from './MediaStep'; import { FormScore } from './FormScore'; +import { MediaStep } from './MediaStep'; import { OrganizerStep } from './OrganizerStep'; import { PriceInformation } from './PriceInformation'; -import { PhysicalLocationStep } from '@/pages/steps/AdditionalInformationStep/PhysicalLocationStep'; -import { Countries } from '@/types/Country'; const getGlobalValue = getValueFromTheme('global'); diff --git a/src/types/Address.ts b/src/types/Address.ts index e05d08ff6..b24e4b88b 100644 --- a/src/types/Address.ts +++ b/src/types/Address.ts @@ -1,6 +1,7 @@ +import { Country } from '@/types/Country'; + import type { SupportedLanguages } from '../i18n'; import type { Values } from './Values'; -import { Country } from '@/types/Country'; type AddressLocality = string; From a1f207daed1b9dd668491affaf868a7ef0e6105d Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Tue, 18 Jul 2023 15:52:31 +0200 Subject: [PATCH 23/26] Update types --- src/pages/organizers/create/OrganizerForm.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/organizers/create/OrganizerForm.tsx b/src/pages/organizers/create/OrganizerForm.tsx index 414b27182..b9185ab41 100644 --- a/src/pages/organizers/create/OrganizerForm.tsx +++ b/src/pages/organizers/create/OrganizerForm.tsx @@ -48,7 +48,7 @@ const configurations = [ shouldShowStep: (form) => form.getValues('nameAndUrl.name') && form.getValues('nameAndUrl.url'), variant: AdditionalInformationStepVariant.ORGANIZER, - name: 'location', + name: 'location' as StepsConfiguration['name'], defaultValue: locationStepConfiguration.defaultValue, }, ]; @@ -108,17 +108,15 @@ const OrganizerForm = (props) => { const updateOrganizerMutation = useUpdateOrganizerMutation(); const upsertOrganizer = async ({ onSuccess }) => { - const mutation = urlOrganizerId - ? updateOrganizerMutation - : createOrganizerMutation; - - let attributes = { + let mutation = createOrganizerMutation; + let attributes: { [key: string]: any } = { name: getValues('nameAndUrl.name'), url: getValues('nameAndUrl.url'), mainLanguage: i18n.language, }; if (urlOrganizerId) { + mutation = updateOrganizerMutation; attributes = { ...attributes, organizerId: urlOrganizerId, From 4b420a90899addc87a8639418caf6d5dc5083105 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Wed, 19 Jul 2023 12:45:49 +0200 Subject: [PATCH 24/26] Fix incorrect weight for description for organizers --- src/pages/steps/AdditionalInformationStep/FormScore.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/steps/AdditionalInformationStep/FormScore.tsx b/src/pages/steps/AdditionalInformationStep/FormScore.tsx index 498c9addc..aaef30961 100644 --- a/src/pages/steps/AdditionalInformationStep/FormScore.tsx +++ b/src/pages/steps/AdditionalInformationStep/FormScore.tsx @@ -138,6 +138,7 @@ const getScopeWeights = (scope: Scope): Weights => { let weights = scoreWeightMapping; if (scope === ScopeTypes.ORGANIZERS) { weights.location.weight = 10; + weights.description.weight = 15; } return weights; From a993230ad184053227c74c42014a694a468f5cd7 Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Wed, 19 Jul 2023 12:47:21 +0200 Subject: [PATCH 25/26] Update query to also get organizers --- src/pages/steps/AdditionalInformationStep/LabelsStep.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx index bc5e9bc0e..6125bcba7 100644 --- a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx @@ -23,6 +23,8 @@ import { getStackProps, Stack, StackProps } from '@/ui/Stack'; import { Text, TextVariants } from '@/ui/Text'; import { getGlobalBorderRadius } from '@/ui/theme'; import { Typeahead } from '@/ui/Typeahead'; +import { useGetEntityByIdAndScope } from '@/hooks/api/scope'; +import { Organizer } from '@/types/Organizer'; type LabelsStepProps = StackProps & TabContentProps; @@ -36,9 +38,9 @@ function LabelsStep({ }: LabelsStepProps) { const { t } = useTranslation(); - const getOfferByIdQuery = useGetOfferByIdQuery({ id: offerId, scope }); + const getEntityByIdQuery = useGetEntityByIdAndScope({ id: offerId, scope }); // @ts-expect-error - const offer: Offer | undefined = getOfferByIdQuery.data; + const entity: Offer | Organizer | undefined = getEntityByIdQuery.data; const ref = useRef(null); @@ -49,7 +51,7 @@ function LabelsStep({ }); const options = labelsQuery.data?.member ?? []; - const [labels, setLabels] = useState(offer?.labels ?? []); + const [labels, setLabels] = useState(entity?.labels ?? []); const addLabelMutation = useAddOfferLabelMutation(); const removeLabelMutation = useRemoveOfferLabelMutation(); From 953c9f6b1f7393592af0549995848bdfb68bf20e Mon Sep 17 00:00:00 2001 From: Emma Fabre Date: Wed, 19 Jul 2023 12:48:24 +0200 Subject: [PATCH 26/26] Linting --- src/pages/steps/AdditionalInformationStep/LabelsStep.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx index 6125bcba7..74abf845d 100644 --- a/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx +++ b/src/pages/steps/AdditionalInformationStep/LabelsStep.tsx @@ -6,14 +6,15 @@ import { UseQueryResult } from 'react-query'; import { useGetLabelsByQuery } from '@/hooks/api/labels'; import { useAddOfferLabelMutation, - useGetOfferByIdQuery, useRemoveOfferLabelMutation, } from '@/hooks/api/offers'; +import { useGetEntityByIdAndScope } from '@/hooks/api/scope'; import { TabContentProps, ValidationStatus, } from '@/pages/steps/AdditionalInformationStep/AdditionalInformationStep'; import { Label, Offer } from '@/types/Offer'; +import { Organizer } from '@/types/Organizer'; import { Alert } from '@/ui/Alert'; import { Badge, BadgeVariants } from '@/ui/Badge'; import { FormElement } from '@/ui/FormElement'; @@ -23,8 +24,6 @@ import { getStackProps, Stack, StackProps } from '@/ui/Stack'; import { Text, TextVariants } from '@/ui/Text'; import { getGlobalBorderRadius } from '@/ui/theme'; import { Typeahead } from '@/ui/Typeahead'; -import { useGetEntityByIdAndScope } from '@/hooks/api/scope'; -import { Organizer } from '@/types/Organizer'; type LabelsStepProps = StackProps & TabContentProps;