2023-08-02 09:35:48 +00:00
|
|
|
import { usePathname, useRouter } from "next/navigation";
|
2023-04-15 00:04:48 +00:00
|
|
|
|
|
|
|
import { getParserWithGeneric } from "@calcom/prisma/zod-utils";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
|
|
|
import { Meta, showToast } from "@calcom/ui";
|
|
|
|
|
|
|
|
import { getLayout } from "../../../settings/layouts/SettingsLayout";
|
2023-04-19 14:15:08 +00:00
|
|
|
import LicenseRequired from "../../common/components/LicenseRequired";
|
2023-04-15 00:04:48 +00:00
|
|
|
import { UserForm } from "../components/UserForm";
|
|
|
|
import { userBodySchema } from "../schemas/userBodySchema";
|
|
|
|
|
|
|
|
const UsersAddView = () => {
|
2023-08-02 09:35:48 +00:00
|
|
|
const pathname = usePathname();
|
2023-04-15 00:04:48 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const mutation = trpc.viewer.users.add.useMutation({
|
|
|
|
onSuccess: async () => {
|
|
|
|
showToast("User added successfully", "success");
|
|
|
|
await utils.viewer.users.list.invalidate();
|
2023-08-02 09:35:48 +00:00
|
|
|
router.replace(pathname?.replace("/add", ""));
|
2023-04-15 00:04:48 +00:00
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
console.error(err.message);
|
|
|
|
showToast("There has been an error adding this user.", "error");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<LicenseRequired>
|
|
|
|
<Meta title="Add new user" description="Here you can add a new user." />
|
|
|
|
<UserForm
|
|
|
|
submitLabel="Add user"
|
|
|
|
onSubmit={async (values) => {
|
|
|
|
const parser = getParserWithGeneric(userBodySchema);
|
|
|
|
const parsedValues = parser(values);
|
|
|
|
mutation.mutate(parsedValues);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</LicenseRequired>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
UsersAddView.getLayout = getLayout;
|
|
|
|
|
|
|
|
export default UsersAddView;
|