@@ -22,33 +22,39 @@ const StyledInputContainer = styled(Box).attrs({
2222 }
2323`
2424
25- export const LoginModal = ( { isShowing , hide , onLogin } ) =>
26- < Modal show = { isShowing } onHideClick = { hide } >
27- < LoginForm onLogin = { onLogin } />
28- </ Modal >
25+ type LoginFormData = {
26+ email_address : string ,
27+ nickname : string
28+ }
2929
30- export const LoginForm = ( { onLogin } ) => {
31- const [ submitting , setSubmitting ] = useState ( false )
32- const [ loginError , setError ] = useState ( null )
30+ type LoginFormProps = {
31+ onLogin : Function
32+ }
3333
34- const { handleSubmit, register, formState, reset } = useForm ( {
34+ export const LoginForm : React . FunctionComponent < LoginFormProps > = ( { onLogin } ) => {
35+ const [ submitting , setSubmitting ] = useState ( false )
36+ const [ loginError , setError ] = useState < string | null > ( null )
37+ const { handleSubmit, register, formState, reset } = useForm < LoginFormData > ( {
3538 mode : 'onTouched' ,
3639 } )
3740
3841 const { errors, isValid, isDirty } = formState
3942
40- const onSubmit = useCallback ( ( data ) => {
43+ const onSubmit = useCallback ( ( data : LoginFormData ) => {
4144 const { email_address, nickname } = data
42- const registerApi = async ( email_address , nickname ) => {
45+ const registerApi = async ( email_address : string , nickname : string ) => {
4346 try {
4447 await registerUser ( email_address , nickname )
4548 if ( typeof onLogin === 'function' ) {
4649 onLogin ( )
4750 }
4851 } catch ( e ) {
49- setError ( e . message )
5052 // Reset form to mark `isDirty` as false
5153 reset ( { } , { keepValues : true } )
54+ console . error ( e )
55+ if ( e instanceof Error ) {
56+ setError ( e . message )
57+ }
5258 } finally {
5359 setSubmitting ( false )
5460 }
@@ -119,4 +125,14 @@ export const LoginForm = ({ onLogin }) => {
119125 )
120126}
121127
128+ type LoginModalProps = {
129+ isShowing : boolean ,
130+ hide : Function ,
131+ onLogin : Function
132+ }
133+ export const LoginModal : React . FunctionComponent < LoginModalProps > = ( { isShowing, hide, onLogin } ) =>
134+ < Modal show = { isShowing } onHideClick = { hide } >
135+ < LoginForm onLogin = { onLogin } />
136+ </ Modal >
137+
122138export default LoginForm
0 commit comments