import { useQueryClient } from "@tanstack/react-query"; import cn from "classnames"; import { Field, Form, Formik } from "formik"; import { useState } from "react"; import { Alert } from "react-bootstrap"; import { createUser } from "src/api/backend"; import { Button, LocalePicker, Page, ThemeSwitcher } from "src/components"; import { useAuthState } from "src/context"; import { intl, T } from "src/locale"; import { validateEmail, validateString } from "src/modules/Validations"; import styles from "./index.module.css"; interface Payload { name: string; email: string; password: string; } export default function Setup() { const queryClient = useQueryClient(); const { login } = useAuthState(); const [errorMsg, setErrorMsg] = useState(null); const onSubmit = async (values: Payload, { setSubmitting }: any) => { setErrorMsg(null); // Set a nickname, which is the first word of the name const nickname = values.name.split(" ")[0]; const { password, ...payload } = { ...values, ...{ nickname, auth: { type: "password", secret: values.password, }, }, }; try { const user = await createUser(payload, true); if (user?.id) { try { await login(user.email, password); // Trigger a Health change await queryClient.refetchQueries({ queryKey: ["health"] }); // window.location.reload(); } catch (err: any) { setErrorMsg(err.message); } } else { setErrorMsg("cannot_create_user"); } } catch (err: any) { setErrorMsg(err.message); } setSubmitting(false); }; return (
Nginx Proxy Manager
setErrorMsg(null)} dismissible> {errorMsg} {({ isSubmitting }) => (


{({ field, form }: any) => (
{form.errors.name ? (
{form.errors.name && form.touched.name ? form.errors.name : null}
) : null}
)}
{({ field, form }: any) => (
{form.errors.email ? (
{form.errors.email && form.touched.email ? form.errors.email : null}
) : null}
)}
{({ field, form }: any) => (
{form.errors.password ? (
{form.errors.password && form.touched.password ? form.errors.password : null}
) : null}
)}
)}
); }