-
Notifications
You must be signed in to change notification settings - Fork 486
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
replace useDispatch with useQuery and request in FacilityCard, FacililyHome and FacilityUsers #6575
Conversation
…tyHome and facilityUsers
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. |
…useEffect with useQuery
@rithviknishad |
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.
Nice work!
@sriharsh05 fix the cypress, its failing |
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.
In addition to the above,
@rithviknishad |
the doctor capacity total count is not working properly |
👋 Hi, @sriharsh05, This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there. |
@rithviknishad Please review the PR. |
LGTM |
WHAT
🤖 Generated by Copilot at ae5cd23
The pull request refactors the code for making and handling API calls in the
Facility
components to use therequest
utility and theuseQuery
hook. It also adds and modifies type definitions for the requests and the responses for various API endpoints insrc/Redux/api.tsx
andsrc/Components/Facility/models.tsx
. The purpose of these changes is to improve the code readability, performance, and type safety.The pull request partially refactors the codebase for managing facility module in the frontend. It replaces the redux actions and states with the custom request function and the useQuery hook for data fetching and updating. It improves the code quality, performance, and readability by removing unnecessary imports, variables, and dependencies.
This pull request makes the required changes to only 3 files and does not close the entire issue.
Proposed Changes
useDispatch
w.useQuery
/request
: Facility (Part 2, E-H) (src/Components/Facility/[E-H]*.tsx
) #6391@coronasafe/care-fe-code-reviewers @coronasafe/code-reviewers
Merge Checklist
HOW
🤖 Generated by Copilot at ae5cd23
request
utility anduseQuery
hook for fetching and caching data from the API endpoints (F0,F1,F2)useDispatch
,statusType
,useAbortableEffect
, and action creators from./src/Components/Facility/FacilityCard.tsx
,./src/Components/Facility/FacilityHome.tsx
, and./src/Components/Facility/FacilityUsers.tsx
(link,link,link)request
,routes
, anduseQuery
from./src/Redux/api.tsx
to./src/Components/Facility/FacilityCard.tsx
,./src/Components/Facility/FacilityHome.tsx
, and./src/Components/Facility/FacilityUsers.tsx
(link,link,link)dispatch
anddispatchAction
fromFacilityCard
andFacilityHome
components as they are no longer used for making API calls (link,link)handleNotifySubmit
function inFacilityCard
component to userequest
utility instead ofdispatchAction
function to send notification messages to the facility, usingroutes.sendNotificationMessages
object to define the API endpoint and the types, and destructuringres
anddata
from the response object (link)fetchData
function inFacilityHome
component to useuseQuery
hook instead ofdispatch
function to fetch the data for the facility, the capacity, the doctor, and the triage, usingroutes
object to define the API endpoints and the types, and destructuringres
,data
, andrefetch
from the objects returned by the hook (link)fetchData
function inside theuseEffect
hook that runs when thepermittedFacilityRes
changes, instead of using theuseAbortableEffect
hook that runs when thefetchData
function changes, and remove theuseAbortableEffect
hook as it is no longer needed (link)handleDeleteSubmit
function inFacilityHome
component to userequest
utility instead ofdispatch
function to delete the facility, usingroutes.deleteFacility
object to define the API endpoint and the types, and passingid
as apathParams
property to therequest
utility (link)handleUpdate
function inFacilityHome
component to usecapacityFetch
anddoctorFetch
functions instead ofdispatch
function to refetch the capacity and doctor data, using the functions returned by theuseQuery
hook that handles the fetching and caching of the data from the API endpoints (link,link,link,link)isLoading
andsetIsLoading
fromFacilityUsers
component as they are no longer needed for handling the loading state of the data fetching (link)fetchFacilityName
function inFacilityUsers
component to userequest
utility instead ofdispatch
function to fetch the facility name and district id, usingroutes.getAnyFacility
object to define the API endpoint and the types, and passingid
as apathParams
property to therequest
utility (link)fetchData
function fromFacilityUsers
component as it is no longer needed for fetching the facility users data, and useuseQuery
hook instead, usingroutes.getFacilityUsers
object to define the API endpoint and the types, passingoffset
,limit
, andfacility_id
asquery
andpathParams
properties to the hook, settingprefetch
property tofacilityId !== undefined
, and settingonResponse
property to a function that updates theusers
andtotalCount
state variables with the data from the response (link)loadFacilities
function inFacilityUsers
component to userequest
utility instead ofdispatch
function to fetch the facilities for a given user, usingroutes.userListFacility
object to define the API endpoint and the types, and passingusername
as apathParams
property to therequest
utility (link)handleUnlinkFacilitySubmit
function inFacilityUsers
component to userequest
utility instead ofdispatch
function to unlink a facility from a user, usingroutes.deleteUserFacility
object to define the API endpoint and the types, and passingfacility
as abody
andusername
as apathParams
property to therequest
utility (link)handleSubmit
function inFacilityUsers
component to userequest
utility instead ofdispatch
function to delete a user, usingroutes.deleteUser
object to define the API endpoint and the types, and passingusername
as apathParams
property to therequest
utility (link)linkFacilitySubmit
function inFacilityUsers
component to userequest
utility instead ofdispatch
function to link a facility to a user, usingroutes.addUserFacility
object to define the API endpoint and the types, and passingfacility
as abody
andusername
as apathParams
property to therequest
utility (link)isLoading
variable from the condition to render themanageUsers
component, and removeloading
prop from theCountCard
component, as they are no longer needed for handling the loading state of the data fetching (link,link)IFacilityNotificationRequest
,IFacilityNotificationResponse
,DeleteModel
, andIUserFacilityRequest
to./src/Components/Facility/models.tsx
(link)CapacityModal
,DoctorModal
,PatientStatsModel
,IFacilityNotificationRequest
,IFacilityNotificationResponse
,IUserFacilityRequest
, andDeleteModel
to./src/Redux/api.tsx
(link)TRes
property toroutes.getUser
,routes.deleteUser
,routes.getFacilityUsers
,routes.deleteFacility
,routes.getCapacity
,routes.listDoctor
, androutes.getTriage
objects to define the type for the response for the API endpoints to get a user by username, to delete a user by username, to get the users for a facility, to delete a facility by id, to get the capacity for a facility, to get the doctor for a facility, and to get the triage for a facility, respectively (link,link,link,link,link,link,link)TBody
andTRes
properties toroutes.addUserFacility
,routes.deleteUserFacility
, androutes.sendNotificationMessages
objects to define the types for the request and the response for the API endpoints to link a facility to a user, to unlink a facility from a user, and to send notification messages to a facility, respectively (link,link,link)path
property ofroutes.deleteUser
androutes.deleteFacility
objects to include the{username}
and{id}
parameters as part of the API endpoint path, respectively (link,link)