From 0a797a7fab47fabc1484d5e517ccd163552b8c35 Mon Sep 17 00:00:00 2001 From: mehedi-hasan Date: Sat, 20 Apr 2024 01:49:39 +0600 Subject: [PATCH] feat: added add organization form --- .../dashboard/organizations/add/page.tsx | 26 ++++++ .../(dashboard)/dashboard/users/add/page.tsx | 9 +-- src/components/add-organization-form.tsx | 79 +++++++++++++++++++ .../{users-add-form.tsx => add-user-form.tsx} | 18 ++--- .../organizations-table/tools-table.tsx | 2 +- 5 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 src/app/(dashboard)/dashboard/organizations/add/page.tsx create mode 100644 src/components/add-organization-form.tsx rename src/components/{users-add-form.tsx => add-user-form.tsx} (94%) diff --git a/src/app/(dashboard)/dashboard/organizations/add/page.tsx b/src/app/(dashboard)/dashboard/organizations/add/page.tsx new file mode 100644 index 0000000..f585d84 --- /dev/null +++ b/src/app/(dashboard)/dashboard/organizations/add/page.tsx @@ -0,0 +1,26 @@ +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import AddOrganizationForm from "@/components/add-organization-form"; + +export default function SettingsDisplayPage() { + return ( + +
+ + + + Create Organization + + + + + + + + +
+ +
+ ); +} diff --git a/src/app/(dashboard)/dashboard/users/add/page.tsx b/src/app/(dashboard)/dashboard/users/add/page.tsx index 4eeefc5..27e0f26 100644 --- a/src/app/(dashboard)/dashboard/users/add/page.tsx +++ b/src/app/(dashboard)/dashboard/users/add/page.tsx @@ -1,3 +1,4 @@ +import AddUserForm from "@/components/add-user-form"; import { Button } from "@/components/ui/button"; import { Card, @@ -8,7 +9,6 @@ import { } 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 ( @@ -23,13 +23,8 @@ export default function SettingsDisplayPage() { - + - {/* - - */} diff --git a/src/components/add-organization-form.tsx b/src/components/add-organization-form.tsx new file mode 100644 index 0000000..d557404 --- /dev/null +++ b/src/components/add-organization-form.tsx @@ -0,0 +1,79 @@ +"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 { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { toast } from "@/components/ui/use-toast"; +import { Input } from "./ui/input"; + +const displayFormSchema = z.object({ + name: z.string().trim().min(1, "Name is required."), +}); + +type DisplayFormValues = z.infer; + +// This can come from your database or API. +const defaultValues: Partial = { + name: "", +}; + +export default function AddOrganizationForm() { + const form = useForm({ + resolver: zodResolver(displayFormSchema), + defaultValues, + }); + + function onSubmit(data: DisplayFormValues) { + toast({ + title: "You submitted the following values:", + description: ( +
+          {JSON.stringify(data, null, 2)}
+        
+ ), + }); + } + + return ( +
+ + ( + + 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. + */} + + + )} + /> + +
+ + +
+ + + ); +} diff --git a/src/components/users-add-form.tsx b/src/components/add-user-form.tsx similarity index 94% rename from src/components/users-add-form.tsx rename to src/components/add-user-form.tsx index ef97558..c145311 100644 --- a/src/components/users-add-form.tsx +++ b/src/components/add-user-form.tsx @@ -18,7 +18,7 @@ import { import { toast } from "@/components/ui/use-toast"; import { Input } from "./ui/input"; -const items = [ +const roles = [ { id: "ROLE_SUPER_ADMIN", label: "ROLE_SUPER_ADMIN", @@ -68,7 +68,7 @@ const defaultValues: Partial = { roles: ["ROLE_USER"], }; -export default function UsersAddForm() { +export default function AddUserForm() { const form = useForm({ resolver: zodResolver(displayFormSchema), defaultValues, @@ -172,33 +172,33 @@ export default function UsersAddForm() { Select the items you want to display in the sidebar. */} - {items.map((item) => ( + {roles.map((role) => ( { return ( { return checked - ? field.onChange([...field.value, item.id]) + ? field.onChange([...field.value, role.id]) : field.onChange( field.value?.filter( - (value) => value !== item.id + (value) => value !== role.id ) ); }} /> - {item.label} + {role.label} ); diff --git a/src/components/organizations-table/tools-table.tsx b/src/components/organizations-table/tools-table.tsx index 20d446d..3779d97 100644 --- a/src/components/organizations-table/tools-table.tsx +++ b/src/components/organizations-table/tools-table.tsx @@ -20,7 +20,7 @@ const ToolsTable = ({ organizations }: { organizations: Organization[] }) => { description="Manage Organizations" />