import { Button, Group, PasswordInput, Stack, Switch, TextInput, } from "@mantine/core"; import { useForm, yupResolver } from "@mantine/form"; import { ModalsContextProps } from "@mantine/modals/lib/context"; import { FormattedMessage } from "react-intl"; import * as yup from "yup"; import useTranslate from "../../../hooks/useTranslate.hook"; 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 t = useTranslate(); const form = useForm({ initialValues: { username: "", email: "", password: undefined, isAdmin: false, setPasswordManually: false, }, validate: yupResolver( yup.object().shape({ email: yup.string().email(t("common.error.invalid-email")), username: yup .string() .min(3, t("common.error.too-short", { length: 3 })), password: yup .string() .min(8, t("common.error.too-short", { length: 8 })) .optional(), }), ), }); return (
{ userService .create(values) .then(() => { getUsers(); modals.closeAll(); }) .catch(toast.axiosError); })} > {smtpEnabled && ( )} {(form.values.setPasswordManually || !smtpEnabled) && ( )}
); }; export default showCreateUserModal;