优化修改用户密码时失败处理
This commit is contained in:
@@ -50,6 +50,7 @@ export function UserInfoEditor({
|
|||||||
if (res) {
|
if (res) {
|
||||||
toast.success("保存成功");
|
toast.success("保存成功");
|
||||||
onUserUpdate(res);
|
onUserUpdate(res);
|
||||||
|
onClose();
|
||||||
} else {
|
} else {
|
||||||
throw new Error();
|
throw new Error();
|
||||||
}
|
}
|
||||||
@@ -75,12 +76,14 @@ export function UserInfoEditor({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const [passwordDialogOpen, setPasswordDialogOpen] = React.useState(false);
|
||||||
const [setPasswordLoading, setSetPasswordLoading] = React.useState(false);
|
const [setPasswordLoading, setSetPasswordLoading] = React.useState(false);
|
||||||
const handleSetPassword = async (userId: string, password: string) => {
|
const handleSetPassword = async (userId: string, password: string) => {
|
||||||
try {
|
try {
|
||||||
setSetPasswordLoading(true);
|
setSetPasswordLoading(true);
|
||||||
await AdminApi.user.setPassword(userId, password);
|
await AdminApi.user.setPassword(userId, password);
|
||||||
toast.success("密码修改成功");
|
toast.success("密码修改成功");
|
||||||
|
setPasswordDialogOpen(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error((error as Error).message || "密码修改失败");
|
toast.error((error as Error).message || "密码修改失败");
|
||||||
} finally {
|
} finally {
|
||||||
@@ -100,6 +103,8 @@ export function UserInfoEditor({
|
|||||||
user={user}
|
user={user}
|
||||||
onSetPassword={handleSetPassword}
|
onSetPassword={handleSetPassword}
|
||||||
onRemove={handleRemove}
|
onRemove={handleRemove}
|
||||||
|
passwordDialogOpen={passwordDialogOpen}
|
||||||
|
setPasswordDialogOpen={setPasswordDialogOpen}
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const formData = new FormData(e.currentTarget);
|
const formData = new FormData(e.currentTarget);
|
||||||
@@ -137,11 +142,13 @@ export function UserInfoEditor({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProfileForm({ className, user, onSetPassword, onRemove, ...props }:
|
function ProfileForm({ className, user, onSetPassword, onRemove, passwordDialogOpen, setPasswordDialogOpen, ...props }:
|
||||||
React.ComponentProps<"form"> & {
|
React.ComponentProps<"form"> & {
|
||||||
user: User,
|
user: User;
|
||||||
onSetPassword: (userId: string, password: string) => Promise<void>,
|
onSetPassword: (userId: string, password: string) => Promise<void>;
|
||||||
onRemove: (userId: string) => Promise<void>,
|
onRemove: (userId: string) => Promise<void>;
|
||||||
|
passwordDialogOpen: boolean;
|
||||||
|
setPasswordDialogOpen: (s: boolean) => void;
|
||||||
}) {
|
}) {
|
||||||
const [newPassword, setNewPassword] = React.useState<string>("");
|
const [newPassword, setNewPassword] = React.useState<string>("");
|
||||||
|
|
||||||
@@ -168,7 +175,7 @@ function ProfileForm({ className, user, onSetPassword, onRemove, ...props }:
|
|||||||
<Input id="phone" name="phone" defaultValue={user.phone} />
|
<Input id="phone" name="phone" defaultValue={user.phone} />
|
||||||
</div>
|
</div>
|
||||||
<div className="w-full flex gap-5">
|
<div className="w-full flex gap-5">
|
||||||
<Dialog>
|
<Dialog open={passwordDialogOpen} onOpenChange={setPasswordDialogOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button type="button" variant="secondary" className="flex-1" onClick={() => setNewPassword('')}>修改密码</Button>
|
<Button type="button" variant="secondary" className="flex-1" onClick={() => setNewPassword('')}>修改密码</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
@@ -194,9 +201,7 @@ function ProfileForm({ className, user, onSetPassword, onRemove, ...props }:
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<DialogClose asChild>
|
|
||||||
<Button type="button" onClick={() => onSetPassword(user.userId, newPassword)}>保存密码</Button>
|
<Button type="button" onClick={() => onSetPassword(user.userId, newPassword)}>保存密码</Button>
|
||||||
</DialogClose>
|
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Reference in New Issue
Block a user