From 3e03aed420fe7c23bd687ef3fe41eeec2b9f8d50 Mon Sep 17 00:00:00 2001 From: camilovegag Date: Tue, 21 May 2024 23:33:36 -0500 Subject: [PATCH] Trim registration data --- packages/berlin/src/pages/Register.tsx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/berlin/src/pages/Register.tsx b/packages/berlin/src/pages/Register.tsx index 13400b07..42c0ec72 100644 --- a/packages/berlin/src/pages/Register.tsx +++ b/packages/berlin/src/pages/Register.tsx @@ -483,6 +483,22 @@ function RegisterForm(props: { const regGroupId = selectedGroupId || prevSelectGroupId; const client = regGroupId === 'none' ? 'user' : 'group'; + // Filter out empty values + const filteredValues = Object.entries(values).reduce( + (acc, [key, value]) => { + if (value.trim() !== '') { + acc[key] = value.trim(); + } + return acc; + }, + {} as Record, + ); + + const registrationData = Object.entries(filteredValues).map(([key, value]) => ({ + registrationFieldId: key, + value: value || '', + })); + if (props.mode === 'edit') { updateRegistrationData({ registrationId: props.registrationId || '', @@ -490,10 +506,7 @@ function RegisterForm(props: { eventId: props.event?.id || '', groupId: client === 'user' ? null : regGroupId, status: 'DRAFT', - registrationData: Object.entries(values).map(([key, value]) => ({ - registrationFieldId: key, - value: value || '', - })), + registrationData: registrationData, }, }); } else { @@ -502,10 +515,7 @@ function RegisterForm(props: { eventId: props.event?.id || '', groupId: client === 'user' ? null : regGroupId, status: 'DRAFT', - registrationData: Object.entries(values).map(([key, value]) => ({ - registrationFieldId: key, - value: value || '', - })), + registrationData: registrationData, }, }); }