Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demonstrate the problems by removing my workarounds #252

Draft
wants to merge 1 commit into
base: issue-250-package-multi
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ export type AugmentedAddon = {
}
}[keyof typeof config.addons]

type AddonSelection = {
[key: string]: {
readonly selected?: boolean
}
}

export interface TicketLevelAddonProps {
readonly addon: AugmentedAddon
readonly formContext: ReturnType<typeof useFunnelForm<'register-ticket-level'>>
Expand Down Expand Up @@ -48,7 +42,7 @@ const TicketLevelAddon = ({ addon, formContext }: TicketLevelAddonProps) => {

// skip expensive processing if this addon does not have requirements
if (requirements.length > 0) {
const nonSelectedAddonIds = Object.entries(value.addons as AddonSelection).filter(([, v]) => v.selected === false).map(([k]) => k as string)
const nonSelectedAddonIds = Object.entries(value.addons).filter(([, v]) => !v.selected).map(([k]) => k)

const includedInMissingRequirements = nonSelectedAddonIds.filter(id => requirements.includes(id))

Expand Down
10 changes: 3 additions & 7 deletions src/state/selectors/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,15 @@ export const getPersonalInfo = () => (s: AppState) => isOpen(s.register) ? s.reg
export const getContactInfo = () => (s: AppState) => isOpen(s.register) ? s.register.registration.registrationInfo.contactInfo : undefined
export const getOptionalInfo = () => (s: AppState) => isOpen(s.register) ? s.register.registration.registrationInfo.optionalInfo : undefined

type AddonCountOptions = {
readonly count?: string
}

export const getInvoice = createSelector(getTicketType(), getTicketLevel(), getPaidAmount(), getDueAmount(), (ticketType, ticketLevel, paid, due) => {
if (ticketLevel === undefined || ticketType === undefined) {
return undefined
}

const ticketLevelConfig = config.ticketLevels[ticketLevel.level]

const convertCount = (countOptions: AddonCountOptions): number => {
const code = countOptions.count ?? '1'
const convertCount = (count: string | undefined): number => {
const code = count ?? '1'

const withoutPrefix = code.replace(/^c/u, '')

Expand All @@ -61,7 +57,7 @@ export const getInvoice = createSelector(getTicketType(), getTicketLevel(), getP
.filter(([, addon]) => addon.selected)
.map(([addonId, addon]) => ({
id: `register-ticket-addons-${addonId}`,
amount: convertCount(addon.options as AddonCountOptions),
amount: convertCount(addon.options?.count),
unitPrice: config.ticketLevels[ticketLevel.level].includes?.includes(addonId) ?? false ? 0 : config.addons[addonId].price,
options: addon.options,
}))
Expand Down