diff --git a/health/micro-ui/web/micro-ui-internals/example/public/index.html b/health/micro-ui/web/micro-ui-internals/example/public/index.html index e50c7a3839..5a1dc2bbab 100644 --- a/health/micro-ui/web/micro-ui-internals/example/public/index.html +++ b/health/micro-ui/web/micro-ui-internals/example/public/index.html @@ -12,7 +12,7 @@ DIGIT - + diff --git a/health/micro-ui/web/micro-ui-internals/packages/css/package.json b/health/micro-ui/web/micro-ui-internals/packages/css/package.json index b56be88c2c..415181a9fd 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/css/package.json +++ b/health/micro-ui/web/micro-ui-internals/packages/css/package.json @@ -1,6 +1,6 @@ { "name": "@egovernments/digit-ui-health-css", - "version": "0.2.2", + "version": "0.2.3", "license": "MIT", "main": "dist/index.css", "author": "Jagankumar ", diff --git a/health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss b/health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss index 22b4eb3e28..8a5dc65c2a 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss +++ b/health/micro-ui/web/micro-ui-internals/packages/css/src/pages/employee/campaign.scss @@ -217,3 +217,23 @@ font-weight: 700; } } +.digit-popup-wrapper.dataMapping { + .digit-popup-children-wrap { + overflow: visible; + } +} +.dataMappingCard { + overflow-y: scroll; +} +.dataMappingDropdown { + min-width: 13rem !important; +} +.data-mapping-filter-switch { + float: right; + margin-bottom: 1.5rem; +} +.digit-label-field-pair.multiselect-label-field { + > div:nth-of-type(1) { + width: 69%; + } +} \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/package.json b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/package.json index 01d892a539..9428232c9e 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/package.json +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/package.json @@ -21,6 +21,8 @@ "@cyntler/react-doc-viewer": "1.10.3", "@egovernments/digit-ui-components": "0.0.2-beta.56", "@egovernments/digit-ui-react-components": "1.8.10", + "react-data-table-component": "7.6.2", + "styled-components": "5.0.0", "@rjsf/core": "5.10.0", "@rjsf/utils": "5.10.0", "@rjsf/validator-ajv8": "5.10.0", @@ -36,6 +38,7 @@ "react-router-dom": "5.3.0", "react-select": "5.7.4", "react-table": "7.7.0", + "exceljs": "^4.4.0", "xlsx": "0.17.5" }, "author": "JaganKumar ", diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js index c28230a408..aa986b565d 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/Module.js @@ -55,11 +55,13 @@ import ViewHierarchy from "./pages/employee/ViewHierarchy"; import MultiSelectDropdown from "./components/MultiSelectDropdown"; import MapView from "./components/MapView"; import NoResultsFound from "./components/NoResultsFound"; +import UploadDataMappingWrapper from "./components/UploadDataMappingWrapper"; +import DataUploadWrapper from "./components/DataUploadWrapper"; /** * MDMS Module name */ -export const CONSOLE_MDMS_MODULENAME="HCM-ADMIN-CONSOLE"; +export const CONSOLE_MDMS_MODULENAME = "HCM-ADMIN-CONSOLE"; /** * The CampaignModule function fetches store data based on state code, module code, and language, and @@ -69,24 +71,27 @@ export const CONSOLE_MDMS_MODULENAME="HCM-ADMIN-CONSOLE"; */ const CampaignModule = ({ stateCode, userType, tenants }) => { const tenantId = Digit.ULBService.getCurrentTenantId(); - const { data: BOUNDARY_HIERARCHY_TYPE , isLoading: hierarchyLoading } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ - name: "HierarchySchema", - "filter": `[?(@.type=='${window.Digit.Utils.campaign.getModuleName()}')]` - }], { - select: (data) => { - return data?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.hierarchy; + const { data: BOUNDARY_HIERARCHY_TYPE, isLoading: hierarchyLoading } = Digit.Hooks.useCustomMDMS( + tenantId, + CONSOLE_MDMS_MODULENAME, + [ + { + name: "HierarchySchema", + filter: `[?(@.type=='${window.Digit.Utils.campaign.getModuleName()}')]`, + }, + ], + { + select: (data) => { + return data?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.hierarchy; + }, }, - }, - { schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` } -); - + { schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` } + ); - const hierarchyData = Digit.Hooks.campaign.useBoundaryRelationshipSearch({BOUNDARY_HIERARCHY_TYPE,tenantId}); + const hierarchyData = Digit.Hooks.campaign.useBoundaryRelationshipSearch({ BOUNDARY_HIERARCHY_TYPE, tenantId }); const modulePrefix = "hcm"; - const moduleCode = BOUNDARY_HIERARCHY_TYPE - ? [`boundary-${BOUNDARY_HIERARCHY_TYPE}`] - : [ "campaignmanager", "schema", "admin-schemas","checklist"]; + const moduleCode = BOUNDARY_HIERARCHY_TYPE ? [`boundary-${BOUNDARY_HIERARCHY_TYPE}`] : ["campaignmanager", "schema", "admin-schemas", "checklist"]; const { path, url } = useRouteMatch(); const language = Digit.StoreData.getCurrentLanguage(); @@ -104,13 +109,19 @@ const CampaignModule = ({ stateCode, userType, tenants }) => { return ( - + ); }; - const componentsToRegister = { CampaignModule: CampaignModule, CampaignCard: CampaignCard, @@ -155,13 +166,15 @@ const componentsToRegister = { BulkUpload, CampaignUpdateSummary, XlsPreview, - MultiSelectDropdownBoundary:MultiSelectDropdown, + MultiSelectDropdownBoundary: MultiSelectDropdown, GeoPode, ViewBoundary, ViewHierarchy, BoundarySummary, MapView, - NoResultsFound + NoResultsFound, + UploadDataMappingWrapper, + DataUploadWrapper, }; const overrideHooks = () => { diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DataUploadWrapper.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DataUploadWrapper.js new file mode 100644 index 0000000000..0db3fe4c1d --- /dev/null +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/DataUploadWrapper.js @@ -0,0 +1,79 @@ +import { Card, Stepper, TextBlock } from "@egovernments/digit-ui-components"; +import React, { Fragment, useEffect, useState } from "react"; +import UploadData from "./UploadData"; +import { useTranslation } from "react-i18next"; +import UploadDataMappingWrapper from "./UploadDataMappingWrapper"; + +function DataUploadWrapper({ formData, props, onSelect }) { + const { t } = useTranslation(); + const { parentId, key: currentKey, ...queryParams } = Digit.Hooks.useQueryParams(); + const categories = [ + "HCM_UPLOAD_FACILITY", + "HCM_UPLOAD_FACILITY_MAPPING", + "HCM_UPLOAD_USER", + "HCM_UPLOAD_USER_MAPPING", + "HCM_UPLOAD_TARGET", + "HCM_SUMMARY", + ]; + const mappingCategories = ["HCM_UPLOAD_FACILITY_MAPPING", "HCM_UPLOAD_USER_MAPPING"]; + const [currentStep, setCurrentStep] = useState(1); + const currentCategories = categories?.[currentStep - 1]; + const [key, setKey] = useState(() => { + return currentKey ? parseInt(currentKey) : 1; + }); + const baseKey = 10; + function updateUrlParams(params) { + const url = new URL(window.location.href); + Object.entries(params).forEach(([key, value]) => { + url.searchParams.set(key, value); + }); + window.history.replaceState({}, "", url); + } + + useEffect(() => { + setKey(currentKey); + setCurrentStep(currentKey - baseKey + 1); + }, [currentKey]); + + useEffect(() => { + updateUrlParams({ key: key }); + window.dispatchEvent(new Event("checking")); + }, [key]); + + const onStepClick = (currentStep) => { + setCurrentStep(currentStep + 1); + if (currentStep === 0) { + setKey(10); + } else if (currentStep === 1) { + setKey(11); + } else if (currentStep === 3) { + setKey(13); + } else if (currentStep === 4) { + setKey(14); + } else setKey(12); + }; + + return ( + <> +
+ {!parentId && ( +
+ + + + + + +
+ )} + {mappingCategories?.includes(currentCategories) ? ( + + ) : ( + + )} +
+ + ); +} + +export default DataUploadWrapper; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js index 145d441674..d9c5bbdb8f 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/campaign-manager/src/components/UploadData.js @@ -5,7 +5,7 @@ import { Card, Modal, CardText } from "@egovernments/digit-ui-react-components"; import BulkUpload from "./BulkUpload"; import Ajv from "ajv"; import XLSX from "xlsx"; -import { InfoCard, PopUp, Toast, Button, DownloadIcon, Stepper, TextBlock ,Tag } from "@egovernments/digit-ui-components"; +import { InfoCard, PopUp, Toast, Button, DownloadIcon, Stepper, TextBlock, Tag } from "@egovernments/digit-ui-components"; import { downloadExcelWithCustomName } from "../utils"; import { CONSOLE_MDMS_MODULENAME } from "../Module"; @@ -38,7 +38,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { const id = searchParams.get("id"); const parentId = searchParams.get("parentId"); const [showExitWarning, setShowExitWarning] = useState(false); - const campaignName = props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName || searchParams.get("campaignName") ; + const campaignName = props?.props?.sessionData?.HCM_CAMPAIGN_NAME?.campaignName || searchParams.get("campaignName"); const { data: Schemas, isLoading: isThisLoading } = Digit.Hooks.useCustomMDMS( tenantId, CONSOLE_MDMS_MODULENAME, @@ -47,11 +47,19 @@ const UploadData = ({ formData, onSelect, ...props }) => { { schemaCode: `${CONSOLE_MDMS_MODULENAME}.adminSchema` } ); - const { data: readMe } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "ReadMeConfig" }] - ,{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.ReadMeConfig` } + const { data: readMe } = Digit.Hooks.useCustomMDMS( + tenantId, + CONSOLE_MDMS_MODULENAME, + [{ name: "ReadMeConfig" }], + { select: (MdmsRes) => MdmsRes }, + { schemaCode: `${CONSOLE_MDMS_MODULENAME}.ReadMeConfig` } ); - const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "baseTimeout" }] , - {select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.baseTimeout` } + const { data: baseTimeOut } = Digit.Hooks.useCustomMDMS( + tenantId, + CONSOLE_MDMS_MODULENAME, + [{ name: "baseTimeout" }], + { select: (MdmsRes) => MdmsRes }, + { schemaCode: `${CONSOLE_MDMS_MODULENAME}.baseTimeout` } ); const [sheetHeaders, setSheetHeaders] = useState({}); const [translatedSchema, setTranslatedSchema] = useState({}); @@ -65,9 +73,9 @@ const UploadData = ({ formData, onSelect, ...props }) => { const totalData = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA"); const [convertedSchema, setConvertedSchema] = useState({}); const [loader, setLoader] = useState(false); - const [currentStep , setCurrentStep] = useState(1); - const [projectType , setprojectType] = useState(props?.props?.projectType) - const baseKey = 10; + const [currentStep, setCurrentStep] = useState(1); + const [projectType, setprojectType] = useState(props?.props?.projectType); + const baseKey = 10; // const projectType = props?.props?.projectType; useEffect(() => { @@ -77,11 +85,11 @@ const UploadData = ({ formData, onSelect, ...props }) => { e.returnValue = ""; // Required for most browsers } }; - + if (showExitWarning) { window.addEventListener("beforeunload", handleBeforeUnload); } - + return () => { window.removeEventListener("beforeunload", handleBeforeUnload); }; @@ -91,7 +99,6 @@ const UploadData = ({ formData, onSelect, ...props }) => { // User performs an action that completes their workflow setShowExitWarning(false); }; - function updateUrlParams(params) { const url = new URL(window.location.href); @@ -101,15 +108,13 @@ const UploadData = ({ formData, onSelect, ...props }) => { window.history.replaceState({}, "", url); } - useEffect(() =>{ + useEffect(() => { setKey(currentKey); - setCurrentStep(currentKey - baseKey + 1); - }, [currentKey]) + }, [currentKey]); - useEffect(() =>{ + useEffect(() => { setprojectType(props?.props?.projectType); - }, [props?.props?.projectType]) - + }, [props?.props?.projectType]); useEffect(() => { if (type === "facilityWithBoundary") { @@ -156,21 +161,22 @@ const UploadData = ({ formData, onSelect, ...props }) => { }; var translateReadMeInfo = (schema) => { - const translatedSchema = schema.map((item) => { - return { - header: t(item.header), - isHeaderBold: item.isHeaderBold, - inSheet: item.inSheet, - inUiInfo: item.inUiInfo, - descriptions: item.descriptions.map((desc) => { - return { - text: t(desc.text), - isStepRequired: desc.isStepRequired, - isBold: desc.isBold, - }; - }), - }; - }); + const translatedSchema = + schema?.map((item) => { + return { + header: t(item.header), + isHeaderBold: item.isHeaderBold, + inSheet: item.inSheet, + inUiInfo: item.inUiInfo, + descriptions: item.descriptions.map((desc) => { + return { + text: t(desc.text), + isStepRequired: desc.isStepRequired, + isBold: desc.isBold, + }; + }), + }; + }) || []; return translatedSchema; }; @@ -234,8 +240,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { ); const boundary = await convertIntoSchema( Schemas?.MdmsRes?.[CONSOLE_MDMS_MODULENAME]?.adminSchema?.filter( - (item) => item.title === "boundaryWithTarget" && - item.campaignType === (totalData?.HCM_CAMPAIGN_TYPE?.projectType?.code || projectType) + (item) => item.title === "boundaryWithTarget" && item.campaignType === (totalData?.HCM_CAMPAIGN_TYPE?.projectType?.code || projectType) )?.[0] ); const user = await convertIntoSchema( @@ -258,15 +263,13 @@ const UploadData = ({ formData, onSelect, ...props }) => { const newUserSchema = await translateSchema(convertedSchema?.userWithBoundary); const filterByUpdateFlag = (schemaProperties) => { - return Object.keys(schemaProperties).filter( - (key) => { - // if (parentId) { - // return schemaProperties[key].isUpdate === true; - // } - return schemaProperties[key].isUpdate !== true; - } - ); - }; + return Object.keys(schemaProperties).filter((key) => { + // if (parentId) { + // return schemaProperties[key].isUpdate === true; + // } + return schemaProperties[key].isUpdate !== true; + }); + }; const headers = { boundary: filterByUpdateFlag(newBoundarySchema?.properties), @@ -290,7 +293,9 @@ const UploadData = ({ formData, onSelect, ...props }) => { const newReadMeFacility = await translateReadMeInfo( readMe?.[CONSOLE_MDMS_MODULENAME]?.ReadMeConfig?.filter((item) => item.type === type)?.[0]?.texts ); - const newReadMeUser = await translateReadMeInfo(readMe?.[CONSOLE_MDMS_MODULENAME]?.ReadMeConfig?.filter((item) => item.type === type)?.[0]?.texts); + const newReadMeUser = await translateReadMeInfo( + readMe?.[CONSOLE_MDMS_MODULENAME]?.ReadMeConfig?.filter((item) => item.type === type)?.[0]?.texts + ); const newReadMeboundary = await translateReadMeInfo( readMe?.[CONSOLE_MDMS_MODULENAME]?.ReadMeConfig?.filter((item) => item.type === type)?.[0]?.texts ); @@ -327,7 +332,9 @@ const UploadData = ({ formData, onSelect, ...props }) => { setDownloadError(false); setIsError(false); setIsSuccess(props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.isSuccess || null); - setShowPopUp(!downloadedTemplates[type] && !props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.uploadedFile.length); + setShowPopUp( + !downloadedTemplates[type] && !props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_BOUNDARY_DATA?.uploadBoundary?.uploadedFile.length + ); break; case "facilityWithBoundary": setUploadedFile(props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.uploadedFile || []); @@ -336,7 +343,9 @@ const UploadData = ({ formData, onSelect, ...props }) => { setDownloadError(false); setIsError(false); setIsSuccess(props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.isSuccess || null); - setShowPopUp(!downloadedTemplates[type] && !props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.uploadedFile.length); + setShowPopUp( + !downloadedTemplates[type] && !props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_FACILITY_DATA?.uploadFacility?.uploadedFile.length + ); break; default: setUploadedFile(props?.props?.sessionData?.HCM_CAMPAIGN_UPLOAD_USER_DATA?.uploadUser?.uploadedFile || []); @@ -603,8 +612,8 @@ const UploadData = ({ formData, onSelect, ...props }) => { for (const row of jsonData) { for (let j = boundaryCodeIndex + 1; j < headersToValidate.length; j++) { const value = row[headersToValidate[j]]; - if(!requiredProperties.includes(headersToValidate[j])) continue; - + if (!requiredProperties.includes(headersToValidate[j])) continue; + if (value === undefined || value === null) { targetError.push( `${t("HCM_DATA_AT_ROW")} ${jsonData.indexOf(row) + 2} ${t("HCM_IN_COLUMN")} "${headersToValidate[j]}" ${t( @@ -982,7 +991,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { const [downloadedTemplates, setDownloadedTemplates] = useState({ boundary: false, facilityWithBoundary: false, - user: false + user: false, }); const downloadTemplate = async () => { @@ -1028,9 +1037,9 @@ const UploadData = ({ formData, onSelect, ...props }) => { setDownloadError(false); if (fileData?.[0]?.id) { downloadExcelWithCustomName({ fileStoreId: fileData?.[0]?.id, customName: fileData?.[0]?.filename }); - setDownloadedTemplates(prev => ({ + setDownloadedTemplates((prev) => ({ ...prev, - [type]: true + [type]: true, })); } } else { @@ -1043,8 +1052,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { if (errorCode == "NativeIoException") { setDownloadError(true); setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") }); - } - else { + } else { setDownloadError(true); setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") }); } @@ -1052,7 +1060,7 @@ const UploadData = ({ formData, onSelect, ...props }) => { } ); }; - // Modify the condition for showing the popup + // Modify the condition for showing the popup useEffect(() => { // Only show popup if the template for this type hasn't been downloaded yet if (downloadedTemplates[type]) { @@ -1079,20 +1087,6 @@ const UploadData = ({ formData, onSelect, ...props }) => { window.dispatchEvent(new Event("checking")); }, [key]); - const onStepClick = (currentStep) => { - setCurrentStep(currentStep+1); - if(currentStep === 0){ - setKey(10); - } - else if(currentStep === 1){ - setKey(11); - } - else if(currentStep === 3){ - setKey(13); - } - else setKey(12); - }; - const getDownloadLabel = () => { if (parentId) { if (type === "boundary") { @@ -1110,97 +1104,82 @@ const UploadData = ({ formData, onSelect, ...props }) => { return ( <>
- {!parentId && ( -
- - - - - - -
- )} {loader && }
- - -
-
- {type === "boundary" ? t("WBH_UPLOAD_TARGET") : type === "facilityWithBoundary" ? t("WBH_UPLOAD_FACILITY") : t("WBH_UPLOAD_USER")} -
-
- {uploadedFile.length === 0 && ( -
- {type === "boundary" ? t("HCM_BOUNDARY_MESSAGE") : type === "facilityWithBoundary" ? t("HCM_FACILITY_MESSAGE") : t("HCM_USER_MESSAGE")} -
- )} - - {showInfoCard && ( - - {errorsType[type] && ( - - {errorsType[type] - .split(",") - .slice(0, 50) - .map((error, index) => ( - - {index > 0 &&
} - {error.trim()} -
- ))} -
- )} - , - ]} - /> - )} -
- ( -
-

{info?.header}

-
    - {info?.descriptions.map((desc, i) => ( -
  • - {desc.isBold ?

    {desc.text}

    :

    {desc.text}

    } -
  • - ))} -
+ + +
+
+ {type === "boundary" ? t("WBH_UPLOAD_TARGET") : type === "facilityWithBoundary" ? t("WBH_UPLOAD_FACILITY") : t("WBH_UPLOAD_USER")} +
+
- ))} - label={"Info"} - /> + {uploadedFile.length === 0 && ( +
+ {type === "boundary" + ? t("HCM_BOUNDARY_MESSAGE") + : type === "facilityWithBoundary" + ? t("HCM_FACILITY_MESSAGE") + : t("HCM_USER_MESSAGE")} +
+ )} + + {showInfoCard && ( + + {errorsType[type] && ( + + {errorsType[type] + .split(",") + .slice(0, 50) + .map((error, index) => ( + + {index > 0 &&
} + {error.trim()} +
+ ))} +
+ )} + , + ]} + /> + )} +
+ ( +
+

{info?.header}

+
    + {info?.descriptions.map((desc, i) => ( +
  • + {desc.isBold ?

    {desc.text}

    :

    {desc.text}

    } +
  • + ))} +
+
+ ))} + label={"Info"} + />
{showPopUp && ( { + const startIdx = (currentPage - 1) * rowsPerPage; + const endIdx = startIdx + rowsPerPage; + return data.slice(startIdx, endIdx); +}; +const reducer = (state, action) => { + switch (action.type) { + case "SET_DATA": + return { + ...state, + data: action.payload?.sheetData, + currentData: getPageData(action.payload?.sheetData, state.currentPage, state.rowsPerPage), // Slice data for current page + workbook: action.payload?.workbook, + totalRows: action.payload?.sheetData?.length, + arrayBuffer: action.payload?.arrayBuffer, + schemas: action?.schemas, + }; + case "SET_PAGE": + return { + ...state, + currentPage: action.payload, + currentData: getPageData(state.data, action.payload, state.rowsPerPage), // Update data for the new page + }; + case "SET_ROWS_PER_PAGE": + return { + ...state, + rowsPerPage: action.payload, + currentPage: 1, // Reset to the first page when rows per page changes + currentData: getPageData(state.data, 1, action.payload), // Update data for the first page with the new page size + }; + case "UPDATE_BOUNDARY": + const temp = + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? state?.data?.map((item) => { + const numberLoc = action.t(action?.schemas?.find((i) => i.description === "Phone Number")?.name); + const BoundaryLoc = action.t(action?.schemas?.find((i) => i.description === "Boundary Code (Mandatory)")?.name); + if (item?.[numberLoc] === action?.payload?.row?.[numberLoc]) { + return { + ...item, + [BoundaryLoc]: action?.payload?.selectedBoundary?.map((i) => i?.code)?.join(","), + }; + } + return item; + }) + : state?.data?.map((item) => { + const BoundaryLoc = action.t(action?.schemas?.find((i) => i.description === "Boundary Code")?.name); + if (item?.[action.t("HCM_ADMIN_CONSOLE_FACILITY_CODE")] === action?.payload?.row?.[action.t("HCM_ADMIN_CONSOLE_FACILITY_CODE")]) { + return { + ...item, + [BoundaryLoc]: action?.payload?.selectedBoundary?.map((i) => i?.code)?.join(","), + }; + } + return item; + }); + return { + ...state, + data: temp, + currentData: getPageData( + state?.filter + ? temp?.filter((i) => + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? i?.[action.t(action?.schemas?.find((i) => i.description === "User Usage")?.name)] === "Active" + : i?.[action.t(action?.schemas?.find((i) => i.description === "Facility usage")?.name)] === "Active" + ) + : temp, + state.currentPage, + state.rowsPerPage + ), + updated: true, + }; + case "UPDATE_STATUS": + const temp1 = + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? state?.data?.map((item) => { + const numberLoc = action.t(action?.schemas?.find((i) => i.description === "Phone Number")?.name); + const ActiveLoc = action.t(action?.schemas?.find((i) => i.description === "User Usage")?.name); + if (item?.[numberLoc] === action?.payload?.row?.[numberLoc]) { + return { + ...item, + [ActiveLoc]: action?.payload?.selectedStatus?.code, + }; + } + return item; + }) + : state?.data?.map((item) => { + const ActiveLoc = action.t(action?.schemas?.find((i) => i.description === "Facility usage")?.name); + if (item?.[action.t("HCM_ADMIN_CONSOLE_FACILITY_CODE")] === action?.payload?.row?.[action.t("HCM_ADMIN_CONSOLE_FACILITY_CODE")]) { + return { + ...item, + [ActiveLoc]: action?.payload?.selectedStatus?.code, + }; + } + return item; + }); + return { + ...state, + data: temp1, + currentData: getPageData( + state?.filter + ? temp1?.filter((i) => + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? i?.[action.t(action?.schemas?.find((i) => i.description === "User Usage")?.name)] === "Active" + : i?.[action.t(action?.schemas?.find((i) => i.description === "Facility usage")?.name)] === "Active" + ) + : temp1, + state.currentPage, + state.rowsPerPage + ), + updated: true, + }; + case "FILTER_BY_ACTIVE": + return { + ...state, + currentData: action.payload?.filter + ? getPageData( + state.data?.filter((i) => + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? i?.[action.t(action?.schemas?.find((i) => i.description === "User Usage")?.name)] === "Active" + : i?.[action.t(action?.schemas?.find((i) => i.description === "Facility usage")?.name)] === "Active" + ), + state.currentPage, + state.rowsPerPage + ) + : getPageData(state.data, state.currentPage, state.rowsPerPage), // Update data for the new page + totalRows: action.payload?.filter + ? state.data?.filter((i) => + action?.currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? i?.[action.t(action?.schemas?.find((i) => i.description === "User Usage")?.name)] === "Active" + : i?.[action.t(action?.schemas?.find((i) => i.description === "Facility usage")?.name)] === "Active" + )?.length + : state.data?.length, + filter: action?.payload?.filter, + }; + default: + return state; + } +}; + +function flattenHierarchyIterative(data) { + const stack = data.map((node) => ({ ...node, parentCode: null })); // Initialize stack with parentCode as null + const result = []; + + while (stack.length > 0) { + const { id, code, boundaryType, children, parentCode } = stack.pop(); + + // Add the current node to the result with the parent code + result.push({ id, name: code, code: code, type: boundaryType, parent: parentCode }); + + // Push children onto the stack with their parentCode set to the current node's code + if (children && children.length > 0) { + stack.push( + ...children.map((child) => ({ + ...child, + parentCode: code, // Set the parent code for the child + })) + ); + } + } + + return result; +} + +const Wrapper = ({ setShowPopUp, alreadyQueuedSelectedState }) => { + const { t } = useTranslation(); + return ( + { + setShowPopUp(false); + }} + onClose={() => { + setShowPopUp(false); + }} + > +
+ {alreadyQueuedSelectedState?.map((item, index) => ( + + ))} +
+
+ ); +}; + +function UploadDataMapping({ formData, onSelect, currentCategories }) { + const { t } = useTranslation(); + const tenantId = Digit.ULBService.getCurrentTenantId(); + const { id, ...queryParams } = Digit.Hooks.useQueryParams(); + const [showPopUp, setShowPopUp] = useState(null); + const [selectedLevel, setSelectedLevel] = useState(null); + const [selectedBoundary, setSelectedBoundary] = useState(null); + const [chipPopUpRowId, setChipPopUpRowId] = useState(null); + const [allLowestHierarchyCodes, setAllLowestHierarchyCodes] = useState(null); + const [allSelectedBoundary, setAllSelectedBoundary] = useState([]); + const sessionData = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_FORM_DATA"); + const paramsData = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_UPLOAD_ID"); + const selectedBoundaryData = sessionData?.["HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA"]?.boundaryType?.selectedData; + const schemaFilter = currentCategories === "HCM_UPLOAD_FACILITY_MAPPING" ? "facility" : "user"; + const [state, dispatch] = useReducer(reducer, initialState); + const boundaryHierarchy = paramsData?.hierarchy?.boundaryHierarchy; + const { data: Schemas, isLoading: isThisLoading, refetch: refetchSchema } = Digit.Hooks.useCustomMDMS( + tenantId, + CONSOLE_MDMS_MODULENAME, + [{ name: "adminSchema" }], + { + cacheTime: 0, + staleTime: 0, + select: (data) => { + const currentSchema = data?.["HCM-ADMIN-CONSOLE"]?.adminSchema?.filter((i) => i?.title === schemaFilter && i?.campaignType === "all"); + const result = Object.values(currentSchema?.[0]?.properties)?.flatMap((arr) => arr?.map((item) => item)); + return result; + }, + }, + { schemaCode: `${CONSOLE_MDMS_MODULENAME}.adminSchema` } + ); + useEffect(() => { + refetchSchema(); + }, [schemaFilter, currentCategories]); + useEffect(() => { + if (state?.updated) { + switch (currentCategories) { + case "HCM_UPLOAD_USER_MAPPING": + onSelect("uploadUserMapping", state); + break; + default: + onSelect("uploadFacilityMapping", state); + break; + } + } + }, [state]); + const { isLoading: hierarchyLoading, data: lowestHierarchy } = Digit.Hooks.useCustomMDMS( + tenantId, + CONSOLE_MDMS_MODULENAME, + [ + { + name: "HierarchySchema", + filter: "[?(@.type=='console')]", + }, + ], + { + enabled: true, + select: (data) => { + return data?.["HCM-ADMIN-CONSOLE"]?.HierarchySchema?.[0]?.lowestHierarchy; + }, + }, + { schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` } + ); + + const reqCriteriaResource = { + url: `/boundary-service/boundary-relationships/_search`, + params: { + tenantId: tenantId, + hierarchyType: paramsData?.hierarchy?.hierarchyType, + includeChildren: true, + codes: allLowestHierarchyCodes?.join(","), + }, + config: { + enabled: allLowestHierarchyCodes?.length > 0 ? true : false, + select: (data) => { + return data?.["TenantBoundary"]?.[0]?.boundary; + }, + }, + }; + + const { isLoading: childrenDataLoading, data: childrenData, isFetching, refetch } = Digit.Hooks.useCustomAPIHook(reqCriteriaResource); + + useEffect(() => { + if (allLowestHierarchyCodes?.length > 0 && childrenData?.length > 0) { + const allLowestBoundaryData = flattenHierarchyIterative(childrenData); + const sessionSelectedData = sessionData?.["HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA"]?.boundaryType?.selectedData; + setAllSelectedBoundary([...allLowestBoundaryData, ...sessionSelectedData]); + } + }, [allLowestHierarchyCodes, childrenData]); + useEffect(() => { + if (lowestHierarchy && sessionData?.["HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA"]?.boundaryType?.selectedData?.length > 0) { + const lowestHierarchyCodes = sessionData?.["HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA"]?.boundaryType?.selectedData + ?.filter((i) => i.type === lowestHierarchy) + ?.map((j) => j.code); + setAllLowestHierarchyCodes(lowestHierarchyCodes); + } + }, [lowestHierarchy]); + + const getFileStoreId = () => { + switch (formData?.name) { + case "uploadFacilityMapping": + return sessionData?.["HCM_CAMPAIGN_UPLOAD_FACILITY_DATA"]?.uploadFacility?.uploadedFile?.[0]?.filestoreId; + break; + case "uploadUserMapping": + return sessionData?.["HCM_CAMPAIGN_UPLOAD_USER_DATA"]?.uploadUser?.uploadedFile?.[0]?.filestoreId; + break; + default: + return null; + break; + } + }; + const { data, isLoading } = Digit.Hooks.campaign.useReadExcelData({ + tenantId: tenantId, + fileStoreId: getFileStoreId(), + currentCategories: currentCategories, + sheetNameToFetch: currentCategories === "HCM_UPLOAD_FACILITY_MAPPING" ? t("HCM_ADMIN_CONSOLE_FACILITIES") : t("HCM_ADMIN_CONSOLE_USER_LIST"), + schemas: Schemas, + t: t, + config: { + enabled: true, + }, + }); + + useEffect(() => { + if (data) { + dispatch({ type: "SET_DATA", payload: data, schemas: Schemas, t: t }); + } + }, [data, Schemas]); + const handlePageChange = (page) => { + dispatch({ type: "SET_PAGE", payload: page, schemas: Schemas, t: t }); + }; + const handleRowsPerPageChange = (newPerPage) => { + dispatch({ type: "SET_ROWS_PER_PAGE", payload: newPerPage, schemas: Schemas, t: t }); + }; + + const columns = + currentCategories === "HCM_UPLOAD_USER_MAPPING" + ? [ + { + name: t("NAME_OF_PERSON"), + selector: (row) => { + return row?.[t(Schemas?.find((i) => i.description === "User Name")?.name)] || t("NA"); + }, + sortable: true, + }, + { + name: t("PHONE_NUMBER"), + selector: (row) => row?.[t(Schemas?.find((i) => i.description === "Phone Number")?.name)] || t("NA"), + sortable: true, + }, + { + name: t("ROLE"), + selector: (row) => row?.[t(Schemas?.find((i) => i.description === "User Role")?.name)] || t("NA"), + sortable: true, + }, + { + name: t("EMPLOYEMENT_TYPE"), + selector: (row) => row?.[t(Schemas?.find((i) => i.description === "Employement Type")?.name)] || t("NA"), + sortable: true, + }, + { + name: t("ACTIVE_STATUS"), + cell: (row) => { + // row?.["Active / Inactive"] || t("NA") + const a = [ + { + code: "Active", + }, + { + code: "Inactive", + }, + ]; + return ( + item?.code === row?.[t(Schemas?.find((i) => i.description === "User Usage")?.name)]) || null} + isMandatory={true} + option={a} + select={(value) => { + dispatch({ + type: "UPDATE_STATUS", + currentCategories: currentCategories, + schemas: Schemas, + t: t, + payload: { + row: row, + selectedStatus: value, + }, + }); + }} + optionKey="code" + t={t} + /> + ); + }, + }, + { + name: t("BOUNDARY"), + cell: (row) => { + return ( + <> + {row?.[t(Schemas?.find((i) => i.description === "Boundary Code (Mandatory)")?.name)] || t("NA")} +
+
+ ); + }, + }, + ]; + return ( + + { + dispatch({ + type: "FILTER_BY_ACTIVE", + t: t, + schemas: Schemas, + currentCategories: currentCategories, + payload: { + filter: value, + }, + }); + }} + shapeOnOff + /> + + } + pagination + paginationServer + customStyles={tableCustomStyle} + // paginationTotalRows={totalRows} + // onChangePage={handlePaginationChange} + // onChangeRowsPerPage={handleRowsPerPageChange} + // paginationPerPage={rowsPerPage} + paginationTotalRows={state.totalRows} + onChangePage={handlePageChange} + onChangeRowsPerPage={handleRowsPerPageChange} + paginationRowsPerPageOptions={[5, 10, 15, 20]} + /> + {showPopUp && ( + + {t("FACILITY_MAPPING_POP_HEADER")} + + {t("CHOOSE_BOUNDARY_LEVEL")} + { + setSelectedLevel(value); + setSelectedBoundary(null); + }} + optionKey="boundaryType" + t={t} + /> + + + {t("CHOOSE_BOUNDARY_LEVEL")} + i.type === selectedLevel?.boundaryType) || []).reduce((acc, item) => { + const { parent, code, type } = item; + + // Initialize the parent group if it doesn't exist + if (!acc[parent]) { + acc[parent] = { + code: parent, + options: [], + }; + } + + // Add each item as a child of the corresponding parent + acc[parent].options.push({ + code, + type, + parent, + }); + + return acc; + }, {}) + ) || [] + } + optionsKey={"code"} + selected={selectedBoundary ? selectedBoundary : []} + onClose={(value) => { + const boundariesInEvent = value?.map((event) => event?.[1]); + setSelectedBoundary(boundariesInEvent); + }} + onSelect={(value) => { + // setSelectedBoundary(value); + }} + addCategorySelectAllCheck={true} + addSelectAllCheck={true} + /> + {/* i.type === selectedLevel?.boundaryType + ) || [] + } + select={(value) => { + setSelectedBoundary(value); + }} + optionKey="code" + t={t} + /> */} + + , + ]} + onOverlayClick={() => { + setShowPopUp(false); + setSelectedLevel(null); + setSelectedBoundary(null); + }} + footerChildren={[ + , - - ]} - className={"new-actionbar"} - /> + { + onActionClick(); + }} + >, + , + ]} + className={"new-actionbar"} + /> )} {showToast && ( - + DIGIT HCM