diff --git a/src/components/AuthUser/ChoseRole/ChoseRole.test.tsx b/src/components/AuthUser/ChoseRole/ChoseRole.test.tsx new file mode 100644 index 0000000000000000000000000000000000000000..0f885e7fb9a7fbc97a7c9b0872ead5b8a3270682 --- /dev/null +++ b/src/components/AuthUser/ChoseRole/ChoseRole.test.tsx @@ -0,0 +1,10 @@ +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(); + }); +}); diff --git a/src/components/AuthUser/ChoseRole/ChoseRole.tsx b/src/components/AuthUser/ChoseRole/ChoseRole.tsx new file mode 100644 index 0000000000000000000000000000000000000000..a100cbf3c255b465611f1ee3df250b35aafa19f1 --- /dev/null +++ b/src/components/AuthUser/ChoseRole/ChoseRole.tsx @@ -0,0 +1,39 @@ +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> + ); +};