Skip to content

Commit b186cfd

Browse files
authored
Solution Framework : Updated the custom mutation hook to handle custo… (#2373)
* Solution Framework : Updated the custom mutation hook to handle custom headers * Updated the library version and changelog * Updated usecustomAPI and custom mutation hook to handle custom method and headers
1 parent aa848c6 commit b186cfd

File tree

8 files changed

+15
-9
lines changed

8 files changed

+15
-9
lines changed

micro-ui/web/micro-ui-internals/example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"start": "react-scripts start"
1010
},
1111
"devDependencies": {
12-
"@egovernments/digit-ui-libraries": "1.8.12",
12+
"@egovernments/digit-ui-libraries": "1.8.13",
1313
"@egovernments/digit-ui-module-workbench": "1.0.21",
1414
"@egovernments/digit-ui-module-pgr": "1.8.12",
1515
"@egovernments/digit-ui-module-dss": "1.8.12",

micro-ui/web/micro-ui-internals/packages/libraries/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [1.8.13] [25-Apr-2025]
4+
- Updated Custom mutation hook and usecutsomAPI hook to handle header and method in request.
5+
36
## [1.8.11] [11-Mar-2025]
47
- Added new function to remove localisation cache
58

micro-ui/web/micro-ui-internals/packages/libraries/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@egovernments/digit-ui-libraries",
3-
"version": "1.8.12",
3+
"version": "1.8.13",
44
"main": "dist/index.js",
55
"module": "dist/index.modern.js",
66
"source": "src/index.js",

micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/useCustomAPIHook.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const useCustomAPIHook = ({
3434
params = {},
3535
body = {},
3636
config = {},
37+
headers = {},
38+
method = "POST",
3739
plainAccessRequest,
3840
changeQueryName = "Random",
3941
options = {},
@@ -48,7 +50,7 @@ const useCustomAPIHook = ({
4850
// Fetch function with error handling
4951
const fetchData = async () => {
5052
try {
51-
const response = await CustomService.getResponse({ url, params, body, plainAccessRequest, ...options });
53+
const response = await CustomService.getResponse({ url, params, body, plainAccessRequest, headers, method, ...options });
5254
return response || null; // Ensure it never returns undefined
5355
} catch (error) {
5456
console.error("Error fetching data:", error);

micro-ui/web/micro-ui-internals/packages/libraries/src/hooks/useCustomAPIMutationHook.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ mutation.mutate({
4444
* @returns {Object} Returns the object which contains data and isLoading flag
4545
*/
4646

47-
const useCustomAPIMutationHook = ({ url, params, body, config = {}, plainAccessRequest, changeQueryName = "Random" }) => {
47+
const useCustomAPIMutationHook = ({ url, params, body, headers={}, method = "POST", config = {}, plainAccessRequest, changeQueryName = "Random" }) => {
4848
const client = useQueryClient();
4949

5050
const { isLoading, data, isFetching, ...rest } = useMutation(
51-
(data) => CustomService.getResponse({ url, params: { ...params, ...data?.params }, body: { ...body, ...data?.body }, plainAccessRequest }),
51+
(data) => CustomService.getResponse({ url, params: { ...params, ...data?.params }, body: { ...body, ...data?.body }, plainAccessRequest, headers: { ...headers, ...data?.headers }, method }),
5252
{
5353
cacheTime: 0,
5454
...config,

micro-ui/web/micro-ui-internals/packages/libraries/src/services/elements/CustomService.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Request } from "../atoms/Utils/Request";
22

33
export const CustomService = {
4-
getResponse: ({ url, params, body, plainAccessRequest,useCache=true,userService=true,setTimeParam=true,userDownload=false,auth=true}) => Request({
4+
getResponse: ({ url, params, body, plainAccessRequest,useCache=true,userService=true,setTimeParam=true,userDownload=false,auth=true, headers={}, method="POST"}) => Request({
55
url: url,
66
data: body,
77
useCache,
88
userService,
9-
method: "POST",
9+
method: method,
1010
auth:auth,
1111
params: params,
12+
headers: headers,
1213
plainAccessRequest: plainAccessRequest,
1314
userDownload:userDownload,
1415
setTimeParam

micro-ui/web/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
],
1515
"homepage": "/digit-ui",
1616
"dependencies": {
17-
"@egovernments/digit-ui-libraries": "1.8.12",
17+
"@egovernments/digit-ui-libraries": "1.8.13",
1818
"@egovernments/digit-ui-module-workbench": "1.0.21",
1919
"@egovernments/digit-ui-module-pgr": "1.8.12",
2020
"@egovernments/digit-ui-module-dss": "1.8.12",

micro-ui/web/sandbox/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"homepage": "/sandbox-ui",
2121
"dependencies": {
22-
"@egovernments/digit-ui-libraries": "1.8.12",
22+
"@egovernments/digit-ui-libraries": "1.8.13",
2323
"@egovernments/digit-ui-module-workbench": "1.0.21",
2424
"@egovernments/digit-ui-module-pgr": "1.8.12",
2525
"@egovernments/digit-ui-module-dss": "1.8.12",

0 commit comments

Comments
 (0)