feat: user edit page
This commit is contained in:
parent
32b31f9df3
commit
1a384dce5f
|
@ -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 (
|
||||
<ScrollArea className="h-[calc(100vh-53px)]">
|
||||
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">
|
||||
<Breadcrumb items={breadcrumbItems} />
|
||||
<Breadcrumb items={breadcrumbItems} />
|
||||
<div className="w-full h-full flex justify-center items-center">
|
||||
<Card className="max-w-[700px] w-full mb-8">
|
||||
<CardHeader>
|
||||
<CardTitle className="mb-4 font-bold text-xl">
|
||||
Create User
|
||||
</CardTitle>
|
||||
<Separator />
|
||||
</CardHeader>
|
||||
<Card className="max-w-[700px] w-full mb-8">
|
||||
<CardHeader>
|
||||
<CardTitle className="mb-4 font-bold text-xl">
|
||||
Create User
|
||||
</CardTitle>
|
||||
<Separator />
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<AddUserForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<CardContent>
|
||||
<AddUserForm />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
<ScrollBar />
|
||||
|
|
|
@ -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 (
|
||||
<ScrollArea className="h-[calc(100vh-53px)]">
|
||||
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">
|
||||
<Breadcrumb items={breadcrumbItems} />
|
||||
<div className="w-full h-full flex justify-center items-center">
|
||||
<Card className="max-w-[700px] w-full mb-8">
|
||||
<CardHeader>
|
||||
<CardTitle className="mb-4 font-bold text-xl">
|
||||
Edit User
|
||||
</CardTitle>
|
||||
<Separator />
|
||||
</CardHeader>
|
||||
|
||||
<CardContent>
|
||||
<UserForm user={user as User} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
<ScrollBar />
|
||||
</ScrollArea>
|
||||
);
|
||||
}
|
|
@ -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<typeof displayFormSchema>;
|
||||
|
||||
// This can come from your database or API.
|
||||
const defaultValues: Partial<DisplayFormValues> = {
|
||||
fullName: "",
|
||||
email: "",
|
||||
roles: ["ROLE_USER"],
|
||||
};
|
||||
|
||||
export default function AddUserForm() {
|
||||
export default function UserForm({ user }: { user?: User }) {
|
||||
const form = useForm<DisplayFormValues>({
|
||||
resolver: zodResolver(displayFormSchema),
|
||||
defaultValues,
|
||||
defaultValues: {
|
||||
fullName: user?.fullName || "",
|
||||
email: user?.email || "",
|
||||
roles: [user?.role || "ROLE_USER"],
|
||||
},
|
||||
});
|
||||
|
||||
function onSubmit(data: DisplayFormValues) {
|
|
@ -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<CellActionProps> = ({ data }) => {
|
|||
|
||||
const onDeleteConfirm = async () => {};
|
||||
|
||||
const handleUpdateStatus = async () => {};
|
||||
|
||||
console.log(data)
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -47,13 +49,17 @@ export const CellAction: React.FC<CellActionProps> = ({ data }) => {
|
|||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Actions</DropdownMenuLabel>
|
||||
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
// onClick={() =>
|
||||
// router.push(`#`)
|
||||
// }
|
||||
>
|
||||
<Edit className="mr-2 h-4 w-4" /> Update
|
||||
<DropdownMenuItem className="cursor-pointer">
|
||||
<UserCheck className="mr-2 h-4 w-4" /> Approve User
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem className="cursor-pointer">
|
||||
<Link
|
||||
href={`/dashboard/users/edit/${data.id}`}
|
||||
className="flex items-center gap-2"
|
||||
>
|
||||
<Edit className="h-4 w-4" /> Edit
|
||||
</Link>
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
|
|
|
@ -9,28 +9,27 @@ import { Organization } from "@/types/organization";
|
|||
import { Skill } from "@/types/skill";
|
||||
import { User } from "@/types/user";
|
||||
import { UserRound, UserRoundCheck } from "lucide-react";
|
||||
import { number } from "zod";
|
||||
|
||||
export const dummyUsers: User[] = [
|
||||
{
|
||||
id: 1,
|
||||
email: "john@gmail.com",
|
||||
fullName: "John Doe",
|
||||
role: "ADMIN",
|
||||
role: "ROLE_ADMIN",
|
||||
created_at: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
email: "linustorvalds@gmail.com",
|
||||
fullName: "Linus Torvalds",
|
||||
role: "USER",
|
||||
role: "ROLE_USER",
|
||||
created_at: new Date().toISOString(),
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
email: "ryandahl@gmail.com",
|
||||
fullName: "Ryan Dahl",
|
||||
role: "ADMIN",
|
||||
role: "ROLE_ADMIN",
|
||||
created_at: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue