import { Button, Group, PasswordInput, Stack, Switch, TextInput, Title, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import * as yup from "yup"; import userService from "../../../services/user.service"; import toast from "../../../utils/toast.util"; const showCreateUserModal = ( modals: ModalsContextProps, smtpEnabled: boolean, getUsers: () => void ) => { return modals.openModal({ title: Create user, children: ( ), }); }; const Body = ({ modals, smtpEnabled, getUsers, }: { modals: ModalsContextProps; smtpEnabled: boolean; getUsers: () => void; }) => { const form = useForm({ initialValues: { username: "", email: "", password: undefined, isAdmin: false, setPasswordManually: false, }, validate: yupResolver( yup.object().shape({ email: yup.string().email(), username: yup.string().min(3), password: yup.string().min(8).optional(), }) ), }); return (
{ userService .create(values) .then(() => { getUsers(); modals.closeAll(); }) .catch(toast.axiosError); })} > {smtpEnabled && ( )} {(form.values.setPasswordManually || !smtpEnabled) && ( )}
); }; export default showCreateUserModal;