From 0c09a8acfb7fafd303abec9f116746e0d724682f Mon Sep 17 00:00:00 2001 From: suryansh-egov Date: Wed, 27 Nov 2024 12:46:18 +0530 Subject: [PATCH] localisation and error codes (#1905) --- .../pages/employee/BoundaryRelationCreate.js | 6 ++++-- .../src/pages/employee/ViewHierarchy.js | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js index d2867da7f74..670924f3e52 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/BoundaryRelationCreate.js @@ -318,7 +318,7 @@ const BoundaryRelationCreate = () => { label = `${t("WBH_BOUNDARY_CREATION_TIMEOUT")}: ${t("WBH_OPERATION_INCOMPLETE")}`; } else { label = `${t("WBH_BOUNDARY_CREATION_FAIL")}: `; - if (error?.message) label += `${t(error?.message)}`; + // if (error?.message) label += `${t(error?.message)}`; } setShowToast({ label, isError: "error" }); @@ -397,10 +397,12 @@ const BoundaryRelationCreate = () => { } catch (error) { const errorMessage = error.message === "LEVELS_CANNOT_BE_EMPTY" ? t("LEVELS_CANNOT_BE_EMPTY") - : error?.response?.data?.Errors?.[0]?.message || t("HIERARCHY_CREATION_FAILED"); + : t(error?.response?.data?.Errors?.[0]?.code) || t("HIERARCHY_CREATION_FAILED"); setCreatingData(false); setShowToast({ label: errorMessage, isError: "error" }); + await sleep(2000); + history.push(`/${window.contextPath}/employee/campaign/boundary/home`,{}); } } const onConfirmClick=()=>{ diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js index c606e5f666e..6e3ca88b32c 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/pages/employee/ViewHierarchy.js @@ -32,7 +32,7 @@ const ViewHierarchy = () => { const [showToast, setShowToast] = useState(null); // State to handle toast notifications const [dataCreateToast, setDataCreateToast] = useState(false); const [disable, setDisable] = useState(false); - const [disableFile, setDisableFile] = useState(false); + const [disableFile, setDisableFile] = useState(true); const [dataCreationGoing, setDataCreationGoing] = useState(false); const [noOfRows, setNoOfRows] = useState(100); @@ -122,10 +122,19 @@ const ViewHierarchy = () => { const handleFileChange = async (event) => { const file = [event.target.files[0]]; // Get the first selected file if (file) { + // Check file extension + const validExtensions = ['xls', 'xlsx']; + const fileExtension = file[0].name.split('.').pop().toLowerCase(); // Get the file extension + + if (!validExtensions.includes(fileExtension)) { + setShowToast({ label: t("INVALID_FILE_FORMAT"), isError: "error" }); + setDisableFile(true); + return; // Exit the function if the file is not valid + } try { // Call function to upload the selected file to an API await uploadFileToAPI(file); - setDisableFile(true); + setDisableFile(false); setShowToast({ label: t("FILE_UPLOADED_SUCCESSFULLY"), isError:"success"}); } catch (error) { setShowToast({ label: error?.response?.data?.Errors?.[0]?.message ? error?.response?.data?.Errors?.[0]?.message : t("FILE_UPLOAD_FAILED") , isError:"error" }); @@ -225,7 +234,7 @@ const ViewHierarchy = () => { // Initialize the label with a failure message label = `${t("WBH_BOUNDARY_CREATION_FAIL")}: `; - if(error?.message) label += `${t(error?.message)}`; + if(error?.message) label += `${t(error?.message)}`; // the message here is sent from the polling mechnism which sendds the error code from backend. } @@ -550,7 +559,7 @@ const ViewHierarchy = () => { />,