Merged in fix/SW-2579-aa-tracking-2-times-bed-sel- (pull request #1932)
Fix: SW-2579 Fixed bed selection triggering twice * Fix: SW-2579 Fixed bed selection triggering twice Approved-by: Tobias Johansson
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { useCallback, useEffect } from "react"
|
import { useCallback, useEffect, useState } from "react"
|
||||||
import { FormProvider, useForm } from "react-hook-form"
|
import { FormProvider, useForm } from "react-hook-form"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -28,6 +28,7 @@ export default function BedType() {
|
|||||||
room: { bedType, bedTypes },
|
room: { bedType, bedTypes },
|
||||||
} = useRoomContext()
|
} = useRoomContext()
|
||||||
const initialBedType = bedType?.roomTypeCode
|
const initialBedType = bedType?.roomTypeCode
|
||||||
|
const [previousBedType, setPreviousBedType] = useState("")
|
||||||
|
|
||||||
const methods = useForm<BedTypeFormSchema>({
|
const methods = useForm<BedTypeFormSchema>({
|
||||||
criteriaMode: "all",
|
criteriaMode: "all",
|
||||||
@@ -57,10 +58,17 @@ export default function BedType() {
|
|||||||
const selectedBedType = methods.watch("bedType")
|
const selectedBedType = methods.watch("bedType")
|
||||||
const handleSubmit = methods.handleSubmit
|
const handleSubmit = methods.handleSubmit
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedBedType) {
|
if (selectedBedType && selectedBedType !== previousBedType) {
|
||||||
handleSubmit(onSubmit)()
|
handleSubmit(onSubmit)()
|
||||||
|
setPreviousBedType(selectedBedType)
|
||||||
}
|
}
|
||||||
}, [selectedBedType, handleSubmit, onSubmit])
|
}, [
|
||||||
|
selectedBedType,
|
||||||
|
previousBedType,
|
||||||
|
handleSubmit,
|
||||||
|
onSubmit,
|
||||||
|
setPreviousBedType,
|
||||||
|
])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
|
|||||||
Reference in New Issue
Block a user