-
Notifications
You must be signed in to change notification settings - Fork 142
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
kingdanie
wants to merge
6
commits into
nkowaokwu:master
Choose a base branch
from
kingdanie:login-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bbb9f94
chore: create a new next.js page called login #603
kingdanie 2389fff
Merge branch 'nkowaokwu:master' into login-page
kingdanie 95cb4c8
Merge branch 'nkowaokwu:master' into login-page
kingdanie b6f0158
fix: add forgot password link
kingdanie 59241bb
Merge branch 'nkowaokwu:master' into login-page
kingdanie daf2153
Merge branch 'nkowaokwu:master' into login-page
kingdanie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
Additionally from the screenshots, you can see that the headers are also not the same. Here is a code snippet: