Skip to content

Commit

Permalink
feat(#213): try something
Browse files Browse the repository at this point in the history
  • Loading branch information
Jumpy-Squirrel committed Dec 28, 2023
1 parent dd53260 commit 8fad78c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,18 @@ const config = checkConfig({
price: -15,
default: true, // don't forget to increment version when changing this
options: {},
unavailableFor: {
type: ['day'],
},
hidden: true,
},
'late': {
price: 15,
default: false, // don't forget to increment version when changing this
options: {},
unavailableFor: {
type: ['day'],
},
hidden: true,
},
'dealer-half': {
Expand Down
38 changes: 36 additions & 2 deletions src/state/reducers/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SubmitForm, SubmitFormActionBundle } from '~/state/actions/forms'
import { LoadRegistrationState, SetLocale } from '~/state/actions/register'
import config from '~/config'
import { DateTime } from 'luxon'
import { map } from 'ramda'

export interface ClosedRegisterState {
readonly isOpen: false | null
Expand Down Expand Up @@ -51,8 +52,41 @@ const transformPersonalInfo = (payload: GetAction<SubmitFormActionBundle<'regist

const registrationInfoReducer = (state: Partial<RegistrationInfo>, action: GetAction<AnyAppAction>): Partial<RegistrationInfo> => {
switch (action.type) {
case SubmitForm('register-ticket-type').type:
return action.payload.type === 'day' ? state : { ...state, ticketType: { type: action.payload.type! } }
case SubmitForm('register-ticket-type').type: {
// here we can force reset ticket level 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,
// reset addons
addons: map(addon => ({
selected: addon.default && !(addon.unavailableFor?.type?.includes('day') ?? false),
options: map(option => option.default as never, addon.options),
}), config.addons),
} }
} else {
return state
}
}

if (state.ticketLevel?.level) {
return { ...state,
ticketLevel: {
level: state.ticketLevel.level,
// reset addons
addons: map(addon => ({
selected: addon.default && !(addon.unavailableFor?.type?.includes('full') ?? false),
options: map(option => option.default as never, addon.options),
}), config.addons),
},
ticketType: { type: action.payload.type! } }
} else {
return { ...state, ticketType: { type: action.payload.type! } }
}
}

case SubmitForm('register-ticket-day').type:
return { ...state, ticketType: { type: 'day', day: DateTime.fromISO(action.payload.day!, { zone: 'Europe/Berlin' }) } }
case SubmitForm('register-ticket-level').type:
Expand Down
19 changes: 17 additions & 2 deletions src/state/selectors/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,29 @@ export const getDefaultFormValues = ((id: FormIds) => (s: AppState): FormValuesT
return {
day: null,
}
case 'register-ticket-level':

case 'register-ticket-level': {
const ticketType = getTicketType()(s)

if (ticketType === undefined) {
return {
level: null,
addons: map(addon => ({
selected: addon.default,
options: map(option => option.default as never, addon.options),
}), config.addons),
}
}

return {
level: null,
addons: map(addon => ({
selected: addon.default,
selected: addon.default && !(addon.unavailableFor?.type?.includes(ticketType.type) ?? false),
options: map(option => option.default as never, addon.options),
}), config.addons),
}
}

case 'register-personal-info':
return {
nickname: null,
Expand Down

0 comments on commit 8fad78c

Please sign in to comment.