Skip to content

Commit fbe071d

Browse files
Merge pull request #54 from Typext/develop
Develop
2 parents f65a758 + 764e50a commit fbe071d

File tree

20 files changed

+231
-174
lines changed

20 files changed

+231
-174
lines changed

src/components/FormUpdate/index.tsx

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import React from 'react';
2-
import { useParams } from 'react-router-dom';
1+
import React, { useCallback } from 'react';
2+
import { useHistory, useParams } from 'react-router-dom';
33

44
import { Form } from '@unform/web';
55

66
import InputForm from 'components/InputForm';
77
import Button from 'components/Button/Button';
88
import Input from 'components/Input/Input';
99

10-
import { Container } from './styles';
10+
import { Container, SectionButton } from './styles';
1111

1212
interface FormUpdateProps {
1313
emailIsNotAllowed?: boolean;
1414
handleSubmit: any;
1515
formRef: any;
1616
hasPasswordField?: boolean;
17+
goBackEnabled?: boolean;
18+
buttonText?: string;
1719
inviteInfo: { name: string; email: string };
1820
user?: {
1921
id: string;
@@ -37,12 +39,19 @@ function FormUpdate({
3739
formRef,
3840
inviteInfo,
3941
hasPasswordField,
42+
goBackEnabled,
43+
buttonText,
4044
user,
4145
}: FormUpdateProps) {
46+
const history = useHistory();
4247
const params = useParams<ParamsProps>();
4348

4449
const paramsEmail = params.email;
4550

51+
const handleGoBack = useCallback(() => {
52+
history.goBack();
53+
}, [history]);
54+
4655
return (
4756
<Container>
4857
<Form onSubmit={handleSubmit} ref={formRef} className="Content">
@@ -106,7 +115,14 @@ function FormUpdate({
106115
)}
107116
</div>
108117

109-
<Button color="var(--green)">Cadastrar</Button>
118+
<SectionButton>
119+
{goBackEnabled && (
120+
<Button color="var(--gray)" onClick={handleGoBack}>
121+
Voltar
122+
</Button>
123+
)}
124+
<Button color="var(--green)">{buttonText || 'Cadastrar'}</Button>
125+
</SectionButton>
110126
</Form>
111127
</Container>
112128
);
@@ -115,6 +131,8 @@ function FormUpdate({
115131
FormUpdate.defaultProps = {
116132
emailIsNotAllowed: false,
117133
hasPasswordField: false,
134+
goBackEnabled: false,
135+
buttonText: '',
118136
user: {
119137
name: '',
120138
email: '',

src/components/FormUpdate/styles.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@ export const Container = styled.div`
3636
}
3737
}
3838
`;
39+
40+
export const SectionButton = styled.section`
41+
width: 100%;
42+
display: flex;
43+
justify-content: flex-end;
44+
align-items: center;
45+
46+
max-width: 90rem;
47+
padding: 0 35px;
48+
49+
button:nth-child(1) {
50+
margin-right: 2rem;
51+
}
52+
`;

src/components/Input/styles.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const StyledInput = styled.div<Props>`
1717
margin: 0;
1818
1919
h3 {
20-
font-weight: 500;
21-
font-size: ${props => props.Size || '1.5rem'};
20+
font-weight: bold;
21+
font-size: ${props => props.Size};
2222
color: ${props => props.Color || 'var(--black)'};
2323
2424
margin-bottom: 5px;
@@ -37,7 +37,7 @@ export const StyledInput = styled.div<Props>`
3737
font-weight: ${props => props.weight || '400'};
3838
3939
outline: none;
40-
border: 0;
40+
border: none;
4141
border-radius: 1.25rem;
4242
4343
color: ${props => props.Color || 'var(--black)'};

src/components/InputForm/styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ export const Container = styled.div<ContainerProps>`
3434
background-color: var(--soft-gray);
3535
3636
border-radius: 1.25rem;
37-
border: 2px solid rgba(206, 207, 208, 0.2);
37+
border: 2px solid rgb(245 245 246);
3838
39-
transition: border-color .3s;
39+
transition: border-color 0.3s;
4040
4141
${props =>
4242
props.isErrored &&
4343
css`
44-
transition: border-color .3s;
44+
transition: border-color 0.3s;
4545
border-color: #c53030;
4646
`}
4747
@@ -52,7 +52,7 @@ export const Container = styled.div<ContainerProps>`
5252
font-family: Roboto;
5353
font-size: 1.3rem;
5454
font-style: normal;
55-
font-weight: bold;
55+
font-weight: normal;
5656
5757
width: 100%;
5858

src/components/Logo/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import logoIcon from 'assets/logo.svg';
3+
4+
import * as s from './styles';
5+
6+
const TypextLogo = () => {
7+
return (
8+
<s.Link href="/">
9+
<s.Image src={logoIcon} alt="logo" />
10+
</s.Link>
11+
);
12+
};
13+
14+
export default TypextLogo;

src/components/Logo/styles.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import styled from 'styled-components';
2+
3+
export const Link = styled.a``;
4+
5+
export const Image = styled.img`
6+
width: 18.125rem;
7+
height: 3.125rem;
8+
`;

src/components/Select/styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,4 @@ export const StyledSelect = styled.div<Props>`
3434
max-width: ${props => props.SelectWidth || '23.75rem'};
3535
width: 100%;
3636
}
37-
3837
`;

src/pages/Invite/components/Select/styles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const Container = styled.div<ContainerProps>`
1212
display: flex;
1313
flex-direction: column;
1414
width: 100%;
15-
max-width: 41.875rem;
15+
max-width: 40rem;
1616
position: relative;
1717
1818
.inputSelect {
@@ -24,6 +24,7 @@ export const Container = styled.div<ContainerProps>`
2424
font-style: normal;
2525
font-weight: 500;
2626
font-size: 2rem;
27+
color: var(--black);
2728
2829
width: 100%;
2930
display: flex;
@@ -39,6 +40,7 @@ export const Container = styled.div<ContainerProps>`
3940
background-color: var(--soft-gray);
4041
border-radius: 1.25rem;
4142
width: 100%;
43+
max-width: 40rem;
4244
height: 4.063rem;
4345
4446
display: flex;
@@ -73,7 +75,7 @@ export const SelectContainer = styled.ul`
7375
position: absolute;
7476
list-style: none;
7577
width: 100%;
76-
max-width: 41.875rem;
78+
max-width: 40rem;
7779
margin-top: 6rem;
7880
background: #f5f5f6;
7981
border-radius: 0 0 12px 12px;

src/pages/Invite/index.tsx

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import React, { useState, useCallback } from 'react';
2-
import { message } from 'antd';
1+
import React, { useRef, useState, useCallback } from 'react';
2+
import * as Yup from 'yup';
3+
import { Form } from '@unform/web';
4+
import { FormHandles } from '@unform/core';
35

46
import { useAuth } from 'contexts/auth';
7+
import getValidationErrors from 'utils/getValidationErrors';
58

6-
import Input from 'components/Input/Input';
9+
import InputForm from 'components/InputForm';
710
import Button from 'components/Button/Button';
811
import Select from './components/Select';
912

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

20+
const formRef = useRef<FormHandles>(null);
21+
1722
const [openInvitationModal, setOpenInvitationModal] = useState<boolean>(
1823
false,
1924
);
2025

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

2528
const handleInviteUser = useCallback(
26-
e => {
27-
e.preventDefault();
28-
29-
if (!userName || !userEmail) {
30-
message.error('Todos os campos devem estar preenchidos');
31-
return;
29+
async (data: { name: string; email: string }) => {
30+
try {
31+
formRef.current?.setErrors({});
32+
33+
const schema = Yup.object().shape({
34+
email: Yup.string()
35+
.required('O email é obrigatório')
36+
.email('Digite um email valído'),
37+
name: Yup.string().required('O nome é obrigatório'),
38+
});
39+
40+
await schema.validate(data, { abortEarly: false });
41+
42+
setOpenInvitationModal(true);
43+
inviteUser({
44+
name: data.name,
45+
email: data.email,
46+
type: userPermission,
47+
});
48+
} catch (err) {
49+
const errors = getValidationErrors(err);
50+
formRef.current?.setErrors(errors);
3251
}
33-
34-
setOpenInvitationModal(true);
35-
inviteUser({
36-
name: userName,
37-
email: userEmail,
38-
type: userPermission,
39-
});
4052
},
41-
[inviteUser, userName, userEmail, userPermission],
53+
[inviteUser, userPermission],
4254
);
4355

4456
return (
@@ -50,22 +62,14 @@ function InviteUsers() {
5062
<StyleInviteUsers>
5163
<h1>Convidar Participante</h1>
5264

53-
<form className="emailAndPermission" onSubmit={handleInviteUser}>
54-
<Input
55-
title="Nome"
56-
color="black"
57-
Size="large"
58-
styleWidth="41.875rem"
59-
onChange={event => setUserName(event.target.value)}
60-
/>
65+
<Form
66+
ref={formRef}
67+
className="emailAndPermission"
68+
onSubmit={handleInviteUser}
69+
>
70+
<InputForm title="Nome" name="name" color="black" />
6171

62-
<Input
63-
title="E-mail"
64-
color="black"
65-
Size="large"
66-
styleWidth="41.875rem"
67-
onChange={event => setUserEmail(event.target.value)}
68-
/>
72+
<InputForm title="E-mail" name="email" color="black" />
6973

7074
<Select
7175
title="Nível de permissão"
@@ -81,7 +85,7 @@ function InviteUsers() {
8185
>
8286
Convidar
8387
</Button>
84-
</form>
88+
</Form>
8589
</StyleInviteUsers>
8690
</>
8791
);

src/pages/Invite/styles.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export const StyleInviteUsers = styled.div`
4747
4848
margin: 6rem 0;
4949
50-
input {
51-
margin-bottom: 2rem;
50+
> div {
51+
margin: 1rem 0;
5252
}
5353
5454
.input-styled h3 {

0 commit comments

Comments
 (0)