From 20a192761e7ea9c503d22fb5910ac14105dd1cca Mon Sep 17 00:00:00 2001 From: Jumpy Squirrel Date: Thu, 28 Dec 2023 22:40:17 +0100 Subject: [PATCH] feat(#213): more cleanup --- src/state/reducers/register.ts | 35 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/state/reducers/register.ts b/src/state/reducers/register.ts index 49fb69d..3e37c19 100644 --- a/src/state/reducers/register.ts +++ b/src/state/reducers/register.ts @@ -50,33 +50,30 @@ const transformPersonalInfo = (payload: GetAction, ticketType: 'day' | 'full'): Partial => { + if (state.ticketLevel?.level) { + return { ...state, + ticketLevel: { + level: state.ticketLevel.level, + addons: determineDefaultAddons(ticketType), + } } + } else { + return state + } +} + const registrationInfoReducer = (state: Partial, action: GetAction): Partial => { switch (action.type) { case SubmitForm('register-ticket-type').type: { // here we can force reset ticket addons to defaults (different hidden packages, different defaults) if (action.payload.type === 'day') { // not setting ticketType - it is set when choosing a day - if (state.ticketLevel?.level) { - return { ...state, - ticketLevel: { - level: state.ticketLevel.level, - addons: determineDefaultAddons('day'), - } } - } else { - return state - } + return resetAddonsInState(state, 'day') } - if (state.ticketLevel?.level) { - return { ...state, - ticketLevel: { - level: state.ticketLevel.level, - addons: determineDefaultAddons('full'), - }, - ticketType: { type: action.payload.type! } } - } else { - return { ...state, ticketType: { type: action.payload.type! } } - } + const stateWithAddonsReset = resetAddonsInState(state, 'full') + + return { ...stateWithAddonsReset, ticketType: { type: action.payload.type! } } } case SubmitForm('register-ticket-day').type: