Revert to the previous version when cannot update fields

This commit is contained in:
Viet Anh Nguyen 2024-03-14 18:29:09 +07:00
parent a7fb22e3b7
commit 57bc7a565a
3 changed files with 23 additions and 11 deletions

View File

@ -330,7 +330,7 @@ const InferencePage = () => {
const updateRevisedData = async (newRevisedData: any) => {
const requestID = currentRequest.RequestID;
const token = localStorage.getItem('sbt-token') || '';
await fetch(`${baseURL}/ctel/request/${requestID}/`, {
const result = await fetch(`${baseURL}/ctel/request/${requestID}/`, {
method: 'POST',
headers: {
"Authorization": `${JSON.parse(token)}`,
@ -341,8 +341,11 @@ const InferencePage = () => {
}),
}).catch((error) => {
console.log(error);
message.error("Could not update revised data");
throw error;
});
if (result.status != 200) {
throw new Error("Could not update revised data");
}
};
const handleSave = (row: DataType) => {
@ -353,7 +356,6 @@ const InferencePage = () => {
...item,
...row,
});
setDataSource(newData);
const newRevisedData = {};
for (let i = 0; i < newData.length; i++) {
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
@ -365,7 +367,11 @@ const InferencePage = () => {
...currentRequest,
["Is Reviewed"]: true,
})
})
}).then(() => {
setDataSource(newData);
}).catch((error) => {
message.error("Could not update revised data. Please check the format.");
});
};
const submitRevisedData = async () => {

View File

@ -389,9 +389,9 @@ const ReviewPage = () => {
};
const updateRevisedData = async (newRevisedData: any) => {
const requestID = newRevisedData.request_id;
const requestID = currentRequest.RequestID;
const token = localStorage.getItem('sbt-token') || '';
await fetch(`${baseURL}/ctel/request/${requestID}/`, {
const result = await fetch(`${baseURL}/ctel/request/${requestID}/`, {
method: 'POST',
headers: {
"Authorization": `${JSON.parse(token)}`,
@ -402,8 +402,11 @@ const ReviewPage = () => {
}),
}).catch((error) => {
console.log(error);
message.error("Could not update revised data");
throw error;
});
if (result.status != 200) {
throw new Error("Could not update revised data");
}
};
const handleSave = (row: DataType) => {
@ -414,7 +417,6 @@ const ReviewPage = () => {
...item,
...row,
});
setDataSource(newData);
const newRevisedData = {};
for (let i = 0; i < newData.length; i++) {
newData[i].revised = normalizeData(newData[i].key, newData[i].revised);
@ -426,7 +428,11 @@ const ReviewPage = () => {
...currentRequest,
["Is Reviewed"]: true,
})
})
}).then(() => {
setDataSource(newData);
}).catch((error) => {
message.error("Could not update revised data. Please check the format.");
});
};
const submitRevisedData = async () => {

View File

@ -18,8 +18,8 @@ const normalizeData = (key, value) => {
if (isAllSpaces(value)) {
value = null;
}
if (["imei_number", "purchase_date"].includes(key) && typeof (value) === "string") {
value = value.split(",")
if (["imei_number", "purchase_date"].includes(key) && typeof(value) === "string") {
value = value.split(",");
}
if (typeof (value) === "object" && value?.length > 0) {
for (let i = 0; i < value.length; i++) {