Skip to content

Commit

Permalink
api call using CudtomApiHook
Browse files Browse the repository at this point in the history
  • Loading branch information
suryansh-egov committed Oct 21, 2024
1 parent 08ce819 commit bb447db
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,79 @@ const UpdateChecklist = () => {
setServiceCode(`${campaignName}.${checklistType}.${role}`)
}, [])

useEffect(() => {

const callSearch = async () => {
const res = await Digit.CustomService.getResponse({
url: `/service-request/service/definition/v1/_search`,
body: {
ServiceDefinitionCriteria: {
"tenantId": tenantId,
"code": [serviceCode]
},
includeDeleted: true,

},
});
return res;
}
const fetchData = async () => {
try {
const res = await callSearch();

if (res?.ServiceDefinitions?.[0]?.attributes) {
setSearching(false);
let temp_data = res?.ServiceDefinitions?.[0]?.attributes
let formatted_data = temp_data.map((item) => item.additionalDetails);
let nvd = formatted_data.filter((value, index, self) =>
index === self.findIndex((t) => t.id === value.id)
);
setViewData(nvd);
// setViewData(formatted_data);

}
}
catch (error) {
}
// useEffect(() => {

// const callSearch = async () => {
// const res = await Digit.CustomService.getResponse({
// url: `/service-request/service/definition/v1/_search`,
// body: {
// ServiceDefinitionCriteria: {
// "tenantId": tenantId,
// "code": [serviceCode]
// },
// includeDeleted: true,

// },
// });
// return res;
// }
// const fetchData = async () => {
// try {
// const res = await callSearch();

// if (res?.ServiceDefinitions?.[0]?.attributes) {
// setSearching(false);
// let temp_data = res?.ServiceDefinitions?.[0]?.attributes
// let formatted_data = temp_data.map((item) => item.additionalDetails);
// let nvd = formatted_data.filter((value, index, self) =>
// index === self.findIndex((t) => t.id === value.id)
// );
// setViewData(nvd);
// // setViewData(formatted_data);

// }
// }
// catch (error) {
// }
// }
// fetchData();
// }, [serviceCode])

const rq = {
url: `/service-request/service/definition/v1/_search`,
body: {
ServiceDefinitionCriteria: {
tenantId: tenantId,
code: [serviceCode],
},
includeDeleted: true,
},
changeQueryName: `${serviceCode}`,
config: {
enabled: serviceCode? true: false,
cacheTime: 5000,
},
};

// Call the hook directly inside the component
const { data: res } = Digit.Hooks.useCustomAPIHook(rq);

useEffect(() => {
if (res?.ServiceDefinitions?.[0]?.attributes) {
setSearching(false);

// Extract and format the data
const temp_data = res?.ServiceDefinitions?.[0]?.attributes;
const formatted_data = temp_data.map((item) => item.additionalDetails);

// Filter out duplicates
const nvd = formatted_data.filter(
(value, index, self) => index === self.findIndex((t) => t.id === value.id)
);

setViewData(nvd);
}
fetchData();
}, [serviceCode])
}, [res]);

useEffect(() => {
const currentTime = new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,41 +116,80 @@ const ViewChecklist = () => {
setServiceCode(`${campaignName}.${checklistType}.${role}`)
}, [])

useEffect(() => {

const callSearch = async () => {
const res = await Digit.CustomService.getResponse({
url: `/service-request/service/definition/v1/_search`,
body: {
ServiceDefinitionCriteria: {
"tenantId": tenantId,
"code": [serviceCode]
},
includeDeleted: true
},
});
return res;
// useEffect(() => {

// const callSearch = async () => {
// const res = await Digit.CustomService.getResponse({
// url: `/service-request/service/definition/v1/_search`,
// body: {
// ServiceDefinitionCriteria: {
// "tenantId": tenantId,
// "code": [serviceCode]
// },
// includeDeleted: true
// },
// });
// return res;
// }
// const fetchData = async () => {
// try {
// const res = await callSearch();

// if (res?.ServiceDefinitions?.[0]?.attributes) {
// setSearching(false);
// let temp_data = res?.ServiceDefinitions?.[0]?.attributes
// let formatted_data = temp_data.map((item) => item.additionalDetails);
// let nvd = formatted_data.filter((value, index, self) =>
// index === self.findIndex((t) => t.id === value.id)
// );
// setViewData(nvd);

// }
// }
// catch (error) {
// }
// }
// fetchData();
// }, [serviceCode])

const rq = {
url: `/service-request/service/definition/v1/_search`,
body: {
ServiceDefinitionCriteria: {
tenantId: tenantId,
code: [serviceCode],
},
includeDeleted: true,
},
changeQueryName: `${serviceCode}`,
config: {
enabled: serviceCode? true: false,
cacheTime: 5000,
},
};

// Call the hook directly inside the component
const { data: res } = Digit.Hooks.useCustomAPIHook(rq);

useEffect(() => {
if (res?.ServiceDefinitions?.[0]?.attributes) {
setSearching(false);

// Extract and format the data
const temp_data = res?.ServiceDefinitions?.[0]?.attributes;
const formatted_data = temp_data.map((item) => item.additionalDetails);

// Filter out duplicates
const nvd = formatted_data.filter(
(value, index, self) => index === self.findIndex((t) => t.id === value.id)
);

setViewData(nvd);
}
const fetchData = async () => {
try {
const res = await callSearch();

if (res?.ServiceDefinitions?.[0]?.attributes) {
setSearching(false);
let temp_data = res?.ServiceDefinitions?.[0]?.attributes
let formatted_data = temp_data.map((item) => item.additionalDetails);
let nvd = formatted_data.filter((value, index, self) =>
index === self.findIndex((t) => t.id === value.id)
);
setViewData(nvd);
}, [res]);



}
}
catch (error) {
}
}
fetchData();
}, [serviceCode])

useEffect(() => {

Expand Down

0 comments on commit bb447db

Please sign in to comment.