feat: SW-276 Updated plurals for labels
This commit is contained in:
@@ -15,21 +15,20 @@ import styles from "./guests-rooms-picker.module.css"
|
||||
export default function GuestsRoomsPickerForm() {
|
||||
const intl = useIntl()
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const guestsData = guestsRoomsStore().rooms
|
||||
const { adultCount, childCount, setIsValidated } = guestsRoomsStore()
|
||||
const { rooms, adultCount, childCount, setIsValidated } = guestsRoomsStore()
|
||||
const ref = useRef<HTMLDivElement | null>(null)
|
||||
function handleOnClick() {
|
||||
setIsOpen((prevIsOpen) => !prevIsOpen)
|
||||
}
|
||||
const closePicker = useCallback(() => {
|
||||
const guestRoomsValidData = guestRoomsSchema.safeParse(guestsData)
|
||||
const guestRoomsValidData = guestRoomsSchema.safeParse(rooms)
|
||||
if (guestRoomsValidData.success) {
|
||||
setIsOpen(false)
|
||||
setIsValidated(false)
|
||||
} else {
|
||||
setIsValidated(true)
|
||||
}
|
||||
}, [guestsData, setIsValidated, setIsOpen])
|
||||
}, [rooms, setIsValidated, setIsOpen])
|
||||
|
||||
useEffect(() => {
|
||||
function handleClickOutside(evt: Event) {
|
||||
@@ -44,27 +43,26 @@ export default function GuestsRoomsPickerForm() {
|
||||
}
|
||||
}, [closePicker])
|
||||
|
||||
const selectedRoomsCount = guestsData.length
|
||||
|
||||
const childCountLabel =
|
||||
childCount > 1
|
||||
? intl.formatMessage({ id: "Children" })
|
||||
: intl.formatMessage({ id: "Child" })
|
||||
|
||||
return (
|
||||
<div className={styles.container} data-isopen={isOpen} ref={ref}>
|
||||
<button className={styles.btn} onClick={handleOnClick} type="button">
|
||||
<Body className={styles.body}>
|
||||
{selectedRoomsCount}{" "}
|
||||
{selectedRoomsCount > 1
|
||||
? intl.formatMessage({ id: "Rooms" })
|
||||
: intl.formatMessage({ id: "Room" })}
|
||||
{intl.formatMessage(
|
||||
{ id: "booking.rooms" },
|
||||
{ totalRooms: rooms.length }
|
||||
)}
|
||||
{", "}
|
||||
{adultCount}{" "}
|
||||
{adultCount > 1
|
||||
? intl.formatMessage({ id: "Adults" })
|
||||
: intl.formatMessage({ id: "Adult" })}
|
||||
{childCount > 0 ? ", " + childCount + " " + childCountLabel : null}
|
||||
{intl.formatMessage(
|
||||
{ id: "booking.adults" },
|
||||
{ totalAdults: adultCount }
|
||||
)}
|
||||
{childCount > 0
|
||||
? ", " +
|
||||
intl.formatMessage(
|
||||
{ id: "booking.children" },
|
||||
{ totalChildren: childCount }
|
||||
)
|
||||
: null}
|
||||
</Body>
|
||||
</button>
|
||||
<div aria-modal className={styles.hideWrapper} role="dialog">
|
||||
|
||||
Reference in New Issue
Block a user