Skip to content

[WIP] Feat/ajaxforgot #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 21 additions & 0 deletions cypress/integration/pages/Forgot/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

describe("Forgot", () => {

it.only("should show success message when ApiForgot return 200", () => {
cy.visit("/auth/forgot")

cy.server()
cy.route({
method: 'POST', // Route all GET requests
url: '/api/forgot_password',
response: []
}).as("ApiForgot")

cy.get("input[name=email]").type("brunooomelo")
cy.contains("Enviar").click()
cy.wait("@ApiForgot")
cy.get("span#success").contains("Por favor, verifique seu e-mail.")
cy.get("input[name=email]").should("have.value", "")
})

})
Binary file added cypress/videos/pages/Forgot/index.test.js.mp4
Binary file not shown.
9 changes: 9 additions & 0 deletions src/components/MessageCollab/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";

import { Message } from "./styles";

function MessageCollab(props) {
return <Message {...props}>{props.content}</Message>;
}

export default MessageCollab;
17 changes: 17 additions & 0 deletions src/components/MessageCollab/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import styled from "styled-components";

import { _h6 } from "../../styles/tools/Typography";

export const Message = styled.span`
${_h6};
display: flex;
flex: 1;
height: 50px;
background: #75daad;
color: white;
flex-direction: column;
justify-content: center;
text-align: center;
margin-top: 50px;
border-radius: var(--radius-big);
`
12 changes: 12 additions & 0 deletions src/components/SubmitCollab/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { Button, Content } from "./styles";

function ButtonCollab(props) {
return (
<Button {...props}>
<Content>{props.content}</Content>
</Button>
);
}

export default ButtonCollab;
34 changes: 34 additions & 0 deletions src/components/SubmitCollab/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import styled from "styled-components";

import { _h6 } from "../../styles/tools/Typography";

export const Button = styled.button`
${_h6};
box-shadow: 2px 2px 4px rgba(0,0,0,0.25);
width: 100%;
height: 42px;
margin-top: var(--gap-bigger);
display: flex;
align-items: center;
justify-content: center;
position: relative;
text-decoration: none;
border: none;
border-radius: var(--radius-big);
background-color: var(--color-fiery-rose);
color: var(--color-floral-white);
opacity: 0.9;
transition: opacity 100ms linear, transform 50ms linear;
z-index: 1;

&:hover,
&:focus {
opacity: 1;
}

&:active {
transform: translateY(2px);
}
`;

export const Content = styled.span``;
28 changes: 23 additions & 5 deletions src/containers/FormForgot/index.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import React from "react";
import React, {useState} from "react";

import TitleCollab from "../../components/TitleCollab";
import FieldCollab from "../../components/FieldCollab";
import ButtonCollab from "../../components/ButtonCollab";
import SubmitCollab from "../../components/SubmitCollab";

import FormAuth from "../../containers/FormAuth";
import LabelCollab from "../../components/LabelCollab";

import AuthService from "../../services/AuthService";
import MessageCollab from "../../components/MessageCollab";

function FormForgot() {
const [email, setEmail] = useState("")
const [success, setSuccess] = useState(false)

function onChange(e) {
setEmail(e.target.value)
}

async function onSubmit(e) {
e.preventDefault()

return AuthService.forgot(email).then(() => setSuccess(true)).then(() => setEmail(""));
}


return (
<FormAuth>
<FormAuth onSubmit={onSubmit}>
<TitleCollab content="Esqueci minha senha" />

<LabelCollab
content="Informe seu e-mail para alterar a sua senha"
warning={true}
/>

<FieldCollab content="E-mail:" htmlFor="email" id="email" />
<FieldCollab content="E-mail:" htmlFor="email" id="email" name="email" onChange={onChange} value={email} />

<ButtonCollab content="Enviar" to="/dashboard" />
<SubmitCollab content="Enviar" />
{ success && <MessageCollab id="success" content="Por favor, verifique seu e-mail." /> }
</FormAuth>
);
}
Expand Down
11 changes: 10 additions & 1 deletion src/services/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ function signup(user) {
.send(user);
}

export default { signup };
function forgot(email) {
const { REACT_APP_API_AUTH } = process.env;

return request
.post(`${REACT_APP_API_AUTH}/api/forgot_password`)
.set("Content-Type", "application/json")
.send(email)
}

export default { signup, forgot };