Merged in feat/SW-1879-aa-tracking-bed-breakfastpayment (pull request #1789)
feat: SW-1879 Tracking enter-details sections * feat: SW-1879 Tracking enter-details sections * feat: SW-1879 removed onSelect to trigger in onSubmit * feat: SW-1879 Removed onSelect and triggered inside onSubmit * feat: SW-1879 Optimized to remove unnecessary useEffect triggers in every re-render * feat: SW-1879 Updated breakfast package typings * feat: SW-1879 Reverted RadioCardProps * feat: SW-1879 Optimised code Approved-by: Tobias Johansson Approved-by: Christian Andolf
This commit is contained in:
@@ -14,6 +14,7 @@ import RadioCard from "@/components/TempDesignSystem/Form/RadioCard"
|
||||
import Body from "@/components/TempDesignSystem/Text/Body"
|
||||
import { useRoomContext } from "@/contexts/Details/Room"
|
||||
import { formatPrice } from "@/utils/numberFormatting"
|
||||
import { trackBreakfastSelection } from "@/utils/tracking"
|
||||
|
||||
import { breakfastFormSchema } from "./schema"
|
||||
|
||||
@@ -25,6 +26,7 @@ import { BreakfastPackageEnum } from "@/types/enums/breakfast"
|
||||
export default function Breakfast() {
|
||||
const intl = useIntl()
|
||||
const packages = useEnterDetailsStore((state) => state.breakfastPackages)
|
||||
const hotelId = useEnterDetailsStore((state) => state.booking.hotelId)
|
||||
const {
|
||||
actions: { updateBreakfast },
|
||||
room,
|
||||
@@ -49,22 +51,26 @@ export default function Breakfast() {
|
||||
|
||||
const onSubmit = useCallback(
|
||||
(values: BreakfastFormSchema) => {
|
||||
const pkg = packages?.find((p) => p.code === values.breakfast)
|
||||
const pkg = packages.find((p) => p.code === values.breakfast)
|
||||
if (pkg) {
|
||||
updateBreakfast(pkg)
|
||||
} else {
|
||||
updateBreakfast(false)
|
||||
}
|
||||
trackBreakfastSelection({
|
||||
breakfastPackage: pkg ?? packages[0],
|
||||
hotelId,
|
||||
units: pkg ? room.adults : 0,
|
||||
})
|
||||
},
|
||||
[packages, updateBreakfast]
|
||||
[packages, hotelId, room.adults, updateBreakfast]
|
||||
)
|
||||
|
||||
const selectedBreakfast = methods.watch("breakfast")
|
||||
const handleSubmit = methods.handleSubmit
|
||||
useEffect(() => {
|
||||
if (methods.formState.isSubmitting) {
|
||||
return
|
||||
}
|
||||
methods.watch(() => methods.handleSubmit(onSubmit)())
|
||||
}, [methods, onSubmit])
|
||||
handleSubmit(onSubmit)()
|
||||
}, [selectedBreakfast, handleSubmit, onSubmit])
|
||||
|
||||
return (
|
||||
<FormProvider {...methods}>
|
||||
|
||||
Reference in New Issue
Block a user