-
Notifications
You must be signed in to change notification settings - Fork 514
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
Replaced useDispatch with useQuery and request in ExternalResult (src/Components/ExternalResult/** ) #6402
Replaced useDispatch with useQuery and request in ExternalResult (src/Components/ExternalResult/** ) #6402
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. |
Hey @rithviknishad |
const [data, setData] = useState([]); | ||
const [resultListData, setResultListData] = useState< | ||
Partial<IExternalResult>[] | ||
>([]); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [totalCount, setTotalCount] = useState(0); |
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 don't need a state here again.
const [totalCount, setTotalCount] = useState(0); | |
const totalCount = data ? data.count : 0 |
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.
@konavivekramakrishna the delete being fetched two times is because, the request
is ending up performing a reattempt because it failed to parse the JSON on first attempt.
Although it was a success response on first attempt, it attempted to parse the empty response body as JSON and hence caused to reattempt.
You can update the request.ts
to only parse the JSON if the response has content type header as JSON.
@rithviknishad |
❌ Deploy Preview for care-net failed.
|
@rithviknishad can you review this |
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! LGTM
LGTM |
…/Components/ExternalResult/** ) (#6402) * replaced dispatch with useQuery in ResultList * replaced useDispatch with useQuery in listfilter * replaced useDispatch with reqeust in ExternalResultUpload * fixed filtering * fix ResultList * rm clg * make code readable * fix build * removed useEffect and useState from ResultList.tsx * Apply changes from code review --------- Co-authored-by: rithviknishad <[email protected]>
…/Components/ExternalResult/** ) (#6402) * replaced dispatch with useQuery in ResultList * replaced useDispatch with useQuery in listfilter * replaced useDispatch with reqeust in ExternalResultUpload * fixed filtering * fix ResultList * rm clg * make code readable * fix build * removed useEffect and useState from ResultList.tsx * Apply changes from code review --------- Co-authored-by: rithviknishad <[email protected]>
…/Components/ExternalResult/** ) (#6402) * replaced dispatch with useQuery in ResultList * replaced useDispatch with useQuery in listfilter * replaced useDispatch with reqeust in ExternalResultUpload * fixed filtering * fix ResultList * rm clg * make code readable * fix build * removed useEffect and useState from ResultList.tsx * Apply changes from code review --------- Co-authored-by: rithviknishad <[email protected]>
WHAT
🤖 Generated by Copilot at de8a84f
This pull request refactors and simplifies the code for the external result feature of the application. It uses the
useQuery
hook and therequest
utility to fetch and update data from the API, and defines the types and interfaces for the external result data and API requests and responses in themodels.ts
file. It also fixes some TypeScript and React errors and warnings, and removes some unused actions from theactions.tsx
file.Proposed Changes
useDispatch
w.useQuery
/request
: ExternalResult (src/Components/ExternalResult/**
) #6360@coronasafe/care-fe-code-reviewers @coronasafe/code-reviewers
Merge Checklist
HOW
🤖 Generated by Copilot at de8a84f
useQuery
hook and therequest
utility for API calls and response handling (link, link, link, link, link, link, link, link)useDispatch
anduseAbortableEffect
hooks from the external result components (link, link, link, link, link)actions.tsx
file (link, link)models.ts
file to define the interfaces and types for the external result data and API requests and responses (link)models.ts
file and add themethod
,TRes
, andTBody
properties to the external result endpoints in theapi.tsx
file (link, link, link, link, link)data
variable toresultItemData
in theResultItem
component to avoid confusion with thedata
variable returned by theuseQuery
hook (link, link, link, link, link, link, link, link, link, link, link, link, link)data
variable toresultListData
in theResultList
component to avoid confusion with thedata
variable returned by theuseQuery
hook (link, link, link)data
variable tordata
in theResultUpdate
component to avoid confusion with thedata
variable returned by therequest
utility (link)ExternalResultUpload
component (link)useQuery
,routes
, andLoading
modules to the imports in theListFilter
component (link)dispatch
variable from theListFilter
component (link)useEffect
hook that was used to fetch the ward and local body lists based on the district from theListFilter
component (link)loading
variable to conditionally render theLoading
component in theListFilter
andResultUpdate
components (link, link)useQuery
,routes
, andrequest
modules to the imports in theResultItem
andResultUpdate
components (link, link)showDeleteAlert
state before calling thehandleDelete
function in theResultItem
component (link)loading
variable to the dependency array of theuseEffect
hook in theResultList
component (link)result.name
variable in a template literal to avoid a TypeScript error in theResultList
component (link)key
prop to theinput
element to avoid a React warning in theResultList
component (link)fetchWards
function to take a number as an argument instead of a string in theResultUpdate
component (link)