From a4a307a548bc56f28f0572cd68c8b9122f491228 Mon Sep 17 00:00:00 2001 From: Diego Alzate Date: Tue, 21 May 2024 12:34:35 +0100 Subject: [PATCH] fix initial registration (#537) --- packages/berlin/src/pages/Register.tsx | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/berlin/src/pages/Register.tsx b/packages/berlin/src/pages/Register.tsx index f772c04f..3a4cba6d 100644 --- a/packages/berlin/src/pages/Register.tsx +++ b/packages/berlin/src/pages/Register.tsx @@ -389,6 +389,10 @@ function RegisterForm(props: { const [selectedGroupId, setSelectedGroupId] = useState(''); const prevSelectGroupId = props.groupId ?? 'none'; + // i want to differentiate between when a group is selected and it is not + // so i can show the correct registration fields + // i will use the selectedGroupId to do this + const { register, formState: { errors, isSubmitting }, @@ -409,16 +413,16 @@ function RegisterForm(props: { }, [props.registrationData, reset]); const sortedRegistrationFields = useMemo(() => { - const sortedFields = filterRegistrationFields( - props.registrationFields || [], - selectedGroupId === 'none' ? 'user' : 'group', - ); + const regGroupId = selectedGroupId || prevSelectGroupId; + const client = regGroupId === 'none' ? 'user' : 'group'; + + const sortedFields = filterRegistrationFields(props.registrationFields || [], client); // Sort by field_display_rank in ascending order sortedFields?.sort((a, b) => (a.fieldDisplayRank || 0) - (b.fieldDisplayRank || 0)); return sortedFields; - }, [props.registrationFields, selectedGroupId]); + }, [props.registrationFields, selectedGroupId, prevSelectGroupId]); const redirectToHoldingPage = (isApproved: boolean) => { if (!isApproved) { @@ -476,12 +480,15 @@ function RegisterForm(props: { }); const onSubmit = (values: Record) => { + const regGroupId = selectedGroupId || prevSelectGroupId; + const client = regGroupId === 'none' ? 'user' : 'group'; + if (props.mode === 'edit') { updateRegistrationData({ registrationId: props.registrationId || '', body: { eventId: props.event?.id || '', - groupId: selectedGroupId === 'none' ? null : selectedGroupId, + groupId: client === 'user' ? null : regGroupId, status: 'DRAFT', registrationData: Object.entries(values).map(([key, value]) => ({ registrationFieldId: key, @@ -493,7 +500,7 @@ function RegisterForm(props: { mutateRegistrationData({ body: { eventId: props.event?.id || '', - groupId: selectedGroupId === 'none' ? null : selectedGroupId, + groupId: client === 'user' ? null : regGroupId, status: 'DRAFT', registrationData: Object.entries(values).map(([key, value]) => ({ registrationFieldId: key,