Skip to content

Commit 080b31b

Browse files
author
justhenrique
committed
Merge branch 'develop' of https://github.com/Typext/typext-frontend into develop
2 parents 4e720b2 + 48d13a8 commit 080b31b

File tree

15 files changed

+323
-128
lines changed

15 files changed

+323
-128
lines changed

src/DTOs/Auth.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { StringifyOptions } from 'node:querystring';
12
import { ReactNode } from 'react';
23

34
export interface AuthState {
@@ -27,7 +28,7 @@ export interface InviteUserCredentials {
2728
}
2829

2930
export interface SignUpCredentials {
30-
token: string;
31+
email: string;
3132
name: string;
3233
password: string;
3334
password_confirmation: string;
@@ -37,6 +38,15 @@ export interface SignUpCredentials {
3738
area: string;
3839
}
3940

41+
export interface RecoveryCredentials {
42+
email: string;
43+
}
44+
45+
export interface ResetCredentials {
46+
password: string;
47+
confirmPassword: string;
48+
}
49+
4050
interface InvitationData {
4151
error: string;
4252
loader: boolean;
@@ -47,6 +57,16 @@ interface RegisterData {
4757
success: boolean;
4858
}
4959

60+
interface RecoveryPassowordData {
61+
error: string;
62+
loader: boolean;
63+
}
64+
65+
interface ResetPasswordData {
66+
error: String;
67+
loader: boolean;
68+
}
69+
5070
export interface AuthContextData {
5171
user: {
5272
id: string;
@@ -61,10 +81,14 @@ export interface AuthContextData {
6181
};
6282
invitation: InvitationData;
6383
register: RegisterData;
84+
recovery: RecoveryPassowordData;
85+
reset: ResetPasswordData;
6486
signIn(crendentials: SignInCredentials): Promise<boolean>;
6587
signUp(crendentials: SignUpCredentials): Promise<void>;
66-
inviteUser(crendentials: InviteUserCredentials): Promise<void>;
6788
signOut(): void;
89+
inviteUser(crendentials: InviteUserCredentials): Promise<void>;
90+
recoveryPassword(crendentials: RecoveryCredentials): Promise<void>;
91+
resetPassword(credentials: ResetCredentials): Promise<void>;
6892
}
6993
export interface AuthProviderProps {
7094
children: ReactNode;

src/assets/shield-icon.svg

Lines changed: 3 additions & 0 deletions
Loading

src/components/FormUpdate/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react';
2+
import { useParams } from 'react-router-dom';
23

34
import { Form } from '@unform/web';
45

56
import InputForm from 'components/InputForm';
67
import Button from 'components/Button/Button';
7-
import Input from 'components/Input/Input';
88

99
import { Container } from './styles';
1010

@@ -26,13 +26,20 @@ interface FormUpdateProps {
2626
};
2727
}
2828

29+
interface ParamsProps {
30+
email: string;
31+
}
2932
function FormUpdate({
3033
handleSubmit,
3134
formRef,
3235
inviteInfo,
3336
hasPasswordField,
3437
user,
3538
}: FormUpdateProps) {
39+
const params = useParams<ParamsProps>();
40+
41+
const paramsEmail = params.email;
42+
3643
return (
3744
<Container>
3845
<Form onSubmit={handleSubmit} ref={formRef} className="Content">
@@ -57,12 +64,11 @@ function FormUpdate({
5764
title="Empresa"
5865
/>
5966

60-
<Input
67+
<InputForm
6168
name="email"
6269
title="E-mail"
63-
styleWidth="40rem"
64-
defaultValue={inviteInfo?.email || user?.phone || ''}
65-
readOnly={!!inviteInfo?.email}
70+
defaultValue={paramsEmail || user?.email || ''}
71+
readOnly={!!paramsEmail}
6672
/>
6773

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

src/contexts/auth.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ const AuthProvider = ({ children }: AuthProviderProps) => {
1414
const [inviteError, setInviteError] = useState<string>('');
1515
const [inviteLoader, setInviteLoader] = useState<boolean>(false);
1616

17+
const [recoveryError, setRecoveryError] = useState<string>('');
18+
const [recoveryLoader, setRecoveryLoader] = useState<boolean>(false);
19+
20+
const [resetError, setResetError] = useState<string>('');
21+
const [resetLoader, setResetLoader] = useState<boolean>(false);
22+
1723
const [data, setData] = useState<AuthState>(() => {
1824
const token = localStorage.getItem('@Typext:token');
1925
const user = localStorage.getItem('@Typext:user');
@@ -108,6 +114,40 @@ const AuthProvider = ({ children }: AuthProviderProps) => {
108114
setInviteLoader(false);
109115
}, []);
110116

117+
const recoveryPassword = useCallback(async ({ email }) => {
118+
setRecoveryLoader(true);
119+
120+
try {
121+
setRecoveryError('');
122+
123+
await api.post('/password/forgot', {
124+
email,
125+
});
126+
} catch (err) {
127+
setRecoveryError(err.response?.data.message);
128+
}
129+
130+
setRecoveryLoader(false);
131+
}, []);
132+
133+
const resetPassword = useCallback(async ({ password, confirmPassword }) => {
134+
setResetLoader(true);
135+
136+
try {
137+
setRecoveryError('');
138+
139+
await api.post('/password/reset', { password, confirmPassword });
140+
} catch (err) {
141+
const errorStatus = err.response?.status;
142+
143+
if (errorStatus === 401) {
144+
setResetError(err.response?.data.message);
145+
}
146+
147+
setResetLoader(false);
148+
}
149+
}, []);
150+
111151
return (
112152
<AuthContext.Provider
113153
value={{
@@ -121,10 +161,20 @@ const AuthProvider = ({ children }: AuthProviderProps) => {
121161
loader: signUpLoader,
122162
success: signUpSuccess,
123163
},
164+
recovery: {
165+
error: recoveryError,
166+
loader: recoveryLoader,
167+
},
168+
reset: {
169+
error: resetError,
170+
loader: resetLoader,
171+
},
124172
signIn,
125173
signUp,
126174
signOut,
127175
inviteUser,
176+
recoveryPassword,
177+
resetPassword,
128178
}}
129179
>
130180
{children}
@@ -143,3 +193,6 @@ function useAuth(): AuthContextData {
143193
}
144194

145195
export { AuthProvider, useAuth };
196+
function async(arg0: { email: any }): any {
197+
throw new Error('Function not implemented.');
198+
}

src/pages/Minute/components/MinuteViewer/data.js

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { useAuth } from 'contexts/auth';
3+
4+
import EmailIcon from 'assets/email.svg';
5+
import EmailErrorIcon from 'assets/email_error.svg';
6+
import Loader from 'components/Loader';
7+
8+
import DefaultModal from 'components/DefaultModal';
9+
import { StyledRecoveryModal, StyledRecoveryModalContent } from './styles';
10+
11+
interface IRecoveryModalProps {
12+
onClose: Function;
13+
}
14+
15+
const RecoveryModal: React.FC<IRecoveryModalProps> = ({
16+
onClose,
17+
}: IRecoveryModalProps) => {
18+
const {
19+
recovery: { error, loader },
20+
} = useAuth();
21+
22+
return (
23+
<StyledRecoveryModal>
24+
<DefaultModal onClose={onClose}>
25+
<>
26+
{loader ? (
27+
<Loader />
28+
) : error === '' ? (
29+
<StyledRecoveryModalContent>
30+
<img src={EmailIcon} alt="" />
31+
<h1>E-MAIL ENVIADO!</h1>
32+
<h3>CONFIRA SUA CAIXA DE E-MAIL.</h3>
33+
</StyledRecoveryModalContent>
34+
) : (
35+
<StyledRecoveryModalContent>
36+
<img src={EmailErrorIcon} alt="" />
37+
<h1>{error.toUpperCase()}</h1>
38+
<h3>REVISE-O E TENTE NOVAMENTE.</h3>
39+
</StyledRecoveryModalContent>
40+
)}
41+
</>
42+
</DefaultModal>
43+
</StyledRecoveryModal>
44+
);
45+
};
46+
47+
export default RecoveryModal;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import styled from 'styled-components';
2+
3+
export const StyledRecoveryModal = styled.div`
4+
display: flex;
5+
justify-content: center;
6+
align-items: center;
7+
`;
8+
9+
export const StyledRecoveryModalContent = styled.div`
10+
display: flex;
11+
flex: 1;
12+
flex-direction: column;
13+
align-items: center;
14+
justify-content: center;
15+
16+
img {
17+
height: 3.438rem;
18+
margin-bottom: 1rem;
19+
}
20+
`;

0 commit comments

Comments
 (0)