diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js index 48b78c2cdca..7c4371d4b12 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/ActivityCard.js @@ -1,8 +1,8 @@ import React, { Fragment } from "react"; import { useTranslation } from "react-i18next"; import { useHistory } from "react-router-dom"; -import { Card, CardHeader } from "@egovernments/digit-ui-react-components"; -import { Card as CardNew } from "@egovernments/digit-ui-components"; +import { CardHeader } from "@egovernments/digit-ui-react-components"; +import { Card, Tag } from "@egovernments/digit-ui-components"; const ActivityHomeCard = ({onClickCard=()=>{},...props}) => { const { t } = useTranslation(); @@ -10,24 +10,24 @@ const ActivityHomeCard = ({onClickCard=()=>{},...props}) => { return ( - - {t(props.title)} + + + {t(props.title)} + {props.module.map((i) => { return ( - { if (!i.disable) { // Check if disabled @@ -38,14 +38,21 @@ const ActivityHomeCard = ({onClickCard=()=>{},...props}) => { children={ <> {i.icon} + {i.doneLabel && } {t(i.name)} > } - > + > ); })} - + ); }; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js index 1094fe0f67f..349530240bc 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/FacilityPopup.js @@ -28,6 +28,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => { const [totalCensusCount, setTotalCensusCount] = useState(0); const [currentPage, setCurrentPage] = useState(1); const [rowsPerPage, setRowsPerPage] = useState(10); + const [disabledAction, setDisabledAction] = useState(false); const [boundaryData, setBoundaryData] = useState([]); const configNavItem = [ { @@ -65,7 +66,27 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => { setLoader(false); }, [currentPage, rowsPerPage]) + // fetch the process instance for the current microplan to check if we need to disabled actions or not + const { isLoading:isProcessLoading, data: processData, } = Digit.Hooks.useCustomAPIHook({ + url: "/egov-workflow-v2/egov-wf/process/_search", + params: { + tenantId: tenantId, + history: true, + businessIds: microplanId, + }, + config: { + enabled: true, + select: (data) => { + return data?.ProcessInstances; + }, + }, + }); + useEffect(() => { + if (processData && processData.some((instance) => instance.action === "FINALIZE_CATCHMENT_MAPPING")) { + setDisabledAction(true); + } + }, [processData]); const { data: planEmployeeDetailsData, isLoading: isLoadingPlanEmployee } = Digit.Hooks.microplanv1.usePlanSearchEmployee({ @@ -181,12 +202,12 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => { } useEffect(() => { - if (isLoadingPlanEmployee || isLoadingCampaign) { + if (isLoadingPlanEmployee || isLoadingCampaign || isProcessLoading) { setLoader(true); } else { setLoader(false); } - }, [isLoadingPlanEmployee, isLoadingCampaign]); + }, [isLoadingPlanEmployee, isLoadingCampaign, isProcessLoading]); const handleRowSelect = (event) => { // Extract the IDs of all selected rows @@ -397,7 +418,7 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => { onChangeRowsPerPage={handleRowsPerPageChange} paginationRowsPerPageOptions={[10, 20, 50, 100]} paginationTotalRows={totalCensusCount} - selectableRows + selectableRows={!disabledAction} selectableRowsHighlight noContextMenu onSelectedRowsChange={handleRowSelect} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/PopInboxTable.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/PopInboxTable.js index 4235d1087a4..8eb6b14a7d4 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/PopInboxTable.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/PopInboxTable.js @@ -166,7 +166,7 @@ const PopInboxTable = ({ ...props }) => { { const { campaignId, microplanId, } = Digit.Hooks.useQueryParams(); const tenantId = Digit.ULBService.getStateId(); const userInfo = Digit.UserService.getUser(); - const { isLoading: isLoadingPlanObject, data: planObject,} = Digit.Hooks.microplanv1.useSearchPlanConfig( + const [activityCardData, setActivityCardData] = useState([]); + + + + const { isLoading: isLoadingPlanObject, data: planObject, refetch: refetchPlanObject} = Digit.Hooks.microplanv1.useSearchPlanConfig( { PlanConfigurationSearchCriteria: { tenantId, @@ -17,10 +21,15 @@ const ChooseActivity = () => { }, }, { - enabled: microplanId ? true : false, + enabled: true, } ); + // // Watch for campaignId or microplanId changes to trigger the fetch + useEffect(() => { + refetchPlanObject(); + }, [microplanId, campaignId]); + const { isLoading: isBusinessServiceLoading, data: workflowData, } = Digit.Hooks.useCustomAPIHook({ url: "/egov-workflow-v2/egov-wf/businessservice/_search", params: { @@ -37,68 +46,85 @@ const ChooseActivity = () => { }, }); + // fetch the process instance for the current microplan to check if current process is done or not + const { isLoading:isProcessLoading, data: processData, revalidate } = Digit.Hooks.useCustomAPIHook({ + url: "/egov-workflow-v2/egov-wf/process/_search", + params: { + tenantId: tenantId, + history: true, + businessIds: microplanId, + }, + config: { + enabled: true, + select: (data) => { + return data?.ProcessInstances; + }, + }, + }); + - if(isLoadingPlanObject || isBusinessServiceLoading){ - return ; - } - else{ - // Merged function to disable a card based on user roles and available actions in the current state - const isCardDisabled = (validRoles = [], currentState, validStatuses = [],) => { - const userRoles = userInfo?.info?.roles?.map((roleData) => roleData?.code) || []; + useEffect(() => { + if(planObject && workflowData && processData){ + const updatedActivityCardData = [ + { + name: t("VALIDATE_N_APPROVE_POPULATION_DATA"), + link: `pop-inbox?campaignId=${campaignId}µplanId=${microplanId}`, + doneLabel: isProcessDone(processData, "APPROVE_CENSUS_DATA") && "CENSUS_VALIDATED_LABEL", + icon: , + disable: isCardDisabled(["POPULATION_DATA_APPROVER", "ROOT_POPULATION_DATA_APPROVER"], isProcessDone(processData, "APPROVE_CENSUS_DATA"), ["EXECUTION_TO_BE_DONE","CENSUS_DATA_APPROVAL_IN_PROGRESS"]), + optionKey: "VALIDATE_N_APPROVE_POPULATION_DATA" + }, + { + name: t("ASSIGN_FACILITIES_TO_VILLAGE"), + link: `assign-facilities-to-villages?campaignId=${campaignId}µplanId=${microplanId}`, + doneLabel: isProcessDone(processData, "FINALIZE_CATCHMENT_MAPPING") && "FACILITY_CATCHEMENT_DONE_LABEL", + icon: , + disable: isCardDisabled(["FACILITY_CATCHMENT_MAPPER", "ROOT_FACILITY_CATCHMENT_MAPPER"], isProcessDone(processData, "FINALIZE_CATCHMENT_MAPPING"), ["CENSUS_DATA_APPROVED"]), + optionKey: "ASSIGN_FACILITIES_TO_VILLAGE" + }, + { + name: t("VALIDATE_N_APPROVE_MICROPLAN_ESTIMATIONS"), + link: `plan-inbox?campaignId=${campaignId}µplanId=${microplanId}`, + doneLabel: isProcessDone(processData, "APPROVE_ESTIMATIONS") && "ESTIMATIONS_APPROVED_LABEL", + icon: , + disable: isCardDisabled(["PLAN_ESTIMATION_APPROVER", "ROOT_PLAN_ESTIMATION_APPROVER"], isProcessDone(processData, "APPROVE_ESTIMATIONS"), ["RESOURCE_ESTIMATION_IN_PROGRESS"]), + optionKey: "VALIDATE_N_APPROVE_MICROPLAN_ESTIMATIONS" + }, + { + name: t("GEOSPATIAL_MAP_VIEW"), + link: null, + icon: , + disable: isCardDisabled([], false), + optionKey: "GEOSPATIAL_MAP_VIEW" + }, + ]; + setActivityCardData(updatedActivityCardData); + } + }, [planObject, workflowData, processData]); + + +// Merged function to disable a card based on user roles +const isCardDisabled = (validRoles = [], isProcessDone, validStatuses = [],) => { + const userRoles = userInfo?.info?.roles?.map((roleData) => roleData?.code) || []; - // Check if user has any valid roles - const hasValidRole = validRoles?.length > 0 && validRoles?.some(role => userRoles.includes(role)); + // Check if user has any valid roles + const hasValidRole = validRoles?.length > 0 && validRoles?.some(role => userRoles.includes(role)); - // Check if there are valid actions in the current state that match user roles - const hasValidNextAction = currentState?.actions?.some(action => - action?.roles.some(role => userRoles?.includes(role)) - ); + const hasValidCurrentStatus = validStatuses?.includes(planObject?.status); + + // Disable if either hasValidRole or hasValidNextAction is false + return !(hasValidRole &&(isProcessDone || hasValidCurrentStatus) /*hasValidNextAction*/ ); +}; - const hasValidCurrentStatus = validStatuses?.includes(planObject?.status); - // Disable if either hasValidRole or hasValidNextAction is false - return !(hasValidRole && hasValidCurrentStatus /*hasValidNextAction*/ ); +// Function to check if process is done for the current card +const isProcessDone = (ProcessInstances, process) => { + // Iterate over each process instance in the array + return ProcessInstances.some((instance) => instance.action === process); }; // Usage in activityCardData - const activityCardData = [ - { - name: t("VALIDATE_N_APPROVE_POPULATION_DATA"), - link: `pop-inbox?campaignId=${campaignId}µplanId=${microplanId}`, - icon: , - disable: isCardDisabled(["POPULATION_DATA_APPROVER", "ROOT_POPULATION_DATA_APPROVER"], workflowData, ["EXECUTION_TO_BE_DONE","CENSUS_DATA_APPROVAL_IN_PROGRESS"]), - optionKey: "VALIDATE_N_APPROVE_POPULATION_DATA" - }, - { - name: t("ASSIGN_FACILITIES_TO_VILLAGE"), - link: `assign-facilities-to-villages?campaignId=${campaignId}µplanId=${microplanId}`, - icon: , - disable: isCardDisabled(["FACILITY_CATCHMENT_MAPPER", "ROOT_FACILITY_CATCHMENT_MAPPER"], workflowData, ["CENSUS_DATA_APPROVED"]), - optionKey: "ASSIGN_FACILITIES_TO_VILLAGE" - }, - { - name: t("VALIDATE_N_APPROVE_MICROPLAN_ESTIMATIONS"), - link: `plan-inbox?campaignId=${campaignId}µplanId=${microplanId}`, - icon: , - disable: isCardDisabled(["PLAN_ESTIMATION_APPROVER", "ROOT_PLAN_ESTIMATION_APPROVER"], workflowData, ["RESOURCE_ESTIMATION_IN_PROGRESS"]), - optionKey: "VALIDATE_N_APPROVE_MICROPLAN_ESTIMATIONS" - }, - { - name: t("GEOSPATIAL_MAP_VIEW"), - link: null, - icon: , - disable: isCardDisabled([], workflowData), - optionKey: "GEOSPATIAL_MAP_VIEW" - }, - //commenting this as for now we are not showing viewer - // { - // name: t("VIEW_MICROPLAN_ESTIMATIONS"), - // link: `pop-inbox?campaignId=${campaignId}µplanId=${microplanId}`, - // icon: , - // disable: isCardDisabled(["MICROPLAN_VIEWER"], workflowData), - // optionKey: "VIEW_MICROPLAN_ESTIMATIONS" - // } - ]; + const updatePlan = async (req) => { const planRes = await Digit.CustomService.getResponse({ @@ -127,12 +153,15 @@ const ChooseActivity = () => { } } + if(isLoadingPlanObject || isBusinessServiceLoading || isProcessLoading){ + return ; + } + return ( ); } -} export default ChooseActivity; \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js index a631237b3d0..b82ae2403c8 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/FacilityCatchmentMapping.js @@ -131,7 +131,7 @@ const FacilityCatchmentMapping = () => { return return ( - + {t("MICROPLAN_ASSIGN_CATCHMENT_VILLAGES")} { {actionBarPopUp && ( { }} /> )} - + ); }; diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js index 84b1db2a1d9..042a3e9daa3 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PlanInbox.js @@ -37,6 +37,7 @@ const PlanInbox = () => { const [totalRows, setTotalRows] = useState(0); const [perPage, setPerPage] = useState(10); const [showToast, setShowToast] = useState(null); + const [disabledAction, setDisabledAction] = useState(false); const [availableActionsForUser, setAvailableActionsForUser] = useState([]); const [limitAndOffset, setLimitAndOffset] = useState({ limit: rowsPerPage, offset: (currentPage - 1) * rowsPerPage }); const [activeLink, setActiveLink] = useState({ @@ -301,6 +302,29 @@ const PlanInbox = () => { } }, [selectedFilter, activeLink, censusJurisdiction, limitAndOffset]); + + // fetch the process instance for the current microplan to check if we need to disabled actions or not + const { isLoading:isProcessLoading, data: processData, } = Digit.Hooks.useCustomAPIHook({ + url: "/egov-workflow-v2/egov-wf/process/_search", + params: { + tenantId: tenantId, + history: true, + businessIds: microplanId, + }, + config: { + enabled: true, + select: (data) => { + return data?.ProcessInstances; + }, + }, + }); + + useEffect(() => { + if (processData && processData.some((instance) => instance.action === "APPROVE_ESTIMATIONS")) { + setDisabledAction(true); + } + }, [processData]); + useEffect(() => { if (selectedFilter === "VALIDATED") { setActiveLink({ code: "", name: "" }); @@ -487,7 +511,7 @@ const PlanInbox = () => { SEND_BACK_FOR_CORRECTION: { isSuffix: true, icon: "ArrowForward" }, }; - if (isPlanEmpSearchLoading || isLoadingCampaignObject || isWorkflowLoading) { + if (isPlanEmpSearchLoading || isLoadingCampaignObject || isWorkflowLoading || isProcessLoading) { return ; } @@ -612,7 +636,7 @@ const PlanInbox = () => { data={planWithCensus?.tableData} pagination paginationServer - selectableRows + selectableRows={!disabledAction} selectableRowsHighlight onChangeRowsPerPage={handlePerRowsChange} onChangePage={handlePageChange} diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js index 862af08c671..8d088efd536 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/PopInbox.js @@ -36,6 +36,7 @@ const PopInbox = () => { const [employeeNameMap, setEmployeeNameMap] = useState({}); const [availableActionsForUser, setAvailableActionsForUser] = useState([]); const [assignedToMeCount, setAssignedToMeCount] = useState(0); + const [disabledAction, setDisabledAction] = useState(false); const [assignedToAllCount, setAssignedToAllCount] = useState(0); const [updatedCensus, setUpdatedCensus] = useState(null); const [limitAndOffset, setLimitAndOffset] = useState({ limit: rowsPerPage, offset: (currentPage - 1) * rowsPerPage }); @@ -66,6 +67,30 @@ const PopInbox = () => { ); + // fetch the process instance for the current microplan to check if we need to disabled actions or not + const { isLoading:isProcessLoading, data: processData, } = Digit.Hooks.useCustomAPIHook({ + url: "/egov-workflow-v2/egov-wf/process/_search", + params: { + tenantId: tenantId, + history: true, + businessIds: microplanId, + }, + config: { + enabled: true, + select: (data) => { + return data?.ProcessInstances; + }, + }, + }); + + + useEffect(() => { + if (processData && processData.some((instance) => instance.action === "APPROVE_CENSUS_DATA")) { + setDisabledAction(true); + } + }, [processData]); + + const handleActionBarClick = () => { setactionBarPopUp(true); }; @@ -541,7 +566,7 @@ const PopInbox = () => { setUpdatedCensus(data); setShowComment(true); }} - conditionalRowStyles={conditionalRowStyles} />} + conditionalRowStyles={conditionalRowStyles} disabledAction={disabledAction}/>} {showComment && (
{t(i.name)}