Files
web/apps/scandic-web/components/GuestsRoomsPicker/AdultSelector/index.tsx
Linus Flood 81887c83ff Merged in feat/sw-1245-bw-button-update (pull request #2262)
Feat/sw 1245 - Booking widget - change button text when new values

* feat(sw-1245) - use isDirty to update button text

* Change text only in booking flow

* Revert test code


Approved-by: Michael Zetterberg
2025-06-02 13:37:53 +00:00

52 lines
1.3 KiB
TypeScript

"use client"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"
import Caption from "@/components/TempDesignSystem/Text/Caption"
import Counter from "../Counter"
import styles from "./adult-selector.module.css"
import type { SelectorProps } from "@/types/components/bookingWidget/guestsRoomsPicker"
export default function AdultSelector({
roomIndex = 0,
currentAdults,
}: SelectorProps) {
const name = `rooms.${roomIndex}.adults`
const intl = useIntl()
const adultsLabel = intl.formatMessage({
defaultMessage: "Adults",
})
const { setValue } = useFormContext()
function increaseAdultsCount() {
if (currentAdults < 6) {
setValue(name, currentAdults + 1, { shouldDirty: true })
}
}
function decreaseAdultsCount() {
if (currentAdults > 1) {
setValue(name, currentAdults - 1, { shouldDirty: true })
}
}
return (
<section className={styles.container}>
<Caption color="uiTextHighContrast" type="bold">
{adultsLabel}
</Caption>
<Counter
count={currentAdults}
handleOnDecrease={decreaseAdultsCount}
handleOnIncrease={increaseAdultsCount}
disableDecrease={currentAdults == 1}
disableIncrease={currentAdults == 6}
/>
</section>
)
}