From 1a384dce5f04bb8a2aae4a29d570b16b4f6c219a Mon Sep 17 00:00:00 2001 From: mehedi-hasan Date: Fri, 3 May 2024 19:43:59 +0600 Subject: [PATCH] feat: user edit page --- .../(dashboard)/dashboard/users/add/page.tsx | 26 +++++------ .../dashboard/users/edit/[id]/page.tsx | 44 +++++++++++++++++++ .../{add-user-form.tsx => user-form.tsx} | 16 +++---- src/components/users-table/cell-action.tsx | 24 ++++++---- src/constants/data.ts | 7 ++- 5 files changed, 82 insertions(+), 35 deletions(-) create mode 100644 src/app/(dashboard)/dashboard/users/edit/[id]/page.tsx rename src/components/{add-user-form.tsx => user-form.tsx} (96%) diff --git a/src/app/(dashboard)/dashboard/users/add/page.tsx b/src/app/(dashboard)/dashboard/users/add/page.tsx index 17aba0d..d678e58 100644 --- a/src/app/(dashboard)/dashboard/users/add/page.tsx +++ b/src/app/(dashboard)/dashboard/users/add/page.tsx @@ -1,4 +1,4 @@ -import AddUserForm from "@/components/add-user-form"; +import AddUserForm from "@/components/user-form"; import Breadcrumb from "@/components/breadcrumb"; import { Button } from "@/components/ui/button"; import { @@ -21,20 +21,20 @@ export default function SettingsDisplayPage() { return (
- +
- - - - Create User - - - + + + + Create User + + + - - - - + + + +
diff --git a/src/app/(dashboard)/dashboard/users/edit/[id]/page.tsx b/src/app/(dashboard)/dashboard/users/edit/[id]/page.tsx new file mode 100644 index 0000000..e19c674 --- /dev/null +++ b/src/app/(dashboard)/dashboard/users/edit/[id]/page.tsx @@ -0,0 +1,44 @@ +import UserForm from "@/components/user-form"; +import Breadcrumb from "@/components/breadcrumb"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area"; +import { Separator } from "@/components/ui/separator"; +import { dummyUsers } from "@/constants/data"; +import { User } from "@/types/user"; + +const breadcrumbItems = [ + { title: "Dashboard", link: "/dashboard" }, + { title: "Users", link: "/dashboard/users" }, + { title: "Edit" }, +]; + +export default function Page({ params }: { params: { id: string } }) { + console.log(params); + + const user = dummyUsers.find((user) => user.id === +params.id); + + console.log(user); + + return ( + +
+ +
+ + + + Edit User + + + + + + + + +
+
+ +
+ ); +} diff --git a/src/components/add-user-form.tsx b/src/components/user-form.tsx similarity index 96% rename from src/components/add-user-form.tsx rename to src/components/user-form.tsx index a3f3e98..1d01ad7 100644 --- a/src/components/add-user-form.tsx +++ b/src/components/user-form.tsx @@ -17,6 +17,7 @@ import { } from "@/components/ui/form"; import { toast } from "@/components/ui/use-toast"; import { Input } from "./ui/input"; +import { User } from "@/types/user"; const roles = [ { @@ -61,17 +62,14 @@ const displayFormSchema = z.object({ type DisplayFormValues = z.infer; -// This can come from your database or API. -const defaultValues: Partial = { - fullName: "", - email: "", - roles: ["ROLE_USER"], -}; - -export default function AddUserForm() { +export default function UserForm({ user }: { user?: User }) { const form = useForm({ resolver: zodResolver(displayFormSchema), - defaultValues, + defaultValues: { + fullName: user?.fullName || "", + email: user?.email || "", + roles: [user?.role || "ROLE_USER"], + }, }); function onSubmit(data: DisplayFormValues) { diff --git a/src/components/users-table/cell-action.tsx b/src/components/users-table/cell-action.tsx index 7df5e56..a6d888a 100644 --- a/src/components/users-table/cell-action.tsx +++ b/src/components/users-table/cell-action.tsx @@ -11,7 +11,8 @@ import { import { useToast } from "@/components/ui/use-toast"; import { User } from "@/types/user"; -import { BookCheck, Edit, MoreHorizontal, Trash } from "lucide-react"; +import { Edit, MoreHorizontal, Trash, UserCheck } from "lucide-react"; +import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; @@ -27,7 +28,8 @@ export const CellAction: React.FC = ({ data }) => { const onDeleteConfirm = async () => {}; - const handleUpdateStatus = async () => {}; + + console.log(data) return ( <> @@ -47,13 +49,17 @@ export const CellAction: React.FC = ({ data }) => { Actions - - // router.push(`#`) - // } - > - Update + + Approve User + + + + + Edit +