diff --git a/src/app/(dashboard)/dashboard/users/add/page.tsx b/src/app/(dashboard)/dashboard/users/add/page.tsx new file mode 100644 index 0000000..4eeefc5 --- /dev/null +++ b/src/app/(dashboard)/dashboard/users/add/page.tsx @@ -0,0 +1,38 @@ +import { Button } from "@/components/ui/button"; +import { + Card, + CardContent, + CardFooter, + CardHeader, + CardTitle, +} from "@/components/ui/card"; +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import UsersAddForm from "@/components/users-add-form"; + +export default function SettingsDisplayPage() { + return ( + +
+ + + + Create User + + + + + + + + {/* + + */} + +
+ +
+ ); +} diff --git a/src/components/users-add-form.tsx b/src/components/users-add-form.tsx new file mode 100644 index 0000000..ef97558 --- /dev/null +++ b/src/components/users-add-form.tsx @@ -0,0 +1,223 @@ +"use client"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; + +import { Button } from "@/components/ui/button"; +import { Checkbox } from "@/components/ui/checkbox"; +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { toast } from "@/components/ui/use-toast"; +import { Input } from "./ui/input"; + +const items = [ + { + id: "ROLE_SUPER_ADMIN", + label: "ROLE_SUPER_ADMIN", + }, + { + id: "ROLE_ADMIN", + label: "ROLE_ADMIN", + }, + { + id: "ROLE_SYSADMIN", + label: "ROLE_SYSADMIN", + }, + { + id: "ROLE_API", + label: "ROLE_API", + }, + { + id: "ROLE_ORGANISATION_ADMIN", + label: "ROLE_ORGANISATION_ADMIN", + }, + { + id: "ROLE_ASSISTANT", + label: "ROLE_ASSISTANT", + }, + { + id: "ROLE_USER", + label: "ROLE_USER", + }, +] as const; + +const displayFormSchema = z.object({ + fullName: z.string().trim().min(1, "Full Name is required."), + email: z.string().trim().email("Email is required."), + newPassword: z.string().trim().min(1, "Password is required."), + repeatPassword: z.string().trim().min(1, "Repeat the new password."), + roles: z.array(z.string()).refine((value) => value.some((item) => item), { + message: "You have to select at least one role.", + }), +}); + +type DisplayFormValues = z.infer; + +// This can come from your database or API. +const defaultValues: Partial = { + fullName: "", + email: "", + roles: ["ROLE_USER"], +}; + +export default function UsersAddForm() { + const form = useForm({ + resolver: zodResolver(displayFormSchema), + defaultValues, + }); + + function onSubmit(data: DisplayFormValues) { + if (data.newPassword !== data.repeatPassword) { + toast({ + variant: "destructive", + title: "Password doesn't match!", + }); + return; + } + + toast({ + title: "You submitted the following values:", + description: ( +
+          {JSON.stringify(data, null, 2)}
+        
+ ), + }); + } + + return ( +
+ + ( + + Full Name + + + + {/* + This is your public display name. It can be your real name or a + pseudonym. You can only change this once every 30 days. + */} + + + )} + /> + ( + + Email + + + + + + )} + /> + ( + + New Password + + + + + + )} + /> + ( + + Repeat Password + + + + + + )} + /> + + ( + +
+ Roles + {/* + Select the items you want to display in the sidebar. + */} +
+ {items.map((item) => ( + { + return ( + + + { + return checked + ? field.onChange([...field.value, item.id]) + : field.onChange( + field.value?.filter( + (value) => value !== item.id + ) + ); + }} + /> + + + {item.label} + + + ); + }} + /> + ))} + +
+ )} + /> +
+ + +
+ + + ); +} diff --git a/src/components/users-table/tools-table.tsx b/src/components/users-table/tools-table.tsx index 54078dd..7099384 100644 --- a/src/components/users-table/tools-table.tsx +++ b/src/components/users-table/tools-table.tsx @@ -16,13 +16,11 @@ const ToolsTable = ({ users }: { users: User[] }) => {
router.push(`/admin-dashboard/tools/add`)} + > Add User