diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js index 5b6d8fe14cb..8b027463b77 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/hooks/useResourceData.js @@ -80,24 +80,31 @@ export const useResourceData = async (data, hierarchyType, type, tenantId, id , const baseDelay = baseTimeOut?.baseTimeout?.[0]?.baseTimeOut; const maxTime = baseTimeOut?.baseTimeout?.[0]?.maxTime; let retryInterval = Math.min(baseDelay * jsonDataLength , maxTime); + if(typeof retryInterval !== "number"){ + retryInterval = 1000; + } await new Promise((resolve) => setTimeout(resolve, retryInterval)); // Retry until a response is received while (status !== "failed" && status !== "invalid" && status !== "completed") { - searchResponse = await Digit.CustomService.getResponse({ - url: "/project-factory/v1/data/_search", - body: { - SearchCriteria: { - id: [response?.ResourceDetails?.id], - tenantId: tenantId, - type: Type, + try { + searchResponse = await Digit.CustomService.getResponse({ + url: "/project-factory/v1/data/_search", + body: { + SearchCriteria: { + id: [response?.ResourceDetails?.id], + tenantId: tenantId, + type: Type, + }, }, - }, - }); - status = searchResponse?.ResourceDetails?.[0]?.status; - if (status !== "failed" && status !== "invalid" && status !== "completed") { - await new Promise((resolve) => setTimeout(resolve, retryInterval)); + }); + status = searchResponse?.ResourceDetails?.[0]?.status; + if (status !== "failed" && status !== "invalid" && status !== "completed") { + await new Promise((resolve) => setTimeout(resolve, retryInterval)); + } + } catch (error) { + console.error("Error while fetching data:", error); } } if (Error.isError) { diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UploadDataCustom.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UploadDataCustom.js index 85fb4a4524a..21bf314a9b5 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UploadDataCustom.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UploadDataCustom.js @@ -610,7 +610,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => { const fileData = fileUrl?.map((i) => { const urlParts = i?.url?.split("/"); // const fileName = urlParts[urlParts?.length - 1]?.split("?")?.[0]; - const fileName = type === "boundary" ? "Target Template" : type === "facilityWithBoundary" ? "Facility Template" : "User Template"; + const fileName = type === "boundary" ? "Population Template" : type === "facilityWithBoundary" ? "Facility Template" : "User Template"; return { ...i, filename: fileName, @@ -789,18 +789,18 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => { footerclassName={"popUpFooter"} heading={ type === "boundary" - ? t("ES_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_HEADER") + ? t("MP_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_HEADER") : type === "facilityWithBoundary" - ? t("ES_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_HEADER") - : t("ES_CAMPAIGN_UPLOAD_USER_DATA_MODAL_HEADER") + ? t("MP_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_HEADER") + : t("MP_CAMPAIGN_UPLOAD_USER_DATA_MODAL_HEADER") } children={[
{type === "boundary" - ? t("ES_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_TEXT") + ? t("MP_CAMPAIGN_UPLOAD_BOUNDARY_DATA_MODAL_TEXT") : type === "facilityWithBoundary" - ? t("ES_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_TEXT") - : t("ES_CAMPAIGN_UPLOAD_USER_DATA_MODAL_TEXT ")} + ? t("MP_CAMPAIGN_UPLOAD_FACILITY_DATA_MODAL_TEXT") + : t("MP_CAMPAIGN_UPLOAD_USER_DATA_MODAL_TEXT ")}
, ]} onOverlayClick={() => { @@ -811,7 +811,7 @@ const UploadDataCustom = React.memo(({ formData, onSelect, ...props }) => { type={"button"} size={"large"} variation={"secondary"} - label={t("HCM_CAMPAIGN_UPLOAD_CANCEL")} + label={t("MP_CAMPAIGN_UPLOAD_SKIP")} onClick={() => { setShowPopUp(false); }} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserUpload.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserUpload.js index 4945331b010..a35b269cfae 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserUpload.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/UserUpload.js @@ -4,7 +4,7 @@ import { useTranslation } from "react-i18next"; import { InfoCard, PopUp, Toast, Button, Stepper, TextBlock, Card } from "@egovernments/digit-ui-components"; import { ActionBar, SubmitBar } from "@egovernments/digit-ui-react-components"; import axios from "axios"; -import { Link } from "react-router-dom"; +import { Link, useHistory } from "react-router-dom"; import { ArrowBack } from "@egovernments/digit-ui-svg-components"; @@ -21,6 +21,7 @@ const UserUpload = React.memo(() => { const { t } = useTranslation(); const tenantId = Digit.ULBService.getCurrentTenantId(); const [uploadedFile, setUploadedFile] = useState([]); + const history = useHistory(); const [errorsType, setErrorsType] = useState({}); const [showToast, setShowToast] = useState(null); const [sheetErrors, setSheetErrors] = useState(0); @@ -66,14 +67,13 @@ const UserUpload = React.memo(() => { setShowToast(null); }; - useEffect(() => { + useEffect(async () => { const fetchData = async () => { if (!errorsType[type] && uploadedFile?.length > 0 && !isSuccess) { // setShowToast({ key: "info", label: t("HCM_VALIDATION_IN_PROGRESS") }); setIsValidation(true); // setIsError(true); setLoader(true); - try { const temp = await Digit.Hooks.campaign.useResourceData( uploadedFile, @@ -189,7 +189,7 @@ const UserUpload = React.memo(() => { } }; - fetchData(); + await fetchData(); }, [errorsType]); const onBulkUploadSubmit = async (file) => { @@ -366,6 +366,57 @@ const UserUpload = React.memo(() => { generateData(); }, [id, boundaryHierarchy]); + const onSubmit = async () => { + setDownloadTemplateLoader(true); + if (isSuccess && uploadedFile?.length > 0 && uploadedFile?.[0]?.filestoreId) { + const fileId = uploadedFile?.[0]?.filestoreId; + const ts = new Date().getTime(); + const reqCriteria = { + url: `/project-factory/v1/data/_create`, + body: { + RequestInfo: { + authToken: Digit.UserService.getUser().access_token, + msgId: `${ts}|${Digit.StoreData.getCurrentLanguage()}` + }, + ResourceDetails: { + tenantId: Digit.ULBService.getCurrentTenantId(), + type: "user", + fileStoreId: fileId, + hierarchyType: boundaryHierarchy, + campaignId: id, + action: "create", + campaignId: id, + additionalDetails: { + source: "microplan" + } + } + } + } + try { + await axios.post(reqCriteria.url, reqCriteria.body); + } catch (error) { + var errorLabel; + if (error?.response && error?.response?.data) { + const errorMessage = error?.response?.data?.Errors?.[0]?.message; + const errorDescription = error?.response?.data?.Errors?.[0]?.description; + if (errorDescription) { + errorLabel = `${errorMessage} : ${errorDescription}`; + } else { + errorLabel = String(error?.message); + } + } + console.error("Error fetching data:", error); + setShowToast({ key: "error", label: errorLabel }); + setDownloadTemplateLoader(false); + return; + } + history.push(`/${window.contextPath}/employee/microplan/upload-user-success`); + } + else { + setShowToast({ key: "error", label: t("ERROR_MANDATORY_FIELDS_FOR_SUBMIT") }); + } + setDownloadTemplateLoader(false); + } return ( <> @@ -376,7 +427,7 @@ const UserUpload = React.memo(() => {
- {t("WBH_UPLOAD_USER")} + {t("MP_UPLOAD_USER")}
{uploadedFile.length === 0 && (
- {t("HCM_USER_MESSAGE")} + {t("MP_USER_MESSAGE")}
)} @@ -460,29 +511,26 @@ const UserUpload = React.memo(() => { )} {showPreview && onFileDownload(processedFile?.[0])} onBack={() => setShowPreview(false)} />} - - {/* Back button */} -