MCPcopy
hub / github.com/fastapi/full-stack-fastapi-template / AddUser

Function AddUser

frontend/src/components/Admin/AddUser.tsx:55–236  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53type FormData = z.infer<typeof formSchema>
54
55const AddUser = () => {
56 const [isOpen, setIsOpen] = useState(false)
57 const queryClient = useQueryClient()
58 const { showSuccessToast, showErrorToast } = useCustomToast()
59
60 const form = useForm<FormData>({
61 resolver: zodResolver(formSchema),
62 mode: "onBlur",
63 criteriaMode: "all",
64 defaultValues: {
65 email: "",
66 full_name: "",
67 password: "",
68 confirm_password: "",
69 is_superuser: false,
70 is_active: false,
71 },
72 })
73
74 const mutation = useMutation({
75 mutationFn: (data: UserCreate) =>
76 UsersService.createUser({ requestBody: data }),
77 onSuccess: () => {
78 showSuccessToast("User created successfully")
79 form.reset()
80 setIsOpen(false)
81 },
82 onError: handleError.bind(showErrorToast),
83 onSettled: () => {
84 queryClient.invalidateQueries({ queryKey: ["users"] })
85 },
86 })
87
88 const onSubmit = (data: FormData) => {
89 mutation.mutate(data)
90 }
91
92 return (
93 <Dialog open={isOpen} onOpenChange={setIsOpen}>
94 <DialogTrigger asChild>
95 <Button className="my-4">
96 <Plus className="mr-2" />
97 Add User
98 </Button>
99 </DialogTrigger>
100 <DialogContent className="sm:max-w-md">
101 <DialogHeader>
102 <DialogTitle>Add User</DialogTitle>
103 <DialogDescription>
104 Fill in the form below to add a new user to the system.
105 </DialogDescription>
106 </DialogHeader>
107 <Form {...form}>
108 <form onSubmit={form.handleSubmit(onSubmit)}>
109 <div className="grid gap-4 py-4">
110 <FormField
111 control={form.control}
112 name="email"

Callers

nothing calls this directly

Calls 3

useCustomToastFunction · 0.85
showSuccessToastFunction · 0.85
createUserMethod · 0.45

Tested by

no test coverage detected