feat: 前端对接设置密码API
This commit is contained in:
@@ -14,27 +14,23 @@ import { Label } from "@/components/ui/label"
|
|||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { DialogProps } from "@radix-ui/react-dialog";
|
import { DialogProps } from "@radix-ui/react-dialog";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import { ApiError } from "next/dist/server/api-utils";
|
import { UserAPI } from "@/lib/api/client";
|
||||||
|
import { handleAPIError } from "@/lib/api/common";
|
||||||
|
|
||||||
export default function SetPassword({ onOpenChange, ...props }: React.ComponentProps<FC<DialogProps>>) {
|
export default function SetPassword({ onOpenChange, ...props }: React.ComponentProps<FC<DialogProps>>) {
|
||||||
async function handleSetPassword(password: string) {
|
async function handleSetPassword(password: string) {
|
||||||
if (! /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/.test(password)) {
|
try {
|
||||||
toast.error('新密码不符合规范,请重新输入');
|
await UserAPI.updatePassword(password);
|
||||||
return;
|
toast.success('新密码设置成功');
|
||||||
|
onOpenChange?.(false);
|
||||||
|
} catch (error) {
|
||||||
|
handleAPIError(error, ({ message }) => toast.error(message || '新密码设置失败'))
|
||||||
}
|
}
|
||||||
|
|
||||||
// try {
|
|
||||||
// await UserApi.updatePassword(password);
|
|
||||||
// toast.success('新密码设置成功');
|
|
||||||
// onOpenChange?.(false);
|
|
||||||
// } catch (error) {
|
|
||||||
// toast.error((error as ApiError).message || '新密码设置失败');
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog onOpenChange={onOpenChange} {...props}>
|
<Dialog onOpenChange={onOpenChange} {...props}>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-100">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>修改密码</DialogTitle>
|
<DialogTitle>修改密码</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
@@ -57,6 +53,7 @@ export default function SetPassword({ onOpenChange, ...props }: React.ComponentP
|
|||||||
<Input
|
<Input
|
||||||
id="password"
|
id="password"
|
||||||
name="password"
|
name="password"
|
||||||
|
type="password"
|
||||||
defaultValue=""
|
defaultValue=""
|
||||||
className="col-span-3"
|
className="col-span-3"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user