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:
Hrishikesh Vaipurkar
2025-05-03 09:21:45 +00:00
parent ffb29ddaad
commit e8b17deb52

View File

@@ -1,7 +1,7 @@
"use client"
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 {
@@ -28,6 +28,7 @@ export default function BedType() {
room: { bedType, bedTypes },
} = useRoomContext()
const initialBedType = bedType?.roomTypeCode
const [previousBedType, setPreviousBedType] = useState("")
const methods = useForm<BedTypeFormSchema>({
criteriaMode: "all",
@@ -57,10 +58,17 @@ export default function BedType() {
const selectedBedType = methods.watch("bedType")
const handleSubmit = methods.handleSubmit
useEffect(() => {
if (selectedBedType) {
if (selectedBedType && selectedBedType !== previousBedType) {
handleSubmit(onSubmit)()
setPreviousBedType(selectedBedType)
}
}, [selectedBedType, handleSubmit, onSubmit])
}, [
selectedBedType,
previousBedType,
handleSubmit,
onSubmit,
setPreviousBedType,
])
return (
<FormProvider {...methods}>