|
1 | 1 | import * as React from "react";
|
2 | 2 | import { zodResolver } from "@hookform/resolvers/zod";
|
3 | 3 | import { useQuery } from "@tanstack/react-query";
|
4 |
| -import { useForm, type FormState, type UseFormRegister } from "react-hook-form"; |
| 4 | +import { |
| 5 | + useForm, |
| 6 | + useWatch, |
| 7 | + type FormState, |
| 8 | + type UseFormRegister, |
| 9 | +} from "react-hook-form"; |
5 | 10 | import { useTranslation } from "react-i18next";
|
6 | 11 | import { useAuth } from "react-oidc-context";
|
7 | 12 |
|
@@ -84,38 +89,23 @@ export const RatesStage = (props: RatesStageProps) => {
|
84 | 89 | }, [rate]),
|
85 | 90 | });
|
86 | 91 |
|
87 |
| - React.useEffect(() => { |
88 |
| - if (rate) { |
89 |
| - form.reset(rate); |
90 |
| - } |
91 |
| - }, [form, rate, rate?.rateName, rateName]); |
92 |
| - |
93 |
| - const isDayRate = React.useMemo( |
94 |
| - () => form.watch("isDayRate"), |
95 |
| - // eslint-disable-next-line react-compiler/react-compiler |
96 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
97 |
| - [form.watch("isDayRate")] |
98 |
| - ); |
99 |
| - const isWeekDayRate = React.useMemo( |
100 |
| - () => form.watch("isDayWeek"), |
101 |
| - // eslint-disable-next-line react-compiler/react-compiler |
102 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
103 |
| - [form.watch("isDayWeek")] |
104 |
| - ); |
| 92 | + const isDayRate = useWatch({ control: form.control, name: "isDayRate" }); |
| 93 | + const isWeekDayRate = useWatch({ control: form.control, name: "isDayWeek" }); |
| 94 | + const totalDays = useWatch({ control: form.control, name: "totalDays" }); |
105 | 95 |
|
106 |
| - const totalDays = React.useMemo( |
107 |
| - () => form.watch("totalDays"), |
108 |
| - // eslint-disable-next-line react-compiler/react-compiler |
109 |
| - // eslint-disable-next-line react-hooks/exhaustive-deps |
110 |
| - [form.watch("totalDays")] |
111 |
| - ); |
112 | 96 | const rentalDays = totalDays ?? 0;
|
113 | 97 |
|
114 | 98 | const commonFormProps: CommonRatesFormProps = {
|
115 | 99 | registerFn: form.register,
|
116 | 100 | formState: form.formState,
|
117 | 101 | };
|
118 | 102 |
|
| 103 | + React.useEffect(() => { |
| 104 | + if (rate) { |
| 105 | + form.reset(rate); |
| 106 | + } |
| 107 | + }, [form, rate, rate?.rateName, rateName]); |
| 108 | + |
119 | 109 | return (
|
120 | 110 | <Form {...form}>
|
121 | 111 | {!isSupportingInfoAvailable && (
|
|
0 commit comments