Skip to content

Commit

Permalink
Trim registration data
Browse files Browse the repository at this point in the history
  • Loading branch information
camilovegag committed May 22, 2024
1 parent a85dd82 commit 3e03aed
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/berlin/src/pages/Register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,30 @@ 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<string, string>,
);

const registrationData = Object.entries(filteredValues).map(([key, value]) => ({
registrationFieldId: key,
value: value || '',
}));

if (props.mode === 'edit') {
updateRegistrationData({
registrationId: props.registrationId || '',
body: {
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 {
Expand All @@ -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,
},
});
}
Expand Down

0 comments on commit 3e03aed

Please sign in to comment.