autobrr/web/src/screens/auth/onboarding.tsx
ze0s 6e5385a490
refactor(web): replace pkg react-query with tanstack/react-query (#868)
* refactor: move to tanstack/react-query and fix cache

* refactor(releases): move to tanstack/react-query

* refactor(logs): move to tanstack/react-query

* refactor(base): move to tanstack/react-query

* refactor(base): move to tanstack/react-query

* refactor(dashboard): move to tanstack/react-query

* refactor(auth): move to tanstack/react-query

* refactor(filters): move to tanstack/react-query

* refactor(settings): move to tanstack/react-query

* chore(pkg): add tanstack/react-query

* refactor(filters): move to tanstack/react-query

* refactor: move to tanstack/react-query

* refactor: invalidate queries

* chore(pkg): remove old react-query

* chore: change imports to root prefixes

* build: remove needs web from test

* set enableReinitialize to true to fix formik caching issues

* fix all property for apiKeys const

* fix toast when enabling/disabling feed

---------

Co-authored-by: martylukyy <35452459+martylukyy@users.noreply.github.com>
2023-04-27 21:26:27 +02:00

81 lines
2.7 KiB
TypeScript

import { Form, Formik } from "formik";
import { useMutation } from "@tanstack/react-query";
import { useNavigate } from "react-router-dom";
import { APIClient } from "@api/APIClient";
import { TextField, PasswordField } from "@components/inputs";
import logo from "@app/logo.png";
interface InputValues {
username: string;
password1: string;
password2: string;
}
export const Onboarding = () => {
const validate = (values: InputValues) => {
const obj: Record<string, string> = {};
if (!values.username)
obj.username = "Required";
if (!values.password1)
obj.password1 = "Required";
if (!values.password2)
obj.password2 = "Required";
if (values.password1 !== values.password2)
obj.password2 = "Passwords don't match!";
return obj;
};
const navigate = useNavigate();
const mutation = useMutation({
mutationFn: (data: InputValues) => APIClient.auth.onboard(data.username, data.password1),
onSuccess: () => navigate("/")
});
return (
<div className="min-h-screen flex flex-col justify-center py-12 sm:px-6 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-md mb-6">
<img className="mx-auto h-12 w-auto" src={logo} alt="logo"/>
<h1 className="text-center text-gray-900 dark:text-gray-200 font-bold pt-2 text-2xl">
autobrr
</h1>
</div>
<div className="sm:mx-auto sm:w-full sm:max-w-md shadow-lg">
<div className="bg-white dark:bg-gray-800 py-8 px-4 sm:rounded-lg sm:px-10">
<Formik
initialValues={{
username: "",
password1: "",
password2: ""
}}
onSubmit={(data) => mutation.mutate(data)}
validate={validate}
>
<Form>
<div className="space-y-6">
<TextField name="username" label="Username" columns={6} autoComplete="username" />
<PasswordField name="password1" label="Password" columns={6} autoComplete="current-password" />
<PasswordField name="password2" label="Confirm password" columns={6} autoComplete="current-password" />
</div>
<div className="mt-6">
<button
type="submit"
className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 dark:bg-blue-600 hover:bg-blue-700 dark:hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 dark:focus:ring-blue-500"
>
Create account
</button>
</div>
</Form>
</Formik>
</div>
</div>
</div>
);
};