import { msg } from "@lingui/core/macro" import { useLingui } from "@lingui/react" import { Trans } from "@lingui/react/macro" import { Anchor, Box, Button, Center, Container, Group, Paper, PasswordInput, Stack, TextInput, Title } from "@mantine/core" import { useForm } from "@mantine/form" import { useAsyncCallback } from "react-async-hook" import { Link } from "react-router-dom" import { client, errorToStrings } from "@/app/client" import { redirectToRootCategory } from "@/app/redirect/thunks" import { useAppDispatch, useAppSelector } from "@/app/store" import type { RegistrationRequest } from "@/app/types" import { Alert } from "@/components/Alert" import { PageTitle } from "@/pages/PageTitle" export function RegistrationPage() { const serverInfos = useAppSelector(state => state.server.serverInfos) const dispatch = useAppDispatch() const { _ } = useLingui() const form = useForm({ initialValues: { name: "", password: "", email: "", }, }) const login = useAsyncCallback(client.user.login, { onSuccess: () => { dispatch(redirectToRootCategory()) }, }) const register = useAsyncCallback(client.user.register, { onSuccess: () => { login.execute(form.values) }, }) return ( <Trans>Sign up</Trans> {serverInfos && !serverInfos.allowRegistrations && ( )} {serverInfos?.allowRegistrations && ( <> {register.error && ( )} {login.error && ( )}
E-mail address} placeholder={_(msg`E-mail address`)} {...form.getInputProps("email")} size="md" required /> Password} placeholder={_(msg`Password`)} {...form.getInputProps("password")} size="md" required />
Have an account? Log in!
)}
) }