mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-10 04:22:00 +10:00
* feat: support i18n * feat: wip support i18n * feat: complete space translation * feat: complete page translation * feat: update space translation * feat: update workspace translation * feat: update group translation * feat: update workspace translation * feat: update page translation * feat: update user translation * chore: update pnpm-lock * feat: add query translation * refactor: merge to single file * chore: remove necessary code * feat: save language to BE * fix: only load current language * feat: save language to locale column * fix: cleanups * add language menu to preferences page * new translations * translate editor * Translate editor placeholders * translate space selection component --------- Co-authored-by: Philip Okugbe <phil@docmost.com> Co-authored-by: Philip Okugbe <16838612+Philipinho@users.noreply.github.com>
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import * as z from "zod";
|
|
import { useForm, zodResolver } from "@mantine/form";
|
|
import useAuth from "@/features/auth/hooks/use-auth";
|
|
import { ILogin } from "@/features/auth/types/auth.types";
|
|
import {
|
|
Container,
|
|
Title,
|
|
TextInput,
|
|
Button,
|
|
PasswordInput,
|
|
Box,
|
|
Anchor,
|
|
} from "@mantine/core";
|
|
import classes from "./auth.module.css";
|
|
import { useRedirectIfAuthenticated } from "@/features/auth/hooks/use-redirect-if-authenticated.ts";
|
|
import { Link, useNavigate } from "react-router-dom";
|
|
import APP_ROUTE from "@/lib/app-route.ts";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
const formSchema = z.object({
|
|
email: z
|
|
.string()
|
|
.min(1, { message: "email is required" })
|
|
.email({ message: "Invalid email address" }),
|
|
password: z.string().min(1, { message: "Password is required" }),
|
|
});
|
|
|
|
export function LoginForm() {
|
|
const { t } = useTranslation();
|
|
const { signIn, isLoading } = useAuth();
|
|
useRedirectIfAuthenticated();
|
|
|
|
const form = useForm<ILogin>({
|
|
validate: zodResolver(formSchema),
|
|
initialValues: {
|
|
email: "",
|
|
password: "",
|
|
},
|
|
});
|
|
|
|
async function onSubmit(data: ILogin) {
|
|
await signIn(data);
|
|
}
|
|
|
|
return (
|
|
<Container size={420} my={40} className={classes.container}>
|
|
<Box p="xl" mt={200}>
|
|
<Title order={2} ta="center" fw={500} mb="md">
|
|
{t("Login")}
|
|
</Title>
|
|
|
|
<form onSubmit={form.onSubmit(onSubmit)}>
|
|
<TextInput
|
|
id="email"
|
|
type="email"
|
|
label={t("Email")}
|
|
placeholder="email@example.com"
|
|
variant="filled"
|
|
{...form.getInputProps("email")}
|
|
/>
|
|
|
|
<PasswordInput
|
|
label={t("Password")}
|
|
placeholder={t("Your password")}
|
|
variant="filled"
|
|
mt="md"
|
|
{...form.getInputProps("password")}
|
|
/>
|
|
|
|
<Button type="submit" fullWidth mt="xl" loading={isLoading}>
|
|
{t("Sign In")}
|
|
</Button>
|
|
</form>
|
|
|
|
<Anchor
|
|
to={APP_ROUTE.AUTH.FORGOT_PASSWORD}
|
|
component={Link}
|
|
underline="never"
|
|
size="sm"
|
|
>
|
|
{t("Forgot your password?")}
|
|
</Anchor>
|
|
</Box>
|
|
</Container>
|
|
);
|
|
}
|