Skip to content
Snippets Groups Projects
Verified Commit 33ed85e5 authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Chose role prototype.

parent a258e850
No related branches found
No related tags found
2 merge requests!56Refined auth flow and new website pages.,!43Move back cookie fetch to SignInForm. Role fetched and saved into a Context. Small refactorings.
Pipeline #12174 passed
import React from 'react';
import { render } from '@testing-library/react';
import { ChoseRole } from './ChoseRole';
describe('<ChoseRole />', () => {
it('renders without crashing', () => {
const wrapper = render(<ChoseRole />);
expect(wrapper.queryByTestId('ChoseRole')).toBeTruthy();
});
});
import React, { FC, useContext, useEffect, useState } from 'react';
import axios from 'axios';
import Button from '@material-ui/core/Button';
import { AuthContext } from '../AuthContext';
const choseAndForward = (e: unknown): void => {
// Do nothing.
};
/**
* Screen that let's users decide role between available roles.
* This is intended to use when a user has more than one role.
* @returns ChoseRole component.
*/
export const ChoseRole: FC = () => {
const [userRoles, setUserRoles] = useState<Array<string>>(['']);
useEffect(() => {
const getUserRoles = async (): Promise<unknown> => {
const response = await axios('/api/web/get_role');
setUserRoles(response.data.token);
return null;
};
getUserRoles();
}, [userRoles]);
const { role } = useContext(AuthContext);
return (
<div data-testid="ChoseRole">
<Button
variant="outlined"
color="default"
onClick={(e) => choseAndForward(e)}
>
{role}
</Button>
</div>
);
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment