Skip to content

Commit

Permalink
Replaced useDispatch w. useQuery/request: Users (src/Components/Users…
Browse files Browse the repository at this point in the history
…/**) [5 out of 5 components] (#6596)

* replaced getUserDetails and getUserListSkills actions with useQuery

* replaced partialUpdateUser action with request

* replaced updatePassword action with request

* replaced dispatch with useQuery in UserFilter.tsx

* Bug Fix: UserFilter tried fetching district when district_id was not available

* addUser and checkUsername action replaced with request

* replaced useDispatch with request in UserAdd component

* replaced useDispatch with useQuery and request in SkillsSlideOver

* replaced useDispatch with useQuery and request in ManageUsers

* solved issue #6652 | passed user skills as props to SkillSelect

* removed unnecessary console logs

* re-added showAll as dependency to skillSearch

* removed unnecessary console logs

* replaced fetchDistrict request with useQuery and removed isLoading

* fixed error notification in ManageUsers

* removed unnecessary useState from ManageUsers

* code fixes in SkillsSlideOver

* code fixes in UserAdd

* code fix in UserFilter

* code fix in UserProfile

* removed redundant code

* added proper types and fixed redundant code

* removed redundant fireRequest actions

* fix http 301 redirect due to missing trailing slash

* Update TRes of userListFacility in src/Redux/api.tsx

Co-authored-by: Rithvik Nishad <[email protected]>

* resolved imports

---------

Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Rithvik Nishad <[email protected]>
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
4 people authored Dec 6, 2023
1 parent 947978c commit a6ed2bc
Show file tree
Hide file tree
Showing 10 changed files with 344 additions and 475 deletions.
21 changes: 9 additions & 12 deletions src/Components/Common/SkillSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { getAllSkills, getUserListSkills } from "../../Redux/actions";
import { getAllSkills } from "../../Redux/actions";
import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { SkillObjectModel } from "../Users/models";
import { SkillModel, SkillObjectModel } from "../Users/models";

interface SkillSelectProps {
id?: string;
Expand All @@ -17,6 +17,7 @@ interface SkillSelectProps {
selected: SkillObjectModel | SkillObjectModel[] | null;
setSelected: (selected: SkillObjectModel) => void;
username?: string;
userSkills?: SkillModel[];
}

export const SkillSelect = (props: SkillSelectProps) => {
Expand All @@ -32,7 +33,8 @@ export const SkillSelect = (props: SkillSelectProps) => {
disabled = false,
className = "",
errors = "",
username,
//username,
userSkills,
} = props;

const dispatchAction: any = useDispatch();
Expand All @@ -47,21 +49,16 @@ export const SkillSelect = (props: SkillSelectProps) => {
};

const res = await dispatchAction(getAllSkills(params));

const linkedSkills = await dispatchAction(
getUserListSkills({ username: username })
);

const skillsList = linkedSkills?.data?.results;
const skillsID: string[] = [];
skillsList.map((skill: any) => skillsID.push(skill.skill_object.id));
userSkills?.map((skill: SkillModel) =>
skillsID.push(skill.skill_object.id)
);
const skills = res?.data?.results.filter(
(skill: any) => !skillsID.includes(skill.id)
);

return skills;
},
[dispatchAction, searchAll, showAll]
[dispatchAction, searchAll, userSkills, showAll]
);

return (
Expand Down
1 change: 1 addition & 0 deletions src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RouteToFacility } from "../Common/RouteToFacilitySelect";
import { ConsultationDiagnosis, CreateDiagnosis } from "../Diagnosis/types";

export interface LocalBodyModel {
id: number;
name: string;
body_type: number;
localbody_code: string;
Expand Down
Loading

0 comments on commit a6ed2bc

Please sign in to comment.