fix: make Bed and Breakfast Accordion texts dynamic based on selection
This commit is contained in:
@@ -11,7 +11,12 @@ import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
|||||||
|
|
||||||
import styles from "./sectionAccordion.module.css"
|
import styles from "./sectionAccordion.module.css"
|
||||||
|
|
||||||
|
import {
|
||||||
|
StepEnum,
|
||||||
|
StepStoreKeys,
|
||||||
|
} from "@/types/components/hotelReservation/enterDetails/step"
|
||||||
import { SectionAccordionProps } from "@/types/components/hotelReservation/selectRate/sectionAccordion"
|
import { SectionAccordionProps } from "@/types/components/hotelReservation/selectRate/sectionAccordion"
|
||||||
|
import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||||
|
|
||||||
export default function SectionAccordion({
|
export default function SectionAccordion({
|
||||||
header,
|
header,
|
||||||
@@ -23,9 +28,27 @@ export default function SectionAccordion({
|
|||||||
const currentStep = useEnterDetailsStore((state) => state.currentStep)
|
const currentStep = useEnterDetailsStore((state) => state.currentStep)
|
||||||
const [isComplete, setIsComplete] = useState(false)
|
const [isComplete, setIsComplete] = useState(false)
|
||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
const isValid = useEnterDetailsStore((state) => state.isValid[step])
|
const isValid = useEnterDetailsStore((state) => state.isValid[step])
|
||||||
const navigate = useEnterDetailsStore((state) => state.navigate)
|
const navigate = useEnterDetailsStore((state) => state.navigate)
|
||||||
|
const stepData = useEnterDetailsStore((state) => state.userData)
|
||||||
|
const stepStoreKey = StepStoreKeys[step]
|
||||||
|
const [title, setTitle] = useState(label)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (step === StepEnum.selectBed) {
|
||||||
|
const value = stepData.bedType
|
||||||
|
value && setTitle(value)
|
||||||
|
}
|
||||||
|
// If breakfast step, check if an option has been selected
|
||||||
|
if (step === StepEnum.breakfast && stepData.breakfast) {
|
||||||
|
const value = stepData.breakfast
|
||||||
|
if (value === BreakfastPackageEnum.NO_BREAKFAST) {
|
||||||
|
setTitle(intl.formatMessage({ id: "No breakfast" }))
|
||||||
|
} else {
|
||||||
|
setTitle(intl.formatMessage({ id: "Breakfast buffet" }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [stepData, stepStoreKey, step, intl])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// We need to set the state on mount because of hydration errors
|
// We need to set the state on mount because of hydration errors
|
||||||
@@ -39,7 +62,6 @@ export default function SectionAccordion({
|
|||||||
function onModify() {
|
function onModify() {
|
||||||
navigate(step)
|
navigate(step)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className={styles.wrapper} data-open={isOpen} data-step={step}>
|
<section className={styles.wrapper} data-open={isOpen} data-step={step}>
|
||||||
<div className={styles.iconWrapper}>
|
<div className={styles.iconWrapper}>
|
||||||
@@ -65,7 +87,7 @@ export default function SectionAccordion({
|
|||||||
className={styles.selection}
|
className={styles.selection}
|
||||||
color="uiTextHighContrast"
|
color="uiTextHighContrast"
|
||||||
>
|
>
|
||||||
{label}
|
{title}
|
||||||
</Subtitle>
|
</Subtitle>
|
||||||
</div>
|
</div>
|
||||||
{isComplete && !isOpen && (
|
{isComplete && !isOpen && (
|
||||||
|
|||||||
@@ -4,3 +4,10 @@ export enum StepEnum {
|
|||||||
details = "details",
|
details = "details",
|
||||||
payment = "payment",
|
payment = "payment",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const StepStoreKeys: Record<StepEnum, "bedType" | "breakfast" | null> = {
|
||||||
|
"select-bed": "bedType",
|
||||||
|
breakfast: "breakfast",
|
||||||
|
details: null,
|
||||||
|
payment: null,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user