@@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react'
22import { Box , Typography , TextField , InputAdornment , Button , Alert , IconButton , CircularProgress } from '@mui/material'
33import '@fontsource/inter/700.css'
44import '@fontsource/inter/400.css'
5- import './App.css'
5+ import './styles/ App.css'
66import { v4 as randomUUID } from 'uuid'
77import { Visibility , VisibilityOff } from '@mui/icons-material'
88import MockHome from './MockHome'
@@ -16,31 +16,31 @@ const Signup = () => {
1616 const [ phonePrefix , setPhonePrefix ] = useState ( GERMANY_PHONE_PREFIX )
1717 const [ emailError , setEmailError ] = useState ( false )
1818 const [ password , setPassword ] = useState ( '' )
19- const [ requestId , setRequestId ] = useState < string | undefined > ( )
20- const [ isAuthenticated , setIsAuthenticated ] = useState < boolean > ( false )
21- const [ verificationResult , setVerificationResult ] = useState < boolean | undefined > ( )
22- const [ signupCompleted , setSignupCompleted ] = useState < boolean | undefined > ( )
23- const [ userAlreadyExists , setUserAlreadyExists ] = useState < boolean > ( false )
2419 const [ showPassword , setShowPassword ] = useState < boolean > ( false )
25- const [ verificationCode , setVerificationCode ] = useState < string > ( '' )
2620 const [ isSubmitting , setIsSubmitting ] = useState < boolean > ( false )
21+ const [ networkRequestId , setNetworkRequestId ] = useState < string | undefined > ( )
22+ const [ isNetworkAuthenticated , setIsNetworkAuthenticated ] = useState < boolean > ( false )
23+ const [ messageVerificationCode , setMessageVerificationCode ] = useState < string > ( '' )
24+ const [ verificationResult , setVerificationResult ] = useState < boolean | undefined > ( )
25+ const [ userAlreadyExists , setUserAlreadyExists ] = useState < boolean > ( false )
26+ const [ signupCompleted , setSignupCompleted ] = useState < boolean | undefined > ( )
2727
28- const authorize = useCallback ( async ( ) => {
29- if ( ! requestId ) return
28+ const networkAuthorize = useCallback ( async ( ) => {
29+ if ( ! networkRequestId ) return
3030 const params = new URLSearchParams ( {
3131 response_type : 'code' ,
3232 client_id : import . meta. env . VITE_CLIENT_ID ,
3333 scope : import . meta. env . VITE_NV_SCOPE ,
3434 redirect_uri : `${ import . meta. env . VITE_BACKEND_URL } /callback` ,
35- state : requestId ! ,
35+ state : networkRequestId ! ,
3636 } )
3737 try {
3838 const response = await fetch ( `${ import . meta. env . VITE_API_GATEWAY } /authorize?${ params . toString ( ) } ` , {
3939 method : 'GET' ,
4040 redirect : 'follow' ,
4141 headers : { 'Content-Type' : 'application/json' }
4242 } )
43- setIsAuthenticated ( response . status === 201 )
43+ setIsNetworkAuthenticated ( response . status === 201 )
4444 if ( ! response . ok ) {
4545 setVerificationResult ( false )
4646 setIsSubmitting ( false )
@@ -49,14 +49,10 @@ const Signup = () => {
4949 setVerificationResult ( false )
5050 setIsSubmitting ( false )
5151 }
52- } , [ requestId ] )
53-
54- const auth = useCallback ( ( ) => {
55- authorize ( )
56- } , [ authorize ] )
52+ } , [ networkRequestId ] )
5753
58- const signup = useCallback ( ( ) => {
59- const params = new URLSearchParams ( requestId ? { state : requestId } : { } )
54+ const performSignup = useCallback ( ( ) => {
55+ const params = new URLSearchParams ( networkRequestId ? { state : networkRequestId } : { } )
6056 setIsSubmitting ( true )
6157 fetch ( `${ import . meta. env . VITE_BACKEND_URL } /signup?${ params . toString ( ) } ` , {
6258 method : 'POST' ,
@@ -84,17 +80,17 @@ const Signup = () => {
8480 setSignupCompleted ( false )
8581 } )
8682 . finally ( ( ) => setIsSubmitting ( false ) )
87- } , [ isPhoneNumber , requestId , userId , phonePrefix , password ] )
83+ } , [ isPhoneNumber , networkRequestId , userId , phonePrefix , password ] )
8884
89- const verifyCode = useCallback ( ( ) => {
90- if ( ! verificationCode . trim ( ) ) return
85+ const verifyMessageVerificationCode = useCallback ( ( ) => {
86+ if ( ! messageVerificationCode . trim ( ) ) return
9187 setIsSubmitting ( true )
9288 fetch ( `${ import . meta. env . VITE_BACKEND_URL } /verify` , {
9389 method : 'POST' ,
9490 headers : { 'Content-Type' : 'application/json' } ,
9591 body : JSON . stringify ( {
9692 id : isPhoneNumber ? `${ phonePrefix } ${ userId . trim ( ) } ` : userId . trim ( ) ,
97- code : verificationCode . trim ( ) ,
93+ code : messageVerificationCode . trim ( ) ,
9894 } )
9995 } )
10096 . then ( async response => {
@@ -112,39 +108,39 @@ const Signup = () => {
112108 setSignupCompleted ( false )
113109 } )
114110 . finally ( ( ) => setIsSubmitting ( false ) )
115- } , [ userId , isPhoneNumber , phonePrefix , verificationCode ] )
111+ } , [ userId , isPhoneNumber , phonePrefix , messageVerificationCode ] )
116112
117113 useEffect ( ( ) => {
118- if ( ! requestId ) return
119- if ( isPhoneNumber && ! isAuthenticated ) {
120- auth ( )
114+ if ( ! networkRequestId ) return
115+ if ( isPhoneNumber && ! isNetworkAuthenticated ) {
116+ networkAuthorize ( )
121117 }
122- if ( ! isPhoneNumber && requestId ) {
123- signup ( )
118+ if ( ! isPhoneNumber && networkRequestId ) {
119+ performSignup ( )
124120 }
125- } , [ requestId , isPhoneNumber , isAuthenticated ] )
121+ } , [ networkRequestId , isPhoneNumber , isNetworkAuthenticated ] )
126122
127123 useEffect ( ( ) => {
128- if ( isAuthenticated ) {
129- signup ( )
124+ if ( isNetworkAuthenticated ) {
125+ performSignup ( )
130126 }
131- } , [ isAuthenticated ] )
127+ } , [ isNetworkAuthenticated ] )
132128
133129 useEffect ( ( ) => {
134- if ( verificationResult === false && requestId && isPhoneNumber ) {
135- signup ( )
130+ if ( verificationResult === false && networkRequestId && isPhoneNumber ) {
131+ performSignup ( )
136132 }
137- } , [ verificationResult , requestId , isPhoneNumber ] )
133+ } , [ verificationResult , networkRequestId , isPhoneNumber ] )
138134
139135 const handleSubmit = ( e : React . FormEvent ) => {
140136 e . preventDefault ( )
141137 setIsSubmitting ( true )
142138 if ( verificationResult === false ) {
143- verifyCode ( )
144- } else if ( ! isAuthenticated && isPhoneNumber ) {
145- setRequestId ( randomUUID ( ) )
139+ verifyMessageVerificationCode ( )
140+ } else if ( ! isNetworkAuthenticated && isPhoneNumber ) {
141+ setNetworkRequestId ( randomUUID ( ) )
146142 } else {
147- signup ( )
143+ performSignup ( )
148144 }
149145 }
150146
@@ -197,12 +193,12 @@ const Signup = () => {
197193 type = "number"
198194 label = "Verification code"
199195 name = "code"
200- value = { verificationCode }
201- onChange = { e => setVerificationCode ( e . target . value ) }
196+ value = { messageVerificationCode }
197+ onChange = { e => setMessageVerificationCode ( e . target . value ) }
202198 fullWidth
203199 margin = "normal"
204200 required
205- error = { verificationCode . trim ( ) . length > 0 && ! / ^ \d + $ / . test ( verificationCode . trim ( ) ) }
201+ error = { messageVerificationCode . trim ( ) . length > 0 && ! / ^ \d + $ / . test ( messageVerificationCode . trim ( ) ) }
206202 />
207203 }
208204 { verificationResult !== false &&
@@ -245,7 +241,7 @@ const Signup = () => {
245241 isSubmitting ||
246242 userId . trim ( ) === '' ||
247243 ( ! isPhoneNumber && password . trim ( ) === '' ) ||
248- ( verificationResult === false && verificationCode . trim ( ) === '' )
244+ ( verificationResult === false && messageVerificationCode . trim ( ) === '' )
249245 }
250246 >
251247 { isSubmitting && < CircularProgress size = { 24 } color = "inherit" /> }
0 commit comments