import type { Action } from 'easy-peasy'; import { action, createContextStore } from 'easy-peasy'; import type { FormikHelpers } from 'formik'; import { Form, Formik } from 'formik'; import tw from 'twin.macro'; import { bool, object, string } from 'yup'; import type { UpdateUserValues } from '@/api/admin/users'; import AdminBox from '@/components/admin/AdminBox'; import RoleSelect from '@/components/admin/users/RoleSelect'; import CopyOnClick from '@/components/elements/CopyOnClick'; import FormikSwitch from '@/components/elements/FormikSwitch'; import Input from '@/components/elements/Input'; import Label from '@/components/elements/Label'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import Button from '@/components/elements/Button'; import Field, { FieldRow } from '@/components/elements/Field'; import type { User, UserRole } from '@definitions/admin'; 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?: UpdateUserValues; children?: React.ReactNode; onSubmit: (values: UpdateUserValues, helpers: FormikHelpers) => void; uuid?: string; role: UserRole | null; } export default function UserForm({ title, initialValues, children, onSubmit, uuid, role }: Params) { const submit = (values: UpdateUserValues, helpers: FormikHelpers) => { onSubmit(values, helpers); }; if (!initialValues) { initialValues = { externalId: '', username: '', email: '', password: '', adminRoleId: null, rootAdmin: false, }; } return ( {({ isSubmitting, isValid }) => ( <>
{uuid && (
)}
{/* TODO: Remove toggle once role permissions are implemented. */}
{children}
)}
); }