Implement save method for revised data

This commit is contained in:
Viet Anh Nguyen 2024-02-22 09:29:49 +07:00
parent d89cc70ec5
commit 7a3ad4c78c
3 changed files with 55 additions and 33 deletions

View File

@ -4,7 +4,7 @@
"Back to Dashboard": "Back to Dashboard",
"Create New Report": "Create New Report",
"Dashboard": "Dashboard",
"Date": "Date",
"Date (GMT+8)": "Date (GMT+8)",
"Download": "Download",
"Download Report": "Download Report",
"Duration": "Duration",
@ -12,6 +12,7 @@
"English": "English",
"Go to Reports": "Go to Reports",
"Inference": "Inference",
"Is Test": "Is Test",
"Language": "Language",
"Login": "Login",
"Logout": "Logout",
@ -28,8 +29,11 @@
"Please specify a password": "Please specify a password",
"Please specify a username": "Please specify a username",
"Report Details": "Report Details",
"Report Filters": "Report Filters",
"Reports": "Reports",
"Retry": "Retry",
"Review": "Review",
"Reviewed": "Reviewed",
"Service temporarily unavailable.": "Service temporarily unavailable.",
"Something went wrong.": "Something went wrong.",
"Sorry, something went wrong.": "Sorry, something went wrong.",

View File

@ -4,7 +4,7 @@
"Back to Dashboard": "",
"Create New Report": "",
"Dashboard": "",
"Date": "",
"Date (GMT+8)": "",
"Download": "",
"Download Report": "",
"Duration": "",
@ -12,6 +12,7 @@
"English": "Tiếng Anh",
"Go to Reports": "",
"Inference": "",
"Is Test": "",
"Language": "Ngôn ngữ",
"Login": "Đăng nhập",
"Logout": "Đăng xuất",
@ -28,8 +29,11 @@
"Please specify a password": "Vui lòng nhập một mật khẩu",
"Please specify a username": "Vui lòng nhập một tên tài khoản",
"Report Details": "",
"Report Filters": "",
"Reports": "",
"Retry": "Thử lại",
"Review": "",
"Reviewed": "",
"Service temporarily unavailable.": "Dịch vụ máy chủ hiện tại không sẵn sàng.",
"Something went wrong.": "Có lỗi xảy ra",
"Sorry, something went wrong.": "Hệ thống gặp lỗi",

View File

@ -305,26 +305,7 @@ const ReviewPage = () => {
const [currentRequestIndex, setCurrentRequestIndex] = useState(1);
const [hasNextRequest, setHasNextRequest] = useState(true);
const [totalPages, setTotalPages] = useState(0);
// purchase_date: "2024-01-20",
// retailername: "Test Retailer",
// sold_to_party: "Test Party",
const dataSource = [];
const predicted = (currentRequest && currentRequest["Reviewed Result"]) ? currentRequest["Reviewed Result"] : {};
const submitted = (currentRequest && currentRequest["Feedback Result"]) ? currentRequest["Feedback Result"] : {};
const revised = (currentRequest && currentRequest["Reviewed Result"]) ? currentRequest["Reviewed Result"] : {};
const keys = Object.keys(predicted);
for (let i = 0; i < keys.length; i++) {
let instance = {};
instance["key"] = keys[i];
instance["predicted"] = predicted[keys[i]];
instance["submitted"] = submitted[keys[i]];
instance["revised"] = revised[keys[i]];
dataSource.push(instance);
}
const [dataSource, setDataSource] = useState([]);
const [pageIndexToGoto, setPageIndexToGoto] = useState(1);
@ -337,6 +318,21 @@ const ReviewPage = () => {
const requestData = fetchRequest(data?.subscription_requests[0].RequestID);
requestData.then(async (data) => {
if (data) setCurrentRequest(data);
const predicted = (data && data["Reviewed Result"]) ? data["Reviewed Result"] : {};
const submitted = (data && data["Feedback Result"]) ? data["Feedback Result"] : {};
const revised = (data && data["Reviewed Result"]) ? data["Reviewed Result"] : {};
const keys = Object.keys(predicted);
const tableRows = [];
for (let i = 0; i < keys.length; i++) {
let instance = {};
instance["key"] = keys[i];
instance["predicted"] = predicted[keys[i]];
instance["submitted"] = submitted[keys[i]];
instance["revised"] = revised[keys[i]];
tableRows.push(instance);
}
setDataSource(tableRows);
setLoading(false);
}).finally(() => {
setLoading(false);
});
@ -407,16 +403,38 @@ const ReviewPage = () => {
revised: string;
};
const updateRevisedData = async (newRevisedData:any) => {
const requestID = newRevisedData.request_id;
const token = localStorage.getItem('sbt-token') || '';
console.log(newRevisedData)
await fetch(`${baseURL}/ctel/request/${requestID}/`, {
method: 'POST',
headers: {
"Authorization": `${JSON.parse(token)}`,
"Content-Type": "application/json",
},
body: JSON.stringify(newRevisedData),
}).catch((error) => {
console.log(error);
message.error("Could not update revised data");
});
};
const handleSave = (row: DataType) => {
const newData = [...dataSource];
console.log(row);
// const index = newData.findIndex((item) => row.key === item.key);
// const item = newData[index];
// newData.splice(index, 1, {
// ...item,
// ...row,
// });
// setDataSource(newData);
const index = newData.findIndex((item) => row.key === item.key);
const item = newData[index];
newData.splice(index, 1, {
...item,
...row,
});
setDataSource(newData);
const newRevisedData = {};
for (let i = 0; i < newData.length; i++) {
newRevisedData[newData[i].key] = newData[i].revised;
}
updateRevisedData(newRevisedData);
};
const columns = defaultColumns.map((col) => {
@ -643,10 +661,6 @@ const ReviewPage = () => {
}}
>
<DatePicker.RangePicker
value={filterDateRange}
onChange={(value) => {
setFilterDateRange(value);
}}
style={{ width: 200 }}
/>
</Form.Item>