Skip to content

Commit

Permalink
FEATURE/HCMPRE-1712: Facility Dropdown for plan Inbox (#2096)
Browse files Browse the repository at this point in the history
* Adding filters

* Working Filter Search

* InboxFilter Changes

* removing console.log

* Css package update

* changes

* changes

* changes

* changes

* changes

* A lot of changes

* changes

* changes

* changes

* uniform payload structure

* Adding Facility Dropdown

* code replacing name attribute

* Loader changes

* comments resolved

* Loader change

* Id to id
  • Loading branch information
abishekTa-egov authored Jan 3, 2025
1 parent dc5e629 commit 0b3dee9
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import React, { useState, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { FilterCard, Dropdown, LabelFieldPair, RadioButtons, TextBlock } from "@egovernments/digit-ui-components";
import { FilterCard, Dropdown, LabelFieldPair, RadioButtons, TextBlock, Loader } from "@egovernments/digit-ui-components";
import { useMyContext } from "../utils/context";



const InboxFilterWrapper = (props) => {
const { state } = useMyContext();
const { t } = useTranslation();
const {microplanId,...rest} = Digit.Hooks.useQueryParams()
const tenantId = Digit.ULBService.getCurrentTenantId();
const [filterValues, setFilterValues] = useState(
{ status: null, onRoadCondition: null, terrain: null, securityQ1: null, securityQ2: null }
);
Expand Down Expand Up @@ -49,6 +51,7 @@ const InboxFilterWrapper = (props) => {
name: `${t(key)} (${value})`,
}));
};


// Generate options from props.options
const resultArray = createArrayFromObject(props?.options, t);
Expand Down Expand Up @@ -92,6 +95,37 @@ const InboxFilterWrapper = (props) => {
}));
};

const planFacilitySearchConfig = {
url: "/plan-service/plan/facility/_search",
body: {
PlanFacilitySearchCriteria: {
tenantId: tenantId,
planConfigurationId: microplanId,
}
},
config: {
enabled: true,
select: (data) => {
if (!data?.PlanFacility || !Array.isArray(data.PlanFacility)) return [];

// Extract facilityName and facilityId for each object
const facilityOptions = data.PlanFacility.map((facility) => ({
code: facility.facilityName,
id: facility.facilityId
}));

return facilityOptions;
},
cacheTime:Infinity
}
};

const { isLoading: isPlanFacilityLoading,error:planFacilityerror, data: planFacility }=Digit.Hooks.useCustomAPIHook(planFacilitySearchConfig);

if(isPlanFacilityLoading){
return <Loader/>
}

return (

<FilterCard
Expand Down Expand Up @@ -145,6 +179,18 @@ const InboxFilterWrapper = (props) => {
disabled={false}
/>
</LabelFieldPair>

<LabelFieldPair vertical>
<TextBlock body={t(`MP_FILTER_FACILITY`)} />
<Dropdown
option={planFacility}
optionKey={"code"}
selected={filterValues["facility"] || defaultSelectedOptions?.facility}
select={(value) => handleDropdownChange("facility", value)}
t={t}
disabled={false}
/>
</LabelFieldPair>


{state.securityQuestions.map((item, index) => {
Expand Down

0 comments on commit 0b3dee9

Please sign in to comment.