-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
src/pages/(admin)/(with-layout)/list/components/view-user.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { zodResolver } from "@hookform/resolvers/zod" | ||
import { useForm } from "react-hook-form" | ||
import type { z } from "zod" | ||
|
||
import { Button } from "@/components/ui/button" | ||
import { DropdownMenuItem } from "@/components/ui/dropdown-menu" | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
} from "@/components/ui/form" | ||
import { Input } from "@/components/ui/input" | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectItem, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "@/components/ui/select" | ||
import { | ||
Sheet, | ||
SheetClose, | ||
SheetContent, | ||
SheetDescription, | ||
SheetFooter, | ||
SheetHeader, | ||
SheetTitle, | ||
SheetTrigger, | ||
} from "@/components/ui/sheet" | ||
import { toast } from "@/components/ui/use-toast" | ||
import type { IUsers } from "@/models/user" | ||
import { userRoles, userSchema } from "@/models/user" | ||
|
||
export function ViewUser({ user }: { user: IUsers }) { | ||
const form = useForm<IUsers>({ | ||
resolver: zodResolver(userSchema), | ||
defaultValues: user, | ||
}) | ||
|
||
function onSubmit(values: z.infer<typeof userSchema>) { | ||
toast({ | ||
title: "You submitted the following values:", | ||
description: ( | ||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> | ||
<code className="text-white">{JSON.stringify(values, null, 2)}</code> | ||
</pre> | ||
), | ||
}) | ||
} | ||
return ( | ||
<> | ||
<Sheet> | ||
<SheetTrigger asChild> | ||
<DropdownMenuItem onSelect={(event) => { | ||
event.preventDefault() | ||
}} | ||
> | ||
View customer | ||
</DropdownMenuItem> | ||
</SheetTrigger> | ||
<SheetContent> | ||
<SheetHeader> | ||
<SheetTitle>View User</SheetTitle> | ||
<SheetDescription> | ||
View user details here. | ||
</SheetDescription> | ||
</SheetHeader> | ||
|
||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)}> | ||
<div className="grid gap-4 py-4"> | ||
<FormField | ||
control={form.control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem className="grid grid-cols-4 items-center gap-4 space-y-0"> | ||
<FormLabel className="text-right">Name</FormLabel> | ||
<FormControl className="col-span-3"> | ||
<Input {...field} placeholder="user name" /> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem className="grid grid-cols-4 items-center gap-4 space-y-0"> | ||
<FormLabel className="text-right">Email</FormLabel> | ||
<FormControl> | ||
<Input {...field} placeholder="[email protected]" className="col-span-3" /> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="role" | ||
render={({ field }) => ( | ||
<FormItem className="grid grid-cols-4 items-center gap-4 space-y-0"> | ||
<FormLabel className="col-span-1 text-right">Role</FormLabel> | ||
<Select onValueChange={field.onChange} defaultValue={field.value}> | ||
<FormControl> | ||
<SelectTrigger className="col-span-3"> | ||
<SelectValue placeholder="Select a role" /> | ||
</SelectTrigger> | ||
</FormControl> | ||
<SelectContent> | ||
{userRoles.map((role) => ( | ||
<SelectItem key={role} value={role}>{role}</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="avatar" | ||
render={({ field }) => ( | ||
<FormItem className="grid grid-cols-4 items-center gap-4 space-y-0"> | ||
<FormLabel className="text-right">Avatar</FormLabel> | ||
<FormControl> | ||
<Input {...field} placeholder="user avatar" className="col-span-3" /> | ||
</FormControl> | ||
</FormItem> | ||
)} | ||
/> | ||
</div> | ||
</form> | ||
</Form> | ||
<SheetFooter> | ||
<SheetClose asChild> | ||
<Button type="submit">Save changes</Button> | ||
</SheetClose> | ||
</SheetFooter> | ||
</SheetContent> | ||
</Sheet> | ||
</> | ||
) | ||
} |