Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/components/FormUpdate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { Form } from '@unform/web';

import InputForm from 'components/InputForm';
import Button from 'components/Button/Button';
import Input from 'components/Input/Input';

import { Container } from './styles';

interface FormUpdateProps {
emailIsNotAllowed?: boolean;
handleSubmit: any;
formRef: any;
hasPasswordField?: boolean;
Expand All @@ -30,6 +32,7 @@ interface ParamsProps {
email: string;
}
function FormUpdate({
emailIsNotAllowed,
handleSubmit,
formRef,
inviteInfo,
Expand Down Expand Up @@ -64,12 +67,24 @@ function FormUpdate({
title="Empresa"
/>

<InputForm
name="email"
title="E-mail"
defaultValue={paramsEmail || user?.email || ''}
readOnly={!!paramsEmail}
/>
{emailIsNotAllowed ? (
<Input
name="email"
title="E-mail"
styleWidth="40rem"
color="var(--black);"
weight="bold"
defaultValue={paramsEmail || user?.email || ''}
readOnly={!!paramsEmail}
/>
) : (
<InputForm
name="email"
title="E-mail"
defaultValue={paramsEmail || user?.email || ''}
readOnly={!!paramsEmail}
/>
)}

<InputForm defaultValue={user?.phone} name="phone" title="Telefone" />

Expand Down Expand Up @@ -98,6 +113,7 @@ function FormUpdate({
}

FormUpdate.defaultProps = {
emailIsNotAllowed: false,
hasPasswordField: false,
user: {
name: '',
Expand Down
6 changes: 5 additions & 1 deletion src/components/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StyledInput } from './styles';
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
title: string;
color?: string;
weight?: string;
Size?: string;
styleWidth?: string;
Type?: string;
Expand All @@ -14,6 +15,7 @@ const Input: React.FC<InputProps> = ({
color,
Size,
styleWidth,
weight,
Type,
...rest
}: InputProps) => {
Expand All @@ -22,6 +24,7 @@ const Input: React.FC<InputProps> = ({
InputWidth={styleWidth || '23.75rem'}
Color={color || 'var(--black)'}
Size={Size || '1.5rem'}
weight={weight}
className="input-styled"
>
<h3>{title}</h3>
Expand All @@ -34,8 +37,9 @@ const Input: React.FC<InputProps> = ({
Input.defaultProps = {
Type: '',
Size: '',
weight: '',
styleWidth: '23.75rem',
color: '',
color: 'var(--black)',
};

export default Input;
4 changes: 3 additions & 1 deletion src/components/Input/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Props {
InputWidth: string;
Color: string;
Size: string;
weight?: string;
}

export const StyledInput = styled.div<Props>`
Expand Down Expand Up @@ -33,12 +34,13 @@ export const StyledInput = styled.div<Props>`
font-family: Roboto;
font-size: 1.3rem;
font-style: normal;
font-weight: 400;
font-weight: ${props => props.weight || '400'};

outline: none;
border: 0;
border-radius: 1.25rem;

color: ${props => props.Color || 'var(--black)'};
max-width: ${props => props.InputWidth || '23.75rem'};
width: 100%;
}
Expand Down
16 changes: 14 additions & 2 deletions src/components/Route/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Route as ReactRoute } from 'react-router-dom';
import { Route as ReactRoute, Redirect } from 'react-router-dom';

import { useAuth } from 'contexts/auth';
import Header from 'components/Header';
Expand All @@ -11,15 +11,26 @@ interface RouteProps {
path: string;
exact?: boolean;
isPrivate?: boolean;
onlyAdmin?: boolean;
}

const Route = ({ component: Component, isPrivate, ...rest }: RouteProps) => {
const Route = ({
component: Component,
isPrivate,
onlyAdmin,
...rest
}: RouteProps) => {
const { user: userContext } = useAuth();
const user = getUser();
const userIsAdmin = user?.type === 'Admin';
const userToken = getUserToken();

const userIsAuthenticated = !!user && !!userToken;

if (onlyAdmin && !userIsAdmin) {
return <Redirect to="404" />;
}

return (
<ReactRoute
{...rest}
Expand Down Expand Up @@ -49,6 +60,7 @@ const Route = ({ component: Component, isPrivate, ...rest }: RouteProps) => {

Route.defaultProps = {
exact: false,
onlyAdmin: false,
isPrivate: false,
};

Expand Down
3 changes: 2 additions & 1 deletion src/pages/UserUpdate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useUsers } from 'contexts/user';
import { IUser } from 'DTOs/User';

import getValidationErrors from 'utils/getValidationErrors';
import updateSchemaValidation from 'utils/updateSchemaValidation copy';
import updateSchemaValidation from 'utils/updateSchemaValidation';

import ModalUpdateUser from './ModalUpdateUser';

Expand Down Expand Up @@ -62,6 +62,7 @@ function UserUpdate() {
inviteInfo={inviteInfo}
handleSubmit={handleSubmit}
user={user}
emailIsNotAllowed
/>
</Container>
</>
Expand Down
17 changes: 5 additions & 12 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react';
import { Switch, BrowserRouter } from 'react-router-dom';
import { Switch, BrowserRouter, Redirect } from 'react-router-dom';

import Route from 'components/Route';

import { useAuth } from 'contexts/auth';

import Recovery from 'pages/Recovery';
import UserUpdate from 'pages/UserUpdate';
import ResetPassword from 'pages/ResetPassword';
Expand All @@ -17,9 +15,6 @@ import NotFound from 'pages/NotFound';
import Users from 'pages/Users';

export default function Routes() {
const { user } = useAuth();
const userIsAdmin = user?.type === 'Admin';

return (
<BrowserRouter>
<Switch>
Expand All @@ -33,12 +28,10 @@ export default function Routes() {
<Route path="/invite/:email" component={Register} />
<Route path="/404" component={NotFound} />

{userIsAdmin && (
<>
<Route path="/invite" exact isPrivate component={Invite} />
<Route path="/users" isPrivate component={Users} />
</>
)}
<Route path="/invite" exact isPrivate onlyAdmin component={Invite} />
<Route path="/users" isPrivate onlyAdmin component={Users} />

<Redirect to="/404" />
</Switch>
</BrowserRouter>
);
Expand Down