Skip to content

Commit 0288e0f

Browse files
committed
Migrate to i18n-based title
1 parent 9a3bd79 commit 0288e0f

File tree

4 files changed

+82
-45
lines changed

4 files changed

+82
-45
lines changed

components/Login/login.tsx

Lines changed: 78 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,86 @@
1+
import { useForm } from "react-hook-form"
2+
import { useRouter } from "next/router"
3+
import {
4+
useSignInWithEmailAndPassword,
5+
SignInWithEmailAndPasswordData
6+
} from "../auth/hooks"
7+
import { Form, Stack, Alert, Container, Row, Col, Card } from "../bootstrap"
8+
import Input from "../forms/Input"
9+
import PasswordInput from "../forms/PasswordInput"
110
import { useTranslation } from "next-i18next"
2-
import styled from "styled-components"
3-
import { Container } from "../bootstrap"
4-
import { SignInWithButton } from "components/auth"
11+
import { LoadingButton } from "../buttons"
12+
import SocialSignOnButtons from "components/auth/SocialSignOnButtons"
13+
import Divider from "../Divider/Divider"
514

6-
export default function LoginPage() {
15+
export default function Login() {
16+
const router = useRouter()
17+
const redirect = (router.query.redirect as string) || "/"
718
const { t } = useTranslation("auth")
819

9-
const StyledContainer = styled(Container)`
10-
@media (min-width: 768px) {
11-
}
12-
`
20+
const {
21+
register,
22+
handleSubmit,
23+
formState: { errors }
24+
} = useForm<SignInWithEmailAndPasswordData>()
25+
26+
const signIn = useSignInWithEmailAndPassword()
27+
28+
const success = () => {
29+
const safeRedirect = redirect.startsWith("/") ? redirect : "/"
30+
router.replace(safeRedirect)
31+
}
32+
const onSubmit = handleSubmit(credentials => {
33+
signIn.execute(credentials).then(success)
34+
})
1335

1436
return (
15-
<StyledContainer>
16-
<div className={`bg-white my-3 overflow-hidden rounded-3`}>
17-
<div
18-
className={`align-items-center d-flex justify-content-center px-2 pt-2 pb-0`}
19-
>
20-
<div className={`px-3 py-0`}>
21-
<div
22-
className={`align-items-center d-flex fs-5 justify-content-center lh-sm mb-1 text-secondary`}
23-
>
24-
<div className={`pe-2`}>
25-
<img
26-
alt="closed lock with key"
27-
src={`/closed-lock-with-key.png`}
28-
width="32"
29-
height="32"
30-
/>{" "}
31-
</div>
32-
{t("almostThere")}
33-
</div>
34-
<br />
35-
<div
36-
className={`align-items-start d-flex fs-5 justify-content-center lh-sm mb-1 text-secondary`}
37-
>
38-
{t("justLogIn")}
39-
</div>
40-
<br />
41-
<div className={`justify-content-center d-flex w-100`}>
42-
<SignInWithButton />
43-
</div>
44-
<br />
45-
</div>
46-
</div>
47-
</div>
48-
</StyledContainer>
37+
<Container className="py-5">
38+
<Row className="justify-content-center">
39+
<Col xs={12} sm={10} md={8} lg={6}>
40+
<Card className="p-4 shadow-lg">
41+
<h2 className="text-center">{t("signInToAccess")}</h2>
42+
43+
<Form onSubmit={onSubmit} noValidate>
44+
{signIn.error && (
45+
<Alert variant="danger">{signIn.error.message}</Alert>
46+
)}
47+
48+
<Stack gap={3}>
49+
<Input
50+
label={t("email")}
51+
type="email"
52+
{...register("email", {
53+
required: t("emailIsRequired") ?? "Email is required"
54+
})}
55+
error={errors.email?.message}
56+
/>
57+
58+
<PasswordInput
59+
label={t("password")}
60+
{...register("password", {
61+
required: t("passwordRequired") ?? "Password is required"
62+
})}
63+
error={errors.password?.message}
64+
/>
65+
66+
<LoadingButton
67+
type="submit"
68+
className="w-100"
69+
loading={signIn.loading}
70+
>
71+
{t("signIn")}
72+
</LoadingButton>
73+
74+
<Divider className="px-4">{t("or")}</Divider>
75+
76+
<SocialSignOnButtons
77+
onComplete={() => router.replace(redirect)}
78+
/>
79+
</Stack>
80+
</Form>
81+
</Card>
82+
</Col>
83+
</Row>
84+
</Container>
4985
)
5086
}

next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.

pages/login.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createPage } from "../components/page"
22
import Login from "components/Login/Login"
33

44
export default createPage({
5-
title: "Login",
5+
titleI18nKey: "navigation.login",
66
Page: () => <Login />
77
})
88
import { serverSideTranslations } from "next-i18next/serverSideTranslations"

public/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@
7979
"supportMaple": "Support MAPLE",
8080
"aboutTestimony": "About Testimony",
8181
"viewProfile": "View Profile",
82-
"whyUseMaple": "Why Use MAPLE"
82+
"whyUseMaple": "Why Use MAPLE",
83+
"login": "Login"
8384
},
8485
"newcomer": "New to MAPLE? For extra support, check",
8586
"newsletter": "Click Here to Subscribe to Our Newsletter",

0 commit comments

Comments
 (0)