replace old client with new client from commafeed-ui repository

This commit is contained in:
Athou
2022-08-13 10:56:07 +02:00
parent ac7b6eeb21
commit 04894f118b
183 changed files with 20326 additions and 12678 deletions

View File

@@ -0,0 +1,91 @@
import { t, Trans } from "@lingui/macro"
import { Anchor, Box, Button, Center, Container, Group, Paper, PasswordInput, Stack, TextInput, Title } from "@mantine/core"
import { useForm } from "@mantine/form"
import { client, errorToStrings } from "app/client"
import { redirectToRootCategory } from "app/slices/redirect"
import { useAppDispatch, useAppSelector } from "app/store"
import { LoginRequest } from "app/types"
import { Alert } from "components/Alert"
import { Logo } from "components/Logo"
import { Link } from "react-router-dom"
import useMutation from "use-mutation"
export function LoginPage() {
const serverInfos = useAppSelector(state => state.server.serverInfos)
const dispatch = useAppDispatch()
const form = useForm<LoginRequest>({
initialValues: {
name: "",
password: "",
},
})
const [login, loginResult] = useMutation(client.user.login, {
onSuccess: () => {
dispatch(redirectToRootCategory())
},
})
const errors = errorToStrings(loginResult.error)
return (
<Container size="xs">
<Center my="xl">
<Logo size={48} />
<Title order={1} ml="md">
CommaFeed
</Title>
</Center>
<Paper>
<Title order={2} mb="md">
<Trans>Log in</Trans>
</Title>
{errors.length > 0 && (
<Box mb="md">
<Alert messages={errors} />
</Box>
)}
<form onSubmit={form.onSubmit(login)}>
<Stack>
<TextInput
label={t`User Name or E-mail`}
placeholder={t`User Name or E-mail`}
{...form.getInputProps("name")}
size="md"
required
/>
<PasswordInput
label={t`Password`}
placeholder={t`Password`}
{...form.getInputProps("password")}
size="md"
required
/>
{serverInfos?.smtpEnabled && (
<Anchor component={Link} to="/passwordRecovery" color="dimmed">
<Trans>Forgot password?</Trans>
</Anchor>
)}
<Button type="submit" loading={loginResult.status === "running"}>
<Trans>Log in</Trans>
</Button>
{serverInfos?.allowRegistrations && (
<Center>
<Group>
<Trans>
<Box>Need an account?</Box>
<Anchor component={Link} to="/register">
Sign up!
</Anchor>
</Trans>
</Group>
</Center>
)}
</Stack>
</form>
</Paper>
</Container>
)
}

View File

@@ -0,0 +1,80 @@
import { t, Trans } from "@lingui/macro"
import { Anchor, Box, Button, Center, Container, Group, Paper, Stack, TextInput, Title } from "@mantine/core"
import { useForm } from "@mantine/form"
import { client, errorToStrings } from "app/client"
import { PasswordResetRequest } from "app/types"
import { Alert } from "components/Alert"
import { Logo } from "components/Logo"
import { useState } from "react"
import { Link } from "react-router-dom"
import useMutation from "use-mutation"
export function PasswordRecoveryPage() {
const [message, setMessage] = useState("")
const form = useForm<PasswordResetRequest>({
initialValues: {
email: "",
},
})
const [recoverPassword, recoverPasswordResult] = useMutation(client.user.passwordReset, {
onMutate: () => {
setMessage("")
},
onSuccess: () => {
setMessage(t`An email has been sent if this address was registered. Check your inbox.`)
},
})
const errors = errorToStrings(recoverPasswordResult.error)
return (
<Container size="xs">
<Center my="xl">
<Logo size={48} />
<Title order={1} ml="md">
CommaFeed
</Title>
</Center>
<Paper>
<Title order={2} mb="md">
<Trans>Password Recovery</Trans>
</Title>
{errors.length > 0 && (
<Box mb="md">
<Alert messages={errors} />
</Box>
)}
{message && (
<Box mb="md">
<Alert level="success" messages={[message]} />
</Box>
)}
<form onSubmit={form.onSubmit(recoverPassword)}>
<Stack>
<TextInput
type="email"
label={t`E-mail`}
placeholder={t`E-mail`}
{...form.getInputProps("email")}
size="md"
required
/>
<Button type="submit" loading={recoverPasswordResult.status === "running"}>
<Trans>Recover password</Trans>
</Button>
<Center>
<Group>
<Anchor component={Link} to="/login">
<Trans>Back to log in</Trans>
</Anchor>
</Group>
</Center>
</Stack>
</form>
</Paper>
</Container>
)
}

View File

@@ -0,0 +1,95 @@
import { t, Trans } from "@lingui/macro"
import { Anchor, Box, Button, Center, Container, Group, Paper, PasswordInput, Stack, TextInput, Title } from "@mantine/core"
import { useForm } from "@mantine/form"
import { client, errorToStrings } from "app/client"
import { redirectToRootCategory } from "app/slices/redirect"
import { useAppDispatch, useAppSelector } from "app/store"
import { RegistrationRequest } from "app/types"
import { Alert } from "components/Alert"
import { Logo } from "components/Logo"
import { Link } from "react-router-dom"
import useMutation from "use-mutation"
export function RegistrationPage() {
const serverInfos = useAppSelector(state => state.server.serverInfos)
const dispatch = useAppDispatch()
const form = useForm<RegistrationRequest>({
initialValues: {
name: "",
password: "",
email: "",
},
})
const [register, registerResult] = useMutation(client.user.register, {
onSuccess: () => {
dispatch(redirectToRootCategory())
},
})
const errors = errorToStrings(registerResult.error)
return (
<Container size="xs">
<Center my="xl">
<Logo size={48} />
<Title order={1} ml="md">
CommaFeed
</Title>
</Center>
<Paper>
<Title order={2} mb="md">
<Trans>Sign up</Trans>
</Title>
{serverInfos && !serverInfos.allowRegistrations && (
<Box mb="md">
<Alert messages={[t`Registrations are closed on this CommaFeed instance`]} />
</Box>
)}
{serverInfos?.allowRegistrations && (
<>
{errors.length > 0 && (
<Box mb="md">
<Alert messages={errors} />
</Box>
)}
<form onSubmit={form.onSubmit(register)}>
<Stack>
<TextInput label="User Name" placeholder="User Name" {...form.getInputProps("name")} size="md" required />
<TextInput
type="email"
label={t`E-mail address`}
placeholder={t`E-mail address`}
{...form.getInputProps("email")}
size="md"
required
/>
<PasswordInput
label={t`Password`}
placeholder={t`Password`}
{...form.getInputProps("password")}
size="md"
required
/>
<Button type="submit" loading={registerResult.status === "running"}>
<Trans>Sign up</Trans>
</Button>
<Center>
<Group>
<Trans>
<Box>Have an account?</Box>
<Anchor component={Link} to="/login">
Log in!
</Anchor>
</Trans>
</Group>
</Center>
</Stack>
</form>
</>
)}
</Paper>
</Container>
)
}