Skip to content

Commit 0aaa31e

Browse files
authored
Fix CreateController lint warning (#1317)
1 parent ecb99d0 commit 0aaa31e

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

packages/keychain/src/components/connect/create/CreateController.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,36 @@ export function CreateController({
170170
);
171171

172172
const validation = useUsernameValidation(validationUsername);
173-
// Debounce the validation result rather than the input value
174173
const { debouncedValue: debouncedValidation } = useDebounce(validation, 200);
175174

176-
useEffect(() => {
177-
if (pendingSubmitRef.current && debouncedValidation.status === "valid") {
178-
pendingSubmitRef.current = false;
179-
handleFormSubmit();
180-
}
181-
}, [debouncedValidation.status]);
182-
183175
const { isLoading, error, setError, handleSubmit } = useCreateController({
184176
onCreated,
185177
isSlot,
186178
loginMode,
187179
});
188180

181+
const handleFormSubmit = () => {
182+
if (!usernameField.value) {
183+
return;
184+
}
185+
186+
if (validation.status === "validating") {
187+
pendingSubmitRef.current = true;
188+
return;
189+
}
190+
191+
if (validation.status === "valid") {
192+
handleSubmit(usernameField.value, !!validation.exists);
193+
}
194+
};
195+
196+
useEffect(() => {
197+
if (pendingSubmitRef.current && debouncedValidation.status === "valid") {
198+
pendingSubmitRef.current = false;
199+
handleFormSubmit();
200+
}
201+
}, [debouncedValidation.status, handleFormSubmit]);
202+
189203
const [{ isInApp }] = useState(() => InAppSpy());
190204

191205
useEffect(() => {
@@ -223,21 +237,6 @@ export function CreateController({
223237
setUsernameField((u) => ({ ...u, value: "" }));
224238
};
225239

226-
const handleFormSubmit = () => {
227-
if (!usernameField.value) {
228-
return;
229-
}
230-
231-
if (validation.status === "validating") {
232-
pendingSubmitRef.current = true;
233-
return;
234-
}
235-
236-
if (validation.status === "valid") {
237-
handleSubmit(usernameField.value, !!validation.exists);
238-
}
239-
};
240-
241240
const handleKeyDown = (e: React.KeyboardEvent) => {
242241
if (e.key === "Enter") {
243242
e.preventDefault();

0 commit comments

Comments
 (0)