feat: SW-1583 Used constants for strings

This commit is contained in:
Hrishikesh Vaipurkar
2025-03-06 16:23:16 +01:00
parent 23eaa772ea
commit 24bf96df41
12 changed files with 55 additions and 35 deletions

View File

@@ -4,6 +4,8 @@ import { useCallback, useEffect, useRef } from "react"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"
import { REDEMPTION } from "@/constants/booking"
import { ErrorCircleIcon } from "@/components/Icons"
import Checkbox from "@/components/TempDesignSystem/Form/Checkbox"
import Body from "@/components/TempDesignSystem/Text/Body"
@@ -13,7 +15,7 @@ import styles from "./reward-night.module.css"
import type { BookingWidgetSchema } from "@/types/components/bookingWidget"
export function RewardNight() {
export default function RewardNight() {
const intl = useIntl()
const {
setValue,
@@ -23,24 +25,27 @@ export function RewardNight() {
} = useFormContext<BookingWidgetSchema>()
const ref = useRef<HTMLDivElement | null>(null)
const reward = intl.formatMessage({ id: "Book Reward Night" })
const redemptionErr = errors["redemption"]
const redemptionErr = errors[REDEMPTION]
const bookingCode = getValues("bookingCode.value")
const isMultiRoomError = redemptionErr?.message?.indexOf("Multi-room") === 0
const errorInfoColor = isMultiRoomError ? "red" : "blue"
function validateBookingWidget(value: boolean) {
trigger("redemption")
function validateRedemption(value: boolean) {
// Validate redemption as per the rules defined in the schema
trigger(REDEMPTION)
if (value && bookingCode) {
setValue("bookingCode.value", "", { shouldValidate: true })
// Hide the notification popup after 5 seconds by re-triggering validation
// This is kept consistent with location search field error notification timeout
setTimeout(() => {
trigger("redemption")
trigger(REDEMPTION)
}, 5000)
}
}
const resetOnMultiroomError = useCallback(() => {
if (isMultiRoomError) {
setValue("redemption", false, { shouldValidate: true })
setValue(REDEMPTION, false, { shouldValidate: true })
}
}, [isMultiRoomError, setValue])
@@ -68,10 +73,10 @@ export function RewardNight() {
<div ref={ref} onBlur={(e) => closeOnBlur(e.nativeEvent)}>
<Checkbox
hideError
name="redemption"
name={REDEMPTION}
registerOptions={{
onChange: (e) => {
validateBookingWidget(e.target.value)
validateRedemption(e.target.value)
},
}}
>