Skip to content
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

[#45] Agregada verificacion al login #48

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
JoeOsG marked this conversation as resolved.
Show resolved Hide resolved
},
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
Expand Down
8 changes: 2 additions & 6 deletions src/atoms/Button-primary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ const ButtonAble = styled.button`
cursor: not-allowed;
}
`;
const ButtonPrimary = ({text, disable, className}) => {
const buttonClick = () => {
console.log('Do something');
};

const ButtonPrimary = ({text, disable, className, typeOfButton, handleClick}) => {
return disable ? (
<ButtonAble disabled className={className}>
{text}
</ButtonAble>
) : (
<ButtonAble className={className} onClick={() => buttonClick()}>
<ButtonAble className={className} type={typeOfButton} onClick={handleClick}>
{text}
</ButtonAble>
);
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/Button-secondary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ButtonSecondary = ({text, disable, buttonClick}) => {
return disable ? (
<ButtonAble disabled>{text}</ButtonAble>
) : (
<ButtonAble onClick={() => buttonClick()}>{text}</ButtonAble>
<ButtonAble onClick={buttonClick}>{text}</ButtonAble>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/atoms/CoffeeBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import IconCoffee from '../image/IconCoffee.svg';
const Logo = styled.div`
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
grid-area: banner;
`;

const LogoIcon = styled.img`
Expand Down
3 changes: 2 additions & 1 deletion src/atoms/InputEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ const InputEmailStyled = styled.input`
padding-left: 1rem;
`;

function InputEmail({name, value, setValue}) {
function InputEmail({name, value, setValue, placeholder}) {
return (
<InputEmailStyled
name={name}
placeholder={placeholder}
type="email"
value={value}
onChange={({target}) => setValue(target.value)}
Expand Down
4 changes: 3 additions & 1 deletion src/atoms/InputPassword.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ function IconPassword({isVisible, setIsVisible}) {
);
}

function InputPassword({name, value, setValue}) {
function InputPassword({name, value, setValue, placeholder, handleBlur}) {
const [isVisible, setIsVisible] = React.useState(false);

return (
<WrapperPassword>
<InputPasswordStyled
name={name}
placeholder={placeholder}
type={isVisible ? 'text' : 'password'}
value={value}
onBlur={handleBlur}
onChange={({target}) => setValue(target.value)}
/>
<IconPassword isVisible={isVisible} setIsVisible={setIsVisible} />
Expand Down
8 changes: 8 additions & 0 deletions src/atoms/p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import styled from '@emotion/styled';

import colors from '../styles/colors';

export const ErrorParagraph = styled.p`
color: ${colors.red};
font-size: 1.5em;
`;
6 changes: 5 additions & 1 deletion src/molecules/ChoosePayment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const SubHeaderSection = styled.div`
`;

export default function ChoosePayment() {
function handleClick() {
console.log('payment');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No debe hacerse commit de los console.log. Si una función debe ser implementada, dejar un comentario o tirar una excepción.

}

return (
<>
<HeaderSection>
Expand All @@ -29,7 +33,7 @@ export default function ChoosePayment() {
</HeaderSection>

<SubHeaderSection>
<ButtonSecondary text={'tarjeta'} />
<ButtonSecondary buttonClick={() => handleClick()} text={'tarjeta'} />
<ButtonSecondary text={'efectivo'} />
</SubHeaderSection>

Expand Down
7 changes: 3 additions & 4 deletions src/molecules/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {CoffeeBanner} from '../atoms/CoffeeBanner';
import {TopMenu} from './TopMenu';

const Container = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 2rem;
display: grid;
grid-template-columns: 5% 35% 30% 30%;
grid-template-areas: 'blank banner separator nav';
`;

export const Header = () => {
Expand Down
73 changes: 63 additions & 10 deletions src/molecules/LoginForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Label from '../atoms/Label';
import ButtonPrimary from '../atoms/Button-primary';
import InputEmail from '../atoms/InputEmail';
import InputPassword from '../atoms/InputPassword';
import {ErrorParagraph} from '../atoms/p';

const Container = styled.div`
display: flex;
Expand All @@ -22,18 +23,70 @@ const LoginButtonStyled = styled(ButtonPrimary)`
export const LoginForm = (className) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [emailError, setEmailError] = useState(``);
const [passwordError, setPasswordError] = useState(``);

function isEmailValid(emailEvaluate) {
const emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

return emailRegex.test(emailEvaluate);
}

function validateEmail(emailToValidate) {
if (!isEmailValid(emailToValidate)) {
setEmailError(`Asegurese de colocar un email correcto`);
} else {
setEmailError(``);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setEmailError, y setPasswordError, existen?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Al parecer son setters de estados del componente.

}
}

function isPasswordValid(passwordToEvaluate) {
const passwordRegex = /^(?=.*\d).{5,}$/;

return passwordRegex.test(passwordToEvaluate);
}

function validatePassword(passwordToValidate) {
if (!isPasswordValid(passwordToValidate)) {
setPasswordError(`Asegurese de que su contraseña tenga al menos 5 caracteres y un numero`);
} else {
setPasswordError(``);
}
}

function handleSubmit(event) {
validateEmail(email);
validatePassword(password);
if (!isPasswordValid(password) || !isEmailValid(email)) {
event.preventDefault();
}
}

return (
<Container className={className}>
<InputField>
<Label>Email</Label>
<InputEmail name="email" setValue={setEmail} value={email} />
</InputField>
<InputField>
<Label>Password</Label>
<InputPassword name="password" setValue={setPassword} value={password} />
</InputField>
<LoginButtonStyled disable={false} text={'Ingresar'} />
<Container className={className} onSubmit={(event) => handleSubmit(event)}>
<form action="/" method="get">
<InputField>
<Label>Email</Label>
<InputEmail
name="email"
placeholder={'Escriba su email'}
setValue={setEmail}
value={email}
/>
</InputField>
{emailError.length > 0 ? <ErrorParagraph>{emailError}</ErrorParagraph> : <></>}
<InputField>
<Label>Password</Label>
<InputPassword
name="password"
placeholder={'escriba su contraseña'}
setValue={setPassword}
value={password}
/>
</InputField>
{passwordError.length > 0 ? <ErrorParagraph>{passwordError}</ErrorParagraph> : <></>}
<LoginButtonStyled disable={false} text={'Ingresar'} typeOfButton={'submit'} />
</form>
</Container>
);
};
4 changes: 2 additions & 2 deletions src/molecules/TopMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import H3 from '../atoms/H3';
const Nav = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
gap: 4rem;
gap: 5rem;
grid-area: nav;
`;

const NavItem = styled.a`
Expand Down
32 changes: 17 additions & 15 deletions src/styles/colors.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
const wordsColor = {
blanco: '#FFF',
crema: '#F2E6D8',
light: '#FFF',
secondary: '#F2E6D8',
JoeOsG marked this conversation as resolved.
Show resolved Hide resolved
naranja: '#D9734E',
cafe: '#602915',
azul: '#483F59',
negro: '#000',
gris: '#C5C5C5',
marron: '#5E3E00',
primary: '#602915',
accentBlue: '#483F59',
black: '#000',
gray: '#C5C5C5',
accentBrown: '#5E3E00',
red: `#fc0339`,
};

export default {
primary: wordsColor.cafe,
secondary: wordsColor.crema,
light: wordsColor.blanco,
dark: wordsColor.negro,
accent: wordsColor.azul,
accent_brown: wordsColor.marron,
blue: wordsColor.azul,
gray: wordsColor.gris,
primary: wordsColor.primary,
secondary: wordsColor.secondary,
light: wordsColor.light,
dark: wordsColor.black,
accent: wordsColor.accentBlue,
accent_brown: wordsColor.accentBrown,
blue: wordsColor.blue,
gray: wordsColor.gray,
red: wordsColor.red,
};