-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fac8d29
commit a8bb9df
Showing
28 changed files
with
345 additions
and
148 deletions.
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,58 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
min-height: 100%; | ||
padding-bottom: 5vh; | ||
`; | ||
|
||
export const LinksContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-top: 30px; | ||
height: 50px; | ||
`; | ||
|
||
export const LogoWrapper = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
`; | ||
|
||
export const CardContainer = styled.div` | ||
max-width: 500px; | ||
width: 100%; | ||
margin: 10px; | ||
`; | ||
|
||
export const ActionsContainer = styled.div` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-top: 20px; | ||
flex-wrap: wrap; | ||
`; | ||
|
||
export const LoginButtonContainer = styled.div( | ||
({ theme: { breakpoints, down } }) => ` | ||
max-width: 200px; | ||
width: 100%; | ||
margin-left: 10px; | ||
${down(breakpoints.sm)} { | ||
max-width: 100%; | ||
margin-left: 0; | ||
margin-top: 20px; | ||
} | ||
`, | ||
); | ||
|
||
export const IconWrapper = styled.div` | ||
color: ${({ theme }) => theme.palette.colors.orange}; | ||
`; |
2 changes: 1 addition & 1 deletion
2
...t/src/containers/SignIn/SignIn.types.d.ts → ...ent/src/containers/Login/Login.types.d.ts
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,114 @@ | ||
import React, { useState } from 'react'; | ||
import { useForm } from 'react-hook-form'; | ||
import { useHistory } from 'react-router-dom'; | ||
|
||
import { BackgroundLogo, Button, Card, Checkbox, Form, Link, TextField } from '../../elements'; | ||
import { useAuth, useSnackbar } from '../../hooks'; | ||
import { EmailIcon, SmartGateLogo } from '../../icons'; | ||
import { | ||
ActionsContainer, | ||
CardContainer, | ||
Container, | ||
IconWrapper, | ||
LinksContainer, | ||
LoginButtonContainer, | ||
LogoWrapper, | ||
} from './Login.styled'; | ||
import { LoginInputs } from './Login.types'; | ||
|
||
const Login = () => { | ||
const history = useHistory(); | ||
const [loading, setLoading] = useState(false); | ||
const showSnackbar = useSnackbar(); | ||
const { register, handleSubmit, errors, reset, trigger } = useForm<LoginInputs>({ | ||
mode: 'onBlur', | ||
}); | ||
const auth = useAuth(); | ||
|
||
if (!auth) { | ||
return null; | ||
} | ||
|
||
const onSubmit = async (values: LoginInputs) => { | ||
setLoading(true); | ||
const isValid = await trigger(); | ||
|
||
if (!isValid) { | ||
setLoading(false); | ||
return; | ||
} | ||
|
||
try { | ||
await auth.login(values); | ||
reset(); | ||
history.push('/dashboard'); | ||
} catch (error) { | ||
if (!error.response) { | ||
showSnackbar({ message: error.message, severity: 'error' }); | ||
} else { | ||
const { message } = error.response.data; | ||
showSnackbar({ message, severity: 'error' }); | ||
} | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
const emailIcon = ( | ||
<IconWrapper> | ||
<EmailIcon /> | ||
</IconWrapper> | ||
); | ||
|
||
return ( | ||
<Container> | ||
<BackgroundLogo /> | ||
<CardContainer> | ||
<Card> | ||
<LogoWrapper> | ||
<SmartGateLogo /> | ||
</LogoWrapper> | ||
<Form | ||
onSubmit={handleSubmit(onSubmit)} | ||
errors={errors} | ||
register={register} | ||
loading={loading} | ||
> | ||
<TextField | ||
name="email" | ||
placeholder="Enter your email" | ||
required | ||
autoFocus | ||
startAdornment={emailIcon} | ||
/> | ||
<TextField | ||
required | ||
name="password" | ||
placeholder="Enter your password" | ||
type="password" | ||
autoComplete="current-password" | ||
/> | ||
<ActionsContainer> | ||
<Checkbox name="keepMeLoggedIn" /> | ||
<LoginButtonContainer> | ||
<Button type="submit" fullWidth disabled={loading} withArrow> | ||
Log in | ||
</Button> | ||
</LoginButtonContainer> | ||
</ActionsContainer> | ||
<LinksContainer> | ||
<Link to="/" colorVariant="grey"> | ||
Forgot password? | ||
</Link> | ||
<Link to="/registration" colorVariant="colour"> | ||
I don’t have an account | ||
</Link> | ||
</LinksContainer> | ||
</Form> | ||
</Card> | ||
</CardContainer> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Login; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...t/src/containers/SignUp/SignUp.types.d.ts → ...ners/Registration/Registration.types.d.ts
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as Dashboard } from './Dashboard'; | ||
export { default as DefaultLayout } from './DefaultLayout'; | ||
export { default as SignIn } from './SignIn'; | ||
export { default as SignUp } from './SignUp'; | ||
export { default as Login } from './Login'; | ||
export { default as Registration } from './Registration'; |
13 changes: 13 additions & 0 deletions
13
packages/client/src/elements/BackgroundLogo/BackgroundLogo.stories.tsx
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,13 @@ | ||
import { Meta, Story } from '@storybook/react/types-6-0'; | ||
import React from 'react'; | ||
|
||
import BackgroundLogo from '.'; | ||
|
||
export default { | ||
title: 'Elements/BackgroundLogo', | ||
component: BackgroundLogo, | ||
} as Meta; | ||
|
||
const Template: Story = (args) => <BackgroundLogo {...args} />; | ||
|
||
export const Default = Template.bind({}); |
20 changes: 20 additions & 0 deletions
20
packages/client/src/elements/BackgroundLogo/BackgroundLogo.styled.ts
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,20 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const BackgroundLogoWrapper = styled.div( | ||
({ theme: { breakpoints, up, palette } }) => ` | ||
display: none; | ||
${up(breakpoints.lg)} { | ||
position: fixed; | ||
z-index: -999; | ||
top: -2%; | ||
right: -15%; | ||
left: 50%; | ||
bottom: -2%; | ||
display: flex; | ||
justify-content: center; | ||
align-items: stretch; | ||
color: ${palette.background.paper}; | ||
opacity: 0.75 | ||
} | ||
`, | ||
); |
Oops, something went wrong.