Files
tonePage/tone-page-web/app/console/(with-menu)/user/components/user-info-editor.tsx
2025-05-12 10:45:56 +08:00

84 lines
2.8 KiB
TypeScript

'use client';
import * as React from "react"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
} from "@/components/ui/drawer"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { useUser } from "@/hooks/admin/user/use-user";
import { User } from "@/lib/types/user";
import { Skeleton } from "@/components/ui/skeleton";
export function UserInfoEditor({
onClose,
userId,
}: {
onClose: () => void,
userId: string
}) {
const { user, isLoading, error } = userId ? useUser(userId) : {};
return (
<Drawer open={!!userId} onClose={onClose} >
<DrawerContent>
<DrawerHeader className="text-left">
<DrawerTitle></DrawerTitle>
<DrawerDescription></DrawerDescription>
</DrawerHeader>
{user && <ProfileForm className="px-4" user={user} onSubmit={(e) => {
e.preventDefault();
}} />}
{isLoading &&
[...Array(5)].map((_, i) => (
<Skeleton className="h-20 mx-4 my-1" key={i} />
))
}
<DrawerFooter className="pt-2">
<DrawerClose asChild>
<Button variant="outline"></Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
)
}
function ProfileForm({ className, user, ...props }: React.ComponentProps<"form"> & { user: User }) {
return (
<form className={cn("grid items-start gap-4", className)} {...props}>
<div className="grid gap-2">
<Label htmlFor="email">UserId</Label>
<Input id="email" defaultValue={user.userId} disabled />
</div>
<div className="grid gap-2">
<Label htmlFor="username"></Label>
<Input id="username" defaultValue={user.username} />
</div>
<div className="grid gap-2">
<Label htmlFor="nickname"></Label>
<Input id="nickname" defaultValue={user.nickname} />
</div>
<div className="grid gap-2">
<Label htmlFor="email"></Label>
<Input id="email" defaultValue={user.email} />
</div>
<div className="grid gap-2">
<Label htmlFor="phone"></Label>
<Input id="phone" defaultValue={user.phone} />
</div>
<Button type="submit"></Button>
</form>
)
}