diff --git a/apps/frontend/app/console/(with-menu)/profile/page.tsx b/apps/frontend/app/console/(with-menu)/profile/page.tsx index 85e5422..892b638 100644 --- a/apps/frontend/app/console/(with-menu)/profile/page.tsx +++ b/apps/frontend/app/console/(with-menu)/profile/page.tsx @@ -1,5 +1,217 @@ +'use client'; + +import { Button } from "@/components/ui/button"; +import { Field, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSeparator, FieldSet } from "@/components/ui/field"; +import { useUserStore } from "@/store/useUserStore"; +import { Checkbox } from "@radix-ui/react-checkbox"; +import { + Table, + TableBody, + TableCaption, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { ReactElement, useMemo, useState } from "react"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { Input } from "@/components/ui/input" +import { Label } from "@/components/ui/label" +import { AuthAPI } from "@/lib/api/client"; +import { GeneralErrorHandler, handleAPIError } from "@/lib/api/common"; +import { startRegistration } from '@simplewebauthn/browser'; +import { toast } from "sonner"; + export default function Page() { + const userStore = useUserStore(); + const user = userStore.user; + return ( -
+
+
{ + e.preventDefault(); + }}> + +
+ 账户基础信息 + 这是当前账户的基础信息 + + { + [ + { + name: 'username', + localName: '用户名', + required: true, + defaultValue: user?.username, + }, + { + name: 'nickname', + localName: '昵称', + required: true, + defaultValue: user?.nickname, + }, + { + name: 'email', + localName: '电子邮箱', + required: false, + defaultValue: user?.email, + }, + { + name: 'phone', + localName: '手机号', + required: false, + defaultValue: user?.phone, + description: '当前仅支持中国大陆(+86)手机号' + }, + ].map(({ name, localName, required, defaultValue, description }) => ( + + + {localName} + + + { + description && ( + + {description} + + ) + } + + )) + } + +
+ + + + +
+
+ + +
+ 通行证列表 + + 通行证(PassKey),一种先进的无密码身份验证技术。 + + +
+ + + +
+
+
+
+ ) +} + + +interface AddPasskeyDialogProps { + children: ReactElement; +} +function AddPasskeyDialog({ children }: AddPasskeyDialogProps) { + const [open, setOpen] = useState(false); + + const handleSubmit = async (name: string) => { + try { + name = name.trim(); + if (name.length === 0) { + throw new Error('通行证名称不能为空') + } + + const options = await AuthAPI.getPasskeyRegisterOptions(); + + const credential = await startRegistration({ optionsJSON: options }).catch(() => null); + + if (credential === null) { + throw new Error('认证超时'); + } + + const registerRes = await AuthAPI.passkeyRegister(name, credential); + if (registerRes.id) { + toast.success('添加成功'); + setOpen(false); + } + } catch (error) { + console.log(error) + handleAPIError(error, GeneralErrorHandler); + } + } + + return ( + + + {children} + + + + 添加通行证 + + 如果能添加成功,则说明您的设备支持;如果添加失败了,说明您的设备不支持😊 + + +
{ + e.preventDefault(); + const formData = new FormData(e.currentTarget); + handleSubmit(formData.get('name')?.toString() || ''); + }}> +
+
+ + +
+
+ + + + + + +
+
+
+ ) +} + +function PasskeyList() { + return ( + + {/* A list of your recent invoices. */} + + + 名称 + 状态 + 创建时间 + 操作 + + + + + INV001 + Paid + Credit Card + $250.00 + + +
) } \ No newline at end of file