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
26 changes: 22 additions & 4 deletions src/components/FormUpdate/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React from 'react';
import { useParams } from 'react-router-dom';
import React, { useCallback } from 'react';
import { useHistory, useParams } from 'react-router-dom';

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';
import { Container, SectionButton } from './styles';

interface FormUpdateProps {
emailIsNotAllowed?: boolean;
handleSubmit: any;
formRef: any;
hasPasswordField?: boolean;
goBackEnabled?: boolean;
buttonText?: string;
inviteInfo: { name: string; email: string };
user?: {
id: string;
Expand All @@ -37,12 +39,19 @@ function FormUpdate({
formRef,
inviteInfo,
hasPasswordField,
goBackEnabled,
buttonText,
user,
}: FormUpdateProps) {
const history = useHistory();
const params = useParams<ParamsProps>();

const paramsEmail = params.email;

const handleGoBack = useCallback(() => {
history.goBack();
}, [history]);

return (
<Container>
<Form onSubmit={handleSubmit} ref={formRef} className="Content">
Expand Down Expand Up @@ -106,7 +115,14 @@ function FormUpdate({
)}
</div>

<Button color="var(--green)">Cadastrar</Button>
<SectionButton>
{goBackEnabled && (
<Button color="var(--gray)" onClick={handleGoBack}>
Voltar
</Button>
)}
<Button color="var(--green)">{buttonText || 'Cadastrar'}</Button>
</SectionButton>
</Form>
</Container>
);
Expand All @@ -115,6 +131,8 @@ function FormUpdate({
FormUpdate.defaultProps = {
emailIsNotAllowed: false,
hasPasswordField: false,
goBackEnabled: false,
buttonText: '',
user: {
name: '',
email: '',
Expand Down
14 changes: 14 additions & 0 deletions src/components/FormUpdate/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@ export const Container = styled.div`
}
}
`;

export const SectionButton = styled.section`
width: 100%;
display: flex;
justify-content: flex-end;
align-items: center;

max-width: 90rem;
padding: 0 35px;

button:nth-child(1) {
margin-right: 2rem;
}
`;
6 changes: 3 additions & 3 deletions src/components/Input/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export const StyledInput = styled.div<Props>`
margin: 0;

h3 {
font-weight: 500;
font-size: ${props => props.Size || '1.5rem'};
font-weight: bold;
font-size: ${props => props.Size};
color: ${props => props.Color || 'var(--black)'};

margin-bottom: 5px;
Expand All @@ -37,7 +37,7 @@ export const StyledInput = styled.div<Props>`
font-weight: ${props => props.weight || '400'};

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

color: ${props => props.Color || 'var(--black)'};
Expand Down
8 changes: 4 additions & 4 deletions src/components/InputForm/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const Container = styled.div<ContainerProps>`
background-color: var(--soft-gray);

border-radius: 1.25rem;
border: 2px solid rgba(206, 207, 208, 0.2);
border: 2px solid rgb(245 245 246);

transition: border-color .3s;
transition: border-color 0.3s;

${props =>
props.isErrored &&
css`
transition: border-color .3s;
transition: border-color 0.3s;
border-color: #c53030;
`}

Expand All @@ -52,7 +52,7 @@ export const Container = styled.div<ContainerProps>`
font-family: Roboto;
font-size: 1.3rem;
font-style: normal;
font-weight: bold;
font-weight: normal;

width: 100%;

Expand Down
14 changes: 14 additions & 0 deletions src/components/Logo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import logoIcon from 'assets/logo.svg';

import * as s from './styles';

const TypextLogo = () => {
return (
<s.Link href="/">
<s.Image src={logoIcon} alt="logo" />
</s.Link>
);
};

export default TypextLogo;
8 changes: 8 additions & 0 deletions src/components/Logo/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import styled from 'styled-components';

export const Link = styled.a``;

export const Image = styled.img`
width: 18.125rem;
height: 3.125rem;
`;
1 change: 0 additions & 1 deletion src/components/Select/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ export const StyledSelect = styled.div<Props>`
max-width: ${props => props.SelectWidth || '23.75rem'};
width: 100%;
}

`;
6 changes: 4 additions & 2 deletions src/pages/Invite/components/Select/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const Container = styled.div<ContainerProps>`
display: flex;
flex-direction: column;
width: 100%;
max-width: 41.875rem;
max-width: 40rem;
position: relative;

.inputSelect {
Expand All @@ -24,6 +24,7 @@ export const Container = styled.div<ContainerProps>`
font-style: normal;
font-weight: 500;
font-size: 2rem;
color: var(--black);

width: 100%;
display: flex;
Expand All @@ -39,6 +40,7 @@ export const Container = styled.div<ContainerProps>`
background-color: var(--soft-gray);
border-radius: 1.25rem;
width: 100%;
max-width: 40rem;
height: 4.063rem;

display: flex;
Expand Down Expand Up @@ -73,7 +75,7 @@ export const SelectContainer = styled.ul`
position: absolute;
list-style: none;
width: 100%;
max-width: 41.875rem;
max-width: 40rem;
margin-top: 6rem;
background: #f5f5f6;
border-radius: 0 0 12px 12px;
Expand Down
74 changes: 39 additions & 35 deletions src/pages/Invite/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React, { useState, useCallback } from 'react';
import { message } from 'antd';
import React, { useRef, useState, useCallback } from 'react';
import * as Yup from 'yup';
import { Form } from '@unform/web';
import { FormHandles } from '@unform/core';

import { useAuth } from 'contexts/auth';
import getValidationErrors from 'utils/getValidationErrors';

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

Expand All @@ -14,31 +17,40 @@ import InviteConfirmationModal from './components/InviteConfirmationModal';
function InviteUsers() {
const { inviteUser } = useAuth();

const formRef = useRef<FormHandles>(null);

const [openInvitationModal, setOpenInvitationModal] = useState<boolean>(
false,
);

const [userPermission, setUserPermission] = useState<string>('Usuário');
const [userName, setUserName] = useState<string>('');
const [userEmail, setUserEmail] = useState<string>('');

const handleInviteUser = useCallback(
e => {
e.preventDefault();

if (!userName || !userEmail) {
message.error('Todos os campos devem estar preenchidos');
return;
async (data: { name: string; email: string }) => {
try {
formRef.current?.setErrors({});

const schema = Yup.object().shape({
email: Yup.string()
.required('O email é obrigatório')
.email('Digite um email valído'),
name: Yup.string().required('O nome é obrigatório'),
});

await schema.validate(data, { abortEarly: false });

setOpenInvitationModal(true);
inviteUser({
name: data.name,
email: data.email,
type: userPermission,
});
} catch (err) {
const errors = getValidationErrors(err);
formRef.current?.setErrors(errors);
}

setOpenInvitationModal(true);
inviteUser({
name: userName,
email: userEmail,
type: userPermission,
});
},
[inviteUser, userName, userEmail, userPermission],
[inviteUser, userPermission],
);

return (
Expand All @@ -50,22 +62,14 @@ function InviteUsers() {
<StyleInviteUsers>
<h1>Convidar Participante</h1>

<form className="emailAndPermission" onSubmit={handleInviteUser}>
<Input
title="Nome"
color="black"
Size="large"
styleWidth="41.875rem"
onChange={event => setUserName(event.target.value)}
/>
<Form
ref={formRef}
className="emailAndPermission"
onSubmit={handleInviteUser}
>
<InputForm title="Nome" name="name" color="black" />

<Input
title="E-mail"
color="black"
Size="large"
styleWidth="41.875rem"
onChange={event => setUserEmail(event.target.value)}
/>
<InputForm title="E-mail" name="email" color="black" />

<Select
title="Nível de permissão"
Expand All @@ -81,7 +85,7 @@ function InviteUsers() {
>
Convidar
</Button>
</form>
</Form>
</StyleInviteUsers>
</>
);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Invite/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const StyleInviteUsers = styled.div`

margin: 6rem 0;

input {
margin-bottom: 2rem;
> div {
margin: 1rem 0;
}

.input-styled h3 {
Expand Down
7 changes: 2 additions & 5 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { FormHandles } from '@unform/core';

import { useAuth } from 'contexts/auth';
import getValidationErrors from 'utils/getValidationErrors';

import InputForm from 'components/InputForm';
import Button from 'components/Button/Button';
import Logo from 'assets/logo.svg';
import TypextLogo from 'components/Logo';
import { getUserToken } from 'services/auth';

import loginSchema from './loginSchema';
Expand Down Expand Up @@ -93,9 +92,7 @@ function Login() {
<>
<Content>
<Form onSubmit={handleSubmit} ref={formRef} className="Login">
<a href="/#">
<img src={Logo} alt="Logo" />
</a>
<TypextLogo />

<div className="EmailPassword">
<InputForm name="email" title="E-mail" />
Expand Down
20 changes: 6 additions & 14 deletions src/pages/Login/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,24 @@ const Content = styled.div`

width: 100%;
height: 100%;
padding: 30px;
padding: 4rem;

.Login {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;

&,
width: 100%;
height: 100%;

.EmailPassword,
.LoginPassForgot {
width: 100%;
max-width: 40rem;
}

a {
width: 18.125rem;
height: 3.125rem;

img {
width: 18.125rem;
height: 3.125rem;
}
}

.EmailPassword {
margin: 10rem;
margin: 14rem 0 2rem 0;

display: flex;
flex-direction: column;
Expand All @@ -53,6 +44,7 @@ const Content = styled.div`

Button {
width: 14.063rem;
margin: 2rem 0;
}

a {
Expand Down
Loading