Merge pull request #12 from forceoranj/login

add login route and login form
This commit is contained in:
Manuel Emeriau 2021-11-27 15:27:42 +01:00 committed by GitHub
commit 2853f5fd93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 117 additions and 0 deletions

View File

@ -49,6 +49,7 @@ module.exports = {
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"testing-library/no-node-access": "off",
"testing-library/render-result-naming-convention": "off",
"jsx-a11y/label-has-associated-control": "off",
},
globals: {
__CLIENT__: true,

46
src/pages/Login/Login.tsx Normal file
View File

@ -0,0 +1,46 @@
import { RouteComponentProps } from "react-router-dom"
import React, { memo, useCallback } from "react"
import { Helmet } from "react-helmet"
import styles from "./styles.module.scss"
export type Props = RouteComponentProps
const Login: React.FC<Props> = (): JSX.Element => {
const onSubmit = useCallback((event: React.SyntheticEvent): void => {
event.preventDefault()
const target = event.target as typeof event.target & {
email: { value: string }
password: { value: string }
}
const email = target.email.value
const password = target.password.value
console.log("email and password checked", email, password)
// call service with email & password
}, [])
return (
<div className={styles.Login}>
<Helmet title="Login" />
<form onSubmit={onSubmit} className={styles.form}>
<div className={styles.LoginIntro} key="login-intro">
Connectez-vous pour accéder à votre espace.
</div>
<div className={styles.formLine} key="line-email">
<label htmlFor="email">Email</label>
<input type="email" id="email" />
</div>
<div className={styles.formLine} key="line-password">
<label htmlFor="password">Mot de passe</label>
<input type="password" id="password" />
</div>
<div className={styles.formButtons}>
<button type="submit">Connexion</button>
</div>
</form>
</div>
)
}
export default memo(Login)

14
src/pages/Login/index.tsx Executable file
View File

@ -0,0 +1,14 @@
import loadable from "@loadable/component"
import { Loading, ErrorBoundary } from "../../components"
import { Props } from "./Login"
const Login = loadable(() => import("./Login"), {
fallback: <Loading />,
})
export default (props: Props): JSX.Element => (
<ErrorBoundary>
<Login {...props} />
</ErrorBoundary>
)

View File

@ -0,0 +1,36 @@
@import "../../theme/variables";
@import "../../theme/mixins";
.Login {
display: flex;
justify-content: center;
align-content: center;
}
.form {
@include page-content-wrapper;
}
.LoginIntro {
margin-bottom: 10px;
}
.formLine {
padding: 5px 0;
label {
display: block;
margin-left: 5px;
}
input {
width: 100%;
border: 1px solid #333;
border-radius: 4px;
}
}
.formButtons {
margin-top: 10px;
padding: 5px 0;
text-align: center;
}

View File

@ -3,6 +3,7 @@ import { RouteConfig } from "react-router-config"
import App from "../app"
import AsyncHome, { loadData as loadHomeData } from "../pages/Home"
import AsyncMembrePage, { loadData as loadMembrePageData } from "../pages/MembrePage"
import Login from "../pages/Login"
import NotFound from "../pages/NotFound"
export default [
@ -20,6 +21,10 @@ export default [
component: AsyncMembrePage,
loadData: loadMembrePageData,
},
{
path: "/login",
component: Login,
},
{
component: NotFound,
},

View File

@ -1,5 +1,20 @@
@import "./variables";
@mixin desktop {
@media (min-width: 800px) {
@content;
}
}
@mixin page-content-wrapper {
margin: 10px;
padding: 10px;
background-color: $color-white;
border-radius: 15px;
border: $border-large;
@include desktop {
padding: 20px;
width: 400px;
}
}