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

chore: created a new next.js page called login #603 #698

Open
wants to merge 6 commits into
base: master
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
17 changes: 17 additions & 0 deletions cypress/e2e/client.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ describe('Igbo API Homepage', () => {
});
});
});

describe('Log in to Account', () => {
beforeEach(() => {
cy.visit('/login');
});

it('render the Login page', () => {
cy.findByText('Log in.');
});

it('fill out the sign up form and submit for developer account', () => {
const email = `${uuid()}@testing.com`;
cy.findByTestId('login-email-input').clear().type(email);
cy.findByTestId('login-password-input').clear().type('password');
cy.findByText('Login').click();
});
});
});

describe('Mobile', () => {
Expand Down
107 changes: 107 additions & 0 deletions src/pages/login.js
Copy link
Collaborator

Choose a reason for hiding this comment

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

we want to start using ChakraUI for all our components (i.e. Box, Heading, Form, Button, Text to replace div, h1, h2, form, button, p, etc.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I will try to refactor the page to reflect these changes.

Copy link
Contributor Author

@kingdanie kingdanie Jun 27, 2023

Choose a reason for hiding this comment

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

chrakra ui components doesn't seem to work well with tailwind classes especially for Box, and Formcontrol.
See screenshots for before I changed div and form to Box and Formcontrol respectively:

Screenshot 2023-06-27 at 10 27 35 Screenshot 2023-06-27 at 10 27 45

Additionally from the screenshots, you can see that the headers are also not the same. Here is a code snippet:

 <div className="w-10/12 lg:w-7/12">
            <Heading as="h1" fontSize="4xl" className="mb-6">{t('Log in.')}</Heading>
            <h1 className="text-5xl mb-6">{t('Log in.')}</h1>

            <Heading as="h2"  fontSize='md' className="text-gray-600 mb-4">{t('Log in to your Igbo API dashboard.')}</Heading>
            <h2 className="text-gray-600 font-normal mb-4">{t('Log in to your Igbo API dashboard.')}</h2>
 </div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { useState } from 'react';
import {
chakra,
Text,
} from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import { useForm, Controller } from 'react-hook-form';
import Navbar from './components/Navbar';
import Input from './components/Input';

const Login = () => {
const { t } = useTranslation('login');
const [buttonText, setButtonText] = useState('Login');
const [errorMessage, setErrorMessage] = useState('');
const [isButtonDisabled, setIsButtonDisabled] = useState(false);
const { handleSubmit, control, errors, reset } = useForm();


/* Changes the button text depending on the response */
const handleLoginResponse = (text) => {
setButtonText(text);
setIsButtonDisabled(true);
};

/* Sends a POST request to the Igbo API to signin the Developer */
const onSubmit = (data) => {
if (!data) {
setErrorMessage('An Error Occured');
handleLoginResponse(t('An error occurred'));
}
handleLoginResponse(t('Login successful!'));
console.log(`${{ data }}`);
reset({
email: '',
password: '',
});
};



return (
<>
<Navbar transparent />

<div className="w-screen h-screen flex flex-row overflow-hidden">
<div className="flex flex-col justify-center items-center w-full lg:w-6/12">
<div className="w-10/12 lg:w-7/12">
<h1 className="text-5xl mb-6">{t('Log in.')}</h1>
<h2 className="text-gray-600 font-normal mb-4">{t('Log in to your Igbo API dashboard.')}</h2>
</div>
<form
data-test="login-form"
onSubmit={handleSubmit(onSubmit)}
className="flex flex-col justify-center items-center w-10/12 lg:w-7/12 h-8/12"
>
<Controller
render={(props) => (
<Input
{...props}
header={t('Your email')}
type="email"
placeholder={t('Email')}
data-test="login-email-input"
/>
)}
name="email"
control={control}
rules={{
required: true,
}}
/>
{errors.email ? <chakra.span className="error">Email is required</chakra.span> : null}
<Controller
render={(props) => (
<Input
{...props}
header={t('Password')}
type="password"
placeholder={t('Password')}
data-test="login-password-input"
/>
)}
name="password"
control={control}
rules={{
required: true,
}}
/>
{errors.password ? <chakra.span className="error">Password is required</chakra.span> : null}
<button type="submit" className="primary-button" disabled={isButtonDisabled}>
{t(buttonText)}
</button>
{errorMessage ? (
<Text className="text-red-600 mt-4" data-test="error-message">
{errorMessage}
</Text>
) : null}
<p className="text-gray-600 mt-4"><a href="/">Forgot password? Reset your password here</a></p>
</form>
</div>
<div className="flex flex-col w-0/12 lg:w-6/12 bg-gradient-to-tr from-green-100 to-green-500" />
</div>
</>
);
};

export default Login;