Fix/STAY-135 & STAY-127 * fix: make quantity and delivery separate steps in mobile * fix: update design for delivery step in ancillary flow * fix: add error state for missing time * fix: only allow points or cash payment for ancillaries * fix: break out stepper to design system * fix: update design of select quantity step in add ancillaries flow * fix: add error states for quantity * fix: handle insufficient points case * fix: update stepper to include optional disabledMessage tooltip * fix: handle validations * fix: change name to camel case Approved-by: Bianca Widstam Approved-by: Chuma Mcphoy (We Ahead)
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
"use client"
|
|
|
|
import { useFormContext } from "react-hook-form"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import Caption from "@scandic-hotels/design-system/Caption"
|
|
import Stepper from "@scandic-hotels/design-system/Stepper"
|
|
|
|
import ChildInfoSelector from "./ChildInfoSelector"
|
|
|
|
import styles from "./child-selector.module.css"
|
|
|
|
import type { Child } from "@scandic-hotels/trpc/types/child"
|
|
|
|
type ChildSelectorProps = {
|
|
roomIndex: number
|
|
currentAdults: number
|
|
currentChildren: Child[]
|
|
childrenInAdultsBed: number
|
|
}
|
|
export default function ChildSelector({
|
|
roomIndex = 0,
|
|
currentAdults,
|
|
childrenInAdultsBed,
|
|
currentChildren,
|
|
}: ChildSelectorProps) {
|
|
const intl = useIntl()
|
|
const childrenLabel = intl.formatMessage({
|
|
id: "common.children",
|
|
defaultMessage: "Children",
|
|
})
|
|
const { setValue } = useFormContext()
|
|
|
|
function increaseChildrenCount(roomIndex: number) {
|
|
if (currentChildren.length < 5) {
|
|
setValue(
|
|
`rooms.${roomIndex}.childrenInRoom.${currentChildren.length}`,
|
|
{
|
|
age: undefined,
|
|
bed: undefined,
|
|
},
|
|
{ shouldDirty: true }
|
|
)
|
|
}
|
|
}
|
|
function decreaseChildrenCount(roomIndex: number) {
|
|
if (currentChildren.length > 0) {
|
|
currentChildren.pop()
|
|
setValue(`rooms.${roomIndex}.childrenInRoom`, currentChildren, {
|
|
shouldDirty: true,
|
|
})
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<section className={styles.container}>
|
|
<Caption color="uiTextHighContrast" type="bold">
|
|
{childrenLabel}
|
|
</Caption>
|
|
<Stepper
|
|
count={currentChildren.length}
|
|
handleOnDecrease={() => {
|
|
decreaseChildrenCount(roomIndex)
|
|
}}
|
|
handleOnIncrease={() => {
|
|
increaseChildrenCount(roomIndex)
|
|
}}
|
|
disableDecrease={currentChildren.length == 0}
|
|
disableIncrease={currentChildren.length == 5}
|
|
/>
|
|
</section>
|
|
{currentChildren.map((child, index) => (
|
|
<ChildInfoSelector
|
|
roomIndex={roomIndex}
|
|
index={index}
|
|
child={child}
|
|
adults={currentAdults}
|
|
key={"child_" + index}
|
|
childrenInAdultsBed={childrenInAdultsBed}
|
|
/>
|
|
))}
|
|
</>
|
|
)
|
|
}
|