-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed all dispatch requests with useQuery and request in asset module #6370
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
✅ Deploy Preview for care-egov-staging ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also have to remove the no longer used actions as mentioned in the EPIC issue.
}, | ||
createAssetBed: { | ||
path: "/api/v1/assetbed/", | ||
method: "POST", | ||
TRes: Res<AssetData>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also have to add TBody
for all requests that will have a body.
@@ -238,6 +251,7 @@ const routes = { | |||
partialUpdateAssetBed: { | |||
path: "/api/v1/assetbed/{external_id}/", | |||
method: "PATCH", | |||
TRes: Res<AssetBedModel>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBody
here too...
@@ -818,13 +834,15 @@ const routes = { | |||
partialUpdateAsset: { | |||
path: "/api/v1/asset/{external_id}/", | |||
method: "PATCH", | |||
TRes: Res<AssetData>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBody
here too..
@@ -844,6 +863,7 @@ const routes = { | |||
updateAssetService: { | |||
path: "/api/v1/asset/{asset_external_id}/service_records/{external_id}", | |||
method: "PUT", | |||
TRes: Res<AssetService>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBody
here too...
} | ||
} | ||
} else { | ||
setLocation(initialLocation); | ||
} | ||
}, | ||
[filter.location] | ||
[facilityId, locationId] | ||
); | ||
|
||
useAbortableEffect((status: statusType) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useAbortableEffect
is no longer needed
if (data) { | ||
setSelectedFacility(data); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you won't need this state when using useQuery
); | ||
useEffect(() => { | ||
async function fetchFacilityName() { | ||
if (!qParams.facility) return setFacilityName(""); | ||
const res = await dispatch(getAnyFacility(qParams.facility, "facility")); | ||
setFacilityName(res?.data?.name); | ||
const { data } = await request(routes.getAnyFacility, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with useQuery
|
||
const fetchFacility = useCallback( | ||
async (status: statusType) => { | ||
if (!qParams.facility) return setFacility(undefined); | ||
setIsLoading(true); | ||
const res = await dispatch(getAnyFacility(qParams.facility)); | ||
const res = await request(routes.getAnyFacility, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with useQuery
const res = await dispatch( | ||
getFacilityAssetLocation(qParams.facility, qParams.location) | ||
); | ||
const { data } = await request(routes.getFacilityAssetLocation, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace with useQuery
setIsLoading(false); | ||
} | ||
}, | ||
[dispatch, qParams.facility, qParams.location] | ||
[qParams.facility, qParams.location] | ||
); | ||
|
||
useAbortableEffect( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useAbortableEffect is not needed when using request
/useQuery
@@ -171,10 +177,14 @@ const routes = { | |||
|
|||
getPermittedFacility: { | |||
path: "/api/v1/facility/{id}/", | |||
method: "GET", | |||
TRes: Res<FacilityModel>(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase with latest develop branch, the Res
has been renamed to Type
to make it generic for use with TBody
too...
@kshitijv256 when making changes, feel free to split the entire refactor into smaller PRs if that would help. It would be easier to make the changes, QA testing, and review. |
@rithviknishad made another PR #6374 with requested changes |
WHAT
🤖 Generated by Copilot at 4f06879
The pull request refactors the code for various components related to assets management, using the
request
utility function and theuseQuery
hook for making API calls instead of thedispatch
action and the action creators. This simplifies the code, reduces the number of imports, and fixes some issues with the API paths and parameters. The pull request also adds response type definitions for the asset and facility API routes in thesrc/Redux/api.tsx
file, using theRes
generic function and the imported interfaces.Proposed Changes
useDispatch
w.useQuery
/request
: Assets (src/Components/Assets/**
) #6326@coronasafe/care-fe-code-reviewers @coronasafe/code-reviewers
HOW
🤖 Generated by Copilot at 4f06879
request
utility function and theuseQuery
hook instead of thedispatch
action and theuseEffect
hook (link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link,link)Res
generic function and the interfaces for the asset models (link,link,link,link,link,link,link,link,link,link,link)