@@ -6,14 +6,21 @@ import { Button, ButtonTypes } from '../../../common/Button';
66import { validateSettings } from '../../../utils/reduxFormUtils' ;
77import { updateSettings , initiateVerification } from '../actions' ;
88import { apiClient } from '../../../utils/apiClient' ;
9+ import {
10+ DuplicateUserCheckQuery ,
11+ UpdateSettingsRequestBody
12+ } from '../../../../common/types' ;
13+ import { RootState } from '../../../reducers' ;
14+ import type { AccountForm as AccountFormType } from '../../../utils/reduxFormUtils' ;
915
10- function asyncValidate ( fieldToValidate , value ) {
16+ function asyncValidate ( fieldToValidate : 'username' | 'email' , value : string ) {
1117 if ( ! value || value . trim ( ) . length === 0 ) {
1218 return '' ;
1319 }
14- const queryParams = { } ;
20+ const queryParams : DuplicateUserCheckQuery = {
21+ check_type : fieldToValidate
22+ } ;
1523 queryParams [ fieldToValidate ] = value ;
16- queryParams . check_type = fieldToValidate ;
1724 return apiClient
1825 . get ( '/signup/duplicate_check' , { params : queryParams } )
1926 . then ( ( response ) => {
@@ -24,27 +31,27 @@ function asyncValidate(fieldToValidate, value) {
2431 } ) ;
2532}
2633
27- function AccountForm ( ) {
34+ export function AccountForm ( ) {
2835 const { t } = useTranslation ( ) ;
29- const user = useSelector ( ( state ) => state . user ) ;
36+ const user = useSelector ( ( state : RootState ) => state . user ) ;
3037 const dispatch = useDispatch ( ) ;
3138
32- const handleInitiateVerification = ( evt ) => {
39+ const handleInitiateVerification = ( evt : React . MouseEvent ) => {
3340 evt . preventDefault ( ) ;
3441 dispatch ( initiateVerification ( ) ) ;
3542 } ;
3643
37- function validateUsername ( username ) {
44+ function validateUsername ( username : AccountFormType [ 'username' ] ) {
3845 if ( username === user . username ) return '' ;
3946 return asyncValidate ( 'username' , username ) ;
4047 }
4148
42- function validateEmail ( email ) {
49+ function validateEmail ( email : AccountFormType [ 'email' ] ) {
4350 if ( email === user . email ) return '' ;
4451 return asyncValidate ( 'email' , email ) ;
4552 }
4653
47- function onSubmit ( formProps ) {
54+ function onSubmit ( formProps : UpdateSettingsRequestBody ) {
4855 return dispatch ( updateSettings ( formProps ) ) ;
4956 }
5057
@@ -54,11 +61,13 @@ function AccountForm() {
5461 validate = { validateSettings }
5562 onSubmit = { onSubmit }
5663 >
57- { ( { handleSubmit, submitting, invalid, restart } ) => (
64+ { ( { handleSubmit, submitting, invalid, form } ) => (
5865 < form
5966 className = "form"
60- onSubmit = { ( event ) => {
61- handleSubmit ( event ) . then ( restart ) ;
67+ onSubmit = { async ( event : React . FormEvent ) => {
68+ const result = await handleSubmit ( event ) ;
69+ form . restart ( ) ;
70+ return result ;
6271 } }
6372 >
6473 < Field
@@ -183,5 +192,3 @@ function AccountForm() {
183192 </ Form >
184193 ) ;
185194}
186-
187- export default AccountForm ;
0 commit comments