import FormikSwitch from '@/components/elements/FormikSwitch'; import React from 'react'; import tw from 'twin.macro'; import { action, Action, createContextStore } from 'easy-peasy'; import { User } from '@/api/admin/users/getUsers'; import AdminBox from '@/components/admin/AdminBox'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import { Form, Formik, FormikHelpers } from 'formik'; import { bool, object, string } from 'yup'; import { Role } from '@/api/admin/roles/getRoles'; import { Values } from '@/api/admin/users/updateUser'; import Button from '@/components/elements/Button'; import Field from '@/components/elements/Field'; import RoleSelect from '@/components/admin/users/RoleSelect'; interface ctx { user: User | undefined; setUser: Action; } export const Context = createContextStore({ user: undefined, setUser: action((state, payload) => { state.user = payload; }), }); export interface Params { title: string; initialValues?: Values; children?: React.ReactNode; onSubmit: (values: Values, helpers: FormikHelpers) => void; role: Role | null; } export default function UserForm ({ title, initialValues, children, onSubmit, role }: Params) { const submit = (values: Values, helpers: FormikHelpers) => { onSubmit(values, helpers); }; if (!initialValues) { initialValues = { username: '', email: '', password: '', adminRoleId: 0, rootAdmin: false, }; } return ( { ({ isSubmitting, isValid }) => ( <>
{children}
) }
); }