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 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, { FieldRow } 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; uuid?: string; role: Role | null; } export default function UserForm ({ title, initialValues, children, onSubmit, uuid, role }: Params) { const submit = (values: Values, 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}
) }
); }