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
5b0efe8c
Verified
Commit
5b0efe8c
authored
3 years ago
by
Defendi Alberto
Browse files
Options
Downloads
Patches
Plain Diff
Fetch roles from api and forward onClick.
parent
a59bd356
No related branches found
No related tags found
2 merge requests
!56
Refined auth flow and new website pages.
,
!45
Polished auth flow including ReservedRoute and role selection.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/AuthUser/ChoseRole/ChoseRole.tsx
+31
-24
31 additions, 24 deletions
src/components/AuthUser/ChoseRole/ChoseRole.tsx
with
31 additions
and
24 deletions
src/components/AuthUser/ChoseRole/ChoseRole.tsx
+
31
−
24
View file @
5b0efe8c
import
React
,
{
FC
,
useContext
,
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
FC
,
useEffect
,
useState
}
from
'
react
'
;
import
axios
from
'
axios
'
;
import
Button
from
'
@material-ui/core/Button
'
;
import
Button
from
'
@material-ui/core/Button
'
;
import
{
AuthContext
}
from
'
../AuthContext
'
;
import
{
getRoles
}
from
'
api/getRoles
'
;
import
{
setRole
}
from
'
api/setRole
'
;
const
choseAndForward
=
(
e
:
unknown
):
void
=>
{
import
{
useHistory
}
from
'
react-router-dom
'
;
// Do nothing.
import
{
AuthRoutes
}
from
'
api/routes
'
;
};
/**
/**
*
Screen
that let's users decide role between available roles.
*
Page
that let's users decide role between available roles.
* This is intended to use when a user has more than one role.
* This is intended to use when a user has more than one role.
* @returns ChoseRole component.
* @returns ChoseRole component.
*/
*/
export
const
ChoseRole
:
FC
=
()
=>
{
export
const
ChoseRole
:
FC
=
()
=>
{
const
[
userRoles
,
setUserRoles
]
=
useState
<
Array
<
string
>>
([
''
]);
const
history
=
useHistory
();
const
[
userRoles
,
setUserRoles
]
=
useState
<
string
[]
>
([
'
hello
'
,
'
world
'
]);
const
choseAndForward
=
(
role
:
string
):
void
=>
{
// Set role in the server.
setRole
(
role
);
// Push to homepage.
history
.
push
(
`
${
AuthRoutes
.
dashboard
}${
AuthRoutes
.
home
}
`
);
};
useEffect
(()
=>
{
useEffect
(()
=>
{
const
getUserRoles
=
async
():
Promise
<
unknown
>
=>
{
getRoles
().
then
((
fetchedRoles
)
=>
setUserRoles
(
fetchedRoles
));
const
response
=
await
axios
(
'
/api/web/get_role
'
);
},
[]);
setUserRoles
(
response
.
data
.
token
);
return
null
;
};
getUserRoles
();
},
[
userRoles
]);
const
{
role
}
=
useContext
(
AuthContext
);
return
(
return
(
<
div
data-testid
=
"ChoseRole"
>
<
div
data-testid
=
"ChoseRole"
>
<
Button
{
userRoles
?
(
variant
=
"outlined"
userRoles
.
map
((
role
)
=>
(
color
=
"default"
<
Button
onClick
=
{
(
e
)
=>
choseAndForward
(
e
)
}
variant
=
"outlined"
>
color
=
"default"
{
role
}
key
=
{
role
}
</
Button
>
onClick
=
{
()
=>
choseAndForward
(
role
)
}
>
{
role
}
</
Button
>
))
)
:
(
<
h1
>
No roles were returned.
</
h1
>
)
}
</
div
>
</
div
>
);
);
};
};
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