Skip to content

Commit bd0a623

Browse files
authored
Merge pull request #551 from PotLock/staging
Staging to prod
2 parents 53031d1 + 532f2a3 commit bd0a623

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/entities/campaign/hooks/forms.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useCallback, useEffect, useMemo } from "react";
1+
import { useCallback, useEffect, useMemo, useRef } from "react";
22

33
import { zodResolver } from "@hookform/resolvers/zod";
44
import { useRouter } from "next/router";
55
import { SubmitHandler, useForm, useWatch } from "react-hook-form";
6+
import { isDeepEqual } from "remeda";
67

78
import { NATIVE_TOKEN_DECIMALS, NATIVE_TOKEN_ID } from "@/common/constants";
89
import { campaignsContractClient } from "@/common/contracts/core/campaigns";
@@ -91,8 +92,15 @@ export const useCampaignForm = ({ campaignId, ftId, onUpdateSuccess }: CampaignF
9192
],
9293
);
9394

95+
// Track previous cross-field errors to prevent infinite loops
96+
const prevCrossFieldErrorsRef = useRef<Record<string, { message: string } | undefined>>({});
97+
9498
useEffect(() => {
95-
const errors: Record<string, { message: string }> = {};
99+
const errors: Record<string, { message: string } | undefined> = {
100+
min_amount: undefined,
101+
max_amount: undefined,
102+
target_amount: undefined,
103+
};
96104

97105
// Validate min_amount vs max_amount
98106
if (parsedMinAmount && parsedMaxAmount && parsedMinAmount > parsedMaxAmount) {
@@ -127,18 +135,27 @@ export const useCampaignForm = ({ campaignId, ftId, onUpdateSuccess }: CampaignF
127135
};
128136
}
129137

138+
// Only update if errors have changed to prevent infinite loops
139+
if (isDeepEqual(prevCrossFieldErrorsRef.current, errors)) {
140+
return;
141+
}
142+
143+
prevCrossFieldErrorsRef.current = errors;
144+
130145
// Clear errors only for fields that are now valid
131-
["min_amount", "max_amount", "target_amount"].forEach((field) => {
146+
(["min_amount", "max_amount", "target_amount"] as const).forEach((field) => {
132147
if (!errors[field]) {
133148
self.clearErrors(field as keyof Values);
134149
}
135150
});
136151

137152
// Set all collected errors
138153
Object.entries(errors).forEach(([field, error]) => {
139-
self.setError(field as keyof Values, error);
154+
if (error) {
155+
self.setError(field as keyof Values, error);
156+
}
140157
});
141-
}, [values, self, parsedMinAmount, parsedMaxAmount, parsedTargetAmount]);
158+
}, [parsedMinAmount, parsedMaxAmount, parsedTargetAmount, self]);
142159

143160
const timeToMilliseconds = (time: number) => {
144161
return new Date(time).getTime();

src/layout/campaign/components/layout.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ const Tabs = ({ options, selectedTab, campaignId }: TabsProps) => {
3838
<Link
3939
key={option.id}
4040
href={`/campaign/${campaignId}?tab=${option.id}`}
41-
shallow
4241
prefetch
4342
className={cn(
4443
"font-500 border-b-solid transition-duration-300 whitespace-nowrap",

0 commit comments

Comments
 (0)