mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-19 07:23:46 +08:00
update user admin
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
||||
Form,
|
||||
} from "antd";
|
||||
import type { GetRef, TableColumnsType } from "antd";
|
||||
import { LockOutlined } from "@ant-design/icons";
|
||||
// import { headers } from 'next/headers'
|
||||
import type { NotificationArgsProps } from "antd";
|
||||
|
||||
@@ -97,10 +98,100 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
||||
setNewPassword(e.target.value.trim());
|
||||
};
|
||||
|
||||
const handleUserEdit = (
|
||||
method: "POST" | "PUT",
|
||||
record: User | undefined,
|
||||
) => {};
|
||||
const handleUserEdit = (method: "POST" | "PUT", record: User | undefined) => {
|
||||
editUserModal.confirm({
|
||||
title: "编辑用户",
|
||||
content: (
|
||||
<Form
|
||||
form={editUserForm}
|
||||
labelCol={{ span: 7 }}
|
||||
wrapperCol={{ span: 28 }}
|
||||
layout="horizontal"
|
||||
autoComplete="off"
|
||||
initialValues={record}
|
||||
preserve={false}
|
||||
>
|
||||
<Form.Item name="id" label="id" rules={[{ required: true }]}>
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item name="name" label="name">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item name="username" label="username">
|
||||
<Input autoComplete="off" />
|
||||
</Form.Item>
|
||||
<Form.Item name="gh_username" label="gh_username">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item name="email" label="email">
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item name="emailVerified" label="emailVerified">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item name="createdAt" label="createdAt">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item name="updatedAt" label="updatedAt">
|
||||
<Input disabled />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="allowToLogin"
|
||||
label="allowToLogin"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Checkbox />
|
||||
</Form.Item>
|
||||
<Form.Item name="isAdmin" label="isAdmin" valuePropName="checked">
|
||||
<Checkbox />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="password" label="password">
|
||||
<Input
|
||||
prefix={<LockOutlined className="site-form-item-icon" />}
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
),
|
||||
onOk: () => {
|
||||
const setting_key = method === "PUT" ? record?.id : "";
|
||||
editUserForm.validateFields().then((values) => {
|
||||
const dataToSubmit = {
|
||||
username: values.username ?? null,
|
||||
email: values.email ?? null,
|
||||
allowToLogin: values.allowToLogin ?? true,
|
||||
isAdmin: values.isAdmin ?? false,
|
||||
password: values.password ?? null,
|
||||
};
|
||||
fetch(`/api/admin/users/${values.id}`, {
|
||||
method: method,
|
||||
credentials: "include",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(dataToSubmit),
|
||||
})
|
||||
.then((response) => response.json())
|
||||
.then((result) => {
|
||||
if (result["result"] == "ok") {
|
||||
openNotification("info", {
|
||||
message: "修改信息",
|
||||
description: `${values.id} 信息修改成功`,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("e", error);
|
||||
openNotification("error", {
|
||||
message: "修改信息",
|
||||
description: `${values.id} 信息修改失败`,
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const confirmPassword = async (id: string) => {
|
||||
console.log("-----", newPassword, id);
|
||||
@@ -240,7 +331,9 @@ function UsersTable({ users, setUsers, loading }: UserInterface) {
|
||||
key: "id",
|
||||
render: (_, record) => (
|
||||
<Space size="small">
|
||||
<a>编辑</a>
|
||||
<a type="link" onClick={() => handleUserEdit("PUT", record)}>
|
||||
编辑
|
||||
</a>
|
||||
<Popconfirm
|
||||
id="user-admin-table-pop_confirm"
|
||||
title="设置密码"
|
||||
|
||||
Reference in New Issue
Block a user