Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
red-giant
dashboard
Commits
0137cc38
Commit
0137cc38
authored
3 years ago
by
Defendi Alberto
Browse files
Options
Downloads
Plain Diff
Merge branch 'signUp' into 'dev'
Sign up form setup See merge request
!41
parents
d7fe0406
20c7d864
No related branches found
No related tags found
2 merge requests
!56
Refined auth flow and new website pages.
,
!41
Sign up form setup
Pipeline
#12011
failed
3 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/App.tsx
+46
-23
46 additions, 23 deletions
src/App.tsx
src/components/AuthUser/AuthUser.tsx
+1
-19
1 addition, 19 deletions
src/components/AuthUser/AuthUser.tsx
src/components/AuthUser/SignUpForm/SignUpForm.tsx
+44
-129
44 additions, 129 deletions
src/components/AuthUser/SignUpForm/SignUpForm.tsx
with
91 additions
and
171 deletions
src/App.tsx
+
46
−
23
View file @
0137cc38
import
React
,
{
FC
}
from
'
react
'
;
import
React
,
{
FC
,
useEffect
,
useState
}
from
'
react
'
;
import
{
BrowserRouter
as
Router
,
Switch
,
Route
}
from
'
react-router-dom
'
;
import
{
BrowserRouter
as
Router
,
Switch
,
Route
}
from
'
react-router-dom
'
;
import
{
HomePage
}
from
'
components/HomePage/HomePage
'
;
import
{
HomePage
}
from
'
components/HomePage/HomePage
'
;
import
{
AuthUser
}
from
'
components/AuthUser/AuthUser
'
;
import
{
AuthUser
}
from
'
components/AuthUser/AuthUser
'
;
...
@@ -9,26 +9,49 @@ import { NotFound } from 'components/NotFound/NotFound';
...
@@ -9,26 +9,49 @@ import { NotFound } from 'components/NotFound/NotFound';
import
{
ProfilePage
}
from
'
components/ProfilePage/ProfilePage
'
;
import
{
ProfilePage
}
from
'
components/ProfilePage/ProfilePage
'
;
import
{
Roles
}
from
'
components/api/userRoles
'
;
import
{
Roles
}
from
'
components/api/userRoles
'
;
import
{
Unauthorized
}
from
'
components/Unauthorized/Unauthorized
'
;
import
{
Unauthorized
}
from
'
components/Unauthorized/Unauthorized
'
;
import
axios
from
'
axios
'
;
export
const
App
:
FC
=
()
=>
(
const
configDjangoCookieName
=
():
void
=>
{
<
Router
>
axios
.
defaults
.
xsrfHeaderName
=
'
X-CSRFTOKEN
'
;
<
div
data-testid
=
"App"
>
axios
.
defaults
.
xsrfCookieName
=
'
csrftoken
'
;
<
Switch
>
axios
.
defaults
.
withCredentials
=
true
;
<
Route
path
=
{
NonAuthRoutes
.
auth
}
component
=
{
AuthUser
}
/>
};
<
Route
exact
path
=
{
NonAuthRoutes
.
home
}
component
=
{
LandingPage
}
/>
<
PrivateRoute
export
const
App
:
FC
=
()
=>
{
path
=
{
AuthRoutes
.
dashboard
}
const
[
isCookieFetched
,
setisCookieFetched
]
=
useState
<
string
>
(
''
);
Component
=
{
HomePage
}
configDjangoCookieName
();
requiredRoles
=
{
[
Roles
.
admin
,
Roles
.
operator
,
Roles
.
senior
]
}
useEffect
(()
=>
{
/>
const
fetchCookie
=
async
():
Promise
<
unknown
>
=>
{
<
PrivateRoute
const
response
=
await
axios
(
'
api/web/csrf
'
);
path
=
{
AuthRoutes
.
profile
}
axios
.
defaults
.
headers
.
common
[
'
X-CSRFTOKEN
'
]
=
response
.
data
.
token
;
Component
=
{
ProfilePage
}
sessionStorage
.
setItem
(
'
X-CSRFTOKEN
'
,
response
.
data
.
token
);
requiredRoles
=
{
[
Roles
.
admin
,
Roles
.
operator
,
Roles
.
senior
]
}
sessionStorage
.
setItem
(
'
ROLE
'
,
'
admin
'
);
/>
setisCookieFetched
(
response
.
data
.
token
);
<
Route
path
=
{
NonAuthRoutes
.
unauthorized
}
component
=
{
Unauthorized
}
/>
return
null
;
<
Route
component
=
{
NotFound
}
/>
};
</
Switch
>
if
(
!
isCookieFetched
)
fetchCookie
();
</
div
>
},
[]);
</
Router
>
);
return
(
<
Router
>
<
div
data-testid
=
"App"
>
<
Switch
>
<
Route
path
=
{
NonAuthRoutes
.
auth
}
component
=
{
AuthUser
}
/>
<
Route
exact
path
=
{
NonAuthRoutes
.
home
}
component
=
{
LandingPage
}
/>
<
PrivateRoute
path
=
{
AuthRoutes
.
dashboard
}
Component
=
{
HomePage
}
requiredRoles
=
{
[
Roles
.
admin
,
Roles
.
operator
,
Roles
.
senior
]
}
/>
<
PrivateRoute
path
=
{
AuthRoutes
.
profile
}
Component
=
{
ProfilePage
}
requiredRoles
=
{
[
Roles
.
admin
,
Roles
.
operator
,
Roles
.
senior
]
}
/>
<
Route
path
=
{
NonAuthRoutes
.
unauthorized
}
component
=
{
Unauthorized
}
/>
<
Route
component
=
{
NotFound
}
/>
</
Switch
>
</
div
>
</
Router
>
);
};
This diff is collapsed.
Click to expand it.
src/components/AuthUser/AuthUser.tsx
+
1
−
19
View file @
0137cc38
import
React
,
{
FC
,
useEffect
}
from
'
react
'
;
import
React
,
{
FC
}
from
'
react
'
;
import
axios
from
'
axios
'
;
import
Container
from
'
@material-ui/core/Container
'
;
import
Container
from
'
@material-ui/core/Container
'
;
import
{
Route
,
useRouteMatch
}
from
'
react-router-dom
'
;
import
{
Route
,
useRouteMatch
}
from
'
react-router-dom
'
;
import
{
NonAuthRoutes
}
from
'
components/api/routes
'
;
import
{
NonAuthRoutes
}
from
'
components/api/routes
'
;
import
{
SignInForm
}
from
'
components/AuthUser/SignInForm/SignInForm
'
;
import
{
SignInForm
}
from
'
components/AuthUser/SignInForm/SignInForm
'
;
import
{
SignUpForm
}
from
'
components/AuthUser/SignUpForm/SignUpForm
'
;
import
{
SignUpForm
}
from
'
components/AuthUser/SignUpForm/SignUpForm
'
;
const
configDjangoCookieName
=
():
void
=>
{
axios
.
defaults
.
xsrfHeaderName
=
'
X-CSRFTOKEN
'
;
axios
.
defaults
.
xsrfCookieName
=
'
csrftoken
'
;
axios
.
defaults
.
withCredentials
=
true
;
};
export
const
AuthUser
:
FC
=
()
=>
{
export
const
AuthUser
:
FC
=
()
=>
{
const
{
path
}
=
useRouteMatch
();
const
{
path
}
=
useRouteMatch
();
configDjangoCookieName
();
useEffect
(()
=>
{
axios
.
get
(
'
api/web/csrf
'
)
.
then
((
response
)
=>
{
axios
.
defaults
.
headers
.
common
[
'
X-CSRFTOKEN
'
]
=
response
.
data
.
token
;
sessionStorage
.
setItem
(
'
X-CSRFTOKEN
'
,
response
.
data
.
token
);
sessionStorage
.
setItem
(
'
ROLE
'
,
'
admin
'
);
})
.
catch
((
error
)
=>
error
);
},
[]);
return
(
return
(
<
Container
maxWidth
=
"sm"
>
<
Container
maxWidth
=
"sm"
>
<
Route
path
=
{
`
${
path
}${
NonAuthRoutes
.
signIn
}
`
}
component
=
{
SignInForm
}
/>
<
Route
path
=
{
`
${
path
}${
NonAuthRoutes
.
signIn
}
`
}
component
=
{
SignInForm
}
/>
...
...
This diff is collapsed.
Click to expand it.
src/components/AuthUser/SignUpForm/SignUpForm.tsx
+
44
−
129
View file @
0137cc38
...
@@ -8,42 +8,53 @@ import axios from 'axios';
...
@@ -8,42 +8,53 @@ import axios from 'axios';
// TODO: Replace notes with big input field
// TODO: Replace notes with big input field
export
const
SignUpForm
:
FC
=
()
=>
{
export
const
SignUpForm
:
FC
=
()
=>
{
type
FormData
=
{
type
FormData
=
{
user
:
{
username
:
string
;
username
:
string
;
password
:
string
;
password
:
string
;
firstName
:
string
;
firstName
:
string
;
lastName
:
string
;
lastName
:
string
;
email
:
string
;
email
:
string
;
};
phoneNumber
:
number
;
homeAddress
:
{
address
:
string
;
};
memberCardIssuer
:
{
name
:
string
;
};
memberCardNumber
:
number
;
notes
:
string
;
};
};
const
{
control
,
errors
,
handleSubmit
}
=
useForm
<
FormData
>
();
const
defaultValues
:
FormData
=
{
username
:
''
,
password
:
''
,
firstName
:
''
,
lastName
:
''
,
email
:
''
,
};
const
{
control
,
errors
,
handleSubmit
}
=
useForm
<
FormData
>
({
defaultValues
,
});
const
onSubmit
:
SubmitHandler
<
FormData
>
=
(
values
:
FormData
)
=>
{
const
onSubmit
:
SubmitHandler
<
FormData
>
=
(
values
:
FormData
)
=>
{
axios
.
post
(
axios
'
/api/web/seniors/
'
,
.
post
(
{
'
/api/web/seniors/
'
,
user
:
values
.
user
,
{
phone_number
:
values
.
phoneNumber
,
user
:
{
home_address
:
values
.
homeAddress
.
address
,
username
:
'
test
'
,
member_card_issuer
:
values
.
memberCardIssuer
,
password
:
values
.
password
,
notes
:
values
.
notes
,
firstName
:
'
a
'
,
},
lastName
:
'
b
'
,
{
email
:
values
.
email
,
headers
:
{
},
'
Content-Type
'
:
'
application/json
'
,
phone_number
:
'
213432234
'
,
home_address
:
{
address
:
'
test street, 3
'
,
},
member_card_issuer
:
{
name
:
'
test issuer
'
,
},
member_card_number
:
'
33333333333
'
,
},
},
},
{
);
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
},
},
)
.
then
((
res
)
=>
console
.
log
(
res
));
};
};
const
classes
=
useStyles
();
const
classes
=
useStyles
();
...
@@ -54,101 +65,6 @@ export const SignUpForm: FC = () => {
...
@@ -54,101 +65,6 @@ export const SignUpForm: FC = () => {
onSubmit
=
{
handleSubmit
(
onSubmit
)
}
onSubmit
=
{
handleSubmit
(
onSubmit
)
}
data-testid
=
"Form"
data-testid
=
"Form"
>
>
<
InputField
name
=
"firstName"
control
=
{
control
}
rules
=
{
{
validate
:
(
value
:
string
)
=>
/^
[
A-Za-z
]
$/
.
test
(
value
),
required
:
{
value
:
true
,
message
:
'
firstName is not valid
'
,
},
}
}
label
=
"First name"
error
=
{
!!
errors
.
user
?.
firstName
}
errorMessage
=
"Insert firstName"
/>
<
InputField
name
=
"lastName"
control
=
{
control
}
rules
=
{
{
validate
:
(
value
:
string
)
=>
/^
[
A-Za-z
]
$/
.
test
(
value
),
required
:
{
value
:
true
,
message
:
'
lastName is not valid
'
,
},
}
}
label
=
"Last name"
error
=
{
!!
errors
.
user
?.
lastName
}
errorMessage
=
"Insert lastName"
/>
<
InputField
name
=
"phoneNumber"
control
=
{
control
}
rules
=
{
{
required
:
{
value
:
true
,
message
:
'
phoneNumber is not valid
'
,
},
}
}
label
=
"Phone number"
error
=
{
!!
errors
.
phoneNumber
}
errorMessage
=
"Insert phoneNumber"
/>
<
InputField
name
=
"memberCardIssuer"
control
=
{
control
}
rules
=
{
{
validate
:
(
value
:
string
)
=>
/^
[
A-Za-z
]
$/
.
test
(
value
),
required
:
{
value
:
true
,
message
:
'
memberCardIssuer is not valid
'
,
},
}
}
label
=
"Member card issuer"
error
=
{
!!
errors
.
memberCardIssuer
?.
name
}
errorMessage
=
"Insert memberCardIssuer"
/>
<
InputField
name
=
"memberCardNumber"
control
=
{
control
}
rules
=
{
{
required
:
{
value
:
true
,
message
:
'
memberCardNumber is not valid
'
,
},
}
}
label
=
"Card number"
error
=
{
!!
errors
.
memberCardNumber
}
errorMessage
=
"Insert memberCardNumber"
/>
<
InputField
name
=
"address"
control
=
{
control
}
rules
=
{
{
validate
:
(
value
:
string
)
=>
/^
[
A-Za-z
]
$/
.
test
(
value
),
required
:
{
value
:
true
,
message
:
'
address is not valid
'
,
},
}
}
label
=
"Home address"
error
=
{
!!
errors
.
homeAddress
?.
address
}
errorMessage
=
"Insert address"
/>
<
InputField
name
=
"notes"
control
=
{
control
}
label
=
"Notes"
error
=
{
!!
errors
.
notes
}
errorMessage
=
"Insert valid password"
/>
<
InputField
<
InputField
name
=
"email"
name
=
"email"
control
=
{
control
}
control
=
{
control
}
...
@@ -161,7 +77,7 @@ export const SignUpForm: FC = () => {
...
@@ -161,7 +77,7 @@ export const SignUpForm: FC = () => {
},
},
}
}
}
}
label
=
"Email"
label
=
"Email"
error
=
{
!!
errors
.
user
?.
email
}
error
=
{
!!
errors
.
email
}
errorMessage
=
"Insert email"
errorMessage
=
"Insert email"
/>
/>
...
@@ -177,10 +93,9 @@ export const SignUpForm: FC = () => {
...
@@ -177,10 +93,9 @@ export const SignUpForm: FC = () => {
},
},
}
}
}
}
label
=
"Password"
label
=
"Password"
error
=
{
!!
errors
.
user
?.
password
}
error
=
{
!!
errors
.
password
}
errorMessage
=
"Insert valid password"
errorMessage
=
"Insert valid password"
/>
/>
<
Button
<
Button
data-testid
=
"Submit"
data-testid
=
"Submit"
type
=
"submit"
type
=
"submit"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment