-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created basic login form layout. References #21.
- Loading branch information
1 parent
97e8b6b
commit ab0c86b
Showing
6 changed files
with
144 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { lazy, Suspense } from 'react'; | ||
|
||
const LazyLoginForm = lazy(() => import('./LoginForm')); | ||
|
||
const LoginForm = ( | ||
props: JSX.IntrinsicAttributes & { children?: React.ReactNode }, | ||
) => ( | ||
<Suspense fallback={null}> | ||
<LazyLoginForm {...props} /> | ||
</Suspense> | ||
); | ||
|
||
export default LoginForm; |
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,5 @@ | ||
.LoginForm { | ||
a { | ||
cursor: pointer; | ||
} | ||
} |
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 @@ | ||
/* eslint-disable */ | ||
import LoginForm from './LoginForm'; | ||
|
||
export default { | ||
title: "LoginForm", | ||
component: LoginForm | ||
}; | ||
|
||
export const Default = () => <LoginForm apiLoginEndpoint=''/>; | ||
|
||
Default.story = { | ||
name: 'default', | ||
}; |
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,14 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import LoginForm from './LoginForm'; | ||
|
||
describe('<LoginForm />', () => { | ||
test('it should mount', () => { | ||
render(<LoginForm />); | ||
|
||
const loginForm = screen.getByTestId('LoginForm'); | ||
|
||
expect(loginForm).toBeInTheDocument(); | ||
}); | ||
}); |
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,95 @@ | ||
import { | ||
Button, | ||
Container, | ||
Grid, | ||
Link, | ||
TextField, | ||
Typography, | ||
} from '@mui/material'; | ||
import axios from 'axios'; | ||
import React, { FC, useState } from 'react'; | ||
|
||
import styles from './LoginForm.module.scss'; | ||
|
||
interface LoginFormProps { | ||
apiLoginEndpoint: string; | ||
} | ||
|
||
const LoginForm: FC<LoginFormProps> = (props: LoginFormProps) => { | ||
const [username, setUsername] = useState<string>(''); | ||
const [password, setPassword] = useState<string>(''); | ||
|
||
const login = async () => { | ||
const response = await axios.post( | ||
props.apiLoginEndpoint, | ||
{ | ||
username, | ||
password, | ||
}, | ||
{ | ||
withCredentials: true, | ||
}, | ||
); | ||
|
||
if (response.data === 'success') { | ||
return (window.location.href = '/'); | ||
} | ||
}; | ||
|
||
const register = () => { | ||
console.log('aaa'); | ||
}; | ||
|
||
return ( | ||
<Container className={styles.LoginForm} data-testid="LoginForm"> | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
<Typography variant="h4">Login</Typography> | ||
</Grid> | ||
<Grid item xs={12}> | ||
<TextField | ||
label="Username" | ||
variant="filled" | ||
type="text" | ||
required | ||
fullWidth | ||
onChange={(e: { | ||
target: { value: React.SetStateAction<string> }; | ||
}) => setUsername(e.target.value)} | ||
/> | ||
</Grid> | ||
|
||
<Grid item xs={12}> | ||
<TextField | ||
label="Password" | ||
variant="filled" | ||
type="password" | ||
required | ||
fullWidth | ||
onChange={(e: { | ||
target: { value: React.SetStateAction<string> }; | ||
}) => setPassword(e.target.value)} | ||
/> | ||
</Grid> | ||
|
||
<Grid item xs={12}> | ||
<Button | ||
type="button" | ||
variant="contained" | ||
size="large" | ||
fullWidth | ||
onClick={() => login()} | ||
> | ||
Log in | ||
</Button> | ||
<Typography align="center"> | ||
Don't have an account?{' '} | ||
<Link onClick={() => register()}>Register!</Link> | ||
</Typography> | ||
</Grid> | ||
</Grid> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default LoginForm; |
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