diff --git a/cope2n-fe/src/pages/inference/index.tsx b/cope2n-fe/src/pages/inference/index.tsx index 2433be2..b4c4d6c 100644 --- a/cope2n-fe/src/pages/inference/index.tsx +++ b/cope2n-fe/src/pages/inference/index.tsx @@ -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 () => { diff --git a/cope2n-fe/src/pages/reviews/index.tsx b/cope2n-fe/src/pages/reviews/index.tsx index 6302b5c..3cc1cef 100644 --- a/cope2n-fe/src/pages/reviews/index.tsx +++ b/cope2n-fe/src/pages/reviews/index.tsx @@ -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 () => { diff --git a/cope2n-fe/src/utils/field-value-process.ts b/cope2n-fe/src/utils/field-value-process.ts index ee24573..69ab9d5 100644 --- a/cope2n-fe/src/utils/field-value-process.ts +++ b/cope2n-fe/src/utils/field-value-process.ts @@ -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++) {