mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-10-01 23:56:39 +08:00
fix little bug
This commit is contained in:
parent
a64f52ecbb
commit
48517034f2
@ -5,11 +5,9 @@ import { User } from "@prisma/client";
|
|||||||
import {
|
import {
|
||||||
Space,
|
Space,
|
||||||
Table,
|
Table,
|
||||||
Tag,
|
|
||||||
Input,
|
Input,
|
||||||
Button,
|
Button,
|
||||||
notification as notificationModule,
|
notification as notificationModule,
|
||||||
Popconfirm,
|
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Modal,
|
Modal,
|
||||||
Form,
|
Form,
|
||||||
@ -40,9 +38,6 @@ interface SearchTextProps {
|
|||||||
setSearchText: Dispatch<SetStateAction<string>>;
|
setSearchText: Dispatch<SetStateAction<string>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type DataIndex = keyof User;
|
|
||||||
type InputRef = GetRef<typeof Input>;
|
|
||||||
|
|
||||||
function UserTableSearchInput({ users, setUsers, setLoading }: UserInterface) {
|
function UserTableSearchInput({ users, setUsers, setLoading }: UserInterface) {
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
// 这里直接搜索,并获取数据不传递搜索的值给表格了。
|
// 这里直接搜索,并获取数据不传递搜索的值给表格了。
|
||||||
@ -89,14 +84,6 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
notificationModule.useNotification();
|
notificationModule.useNotification();
|
||||||
const [editUserModal, editUserModalContextHolder] = Modal.useModal();
|
const [editUserModal, editUserModalContextHolder] = Modal.useModal();
|
||||||
const [editUserForm] = Form.useForm();
|
const [editUserForm] = Form.useForm();
|
||||||
const [newPassword, setNewPassword] = useState("");
|
|
||||||
|
|
||||||
const newPasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
// if ((e.nativeEvent as InputEvent).isComposing) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
setNewPassword(e.target.value.trim());
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleUserEdit = (method: "POST" | "PUT", record: User | undefined) => {
|
const handleUserEdit = (method: "POST" | "PUT", record: User | undefined) => {
|
||||||
editUserModal.confirm({
|
editUserModal.confirm({
|
||||||
@ -193,44 +180,6 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const confirmPassword = async (id: string) => {
|
|
||||||
console.log("-----", newPassword, id);
|
|
||||||
try {
|
|
||||||
fetch(`/api/admin/users/${id}`, {
|
|
||||||
method: "put",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
password: newPassword,
|
|
||||||
}),
|
|
||||||
credentials: "include",
|
|
||||||
})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((res) => {
|
|
||||||
if (res["result"] == "ok") {
|
|
||||||
openNotification("info", {
|
|
||||||
message: "修改密码",
|
|
||||||
description: `${id} 密码修改成功`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("e", error);
|
|
||||||
openNotification("error", {
|
|
||||||
message: "修改密码",
|
|
||||||
description: `${id} 密码修改失败`,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
openNotification("error", {
|
|
||||||
message: "修改密码",
|
|
||||||
description: `${id} 密码修改失败`,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
setNewPassword("");
|
|
||||||
};
|
|
||||||
|
|
||||||
const openNotification = (level: string, arms: NotificationArgsProps) => {
|
const openNotification = (level: string, arms: NotificationArgsProps) => {
|
||||||
if (level === "error") {
|
if (level === "error") {
|
||||||
notification.error({
|
notification.error({
|
||||||
@ -312,49 +261,18 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// title: "编辑",
|
|
||||||
// dataIndex: "",
|
|
||||||
// key: "id",
|
|
||||||
// width: 80,
|
|
||||||
// render: (value) => {
|
|
||||||
// return (
|
|
||||||
// <div>
|
|
||||||
// <a >编辑</a>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
title: "Action",
|
title: "Action",
|
||||||
dataIndex: "",
|
dataIndex: "",
|
||||||
key: "id",
|
key: "id",
|
||||||
render: (_, record) => (
|
render: (_, record) => (
|
||||||
<Space size="small">
|
<Space size="small">
|
||||||
<a type="link" onClick={() => handleUserEdit("PUT", record)}>
|
<Button type="link" onClick={() => handleUserEdit("PUT", record)}>
|
||||||
编辑
|
编辑
|
||||||
</a>
|
</Button>
|
||||||
<Popconfirm
|
<Button type="link" onClick={() => handleDeleteUser(record)}>
|
||||||
id="user-admin-table-pop_confirm"
|
删除
|
||||||
title="设置密码"
|
</Button>
|
||||||
description={
|
|
||||||
<>
|
|
||||||
<Input.Password
|
|
||||||
autoComplete="new-password"
|
|
||||||
value={newPassword}
|
|
||||||
onCompositionStart={(e) => e.preventDefault()}
|
|
||||||
onChange={newPasswordChange}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
onConfirm={() => confirmPassword(record.id)}
|
|
||||||
onOpenChange={() => console.log("open change")}
|
|
||||||
>
|
|
||||||
<Button type="primary" size="small">
|
|
||||||
设置密码
|
|
||||||
</Button>
|
|
||||||
</Popconfirm>
|
|
||||||
<a onClick={() => handleDeleteUser(record)}>删除</a>
|
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user