Support user uploading via xlsx.

This commit is contained in:
Yang Luo
2021-12-31 12:56:19 +08:00
parent 5e8897e41b
commit 4b65320a96
17 changed files with 334 additions and 3 deletions

View File

@ -14,7 +14,8 @@
import React from "react";
import {Link} from "react-router-dom";
import {Button, Popconfirm, Switch, Table} from 'antd';
import {Button, Popconfirm, Switch, Table, Upload} from 'antd';
import {UploadOutlined} from "@ant-design/icons";
import moment from "moment";
import * as Setting from "./Setting";
import * as UserBackend from "./backend/UserBackend";
@ -92,6 +93,43 @@ class UserListPage extends BaseListPage {
});
}
uploadFile(info) {
const { status, response: res } = info.file;
if (status === 'done') {
if (res.status === 'ok') {
Setting.showMessage("success", `Users uploaded successfully, refreshing the page`);
const { pagination } = this.state;
this.fetch({ pagination });
} else {
Setting.showMessage("error", `Users failed to upload: ${res.msg}`);
}
} else if (status === 'error') {
Setting.showMessage("error", `File failed to upload`);
}
}
renderUpload() {
const props = {
name: 'file',
accept: '.xlsx',
method: 'post',
action: `${Setting.ServerUrl}/api/upload-users`,
withCredentials: true,
onChange: (info) => {
this.uploadFile(info);
},
};
return (
<Upload {...props}>
<Button type="primary" size="small">
<UploadOutlined /> {i18next.t("user:Upload (.xlsx)")}
</Button>
</Upload>
)
}
renderTable(users) {
// transfer country code to name based on selected language
var countries = require("i18n-iso-countries");
@ -316,8 +354,11 @@ class UserListPage extends BaseListPage {
<Table scroll={{x: 'max-content'}} columns={columns} dataSource={users} rowKey="name" size="middle" bordered pagination={paginationProps}
title={() => (
<div>
{i18next.t("general:Users")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button type="primary" size="small" onClick={this.addUser.bind(this)}>{i18next.t("general:Add")}</Button>
{i18next.t("general:Users")}&nbsp;&nbsp;&nbsp;&nbsp;
<Button style={{marginRight: "5px"}} type="primary" size="small" onClick={this.addUser.bind(this)}>{i18next.t("general:Add")}</Button>
{
this.renderUpload()
}
</div>
)}
loading={this.state.loading}

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "Title - Tooltip",
"Two passwords you typed do not match.": "Two passwords you typed do not match.",
"Unlink": "Unlink",
"Upload (.xlsx)": "Upload (.xlsx)",
"Upload a photo": "Upload a photo",
"input password": "input password"
},

View File

@ -437,6 +437,7 @@
"Title - Tooltip": "在单位/公司的职务",
"Two passwords you typed do not match.": "两次输入的密码不匹配。",
"Unlink": "解绑",
"Upload (.xlsx)": "上传(.xlsx",
"Upload a photo": "上传头像",
"input password": "输入密码"
},