diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59553a7a6c..4a39783065 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,13 +7,12 @@ jobs: name: Test and lint code base runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '18.20.x' - - run: npm install - - run: npm run test - - run: npm run lint - - + - uses: actions/checkout@v2 + - name: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: '18.20.x' + - run: npm install + - run: npm run test + - run: npm run typecheck + - run: npm run lint diff --git a/client/modules/User/components/AccountForm.jsx b/client/modules/User/components/AccountForm.tsx similarity index 83% rename from client/modules/User/components/AccountForm.jsx rename to client/modules/User/components/AccountForm.tsx index 4ef40e4298..0de68e3dc6 100644 --- a/client/modules/User/components/AccountForm.jsx +++ b/client/modules/User/components/AccountForm.tsx @@ -6,14 +6,23 @@ import { Button, ButtonTypes } from '../../../common/Button'; import { validateSettings } from '../../../utils/reduxFormUtils'; import { updateSettings, initiateVerification } from '../actions'; import { apiClient } from '../../../utils/apiClient'; +import type { + DuplicateUserCheckQuery, + UpdateSettingsRequestBody +} from '../../../../common/types'; +import type { RootState } from '../../../reducers'; -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) => { @@ -26,25 +35,27 @@ function asyncValidate(fieldToValidate, value) { 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)); } @@ -54,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; }} > ) : (