-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added plan with census call hook * added page size change fix * remove commit --------- Co-authored-by: NabeelAyubee <[email protected]>
- Loading branch information
1 parent
925601f
commit 569c551
Showing
6 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../micro-ui-internals/packages/modules/microplan/src/hooks/services/searchPlanWithCensus.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const searchPlanWithCensus = async ({ tenantId, microplanId, body, limit, offset, roles = "" }) => { | ||
try { | ||
const response = await Digit.CustomService.getResponse({ | ||
url: "/plan-service/plan/_search", | ||
useCache: false, | ||
method: "POST", | ||
userService: false, | ||
params: {}, | ||
body: body, | ||
}); | ||
|
||
if (!response) { | ||
throw new Error("Employee not found with the given role"); | ||
} | ||
|
||
const localityArray = [...new Set(response?.Plan?.map((item) => item?.locality))]; | ||
|
||
const fetchCensusData = await Digit.CustomService.getResponse({ | ||
url: `/census-service/_search`, | ||
useCache: false, | ||
method: "POST", | ||
userService: false, | ||
params: {}, | ||
body: { | ||
CensusSearchCriteria: { | ||
tenantId: tenantId, | ||
source: microplanId, | ||
jurisdiction: localityArray, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!fetchCensusData) { | ||
throw new Error("Employee not found with the given role"); | ||
} | ||
|
||
return { | ||
planData: response?.Plan, | ||
censusData: fetchCensusData?.Census, | ||
}; | ||
} catch (error) { | ||
if (error?.response?.data?.Errors) { | ||
throw new Error(error.response.data.Errors[0].message); | ||
} | ||
throw new Error("An unknown error occurred"); | ||
} | ||
}; | ||
|
||
export default searchPlanWithCensus; |
13 changes: 13 additions & 0 deletions
13
...ui/web/micro-ui-internals/packages/modules/microplan/src/hooks/usePlanSearchWithCensus.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { useQuery } from "react-query"; | ||
import searchPlanWithCensus from "./services/searchPlanWithCensus"; | ||
const usePlanSearchWithCensus = ({ tenantId, microplanId, body, limit = 5, offset = 0, roles, config = {} }) => { | ||
return useQuery( | ||
["PLAN_SEARCH_EMPLOYEE_WITH_TAGGING", tenantId, microplanId, body, limit, offset, roles, config?.queryKey], | ||
() => searchPlanWithCensus({ tenantId, microplanId, body, limit, offset, roles }), | ||
{ | ||
...config, | ||
} | ||
); | ||
}; | ||
|
||
export default usePlanSearchWithCensus; |