diff options
| author | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-24 13:09:50 +0000 |
| commit | 396acf3bbbe00a192cb0ea0a9ccf91b1d8d2850b (patch) | |
| tree | b9df4ca6a70db45cfffbae6fdd7252e20fb8e93c /src/app/login/LoginForm.tsx | |
| download | umami-main.tar.xz umami-main.zip | |
Created from https://vercel.com/new
Diffstat (limited to 'src/app/login/LoginForm.tsx')
| -rw-r--r-- | src/app/login/LoginForm.tsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/app/login/LoginForm.tsx b/src/app/login/LoginForm.tsx new file mode 100644 index 0000000..26d78dd --- /dev/null +++ b/src/app/login/LoginForm.tsx @@ -0,0 +1,70 @@ +import { + Column, + Form, + FormButtons, + FormField, + FormSubmitButton, + Heading, + Icon, + PasswordField, + TextField, +} from '@umami/react-zen'; +import { useRouter } from 'next/navigation'; +import { useMessages, useUpdateQuery } from '@/components/hooks'; +import { Logo } from '@/components/svg'; +import { setClientAuthToken } from '@/lib/client'; +import { setUser } from '@/store/app'; + +export function LoginForm() { + const { formatMessage, labels, getErrorMessage } = useMessages(); + const router = useRouter(); + const { mutateAsync, error } = useUpdateQuery('/auth/login'); + + const handleSubmit = async (data: any) => { + await mutateAsync(data, { + onSuccess: async ({ token, user }) => { + setClientAuthToken(token); + setUser(user); + router.push('/'); + }, + }); + }; + + return ( + <Column justifyContent="center" alignItems="center" gap="6"> + <Icon size="lg"> + <Logo /> + </Icon> + <Heading>umami</Heading> + <Form onSubmit={handleSubmit} error={getErrorMessage(error)}> + <FormField + label={formatMessage(labels.username)} + data-test="input-username" + name="username" + rules={{ required: formatMessage(labels.required) }} + > + <TextField autoComplete="username" /> + </FormField> + + <FormField + label={formatMessage(labels.password)} + data-test="input-password" + name="password" + rules={{ required: formatMessage(labels.required) }} + > + <PasswordField autoComplete="current-password" /> + </FormField> + <FormButtons> + <FormSubmitButton + data-test="button-submit" + variant="primary" + style={{ flex: 1 }} + isDisabled={false} + > + {formatMessage(labels.login)} + </FormSubmitButton> + </FormButtons> + </Form> + </Column> + ); +} |