import FormHelperText from "@material-ui/core/FormHelperText" import TextField from "@material-ui/core/TextField" import { FormikContextType, FormikErrors, useFormik } from "formik" import { FC } from "react" import * as Yup from "yup" import { getFormHelpers, nameValidator, onChangeTrimmed } from "../../util/formUtils" import { LoadingButton } from "../LoadingButton/LoadingButton" import { Stack } from "../Stack/Stack" interface AccountFormValues { username: string } export const Language = { usernameLabel: "Username", emailLabel: "Email", updateSettings: "Update settings", } const validationSchema = Yup.object({ username: nameValidator(Language.usernameLabel), }) export type AccountFormErrors = FormikErrors export interface AccountFormProps { email: string isLoading: boolean initialValues: AccountFormValues onSubmit: (values: AccountFormValues) => void formErrors?: AccountFormErrors error?: string } export const AccountForm: FC = ({ email, isLoading, onSubmit, initialValues, formErrors = {}, error, }) => { const form: FormikContextType = useFormik({ initialValues, validationSchema, onSubmit, }) const getFieldHelpers = getFormHelpers(form, formErrors) return ( <>
{error && {error}}
{isLoading ? "" : Language.updateSettings}
) }