From b3b3b8e82738df0fbdb6178f3f8c018828f84e68 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 24 Oct 2025 16:05:42 +0100 Subject: [PATCH 1/6] AccountForm: migrate to ts, no-verify --- .../modules/User/components/{AccountForm.jsx => AccountForm.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename client/modules/User/components/{AccountForm.jsx => AccountForm.tsx} (100%) diff --git a/client/modules/User/components/AccountForm.jsx b/client/modules/User/components/AccountForm.tsx similarity index 100% rename from client/modules/User/components/AccountForm.jsx rename to client/modules/User/components/AccountForm.tsx From 175f29a79a6aaf1334f139fc65e3fd951151b871 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 24 Oct 2025 16:06:00 +0100 Subject: [PATCH 2/6] AccountForm: migrate to ts, no-verify --- client/modules/User/components/AccountForm.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/modules/User/components/AccountForm.tsx b/client/modules/User/components/AccountForm.tsx index 4ef40e4298..e98f7f7b94 100644 --- a/client/modules/User/components/AccountForm.tsx +++ b/client/modules/User/components/AccountForm.tsx @@ -6,6 +6,7 @@ import { Button, ButtonTypes } from '../../../common/Button'; import { validateSettings } from '../../../utils/reduxFormUtils'; import { updateSettings, initiateVerification } from '../actions'; import { apiClient } from '../../../utils/apiClient'; +import {} function asyncValidate(fieldToValidate, value) { if (!value || value.trim().length === 0) { From 949a158ce22b8b98328ae66fdb29a5e98aae50da Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 24 Oct 2025 16:16:11 +0100 Subject: [PATCH 3/6] update asyncValidate --- client/modules/User/components/AccountForm.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/client/modules/User/components/AccountForm.tsx b/client/modules/User/components/AccountForm.tsx index e98f7f7b94..2de9704d21 100644 --- a/client/modules/User/components/AccountForm.tsx +++ b/client/modules/User/components/AccountForm.tsx @@ -6,15 +6,19 @@ import { Button, ButtonTypes } from '../../../common/Button'; import { validateSettings } from '../../../utils/reduxFormUtils'; import { updateSettings, initiateVerification } from '../actions'; import { apiClient } from '../../../utils/apiClient'; -import {} +import type { DuplicateUserCheckQuery } from '../../../../common/types'; -function asyncValidate(fieldToValidate, value) { +function asyncValidate( + fieldToValidate: DuplicateUserCheckQuery['check_type'], + value: string +) { if (!value || value.trim().length === 0) { return ''; } - const queryParams = {}; + const queryParams: DuplicateUserCheckQuery = { + check_type: fieldToValidate + }; queryParams[fieldToValidate] = value; - queryParams.check_type = fieldToValidate; return apiClient .get('/signup/duplicate_check', { params: queryParams }) .then((response) => { From b5e724e74f78db3cf97261da2715126192d00166 Mon Sep 17 00:00:00 2001 From: Claire Peng Date: Fri, 24 Oct 2025 16:30:16 +0100 Subject: [PATCH 4/6] AccountForm: update with types on handlers --- .../modules/User/components/AccountForm.tsx | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/client/modules/User/components/AccountForm.tsx b/client/modules/User/components/AccountForm.tsx index 2de9704d21..0de68e3dc6 100644 --- a/client/modules/User/components/AccountForm.tsx +++ b/client/modules/User/components/AccountForm.tsx @@ -6,7 +6,11 @@ import { Button, ButtonTypes } from '../../../common/Button'; import { validateSettings } from '../../../utils/reduxFormUtils'; import { updateSettings, initiateVerification } from '../actions'; import { apiClient } from '../../../utils/apiClient'; -import type { DuplicateUserCheckQuery } from '../../../../common/types'; +import type { + DuplicateUserCheckQuery, + UpdateSettingsRequestBody +} from '../../../../common/types'; +import type { RootState } from '../../../reducers'; function asyncValidate( fieldToValidate: DuplicateUserCheckQuery['check_type'], @@ -31,25 +35,27 @@ function asyncValidate( function AccountForm() { const { t } = useTranslation(); - const user = useSelector((state) => state.user); + const user = useSelector((state: RootState) => state.user); const dispatch = useDispatch(); - const handleInitiateVerification = (evt) => { + const handleInitiateVerification = ( + evt: React.MouseEvent + ) => { evt.preventDefault(); dispatch(initiateVerification()); }; - function validateUsername(username) { - if (username === user.username) return ''; + function validateUsername(username: DuplicateUserCheckQuery['username']) { + if (username === user.username || !username) return ''; return asyncValidate('username', username); } - function validateEmail(email) { - if (email === user.email) return ''; + function validateEmail(email: DuplicateUserCheckQuery['email']) { + if (email === user.email || !email) return ''; return asyncValidate('email', email); } - function onSubmit(formProps) { + function onSubmit(formProps: UpdateSettingsRequestBody) { return dispatch(updateSettings(formProps)); } @@ -59,11 +65,13 @@ function AccountForm() { validate={validateSettings} onSubmit={onSubmit} > - {({ handleSubmit, submitting, invalid, restart }) => ( + {({ handleSubmit, submitting, invalid, form }) => (
{ - handleSubmit(event).then(restart); + onSubmit={async (event) => { + const result = await handleSubmit(event); + form.restart(); + return result; }} > ) : (