From d6304d5b6b770d0f6be277ba6298d68885615022 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Sun, 12 Nov 2023 08:36:42 +0530 Subject: [PATCH 01/26] replaced getUserDetails and getUserListSkills actions with useQuery --- src/Components/Users/UserProfile.tsx | 106 +++++++++++++-------------- src/Components/Users/models.tsx | 6 +- src/Redux/api.tsx | 5 +- 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 441a6862634..dd7fbb817c9 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -1,13 +1,7 @@ -import { useState, useCallback, useReducer, lazy, FormEvent } from "react"; -import { statusType, useAbortableEffect } from "../../Common/utils"; +import { useState, useReducer, lazy, FormEvent, useEffect } from "react"; import { GENDER_TYPES } from "../../Common/constants"; import { useDispatch } from "react-redux"; -import { - getUserDetails, - getUserListSkills, - partialUpdateUser, - updateUserPassword, -} from "../../Redux/actions"; +import { partialUpdateUser, updateUserPassword } from "../../Redux/actions"; import { validateEmailAddress } from "../../Common/validation"; import * as Notification from "../../Utils/Notifications.js"; import LanguageSelector from "../../Components/Common/LanguageSelector"; @@ -23,6 +17,8 @@ import UpdatableApp, { checkForUpdate } from "../Common/UpdatableApp"; import dayjs from "../../Utils/dayjs"; import useAuthUser from "../../Common/hooks/useAuthUser"; import { PhoneNumberValidator } from "../Form/FieldValidators"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const Loading = lazy(() => import("../Common/Loading")); @@ -125,53 +121,55 @@ export default function UserProfile() { const initialDetails: any = [{}]; const [details, setDetails] = useState(initialDetails); - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const res = await dispatchAction(getUserDetails(authUser.username)); - const resSkills = await dispatchAction( - getUserListSkills({ username: authUser.username }) - ); - if (!status.aborted) { - if (res && res.data && resSkills) { - res.data.skills = resSkills.data.results.map( - (skill: SkillModel) => skill.skill_object - ); - setDetails(res.data); - const formData: EditForm = { - firstName: res.data.first_name, - lastName: res.data.last_name, - age: res.data.age, - gender: res.data.gender, - email: res.data.email, - phoneNumber: res.data.phone_number, - altPhoneNumber: res.data.alt_phone_number, - doctor_qualification: res.data.doctor_qualification, - doctor_experience_commenced_on: dayjs().diff( - dayjs(res.data.doctor_experience_commenced_on), - "years" - ), - doctor_medical_council_registration: - res.data.doctor_medical_council_registration, - weekly_working_hours: res.data.weekly_working_hours, - }; - dispatch({ - type: "set_form", - form: formData, - }); - } - setIsLoading(false); - } - }, - [dispatchAction, authUser.username] + const { data: res, loading: isUserLoading } = useQuery( + routes.getUserDetails, + { + pathParams: { username: authUser.username }, + } ); - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [fetchData] + + const { data: resSkills, loading: isSkillsLoading } = useQuery( + routes.userListSkill, + { + pathParams: { username: authUser.username }, + } ); + useEffect(() => { + const fetchData = async () => { + if (!isUserLoading && !isSkillsLoading && res && resSkills) { + setDetails({ + ...res, + skills: resSkills.results.map( + (skill: SkillModel) => skill.skill_object + ), + }); + const formData: EditForm = { + firstName: res.first_name, + lastName: res.last_name, + age: res.age?.toString() || "", + gender: res.gender || "", + email: res.email, + phoneNumber: res.phone_number?.toString() || "", + altPhoneNumber: res.alt_phone_number?.toString() || "", + doctor_qualification: res.doctor_qualification, + doctor_experience_commenced_on: dayjs().diff( + dayjs(res.doctor_experience_commenced_on), + "years" + ), + doctor_medical_council_registration: + res.doctor_medical_council_registration, + weekly_working_hours: res.weekly_working_hours, + }; + dispatch({ + type: "set_form", + form: formData, + }); + } + }; + fetchData(); + }, [isUserLoading, isSkillsLoading, res, resSkills]); + const validateForm = () => { const errors = { ...initError }; let invalidForm = false; @@ -324,7 +322,7 @@ export default function UserProfile() { const res = await dispatchAction( partialUpdateUser(authUser.username, data) ); - if (res && res.data) { + if (res) { Notification.Success({ msg: "Details updated successfully", }); @@ -344,7 +342,7 @@ export default function UserProfile() { } }; - if (isLoading) { + if (isLoading || isUserLoading || isSkillsLoading) { return ; } diff --git a/src/Components/Users/models.tsx b/src/Components/Users/models.tsx index ae3229933c5..e13bae163d3 100644 --- a/src/Components/Users/models.tsx +++ b/src/Components/Users/models.tsx @@ -16,13 +16,15 @@ export type UserBareMinimum = { last_login: string | undefined; }; +export type GenderType = "Male" | "Female" | "Transgender"; + export type UserModel = UserBareMinimum & { local_body?: number; district?: number; state?: number; phone_number?: string; alt_phone_number?: string; - gender?: number; + gender?: GenderType; age?: number; is_superuser?: boolean; verified?: boolean; @@ -33,6 +35,7 @@ export type UserModel = UserBareMinimum & { doctor_qualification?: string; doctor_experience_commenced_on?: string; doctor_medical_council_registration?: string; + weekly_working_hours?: string; }; export interface SkillObjectModel { @@ -60,5 +63,6 @@ export interface UserAssignedModel extends UserBareMinimum { doctor_qualification?: string; doctor_experience_commenced_on?: Date; doctor_medical_council_registration?: string; + weekly_working_hours?: string; skills: SkillObjectModel[]; } diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 1ff80b55304..dcec24aa191 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -43,7 +43,7 @@ import { ILocalBodyByDistrict, IPartialUpdateExternalResult, } from "../Components/ExternalResult/models"; -import { UserModel } from "../Components/Users/models"; +import { SkillModel, UserModel } from "../Components/Users/models"; import { PaginatedResponse } from "../Utils/request/types"; import { NotificationData, @@ -142,6 +142,8 @@ const routes = { userListSkill: { path: "/api/v1/users/{username}/skill/", + method: "GET", + TRes: Type>(), }, userListFacility: { @@ -736,6 +738,7 @@ const routes = { getUserDetails: { path: "/api/v1/users/{username}/", method: "GET", + TRes: Type(), }, updateUserDetails: { path: "/api/v1/users", From 75d1cf8f1584c7be8263c7a467a442cf7ddcb779 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 14 Nov 2023 01:32:55 +0530 Subject: [PATCH 02/26] replaced partialUpdateUser action with request --- src/Components/Users/UserProfile.tsx | 13 +++++++------ src/Redux/api.tsx | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index dd7fbb817c9..62d3b6f90e6 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -1,7 +1,7 @@ import { useState, useReducer, lazy, FormEvent, useEffect } from "react"; import { GENDER_TYPES } from "../../Common/constants"; import { useDispatch } from "react-redux"; -import { partialUpdateUser, updateUserPassword } from "../../Redux/actions"; +import { updateUserPassword } from "../../Redux/actions"; import { validateEmailAddress } from "../../Common/validation"; import * as Notification from "../../Utils/Notifications.js"; import LanguageSelector from "../../Components/Common/LanguageSelector"; @@ -19,6 +19,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser"; import { PhoneNumberValidator } from "../Form/FieldValidators"; import useQuery from "../../Utils/request/useQuery"; import routes from "../../Redux/api"; +import request from "../../Utils/request/request"; const Loading = lazy(() => import("../Common/Loading")); @@ -116,7 +117,6 @@ export default function UserProfile() { const [showEdit, setShowEdit] = useState(false); const [isLoading, setIsLoading] = useState(false); - const dispatchAction: any = useDispatch(); const initialDetails: any = [{}]; const [details, setDetails] = useState(initialDetails); @@ -319,10 +319,11 @@ export default function UserProfile() { : undefined, weekly_working_hours: states.form.weekly_working_hours, }; - const res = await dispatchAction( - partialUpdateUser(authUser.username, data) - ); - if (res) { + const { res } = await request(routes.partialUpdateUser, { + pathParams: { username: authUser.username }, + body: data, + }); + if (res?.status === 200) { Notification.Success({ msg: "Details updated successfully", }); diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index dcec24aa191..9fdb3a2381c 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -189,6 +189,7 @@ const routes = { partialUpdateUser: { path: "/api/v1/users/{username}/", method: "PATCH", + TRes: undefined, }, deleteUser: { From 3477a15c59fb5d9094ed78777769162f844df30c Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 14 Nov 2023 02:09:39 +0530 Subject: [PATCH 03/26] replaced updatePassword action with request --- src/Components/Users/UserProfile.tsx | 42 ++++++++++++++-------------- src/Redux/api.tsx | 3 +- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 62d3b6f90e6..e80df1bc0a2 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -1,7 +1,5 @@ import { useState, useReducer, lazy, FormEvent, useEffect } from "react"; import { GENDER_TYPES } from "../../Common/constants"; -import { useDispatch } from "react-redux"; -import { updateUserPassword } from "../../Redux/actions"; import { validateEmailAddress } from "../../Common/validation"; import * as Notification from "../../Utils/Notifications.js"; import LanguageSelector from "../../Components/Common/LanguageSelector"; @@ -86,7 +84,6 @@ const editFormReducer = (state: State, action: Action) => { }; export default function UserProfile() { const [states, dispatch] = useReducer(editFormReducer, initialState); - const reduxDispatch: any = useDispatch(); const [updateStatus, setUpdateStatus] = useState({ isChecking: false, isUpdateAvailable: false, @@ -366,7 +363,7 @@ export default function UserProfile() { } }; - const changePassword = (e: any) => { + const changePassword = async (e: any) => { e.preventDefault(); //validating form if ( @@ -382,24 +379,27 @@ export default function UserProfile() { username: authUser.username, new_password: changePasswordForm.new_password_1, }; - reduxDispatch(updateUserPassword(form)).then((resp: any) => { - setIsLoading(false); - const res = resp && resp.data; - if (res.message === "Password updated successfully") { - Notification.Success({ - msg: "Password changed!", - }); - } else { - Notification.Error({ - msg: "There was some error. Please try again in some time.", - }); - } - setChangePasswordForm({ - ...changePasswordForm, - new_password_1: "", - new_password_2: "", - old_password: "", + const { res, data } = await request(routes.updatePassword, { + body: form, + }); + setIsLoading(false); + if ( + res?.status == 200 && + data?.message === "Password updated successfully" + ) { + Notification.Success({ + msg: "Password changed!", }); + } else { + Notification.Error({ + msg: "There was some error. Please try again in some time.", + }); + } + setChangePasswordForm({ + ...changePasswordForm, + new_password_1: "", + new_password_2: "", + old_password: "", }); } }; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 9fdb3a2381c..29e5fff3165 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -127,6 +127,7 @@ const routes = { updatePassword: { path: "/api/v1/password_change/", method: "PUT", + TRes: Type<{ [key: string]: string | string[] }>(), }, // User Endpoints currentUser: { @@ -189,7 +190,7 @@ const routes = { partialUpdateUser: { path: "/api/v1/users/{username}/", method: "PATCH", - TRes: undefined, + TRes: Type<{ [key: string]: object }>(), }, deleteUser: { From 7a7ad191a89b515dc0cdb55f811aa1900b0d82a8 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 14 Nov 2023 10:34:09 +0530 Subject: [PATCH 04/26] replaced dispatch with useQuery in UserFilter.tsx --- src/Components/Users/UserFilter.tsx | 24 ++++++++++++------------ src/Redux/api.tsx | 3 +++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 1450e6b6f79..e8a3dbe602b 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -1,6 +1,4 @@ import { useEffect } from "react"; -import { useDispatch } from "react-redux"; -import { getDistrict } from "../../Redux/actions"; import { navigate } from "raviger"; import DistrictSelect from "../Facility/FacilityFilter/DistrictSelect"; import { parsePhoneNumber } from "../../Utils/utils"; @@ -11,6 +9,8 @@ import { USER_TYPE_OPTIONS } from "../../Common/constants"; import useMergeState from "../../Common/hooks/useMergeState"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const parsePhoneNumberForFilterParam = (phoneNumber: string) => { if (!phoneNumber) return ""; @@ -21,7 +21,6 @@ const parsePhoneNumberForFilterParam = (phoneNumber: string) => { export default function UserFilter(props: any) { const { filter, onChange, closeFilter } = props; - const dispatch: any = useDispatch(); const [filterState, setFilterState] = useMergeState({ first_name: filter.first_name || "", last_name: filter.last_name || "", @@ -69,17 +68,18 @@ export default function UserFilter(props: any) { onChange(data); }; + const { data: districtData, refetch } = useQuery(routes.getDistrict, { + prefetch: false, + pathParams: { id: filter.district_id }, + }); + useEffect(() => { - async function fetchData() { - if (filter.district_id) { - const { data: districtData } = await dispatch( - getDistrict(filter.district_id, "district") - ); - setFilterState({ district_ref: districtData }); - } - } + const fetchData = async () => { + await refetch(); + setFilterState({ district_ref: districtData }); + }; fetchData(); - }, [dispatch]); + }, [filter.district_id]); const handleChange = ({ name, value }: any) => setFilterState({ ...filterState, [name]: value }); diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 29e5fff3165..8097c5bdfb2 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -31,6 +31,7 @@ import { import { ConsultationModel, CurrentBed, + DistrictModel, FacilityModel, LocationModel, WardModel, @@ -621,6 +622,8 @@ const routes = { getDistrict: { path: "/api/v1/district/{id}/", + method: "GET", + TRes: Type>(), }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", From d796faab1a42defd01164bac610dfc4fc319711f Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 14 Nov 2023 10:57:01 +0530 Subject: [PATCH 05/26] Bug Fix: UserFilter tried fetching district when district_id was not available --- src/Components/Users/UserFilter.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index e8a3dbe602b..de49941f99f 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -75,8 +75,10 @@ export default function UserFilter(props: any) { useEffect(() => { const fetchData = async () => { - await refetch(); - setFilterState({ district_ref: districtData }); + if (filter.district_id) { + await refetch(); + setFilterState({ district_ref: districtData }); + } }; fetchData(); }, [filter.district_id]); From 46711b3e0ce17290307aa0e8f0b4ac9328187986 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Sun, 19 Nov 2023 06:08:04 +0530 Subject: [PATCH 06/26] addUser and checkUsername action replaced with request --- src/Components/Users/UserAdd.tsx | 21 +++++++++------------ src/Redux/api.tsx | 2 ++ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index a6553bad01b..d31b405694f 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -14,12 +14,10 @@ import { validateUsername, } from "../../Common/validation"; import { - addUser, getDistrictByState, getLocalbodyByDistrict, getStates, getUserListFacility, - checkUsername, } from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; import { FacilitySelect } from "../Common/FacilitySelect"; @@ -45,6 +43,8 @@ import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave"; import dayjs from "../../Utils/dayjs"; import useAuthUser from "../../Common/hooks/useAuthUser"; import { PhoneNumberValidator } from "../Form/FieldValidators"; +import routes from "../../Redux/api"; +import request from "../../Utils/request/request"; const Loading = lazy(() => import("../Common/Loading")); @@ -198,9 +198,9 @@ export const UserAdd = (props: UserProps) => { const check_username = async (username: string) => { setUsernameExists(userExistsEnums.checking); - const usernameCheck = await dispatchAction( - checkUsername({ username: username }) - ); + const { res: usernameCheck } = await request(routes.checkUsername, { + pathParams: { username }, + }); if (usernameCheck === undefined || usernameCheck.status === 409) setUsernameExists(userExistsEnums.exists); else if (usernameCheck.status === 200) @@ -605,13 +605,10 @@ export const UserAdd = (props: UserProps) => { : undefined, }; - const res = await dispatchAction(addUser(data)); - if ( - res && - (res.data || res.data === "") && - res.status >= 200 && - res.status < 300 - ) { + const { res } = await request(routes.addUser, { + body: data, + }); + if (res && res.status >= 200 && res.status < 300) { dispatch({ type: "set_form", form: initForm }); if (!userId) { Notification.Success({ diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 8097c5bdfb2..128f134c11c 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -202,6 +202,7 @@ const routes = { addUser: { path: "/api/v1/users/add_user/", method: "POST", + TRes: Type(), }, searchUser: { @@ -738,6 +739,7 @@ const routes = { checkUsername: { path: "/api/v1/users/{username}/check_availability/", method: "GET", + TRes: undefined, }, getUserDetails: { From 01a21c5b775478de16e02f7074ee713d78ea167b Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Sun, 19 Nov 2023 07:46:21 +0530 Subject: [PATCH 07/26] replaced useDispatch with request in UserAdd component --- src/Components/Users/UserAdd.tsx | 44 ++++++++++++++------------------ src/Redux/api.tsx | 7 +++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index d31b405694f..3e5c376bfb4 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -1,6 +1,5 @@ import { Link, navigate } from "raviger"; import { lazy, useCallback, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; import { GENDER_TYPES, USER_TYPES, @@ -13,12 +12,6 @@ import { validatePassword, validateUsername, } from "../../Common/validation"; -import { - getDistrictByState, - getLocalbodyByDistrict, - getStates, - getUserListFacility, -} from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; import { FacilitySelect } from "../Common/FacilitySelect"; import { FacilityModel } from "../Facility/models"; @@ -163,7 +156,6 @@ export const validateRule = ( export const UserAdd = (props: UserProps) => { const { goBack } = useAppHistory(); - const dispatchAction: any = useDispatch(); const { userId } = props; const [state, dispatch] = useAutoSaveReducer( @@ -258,8 +250,10 @@ export const UserAdd = (props: UserProps) => { async (id: number) => { if (id > 0) { setIsDistrictLoading(true); - const districtList = await dispatchAction(getDistrictByState({ id })); - if (districtList) { + const districtList = await request(routes.getDistrictByState, { + pathParams: { id: id.toString() }, + }); + if (districtList && districtList.data) { if (userIndex <= USER_TYPES.indexOf("DistrictAdmin")) { setDistricts([ { @@ -274,18 +268,18 @@ export const UserAdd = (props: UserProps) => { setIsDistrictLoading(false); } }, - [dispatchAction] + [authUser.district, authUser.district_object?.name, userIndex] ); const fetchLocalBody = useCallback( async (id: number) => { if (id > 0) { setIsLocalbodyLoading(true); - const localBodyList = await dispatchAction( - getLocalbodyByDistrict({ id }) - ); + const localBodyList = await request(routes.getLocalbodyByDistrict, { + pathParams: { id: id.toString() }, + }); setIsLocalbodyLoading(false); - if (localBodyList) { + if (localBodyList && localBodyList.data) { if (userIndex <= USER_TYPES.indexOf("LocalBodyAdmin")) { setLocalBodies([ { @@ -299,14 +293,14 @@ export const UserAdd = (props: UserProps) => { } } }, - [dispatchAction] + [authUser.local_body, authUser.local_body_object?.name, userIndex] ); const fetchStates = useCallback( async (status: statusType) => { setIsStateLoading(true); - const statesRes = await dispatchAction(getStates()); - if (!status.aborted && statesRes.data.results) { + const { data: statesData } = await request(routes.statesList, {}); + if (!status.aborted && statesData && statesData.results) { if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { setStates([ { @@ -315,26 +309,26 @@ export const UserAdd = (props: UserProps) => { }, ]); } else { - setStates(statesRes.data.results); + setStates(statesData.results); } } setIsStateLoading(false); }, - [dispatchAction] + [authUser.state, authUser.state_object?.name, userIndex] ); const fetchFacilities = useCallback( - async (status: any) => { + async (status: statusType) => { setIsStateLoading(true); - const res = await dispatchAction( - getUserListFacility({ username: authUser.username }) - ); + const res = await request(routes.userListFacility, { + pathParams: { username: authUser.username }, + }); if (!status.aborted && res && res.data) { setFacilities(res.data); } setIsStateLoading(false); }, - [dispatchAction, authUser.username] + [authUser.username] ); useAbortableEffect( diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 128f134c11c..168f4e05dd3 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -34,6 +34,7 @@ import { DistrictModel, FacilityModel, LocationModel, + StateModel, WardModel, } from "../Components/Facility/models"; import { @@ -150,6 +151,8 @@ const routes = { userListFacility: { path: "/api/v1/users/{username}/get_facilities/", + method: "GET", + TRes: Type(), }, addUserFacility: { @@ -613,6 +616,8 @@ const routes = { // States statesList: { path: "/api/v1/state/", + method: "GET", + TRes: Type>(), }, getState: { @@ -628,6 +633,8 @@ const routes = { }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", + method: "GET", + TRes: Type(), }, getDistrictByName: { path: "/api/v1/district/", From 98fcdbf6837077d7dfdc32a9e58476728815cd22 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Mon, 20 Nov 2023 10:32:29 +0530 Subject: [PATCH 08/26] replaced useDispatch with useQuery and request in SkillsSlideOver --- src/Components/Users/SkillsSlideOver.tsx | 51 ++++++++++++------------ src/Redux/api.tsx | 3 ++ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/Components/Users/SkillsSlideOver.tsx b/src/Components/Users/SkillsSlideOver.tsx index 833313d780a..eb5ccff21ab 100644 --- a/src/Components/Users/SkillsSlideOver.tsx +++ b/src/Components/Users/SkillsSlideOver.tsx @@ -2,20 +2,17 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import SlideOverCustom from "../../CAREUI/interactive/SlideOver"; import { SkillModel, SkillObjectModel } from "../Users/models"; import { SkillSelect } from "../Common/SkillSelect"; -import { - addUserSkill, - getUserListSkills, - deleteUserSkill, -} from "../../Redux/actions"; import UnlinkSkillDialog from "./UnlinkSkillDialog"; import * as Notification from "../../Utils/Notifications.js"; -import { useDispatch } from "react-redux"; import ButtonV2 from "../Common/components/ButtonV2"; import AuthorizeFor from "../../Utils/AuthorizeFor"; import { useIsAuthorized } from "../../Common/hooks/useIsAuthorized"; import { AddSkillsPlaceholder, SkillsArray } from "./SkillsSlideOverComponents"; import { useTranslation } from "react-i18next"; import CircularProgress from "../Common/components/CircularProgress"; +import useQuery from "../../Utils/request/useQuery"; +import request from "../../Utils/request/request"; +import routes from "../../Redux/api"; interface IProps { username: string; @@ -32,25 +29,23 @@ export default ({ show, setShow, username }: IProps) => { ); const [isLoading, setIsLoading] = useState(false); const [deleteSkill, setDeleteSkill] = useState(null); - const dispatch: any = useDispatch(); - const fetchSkills = useCallback( - async (username: string) => { - setIsLoading(true); - const res = await dispatch(getUserListSkills({ username })); - if (res && res.data) { - setSkills(res.data.results); - } - setIsLoading(false); - }, - [dispatch] - ); + const { + data: userSkills, + loading: userSkillsLoading, + refetch: refetchUserSkills, + } = useQuery(routes.userListSkill, { + pathParams: { username }, + }); const addSkill = useCallback( async (username: string, skill: SkillObjectModel | null) => { if (!skill) return; setIsLoading(true); - const res = await dispatch(addUserSkill(username, skill.id)); + const { res } = await request(routes.addUserSkill, { + pathParams: { username }, + body: { skill: skill.id }, + }); if (res?.status !== 201) { Notification.Error({ msg: "Error while adding skill", @@ -62,30 +57,34 @@ export default ({ show, setShow, username }: IProps) => { } setSelectedSkill(null); setIsLoading(false); - fetchSkills(username); + await refetchUserSkills(); }, - [dispatch, fetchSkills] + [refetchUserSkills] ); const removeSkill = useCallback( async (username: string, skillId: string) => { - const res = await dispatch(deleteUserSkill(username, skillId)); + const { res } = await request(routes.deleteUserSkill, { + pathParams: { username, id: skillId }, + }); if (res?.status !== 204) { Notification.Error({ msg: "Error while unlinking skill", }); } setDeleteSkill(null); - fetchSkills(username); + await refetchUserSkills(); }, - [dispatch, fetchSkills] + [refetchUserSkills] ); useEffect(() => { setIsLoading(true); - if (username) fetchSkills(username); + if (userSkills && !userSkillsLoading) { + setSkills(userSkills.results); + } setIsLoading(false); - }, [username, fetchSkills]); + }, [userSkills, userSkillsLoading]); const authorizeForAddSkill = useIsAuthorized( AuthorizeFor(["DistrictAdmin", "StateAdmin"]) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 168f4e05dd3..a0b86666946 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -163,6 +163,8 @@ const routes = { addUserSkill: { path: "/api/v1/users/{username}/skill/", method: "POST", + TBody: Type<{ skill: string }>(), + TRes: Type(), }, deleteUserFacility: { @@ -178,6 +180,7 @@ const routes = { deleteUserSkill: { path: "/api/v1/users/{username}/skill/{id}/", method: "DELETE", + TRes: undefined, }, createUser: { From cfed5c9a1e68f56e1436ca0a4ba90cc048b156d9 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 21 Nov 2023 12:47:12 +0530 Subject: [PATCH 09/26] replaced useDispatch with useQuery and request in ManageUsers --- src/Components/Users/ManageUsers.tsx | 197 +++++++++++++-------------- src/Redux/api.tsx | 10 +- 2 files changed, 100 insertions(+), 107 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 94791e55ae1..ba61526165f 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -1,17 +1,5 @@ import * as Notification from "../../Utils/Notifications.js"; -import { - addUserFacility, - clearHomeFacility, - deleteUser, - deleteUserFacility, - getDistrict, - getUserList, - getUserListFacility, - partialUpdateUser, -} from "../../Redux/actions"; -import { statusType, useAbortableEffect } from "../../Common/utils"; import { lazy, useCallback, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; import ButtonV2, { Submit } from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; @@ -36,6 +24,9 @@ import Page from "../Common/components/Page.js"; import dayjs from "dayjs"; import TextFormField from "../Form/FormFields/TextFormField.js"; import useAuthUser from "../../Common/hooks/useAuthUser.js"; +import routes from "../../Redux/api.js"; +import useQuery from "../../Utils/request/useQuery.js"; +import request from "../../Utils/request/request.js"; const Loading = lazy(() => import("../Common/Loading")); @@ -49,7 +40,6 @@ export default function ManageUsers() { advancedFilter, resultsPerPage, } = useFilters({ limit: 18 }); - const dispatch: any = useDispatch(); const initialData: any[] = []; let manageUsers: any = null; const [users, setUsers] = useState(initialData); @@ -79,59 +69,50 @@ export default function ManageUsers() { const isExtremeSmallScreen = width <= extremeSmallScreenBreakpoint ? true : false; - const fetchData = useCallback( - async (status: statusType) => { - setIsLoading(true); - const params = { - limit: resultsPerPage, - offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, - username: qParams.username, - first_name: qParams.first_name, - last_name: qParams.last_name, - phone_number: qParams.phone_number, - alt_phone_number: qParams.alt_phone_number, - user_type: qParams.user_type, - district_id: qParams.district_id, - }; - if (qParams.district_id) { - const dis = await dispatch(getDistrict(qParams.district_id)); - if (!status.aborted) { - if (dis && dis.data) { - setDistrictName(dis.data.name); - } - } - } else { - setDistrictName(undefined); - } - const res = await dispatch(getUserList(params)); - if (!status.aborted) { - if (res && res.data) { - setUsers(res.data.results); - setTotalCount(res.data.count); - } - setIsLoading(false); - } + const { + data: userListData, + loading: userListLoading, + refetch: refetchUserList, + } = useQuery(routes.userList, { + query: { + limit: resultsPerPage.toString(), + offset: ( + (qParams.page ? qParams.page - 1 : 0) * resultsPerPage + ).toString(), + username: qParams.username, + first_name: qParams.first_name, + last_name: qParams.last_name, + phone_number: qParams.phone_number, + alt_phone_number: qParams.alt_phone_number, + user_type: qParams.user_type, + district_id: qParams.district_id, }, - [ - resultsPerPage, - qParams.page, - qParams.username, - qParams.first_name, - qParams.last_name, - qParams.phone_number, - qParams.alt_phone_number, - qParams.user_type, - qParams.district_id, - dispatch, - ] - ); + }); - useAbortableEffect( - (status: statusType) => { - fetchData(status); - }, - [fetchData] - ); + const fetchDistrict = useCallback(async () => { + setIsLoading(true); + if (qParams.district_id) { + const { data: districtData } = await request(routes.getDistrict, { + pathParams: { id: qParams.district_id }, + }); + if (districtData) setDistrictName(districtData.name); + else setDistrictName(undefined); + } + setIsLoading(false); + }, [qParams.district_id]); + + useEffect(() => { + setIsLoading(true); + if (userListData && !userListLoading) { + setUsers(userListData.results); + setTotalCount(userListData.count); + } + setIsLoading(false); + }, [userListData, userListLoading]); + + useEffect(() => { + fetchDistrict(); + }, [fetchDistrict]); const addUser = ( { const username = userData.username; - const res = await dispatch(deleteUser(username)); + const { res, data } = await request(routes.deleteUser, { + body: { username }, + }); if (res?.status === 204) { Notification.Success({ msg: "User deleted successfully", }); } else { Notification.Error({ - msg: "Error while deleting User: " + (res?.data?.detail || ""), + msg: "Error while deleting User: " + (data?.detail || ""), }); } setUserData({ show: false, username: "", name: "" }); - fetchData({ aborted: false }); + await fetchDistrict(); + await refetchUserList(); }; const handleDelete = (user: any) => { @@ -463,7 +446,7 @@ export default function ManageUsers() { ); })); - if (isLoading || !users) { + if (isLoading || userListLoading || !users) { manageUsers = ; } else if (users?.length) { manageUsers = ( @@ -540,7 +523,7 @@ export default function ManageUsers() { @@ -596,7 +579,6 @@ export default function ManageUsers() { function UserFacilities(props: { user: any }) { const { user } = props; const username = user.username; - const dispatch: any = useDispatch(); const [facilities, setFacilities] = useState([]); const [isLoading, setIsLoading] = useState(false); const [facility, setFacility] = useState(null); @@ -635,61 +617,64 @@ function UserFacilities(props: { user: any }) { }); }; - const fetchFacilities = async () => { - setIsLoading(true); - const res = await dispatch(getUserListFacility({ username })); - if (res && res.data) { - setFacilities(res.data); - } - setIsLoading(false); - }; + const { + data: userFacilities, + loading: userFacilitiesLoading, + refetch: refetchUserFacilities, + } = useQuery(routes.userListFacility, { + pathParams: { username }, + }); const updateHomeFacility = async (username: string, facility: any) => { setIsLoading(true); - const res = await dispatch( - partialUpdateUser(username, { home_facility: facility.id }) - ); + const { res } = await request(routes.partialUpdateUser, { + pathParams: { username }, + body: { home_facility: facility.id.toString() }, + }); if (res && res.status === 200) user.home_facility_object = facility; - fetchFacilities(); + await refetchUserFacilities(); setIsLoading(false); }; const handleUnlinkFacilitySubmit = async () => { setIsLoading(true); if (unlinkFacilityData.isHomeFacility) { - const res = await dispatch( - clearHomeFacility(unlinkFacilityData.userName) - ); + const { res } = await request(routes.clearHomeFacility, { + pathParams: { username }, + }); if (res && res.status === 204) user.home_facility_object = null; } else { - await dispatch( - deleteUserFacility( - unlinkFacilityData.userName, - String(unlinkFacilityData?.facility?.id) - ) - ); + await request(routes.deleteUserFacility, { + pathParams: { username }, + body: { facility: unlinkFacilityData?.facility?.id?.toString() }, + }); } - fetchFacilities(); + await refetchUserFacilities(); setIsLoading(false); hideUnlinkFacilityModal(); }; const addFacility = async (username: string, facility: any) => { setIsLoading(true); - const res = await dispatch(addUserFacility(username, String(facility.id))); + const { res } = await request(routes.addUserFacility, { + pathParams: { username }, + body: { facility: facility.id.toString() }, + }); if (res?.status !== 201) { Notification.Error({ msg: "Error while linking facility", }); } + await refetchUserFacilities(); setIsLoading(false); setFacility(null); - fetchFacilities(); }; useEffect(() => { - fetchFacilities(); - }, []); + if (userFacilities && !userFacilitiesLoading) { + setFacilities(userFacilities); + } + }, [userFacilities, userFacilitiesLoading]); return (
@@ -723,7 +708,7 @@ function UserFacilities(props: { user: any }) { Add
- {isLoading ? ( + {isLoading || userFacilitiesLoading ? (
diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index a0b86666946..ff9fbf01426 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -158,6 +158,8 @@ const routes = { addUserFacility: { path: "/api/v1/users/{username}/add_facility/", method: "PUT", + TBody: Type<{ facility: string }>(), + TRes: undefined, }, addUserSkill: { @@ -170,11 +172,14 @@ const routes = { deleteUserFacility: { path: "/api/v1/users/{username}/delete_facility/", method: "DELETE", + TBody: Type<{ facility: string }>(), + TRes: undefined, }, clearHomeFacility: { path: "/api/v1/users/{username}/clear_home_facility/", method: "DELETE", + TRes: undefined, }, deleteUserSkill: { @@ -198,11 +203,14 @@ const routes = { path: "/api/v1/users/{username}/", method: "PATCH", TRes: Type<{ [key: string]: object }>(), + TBody: Type<{ [key: string]: string | object | undefined }>(), }, deleteUser: { path: "/api/v1/users", method: "DELETE", + TRes: Type<{ [key: string]: object }>(), + TBody: Type<{ username: string }>(), }, addUser: { @@ -632,7 +640,7 @@ const routes = { getDistrict: { path: "/api/v1/district/{id}/", method: "GET", - TRes: Type>(), + TRes: Type(), }, getDistrictByState: { path: "/api/v1/state/{id}/districts/", From 693b0d6bba4efedef726a2b773c55c7764aae8b1 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 21 Nov 2023 14:33:17 +0530 Subject: [PATCH 10/26] solved issue #6652 | passed user skills as props to SkillSelect --- src/Components/Common/SkillSelect.tsx | 24 ++++++++++++------------ src/Components/Users/SkillsSlideOver.tsx | 1 + src/Redux/api.tsx | 8 +++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Components/Common/SkillSelect.tsx b/src/Components/Common/SkillSelect.tsx index 3257971d03c..7e02e087ed9 100644 --- a/src/Components/Common/SkillSelect.tsx +++ b/src/Components/Common/SkillSelect.tsx @@ -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; @@ -17,6 +17,7 @@ interface SkillSelectProps { selected: SkillObjectModel | SkillObjectModel[] | null; setSelected: (selected: SkillObjectModel) => void; username?: string; + userSkills?: SkillModel[]; } export const SkillSelect = (props: SkillSelectProps) => { @@ -32,7 +33,8 @@ export const SkillSelect = (props: SkillSelectProps) => { disabled = false, className = "", errors = "", - username, + //username, + userSkills, } = props; const dispatchAction: any = useDispatch(); @@ -47,21 +49,19 @@ export const SkillSelect = (props: SkillSelectProps) => { }; const res = await dispatchAction(getAllSkills(params)); - - const linkedSkills = await dispatchAction( - getUserListSkills({ username: username }) - ); - - const skillsList = linkedSkills?.data?.results; + console.log(userSkills); const skillsID: string[] = []; - skillsList.map((skill: any) => skillsID.push(skill.skill_object.id)); + userSkills?.map((skill: SkillModel) => + skillsID.push(skill.skill_object.id) + ); + console.log(skillsID); const skills = res?.data?.results.filter( (skill: any) => !skillsID.includes(skill.id) ); - + console.log(skills); return skills; }, - [dispatchAction, searchAll, showAll] + [dispatchAction, searchAll, userSkills, showAll] ); return ( diff --git a/src/Components/Users/SkillsSlideOver.tsx b/src/Components/Users/SkillsSlideOver.tsx index eb5ccff21ab..0afdf7d9e37 100644 --- a/src/Components/Users/SkillsSlideOver.tsx +++ b/src/Components/Users/SkillsSlideOver.tsx @@ -126,6 +126,7 @@ export default ({ show, setShow, username }: IProps) => { setSelected={setSelectedSkill} errors="" username={username} + userSkills={skills} /> >(), }, // Facility Endpoints From ae1f31b927750bae9f2294f16fe54ecad909c673 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 21 Nov 2023 14:36:21 +0530 Subject: [PATCH 11/26] removed unnecessary console logs --- src/Components/Common/SkillSelect.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Components/Common/SkillSelect.tsx b/src/Components/Common/SkillSelect.tsx index 7e02e087ed9..c7c7f37d46f 100644 --- a/src/Components/Common/SkillSelect.tsx +++ b/src/Components/Common/SkillSelect.tsx @@ -28,7 +28,6 @@ export const SkillSelect = (props: SkillSelectProps) => { selected, setSelected, searchAll, - showAll = true, showNOptions = 10, disabled = false, className = "", @@ -49,19 +48,16 @@ export const SkillSelect = (props: SkillSelectProps) => { }; const res = await dispatchAction(getAllSkills(params)); - console.log(userSkills); const skillsID: string[] = []; userSkills?.map((skill: SkillModel) => skillsID.push(skill.skill_object.id) ); - console.log(skillsID); const skills = res?.data?.results.filter( (skill: any) => !skillsID.includes(skill.id) ); - console.log(skills); return skills; }, - [dispatchAction, searchAll, userSkills, showAll] + [dispatchAction, searchAll, userSkills] ); return ( From 50522a1d7dab353df31ffa8d98ee050145f7aa2c Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 21 Nov 2023 14:39:59 +0530 Subject: [PATCH 12/26] re-added showAll as dependency to skillSearch --- src/Components/Common/SkillSelect.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Components/Common/SkillSelect.tsx b/src/Components/Common/SkillSelect.tsx index c7c7f37d46f..7e02e087ed9 100644 --- a/src/Components/Common/SkillSelect.tsx +++ b/src/Components/Common/SkillSelect.tsx @@ -28,6 +28,7 @@ export const SkillSelect = (props: SkillSelectProps) => { selected, setSelected, searchAll, + showAll = true, showNOptions = 10, disabled = false, className = "", @@ -48,16 +49,19 @@ export const SkillSelect = (props: SkillSelectProps) => { }; const res = await dispatchAction(getAllSkills(params)); + console.log(userSkills); const skillsID: string[] = []; userSkills?.map((skill: SkillModel) => skillsID.push(skill.skill_object.id) ); + console.log(skillsID); const skills = res?.data?.results.filter( (skill: any) => !skillsID.includes(skill.id) ); + console.log(skills); return skills; }, - [dispatchAction, searchAll, userSkills] + [dispatchAction, searchAll, userSkills, showAll] ); return ( From 56e32e765ca0534072b73432812e54eccd6b238e Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Tue, 21 Nov 2023 14:43:23 +0530 Subject: [PATCH 13/26] removed unnecessary console logs --- src/Components/Common/SkillSelect.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Components/Common/SkillSelect.tsx b/src/Components/Common/SkillSelect.tsx index 7e02e087ed9..941c29790d1 100644 --- a/src/Components/Common/SkillSelect.tsx +++ b/src/Components/Common/SkillSelect.tsx @@ -49,16 +49,13 @@ export const SkillSelect = (props: SkillSelectProps) => { }; const res = await dispatchAction(getAllSkills(params)); - console.log(userSkills); const skillsID: string[] = []; userSkills?.map((skill: SkillModel) => skillsID.push(skill.skill_object.id) ); - console.log(skillsID); const skills = res?.data?.results.filter( (skill: any) => !skillsID.includes(skill.id) ); - console.log(skills); return skills; }, [dispatchAction, searchAll, userSkills, showAll] From fc3dd26669789e28e01c2ae923718a858602c1d8 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Wed, 22 Nov 2023 16:29:08 +0530 Subject: [PATCH 14/26] replaced fetchDistrict request with useQuery and removed isLoading --- src/Components/Users/ManageUsers.tsx | 66 ++++++++++++---------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index ba61526165f..62efa4a6435 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -1,5 +1,5 @@ import * as Notification from "../../Utils/Notifications.js"; -import { lazy, useCallback, useEffect, useState } from "react"; +import { lazy, useEffect, useState } from "react"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; import ButtonV2, { Submit } from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; @@ -40,13 +40,8 @@ export default function ManageUsers() { advancedFilter, resultsPerPage, } = useFilters({ limit: 18 }); - const initialData: any[] = []; let manageUsers: any = null; - const [users, setUsers] = useState(initialData); - const [isLoading, setIsLoading] = useState(false); const [expandSkillList, setExpandSkillList] = useState(false); - const [totalCount, setTotalCount] = useState(0); - const [districtName, setDistrictName] = useState(); const [expandFacilityList, setExpandFacilityList] = useState(false); const [selectedUser, setSelectedUser] = useState(null); const [expandWorkingHours, setExpandWorkingHours] = useState(false); @@ -89,30 +84,21 @@ export default function ManageUsers() { }, }); - const fetchDistrict = useCallback(async () => { - setIsLoading(true); - if (qParams.district_id) { - const { data: districtData } = await request(routes.getDistrict, { - pathParams: { id: qParams.district_id }, - }); - if (districtData) setDistrictName(districtData.name); - else setDistrictName(undefined); - } - setIsLoading(false); - }, [qParams.district_id]); + const { + data: districtData, + loading: districtDataLoading, + refetch: refetchDistrictData, + } = useQuery(routes.getDistrict, { + prefetch: false, + pathParams: { id: qParams.district_id }, + }); useEffect(() => { - setIsLoading(true); - if (userListData && !userListLoading) { - setUsers(userListData.results); - setTotalCount(userListData.count); + if (qParams.district_id) { + console.log("refetching district data"); + refetchDistrictData(); } - setIsLoading(false); - }, [userListData, userListLoading]); - - useEffect(() => { - fetchDistrict(); - }, [fetchDistrict]); + }, [qParams.district_id, refetchDistrictData]); const addUser = ( { + userListData?.results && + userListData.results.length && + (userList = userListData.results.map((user: any, idx) => { const cur_online = isUserOnline(user); return (
; - } else if (users?.length) { + } else if (userListData?.results.length) { manageUsers = (
{userList}
- +
); - } else if (users && users.length === 0) { + } else if (userListData?.results && userListData?.results.length === 0) { manageUsers = (
No Users Found
@@ -522,8 +506,8 @@ export default function ManageUsers() {
@@ -557,7 +541,11 @@ export default function ManageUsers() { phoneNumber(), phoneNumber("WhatsApp no.", "alt_phone_number"), badge("Role", "user_type"), - value("District", "district_id", districtName || ""), + value( + "District", + "district_id", + qParams.district_id ? districtData?.name || "" : "" + ), ]} />
From 7151dc2126e9ecc71f52dff0529e7beeedad5061 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Wed, 22 Nov 2023 16:49:43 +0530 Subject: [PATCH 15/26] fixed error notification in ManageUsers --- src/Components/Users/ManageUsers.tsx | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 62efa4a6435..90b48e4951f 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -84,21 +84,13 @@ export default function ManageUsers() { }, }); - const { - data: districtData, - loading: districtDataLoading, - refetch: refetchDistrictData, - } = useQuery(routes.getDistrict, { - prefetch: false, - pathParams: { id: qParams.district_id }, - }); - - useEffect(() => { - if (qParams.district_id) { - console.log("refetching district data"); - refetchDistrictData(); + const { data: districtData, loading: districtDataLoading } = useQuery( + routes.getDistrict, + { + prefetch: !!qParams.district_id, + pathParams: { id: qParams.district_id }, } - }, [qParams.district_id, refetchDistrictData]); + ); const addUser = ( { const username = userData.username; - const { res, data } = await request(routes.deleteUser, { + const { res, error } = await request(routes.deleteUser, { body: { username }, }); if (res?.status === 204) { @@ -152,7 +144,7 @@ export default function ManageUsers() { }); } else { Notification.Error({ - msg: "Error while deleting User: " + (data?.detail || ""), + msg: "Error while deleting User: " + (error || ""), }); } From 0af88d44bfa3e2f6273171d1569fc71d93c4af1c Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Wed, 22 Nov 2023 17:22:13 +0530 Subject: [PATCH 16/26] removed unnecessary useState from ManageUsers --- src/Components/Users/ManageUsers.tsx | 42 ++++++++++++---------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 90b48e4951f..eda270fc23e 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -1,5 +1,5 @@ import * as Notification from "../../Utils/Notifications.js"; -import { lazy, useEffect, useState } from "react"; +import { lazy, useState } from "react"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; import ButtonV2, { Submit } from "../Common/components/ButtonV2"; import CareIcon from "../../CAREUI/icons/CareIcon"; @@ -559,7 +559,6 @@ export default function ManageUsers() { function UserFacilities(props: { user: any }) { const { user } = props; const username = user.username; - const [facilities, setFacilities] = useState([]); const [isLoading, setIsLoading] = useState(false); const [facility, setFacility] = useState(null); const [unlinkFacilityData, setUnlinkFacilityData] = useState<{ @@ -630,8 +629,8 @@ function UserFacilities(props: { user: any }) { }); } await refetchUserFacilities(); - setIsLoading(false); hideUnlinkFacilityModal(); + setIsLoading(false); }; const addFacility = async (username: string, facility: any) => { @@ -650,12 +649,6 @@ function UserFacilities(props: { user: any }) { setFacility(null); }; - useEffect(() => { - if (userFacilities && !userFacilitiesLoading) { - setFacilities(userFacilities); - } - }, [userFacilities, userFacilitiesLoading]); - return (
{unlinkFacilityData.show && ( @@ -726,13 +719,13 @@ function UserFacilities(props: { user: any }) { )} {/* Linked Facilities section */} - {facilities.length > 0 && ( + {userFacilities && userFacilities.length > 0 && (
Linked Facilities
- {facilities.map((facility: any, i: number) => { + {userFacilities.map((facility: any, i: number) => { if (user?.home_facility_object?.id === facility.id) { // skip if it's a home facility return null; @@ -796,20 +789,21 @@ function UserFacilities(props: { user: any }) {
)} - {!user?.home_facility_object && facilities.length === 0 && ( -
-
- No linked facilities + {!user?.home_facility_object && + (userFacilities ? userFacilities.length === 0 : 0) && ( +
+
+ No linked facilities +
+

+ No Linked Facilities +

-

- No Linked Facilities -

-
- )} + )}
)} {replaceHomeFacility.show && ( From 884e1349b52e7c519cf37f03f0915d898fce9285 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Wed, 22 Nov 2023 20:23:30 +0530 Subject: [PATCH 17/26] code fixes in SkillsSlideOver --- src/Components/Users/SkillsSlideOver.tsx | 29 ++++++++---------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Components/Users/SkillsSlideOver.tsx b/src/Components/Users/SkillsSlideOver.tsx index 0afdf7d9e37..71328d40b9e 100644 --- a/src/Components/Users/SkillsSlideOver.tsx +++ b/src/Components/Users/SkillsSlideOver.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useMemo, useState } from "react"; import SlideOverCustom from "../../CAREUI/interactive/SlideOver"; import { SkillModel, SkillObjectModel } from "../Users/models"; import { SkillSelect } from "../Common/SkillSelect"; @@ -23,7 +23,6 @@ interface IProps { export default ({ show, setShow, username }: IProps) => { /* added const {t} hook here and relevant text to Common.json to avoid eslint error */ const { t } = useTranslation(); - const [skills, setSkills] = useState([]); const [selectedSkill, setSelectedSkill] = useState( null ); @@ -31,8 +30,8 @@ export default ({ show, setShow, username }: IProps) => { const [deleteSkill, setDeleteSkill] = useState(null); const { - data: userSkills, - loading: userSkillsLoading, + data: skills, + loading: skillsLoading, refetch: refetchUserSkills, } = useQuery(routes.userListSkill, { pathParams: { username }, @@ -46,7 +45,7 @@ export default ({ show, setShow, username }: IProps) => { pathParams: { username }, body: { skill: skill.id }, }); - if (res?.status !== 201) { + if (!res?.ok) { Notification.Error({ msg: "Error while adding skill", }); @@ -78,19 +77,11 @@ export default ({ show, setShow, username }: IProps) => { [refetchUserSkills] ); - useEffect(() => { - setIsLoading(true); - if (userSkills && !userSkillsLoading) { - setSkills(userSkills.results); - } - setIsLoading(false); - }, [userSkills, userSkillsLoading]); - const authorizeForAddSkill = useIsAuthorized( AuthorizeFor(["DistrictAdmin", "StateAdmin"]) ); - const hasSkills = useMemo(() => skills.length > 0, [skills]); + const hasSkills = useMemo(() => skills?.results?.length || 0 > 0, [skills]); return (
@@ -113,7 +104,7 @@ export default ({ show, setShow, username }: IProps) => { >
- {!isLoading && ( + {(!isLoading || !skillsLoading) && (
{ setSelected={setSelectedSkill} errors="" username={username} - userSkills={skills} + userSkills={skills?.results || []} /> { )}
)} - {isLoading ? ( + {isLoading || skillsLoading ? (
@@ -151,8 +142,8 @@ export default ({ show, setShow, username }: IProps) => {
{hasSkills ? ( From 3e92f4f369308d90b9336431c5948e508fb4a10b Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Wed, 22 Nov 2023 23:44:11 +0530 Subject: [PATCH 18/26] code fixes in UserAdd --- src/Components/Users/UserAdd.tsx | 146 +++++++++++-------------------- 1 file changed, 50 insertions(+), 96 deletions(-) diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 3e5c376bfb4..95aacfa3e7f 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -1,11 +1,11 @@ import { Link, navigate } from "raviger"; -import { lazy, useCallback, useEffect, useState } from "react"; +import { lazy, useEffect, useState } from "react"; import { GENDER_TYPES, USER_TYPES, USER_TYPE_OPTIONS, } from "../../Common/constants"; -import { statusType, useAbortableEffect } from "../../Common/utils"; +import { useAbortableEffect } from "../../Common/utils"; import { validateEmailAddress, validateName, @@ -38,6 +38,7 @@ import useAuthUser from "../../Common/hooks/useAuthUser"; import { PhoneNumberValidator } from "../Form/FieldValidators"; import routes from "../../Redux/api"; import request from "../../Utils/request/request"; +import useQuery from "../../Utils/request/useQuery"; const Loading = lazy(() => import("../Common/Loading")); @@ -163,13 +164,9 @@ export const UserAdd = (props: UserProps) => { initialState ); const [isLoading, setIsLoading] = useState(false); - const [isStateLoading, setIsStateLoading] = useState(false); - const [isDistrictLoading, setIsDistrictLoading] = useState(false); - const [isLocalbodyLoading, setIsLocalbodyLoading] = useState(false); - const [_current_user_facilities, setFacilities] = useState< - Array - >([]); const [states, setStates] = useState([]); + const [selectedStateId, setSelectedStateId] = useState(0); + const [selectedDistrictId, setSelectedDistrictId] = useState(0); const [districts, setDistricts] = useState([]); const [localBodies, setLocalBodies] = useState([]); const [selectedFacility, setSelectedFacility] = useState([]); @@ -246,103 +243,60 @@ export const UserAdd = (props: UserProps) => { state.form.user_type === "StaffReadOnly" ); - const fetchDistricts = useCallback( - async (id: number) => { - if (id > 0) { - setIsDistrictLoading(true); - const districtList = await request(routes.getDistrictByState, { - pathParams: { id: id.toString() }, - }); - if (districtList && districtList.data) { - if (userIndex <= USER_TYPES.indexOf("DistrictAdmin")) { - setDistricts([ - { - id: authUser.district!, - name: authUser.district_object?.name as string, - }, - ]); - } else { - setDistricts(districtList.data); - } - } - setIsDistrictLoading(false); - } - }, - [authUser.district, authUser.district_object?.name, userIndex] - ); - - const fetchLocalBody = useCallback( - async (id: number) => { - if (id > 0) { - setIsLocalbodyLoading(true); - const localBodyList = await request(routes.getLocalbodyByDistrict, { - pathParams: { id: id.toString() }, - }); - setIsLocalbodyLoading(false); - if (localBodyList && localBodyList.data) { - if (userIndex <= USER_TYPES.indexOf("LocalBodyAdmin")) { - setLocalBodies([ - { - id: authUser.local_body!, - name: authUser.local_body_object?.name as string, - }, - ]); - } else { - setLocalBodies(localBodyList.data); - } - } + const { loading: isDistrictLoading } = useQuery(routes.getDistrictByState, { + prefetch: !!(selectedStateId > 0), + pathParams: { id: selectedStateId.toString() }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + if (userIndex <= USER_TYPES.indexOf("DistrictAdmin")) { + setDistricts([ + { + id: authUser.district!, + name: authUser.district_object?.name as string, + }, + ]); + } else { + setDistricts(result.data); } }, - [authUser.local_body, authUser.local_body_object?.name, userIndex] - ); - - const fetchStates = useCallback( - async (status: statusType) => { - setIsStateLoading(true); - const { data: statesData } = await request(routes.statesList, {}); - if (!status.aborted && statesData && statesData.results) { - if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { - setStates([ + }); + + const { loading: isLocalbodyLoading } = useQuery( + routes.getAllLocalBodyByDistrict, + { + prefetch: !!(selectedDistrictId > 0), + pathParams: { id: selectedDistrictId.toString() }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + if (userIndex <= USER_TYPES.indexOf("LocalBodyAdmin")) { + setLocalBodies([ { - id: authUser.state!, - name: authUser.state_object?.name as string, + id: authUser.local_body!, + name: authUser.local_body_object?.name as string, }, ]); } else { - setStates(statesData.results); + setLocalBodies(result.data); } - } - setIsStateLoading(false); - }, - [authUser.state, authUser.state_object?.name, userIndex] - ); - - const fetchFacilities = useCallback( - async (status: statusType) => { - setIsStateLoading(true); - const res = await request(routes.userListFacility, { - pathParams: { username: authUser.username }, - }); - if (!status.aborted && res && res.data) { - setFacilities(res.data); - } - setIsStateLoading(false); - }, - [authUser.username] + }, + } ); - useAbortableEffect( - (status: statusType) => { - fetchStates(status); - if ( - authUser.user_type === "Staff" || - authUser.user_type === "StaffReadOnly" - ) { - fetchFacilities(status); + const { loading: isStateLoading } = useQuery(routes.statesList, { + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { + setStates([ + { + id: authUser.state!, + name: authUser.state_object?.name as string, + }, + ]); + } else { + setStates(result.data.results); } }, - [dispatch] - ); + }); const handleDateChange = (e: FieldChangeEvent) => { if (dayjs(e.value).isValid()) { @@ -907,7 +861,7 @@ export const UserAdd = (props: UserProps) => { optionValue={(o) => o.id} onChange={(e) => { handleFieldChange(e); - if (e) fetchDistricts(e.value); + if (e) setSelectedStateId(e.value); }} /> )} @@ -925,7 +879,7 @@ export const UserAdd = (props: UserProps) => { optionValue={(o) => o.id} onChange={(e) => { handleFieldChange(e); - if (e) fetchLocalBody(e.value); + if (e) setSelectedDistrictId(e.value); }} /> )} From 94fae55612589acedaa14e5e61bf041e51f6b162 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Thu, 23 Nov 2023 11:35:18 +0530 Subject: [PATCH 19/26] code fix in UserFilter --- src/Components/Users/UserFilter.tsx | 19 ++--- src/Components/Users/UserProfile.tsx | 123 ++++++++++++++------------- 2 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index de49941f99f..83b51e5c47d 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -1,4 +1,3 @@ -import { useEffect } from "react"; import { navigate } from "raviger"; import DistrictSelect from "../Facility/FacilityFilter/DistrictSelect"; import { parsePhoneNumber } from "../../Utils/utils"; @@ -68,21 +67,15 @@ export default function UserFilter(props: any) { onChange(data); }; - const { data: districtData, refetch } = useQuery(routes.getDistrict, { - prefetch: false, + useQuery(routes.getDistrict, { + prefetch: !!filter.district_id, pathParams: { id: filter.district_id }, + onResponse: (result) => { + if (!result || !result.data || !result.res) return; + setFilterState({ district_ref: result.data }); + }, }); - useEffect(() => { - const fetchData = async () => { - if (filter.district_id) { - await refetch(); - setFilterState({ district_ref: districtData }); - } - }; - fetchData(); - }, [filter.district_id]); - const handleChange = ({ name, value }: any) => setFilterState({ ...filterState, [name]: value }); diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index e80df1bc0a2..478103bf78b 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -1,4 +1,4 @@ -import { useState, useReducer, lazy, FormEvent, useEffect } from "react"; +import { useState, useReducer, lazy, FormEvent } from "react"; import { GENDER_TYPES } from "../../Common/constants"; import { validateEmailAddress } from "../../Common/validation"; import * as Notification from "../../Utils/Notifications.js"; @@ -118,54 +118,47 @@ export default function UserProfile() { const initialDetails: any = [{}]; const [details, setDetails] = useState(initialDetails); - const { data: res, loading: isUserLoading } = useQuery( - routes.getUserDetails, - { - pathParams: { username: authUser.username }, - } - ); - - const { data: resSkills, loading: isSkillsLoading } = useQuery( - routes.userListSkill, - { - pathParams: { username: authUser.username }, - } - ); + const { loading: isUserLoading } = useQuery(routes.getUserDetails, { + pathParams: { username: authUser.username }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + setDetails(result.data); + const formData: EditForm = { + firstName: result.data.first_name, + lastName: result.data.last_name, + age: result.data.age?.toString() || "", + gender: result.data.gender || "", + email: result.data.email, + phoneNumber: result.data.phone_number?.toString() || "", + altPhoneNumber: result.data.alt_phone_number?.toString() || "", + doctor_qualification: result.data.doctor_qualification, + doctor_experience_commenced_on: dayjs().diff( + dayjs(result.data.doctor_experience_commenced_on), + "years" + ), + doctor_medical_council_registration: + result.data.doctor_medical_council_registration, + weekly_working_hours: result.data.weekly_working_hours, + }; + dispatch({ + type: "set_form", + form: formData, + }); + }, + }); - useEffect(() => { - const fetchData = async () => { - if (!isUserLoading && !isSkillsLoading && res && resSkills) { - setDetails({ - ...res, - skills: resSkills.results.map( - (skill: SkillModel) => skill.skill_object - ), - }); - const formData: EditForm = { - firstName: res.first_name, - lastName: res.last_name, - age: res.age?.toString() || "", - gender: res.gender || "", - email: res.email, - phoneNumber: res.phone_number?.toString() || "", - altPhoneNumber: res.alt_phone_number?.toString() || "", - doctor_qualification: res.doctor_qualification, - doctor_experience_commenced_on: dayjs().diff( - dayjs(res.doctor_experience_commenced_on), - "years" - ), - doctor_medical_council_registration: - res.doctor_medical_council_registration, - weekly_working_hours: res.weekly_working_hours, - }; - dispatch({ - type: "set_form", - form: formData, - }); - } - }; - fetchData(); - }, [isUserLoading, isSkillsLoading, res, resSkills]); + const { loading: isSkillsLoading } = useQuery(routes.userListSkill, { + pathParams: { username: authUser.username }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + setDetails({ + ...details, + skills: result.data.results.map( + (skill: SkillModel) => skill.skill_object + ), + }); + }, + }); const validateForm = () => { const errors = { ...initError }; @@ -431,7 +424,7 @@ export default function UserProfile() {
- {!showEdit && ( + {!showEdit && !isUserLoading && !isSkillsLoading && (
- {details.username || "-"} + {details.username ? details.username : "-"}
- {details.phone_number || "-"} + {details.phone_number ? details.phone_number : "-"}
@@ -465,7 +458,9 @@ export default function UserProfile() { Whatsapp No
- {details.alt_phone_number || "-"} + {details.alt_phone_number + ? details.alt_phone_number + : "-"}
- {details.email || "-"} + {details.email ? details.email : "-"}
- {details.first_name || "-"} + {details.first_name ? details.first_name : "-"}
- {details.last_name || "-"} + {details.last_name ? details.last_name : "-"}
@@ -506,7 +501,7 @@ export default function UserProfile() { Age
- {details.age || "-"} + {details.age ? details.age : "-"}
@@ -515,7 +510,7 @@ export default function UserProfile() {
{" "} - {details.user_type || "-"} + {details.user_type ? details.user_type : "-"}
- {details.gender || "-"} + {details.gender ? details.gender : "-"}
@@ -534,7 +529,9 @@ export default function UserProfile() { Local Body
- {details.local_body_object?.name || "-"} + {details.local_body_object?.name + ? details.local_body_object.name + : "-"}
@@ -542,7 +539,9 @@ export default function UserProfile() { District
- {details.district_object?.name || "-"} + {details.district_object?.name + ? details.district_object.name + : "-"}
@@ -550,7 +549,9 @@ export default function UserProfile() { State
- {details.state_object?.name || "-"} + {details.state_object?.name + ? details.state_object.name + : "-"}
From 15227b009015ea73a72727a8636bc6b15ab4515c Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Fri, 24 Nov 2023 11:46:25 +0530 Subject: [PATCH 20/26] code fix in UserProfile --- src/Components/Users/UserProfile.tsx | 155 ++++++++++++--------------- 1 file changed, 66 insertions(+), 89 deletions(-) diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 478103bf78b..5de1d09f1cb 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -10,7 +10,7 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; import { FieldChangeEvent } from "../Form/FormFields/Utils"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; -import { SkillModel, SkillObjectModel } from "../Users/models"; +import { SkillModel } from "../Users/models"; import UpdatableApp, { checkForUpdate } from "../Common/UpdatableApp"; import dayjs from "../../Utils/dayjs"; import useAuthUser from "../../Common/hooks/useAuthUser"; @@ -29,6 +29,7 @@ type EditForm = { email: string; phoneNumber: string; altPhoneNumber: string; + user_type: string | undefined; doctor_qualification: string | undefined; doctor_experience_commenced_on: number | string | undefined; doctor_medical_council_registration: string | undefined; @@ -50,6 +51,7 @@ const initForm: EditForm = { email: "", phoneNumber: "", altPhoneNumber: "", + user_type: "", doctor_qualification: undefined, doctor_experience_commenced_on: undefined, doctor_medical_council_registration: undefined, @@ -82,6 +84,7 @@ const editFormReducer = (state: State, action: Action) => { } } }; + export default function UserProfile() { const [states, dispatch] = useReducer(editFormReducer, initialState); const [updateStatus, setUpdateStatus] = useState({ @@ -115,50 +118,44 @@ export default function UserProfile() { const [isLoading, setIsLoading] = useState(false); - const initialDetails: any = [{}]; - const [details, setDetails] = useState(initialDetails); - - const { loading: isUserLoading } = useQuery(routes.getUserDetails, { - pathParams: { username: authUser.username }, - onResponse: (result) => { - if (!result || !result.res || !result.data) return; - setDetails(result.data); - const formData: EditForm = { - firstName: result.data.first_name, - lastName: result.data.last_name, - age: result.data.age?.toString() || "", - gender: result.data.gender || "", - email: result.data.email, - phoneNumber: result.data.phone_number?.toString() || "", - altPhoneNumber: result.data.alt_phone_number?.toString() || "", - doctor_qualification: result.data.doctor_qualification, - doctor_experience_commenced_on: dayjs().diff( - dayjs(result.data.doctor_experience_commenced_on), - "years" - ), - doctor_medical_council_registration: - result.data.doctor_medical_council_registration, - weekly_working_hours: result.data.weekly_working_hours, - }; - dispatch({ - type: "set_form", - form: formData, - }); - }, - }); + const { data: userData, loading: isUserLoading } = useQuery( + routes.getUserDetails, + { + pathParams: { username: authUser.username }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + const formData: EditForm = { + firstName: result.data.first_name, + lastName: result.data.last_name, + age: result.data.age?.toString() || "", + gender: result.data.gender || "", + email: result.data.email, + phoneNumber: result.data.phone_number?.toString() || "", + altPhoneNumber: result.data.alt_phone_number?.toString() || "", + user_type: result.data.user_type, + doctor_qualification: result.data.doctor_qualification, + doctor_experience_commenced_on: dayjs().diff( + dayjs(result.data.doctor_experience_commenced_on), + "years" + ), + doctor_medical_council_registration: + result.data.doctor_medical_council_registration, + weekly_working_hours: result.data.weekly_working_hours, + }; + dispatch({ + type: "set_form", + form: formData, + }); + }, + } + ); - const { loading: isSkillsLoading } = useQuery(routes.userListSkill, { - pathParams: { username: authUser.username }, - onResponse: (result) => { - if (!result || !result.res || !result.data) return; - setDetails({ - ...details, - skills: result.data.results.map( - (skill: SkillModel) => skill.skill_object - ), - }); - }, - }); + const { data: skillsView, loading: isSkillsLoading } = useQuery( + routes.userListSkill, + { + pathParams: { username: authUser.username }, + } + ); const validateForm = () => { const errors = { ...initError }; @@ -232,7 +229,7 @@ export default function UserProfile() { case "doctor_qualification": case "doctor_experience_commenced_on": case "doctor_medical_council_registration": - if (details.user_type === "Doctor" && !states.form[field]) { + if (states.form.user_type === "Doctor" && !states.form[field]) { errors[field] = "Field is required"; invalidForm = true; } @@ -288,11 +285,11 @@ export default function UserProfile() { gender: states.form.gender, age: states.form.age, doctor_qualification: - details.user_type === "Doctor" + states.form.user_type === "Doctor" ? states.form.doctor_qualification : undefined, doctor_experience_commenced_on: - details.user_type === "Doctor" + states.form.user_type === "Doctor" ? dayjs() .subtract( parseInt( @@ -304,7 +301,7 @@ export default function UserProfile() { .format("YYYY-MM-DD") : undefined, doctor_medical_council_registration: - details.user_type === "Doctor" + states.form.user_type === "Doctor" ? states.form.doctor_medical_council_registration : undefined, weekly_working_hours: states.form.weekly_working_hours, @@ -313,22 +310,11 @@ export default function UserProfile() { pathParams: { username: authUser.username }, body: data, }); - if (res?.status === 200) { + if (res?.ok) { Notification.Success({ msg: "Details updated successfully", }); window.location.reload(); - setDetails({ - ...details, - first_name: states.form.firstName, - last_name: states.form.lastName, - age: states.form.age, - gender: states.form.gender, - email: states.form.email, - phone_number: states.form.phoneNumber, - alt_phone_number: states.form.altPhoneNumber, - }); - setShowEdit(false); } } }; @@ -376,10 +362,7 @@ export default function UserProfile() { body: form, }); setIsLoading(false); - if ( - res?.status == 200 && - data?.message === "Password updated successfully" - ) { + if (res?.ok && data?.message === "Password updated successfully") { Notification.Success({ msg: "Password changed!", }); @@ -435,7 +418,7 @@ export default function UserProfile() { Username
- {details.username ? details.username : "-"} + {userData?.username || "-"}
- {details.phone_number ? details.phone_number : "-"} + {userData?.phone_number || "-"}
@@ -458,9 +441,7 @@ export default function UserProfile() { Whatsapp No
- {details.alt_phone_number - ? details.alt_phone_number - : "-"} + {userData?.alt_phone_number || "-"}
- {details.email ? details.email : "-"} + {userData?.email || "-"}
- {details.first_name ? details.first_name : "-"} + {userData?.first_name || "-"}
- {details.last_name ? details.last_name : "-"} + {userData?.last_name || "-"}
@@ -501,7 +482,7 @@ export default function UserProfile() { Age
- {details.age ? details.age : "-"} + {userData?.age || "-"}
@@ -510,7 +491,7 @@ export default function UserProfile() {
{" "} - {details.user_type ? details.user_type : "-"} + {userData?.user_type || "-"}
- {details.gender ? details.gender : "-"} + {userData?.gender || "-"}
@@ -529,9 +510,7 @@ export default function UserProfile() { Local Body
- {details.local_body_object?.name - ? details.local_body_object.name - : "-"} + {userData?.local_body_object?.name || "-"}
@@ -539,9 +518,7 @@ export default function UserProfile() { District
- {details.district_object?.name - ? details.district_object.name - : "-"} + {userData?.district_object?.name || "-"}
@@ -549,9 +526,7 @@ export default function UserProfile() { State
- {details.state_object?.name - ? details.state_object.name - : "-"} + {userData?.state_object?.name || "-"}
@@ -563,11 +538,13 @@ export default function UserProfile() { className="flex flex-wrap gap-2" id="already-linked-skills" > - {details.skills && details.skills.length - ? details.skills?.map((skill: SkillObjectModel) => { + {skillsView?.results?.length + ? skillsView.results?.map((skill: SkillModel) => { return ( -

{skill.name}

+

+ {skill.skill_object.name} +

); }) @@ -583,7 +560,7 @@ export default function UserProfile() { Average weekly working hours
- {details.weekly_working_hours ?? "-"} + {userData?.weekly_working_hours || "-"}
@@ -649,7 +626,7 @@ export default function UserProfile() { required type="email" /> - {details.user_type === "Doctor" && ( + {states.form.user_type === "Doctor" && ( <> Date: Fri, 24 Nov 2023 12:05:30 +0530 Subject: [PATCH 21/26] removed redundant code --- src/Components/Users/UserProfile.tsx | 66 ++++++++++++++-------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index 5de1d09f1cb..b679a85b20e 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -118,37 +118,38 @@ export default function UserProfile() { const [isLoading, setIsLoading] = useState(false); - const { data: userData, loading: isUserLoading } = useQuery( - routes.getUserDetails, - { - pathParams: { username: authUser.username }, - onResponse: (result) => { - if (!result || !result.res || !result.data) return; - const formData: EditForm = { - firstName: result.data.first_name, - lastName: result.data.last_name, - age: result.data.age?.toString() || "", - gender: result.data.gender || "", - email: result.data.email, - phoneNumber: result.data.phone_number?.toString() || "", - altPhoneNumber: result.data.alt_phone_number?.toString() || "", - user_type: result.data.user_type, - doctor_qualification: result.data.doctor_qualification, - doctor_experience_commenced_on: dayjs().diff( - dayjs(result.data.doctor_experience_commenced_on), - "years" - ), - doctor_medical_council_registration: - result.data.doctor_medical_council_registration, - weekly_working_hours: result.data.weekly_working_hours, - }; - dispatch({ - type: "set_form", - form: formData, - }); - }, - } - ); + const { + data: userData, + loading: isUserLoading, + refetch: refetchUserData, + } = useQuery(routes.getUserDetails, { + pathParams: { username: authUser.username }, + onResponse: (result) => { + if (!result || !result.res || !result.data) return; + const formData: EditForm = { + firstName: result.data.first_name, + lastName: result.data.last_name, + age: result.data.age?.toString() || "", + gender: result.data.gender || "", + email: result.data.email, + phoneNumber: result.data.phone_number?.toString() || "", + altPhoneNumber: result.data.alt_phone_number?.toString() || "", + user_type: result.data.user_type, + doctor_qualification: result.data.doctor_qualification, + doctor_experience_commenced_on: dayjs().diff( + dayjs(result.data.doctor_experience_commenced_on), + "years" + ), + doctor_medical_council_registration: + result.data.doctor_medical_council_registration, + weekly_working_hours: result.data.weekly_working_hours, + }; + dispatch({ + type: "set_form", + form: formData, + }); + }, + }); const { data: skillsView, loading: isSkillsLoading } = useQuery( routes.userListSkill, @@ -314,7 +315,8 @@ export default function UserProfile() { Notification.Success({ msg: "Details updated successfully", }); - window.location.reload(); + await refetchUserData(); + setShowEdit(false); } } }; From 9a0bfadd8ef8abe123ac9da6aeb212d3fe71a6c8 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Fri, 24 Nov 2023 23:27:34 +0530 Subject: [PATCH 22/26] added proper types and fixed redundant code --- src/Components/Facility/models.tsx | 1 + src/Components/Users/ManageUsers.tsx | 40 +++++++++++------------- src/Components/Users/SkillsSlideOver.tsx | 4 +-- src/Components/Users/UserAdd.tsx | 23 +++----------- src/Components/Users/UserProfile.tsx | 40 +++++++++++++++--------- src/Components/Users/models.tsx | 8 +++++ src/Redux/actions.tsx | 2 +- src/Redux/api.tsx | 23 +++++++------- 8 files changed, 73 insertions(+), 68 deletions(-) diff --git a/src/Components/Facility/models.tsx b/src/Components/Facility/models.tsx index 8dcc5f71e0d..5aaa6a45f5b 100644 --- a/src/Components/Facility/models.tsx +++ b/src/Components/Facility/models.tsx @@ -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; diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index eda270fc23e..3b469081754 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -46,7 +46,7 @@ export default function ManageUsers() { const [selectedUser, setSelectedUser] = useState(null); const [expandWorkingHours, setExpandWorkingHours] = useState(false); const authUser = useAuthUser(); - const [weeklyHours, setWeeklyHours] = useState(0); + const [weeklyHours, setWeeklyHours] = useState("0"); const userIndex = USER_TYPES.indexOf(authUser.user_type); const userTypes = authUser.is_superuser ? [...USER_TYPES] @@ -109,7 +109,7 @@ export default function ManageUsers() { const handleWorkingHourSubmit = async () => { const username = selectedUser; - if (!username || !weeklyHours || weeklyHours < 0 || weeklyHours > 168) { + if (!username || !weeklyHours || +weeklyHours < 0 || +weeklyHours > 168) { setWeeklyHoursError("Value should be between 0 and 168"); return; } @@ -128,15 +128,14 @@ export default function ManageUsers() { msg: "Error while updating working hours: " + (error || ""), }); } - setWeeklyHours(0); + setWeeklyHours("0"); setWeeklyHoursError(""); await refetchUserList(); }; const handleSubmit = async () => { - const username = userData.username; const { res, error } = await request(routes.deleteUser, { - body: { username }, + pathParams: { username: userData.username }, }); if (res?.status === 204) { Notification.Success({ @@ -464,7 +463,7 @@ export default function ManageUsers() { open={expandWorkingHours} setOpen={(state) => { setExpandWorkingHours(state); - setWeeklyHours(0); + setWeeklyHours("0"); setWeeklyHoursError(""); }} slideFrom="right" @@ -719,7 +718,7 @@ function UserFacilities(props: { user: any }) { )} {/* Linked Facilities section */} - {userFacilities && userFacilities.length > 0 && ( + {userFacilities?.length && (
Linked Facilities @@ -789,21 +788,20 @@ function UserFacilities(props: { user: any }) {
)} - {!user?.home_facility_object && - (userFacilities ? userFacilities.length === 0 : 0) && ( -
-
- No linked facilities -
-

- No Linked Facilities -

+ {!user?.home_facility_object && !userFacilities?.length && ( +
+
+ No linked facilities
- )} +

+ No Linked Facilities +

+
+ )}
)} {replaceHomeFacility.show && ( diff --git a/src/Components/Users/SkillsSlideOver.tsx b/src/Components/Users/SkillsSlideOver.tsx index 71328d40b9e..744dfacde7e 100644 --- a/src/Components/Users/SkillsSlideOver.tsx +++ b/src/Components/Users/SkillsSlideOver.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useState } from "react"; +import { useCallback, useState } from "react"; import SlideOverCustom from "../../CAREUI/interactive/SlideOver"; import { SkillModel, SkillObjectModel } from "../Users/models"; import { SkillSelect } from "../Common/SkillSelect"; @@ -81,7 +81,7 @@ export default ({ show, setShow, username }: IProps) => { AuthorizeFor(["DistrictAdmin", "StateAdmin"]) ); - const hasSkills = useMemo(() => skills?.results?.length || 0 > 0, [skills]); + const hasSkills = skills?.results?.length || 0 > 0; return (
diff --git a/src/Components/Users/UserAdd.tsx b/src/Components/Users/UserAdd.tsx index 95aacfa3e7f..7df0089cdac 100644 --- a/src/Components/Users/UserAdd.tsx +++ b/src/Components/Users/UserAdd.tsx @@ -249,12 +249,7 @@ export const UserAdd = (props: UserProps) => { onResponse: (result) => { if (!result || !result.res || !result.data) return; if (userIndex <= USER_TYPES.indexOf("DistrictAdmin")) { - setDistricts([ - { - id: authUser.district!, - name: authUser.district_object?.name as string, - }, - ]); + setDistricts([authUser.district_object!]); } else { setDistricts(result.data); } @@ -269,12 +264,7 @@ export const UserAdd = (props: UserProps) => { onResponse: (result) => { if (!result || !result.res || !result.data) return; if (userIndex <= USER_TYPES.indexOf("LocalBodyAdmin")) { - setLocalBodies([ - { - id: authUser.local_body!, - name: authUser.local_body_object?.name as string, - }, - ]); + setLocalBodies([authUser.local_body_object!]); } else { setLocalBodies(result.data); } @@ -286,12 +276,7 @@ export const UserAdd = (props: UserProps) => { onResponse: (result) => { if (!result || !result.res || !result.data) return; if (userIndex <= USER_TYPES.indexOf("StateAdmin")) { - setStates([ - { - id: authUser.state!, - name: authUser.state_object?.name as string, - }, - ]); + setStates([authUser.state_object!]); } else { setStates(result.data.results); } @@ -556,7 +541,7 @@ export const UserAdd = (props: UserProps) => { const { res } = await request(routes.addUser, { body: data, }); - if (res && res.status >= 200 && res.status < 300) { + if (res?.ok) { dispatch({ type: "set_form", form: initForm }); if (!userId) { Notification.Success({ diff --git a/src/Components/Users/UserProfile.tsx b/src/Components/Users/UserProfile.tsx index b679a85b20e..76a94745c1a 100644 --- a/src/Components/Users/UserProfile.tsx +++ b/src/Components/Users/UserProfile.tsx @@ -10,7 +10,7 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; import { FieldChangeEvent } from "../Form/FormFields/Utils"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; -import { SkillModel } from "../Users/models"; +import { GenderType, SkillModel, UpdatePasswordForm } from "../Users/models"; import UpdatableApp, { checkForUpdate } from "../Common/UpdatableApp"; import dayjs from "../../Utils/dayjs"; import useAuthUser from "../../Common/hooks/useAuthUser"; @@ -22,6 +22,20 @@ import request from "../../Utils/request/request"; const Loading = lazy(() => import("../Common/Loading")); type EditForm = { + firstName: string; + lastName: string; + age: string; + gender: GenderType; + email: string; + phoneNumber: string; + altPhoneNumber: string; + user_type: string | undefined; + doctor_qualification: string | undefined; + doctor_experience_commenced_on: number | string | undefined; + doctor_medical_council_registration: string | undefined; + weekly_working_hours: string | undefined; +}; +type ErrorForm = { firstName: string; lastName: string; age: string; @@ -37,17 +51,17 @@ type EditForm = { }; type State = { form: EditForm; - errors: EditForm; + errors: ErrorForm; }; type Action = | { type: "set_form"; form: EditForm } - | { type: "set_error"; errors: EditForm }; + | { type: "set_error"; errors: ErrorForm }; const initForm: EditForm = { firstName: "", lastName: "", age: "", - gender: "", + gender: "Male", email: "", phoneNumber: "", altPhoneNumber: "", @@ -58,7 +72,7 @@ const initForm: EditForm = { weekly_working_hours: undefined, }; -const initError: EditForm = Object.assign( +const initError: ErrorForm = Object.assign( {}, ...Object.keys(initForm).map((k) => ({ [k]: "" })) ); @@ -116,8 +130,6 @@ export default function UserProfile() { const [showEdit, setShowEdit] = useState(false); - const [isLoading, setIsLoading] = useState(false); - const { data: userData, loading: isUserLoading, @@ -130,7 +142,7 @@ export default function UserProfile() { firstName: result.data.first_name, lastName: result.data.last_name, age: result.data.age?.toString() || "", - gender: result.data.gender || "", + gender: result.data.gender || "Male", email: result.data.email, phoneNumber: result.data.phone_number?.toString() || "", altPhoneNumber: result.data.alt_phone_number?.toString() || "", @@ -284,7 +296,7 @@ export default function UserProfile() { phone_number: parsePhoneNumber(states.form.phoneNumber) ?? "", alt_phone_number: parsePhoneNumber(states.form.altPhoneNumber) ?? "", gender: states.form.gender, - age: states.form.age, + age: +states.form.age, doctor_qualification: states.form.user_type === "Doctor" ? states.form.doctor_qualification @@ -321,7 +333,9 @@ export default function UserProfile() { } }; - if (isLoading || isUserLoading || isSkillsLoading) { + const isLoading = isUserLoading || isSkillsLoading; + + if (isLoading) { return ; } @@ -354,8 +368,7 @@ export default function UserProfile() { msg: "Passwords are different in the new and the confirmation column.", }); } else { - setIsLoading(true); - const form = { + const form: UpdatePasswordForm = { old_password: changePasswordForm.old_password, username: authUser.username, new_password: changePasswordForm.new_password_1, @@ -363,7 +376,6 @@ export default function UserProfile() { const { res, data } = await request(routes.updatePassword, { body: form, }); - setIsLoading(false); if (res?.ok && data?.message === "Password updated successfully") { Notification.Success({ msg: "Password changed!", @@ -409,7 +421,7 @@ export default function UserProfile() {
- {!showEdit && !isUserLoading && !isSkillsLoading && ( + {!showEdit && !isLoading && (
{ return fireRequest("addUser", [], params); }; export const deleteUser = (username: string) => { - return fireRequest("deleteUser", [username], {}); + return fireRequest("deleteUser", [], {}, { username }); }; export const checkResetToken = (params: object) => { diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index f0e311b51f3..833298f94f9 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -51,6 +51,7 @@ import { import { SkillModel, SkillObjectModel, + UpdatePasswordForm, UserModel, } from "../Components/Users/models"; import { Prescription } from "../Components/Medicine/models"; @@ -148,7 +149,8 @@ const routes = { updatePassword: { path: "/api/v1/password_change/", method: "PUT", - TRes: Type<{ [key: string]: string | string[] }>(), + TRes: Type>(), + TBody: Type(), }, // User Endpoints currentUser: { @@ -178,7 +180,7 @@ const routes = { path: "/api/v1/users/{username}/add_facility/", method: "PUT", TBody: Type<{ facility: string }>(), - TRes: undefined, + TRes: Type>(), }, addUserSkill: { @@ -192,19 +194,19 @@ const routes = { path: "/api/v1/users/{username}/delete_facility/", method: "DELETE", TBody: Type<{ facility: string }>(), - TRes: undefined, + TRes: Type>(), }, clearHomeFacility: { path: "/api/v1/users/{username}/clear_home_facility/", method: "DELETE", - TRes: undefined, + TRes: Type>(), }, deleteUserSkill: { path: "/api/v1/users/{username}/skill/{id}/", method: "DELETE", - TRes: undefined, + TRes: Type>(), }, createUser: { @@ -221,15 +223,14 @@ const routes = { partialUpdateUser: { path: "/api/v1/users/{username}/", method: "PATCH", - TRes: Type<{ [key: string]: object }>(), - TBody: Type<{ [key: string]: string | object | undefined }>(), + TRes: Type(), + TBody: Type>(), }, deleteUser: { - path: "/api/v1/users", + path: "/api/v1/users/{username}", method: "DELETE", - TRes: Type<{ [key: string]: object }>(), - TBody: Type<{ username: string }>(), + TRes: Type>(), }, addUser: { @@ -789,7 +790,7 @@ const routes = { checkUsername: { path: "/api/v1/users/{username}/check_availability/", method: "GET", - TRes: undefined, + TRes: Type>(), }, getUserDetails: { From 723ff553dcdfaa4a369ff56920959b30dea75215 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh Date: Sat, 25 Nov 2023 00:30:40 +0530 Subject: [PATCH 23/26] removed redundant fireRequest actions --- src/Redux/actions.tsx | 33 --------------------------------- src/Redux/api.tsx | 2 +- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index eacd9fdf994..94a0a29dd28 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -15,9 +15,6 @@ export const getCurrentUser = () => { export const signupUser = (params: object) => { return fireRequest("createUser", [], params); }; -export const addUser = (params: object) => { - return fireRequest("addUser", [], params); -}; export const deleteUser = (username: string) => { return fireRequest("deleteUser", [], {}, { username }); }; @@ -34,10 +31,6 @@ export const postForgotPassword = (form: object) => { return fireRequest("forgotPassword", [], form); }; -export const updateUserPassword = (form: object) => { - return fireRequest("updatePassword", [], form); -}; - export const getUserPnconfig = (pathParams: object) => { return fireRequest("getUserPnconfig", [], {}, pathParams); }; @@ -65,14 +58,6 @@ export const deleteFacilityCoverImage = (id: string) => { export const getUserList = (params: object, key?: string) => { return fireRequest("userList", [], params, null, key); }; - -export const getUserListSkills = (pathParam: object) => { - return fireRequest("userListSkill", [], {}, pathParam); -}; - -export const partialUpdateUser = (username: string, data: any) => { - return fireRequest("partialUpdateUser", [], data, { username }); -}; export const getUserListFacility = (pathParam: object) => { return fireRequest("userListFacility", [], {}, pathParam); }; @@ -98,10 +83,6 @@ export const deleteUserFacility = (username: string, facility: string) => { ); }; -export const clearHomeFacility = (username: string) => { - return fireRequest("clearHomeFacility", [], {}, { username }); -}; - export const getPermittedFacilities = (params: object) => { return fireRequest("getPermittedFacilities", [], params); }; @@ -608,20 +589,6 @@ export const dischargePatient = (params: object, pathParams: object) => { //Profile -export const checkUsername = (params: object) => { - return fireRequest("checkUsername", [], {}, params, undefined, true); -}; - -export const getUserDetails = (username: string, suppress?: boolean) => { - return fireRequest( - "getUserDetails", - [], - {}, - { username: username }, - undefined, - suppress ?? true - ); -}; export const updateUserDetails = (username: string, data: object) => { return fireRequest("updateUserDetails", [username], data); }; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 833298f94f9..dd61affe816 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -179,8 +179,8 @@ const routes = { addUserFacility: { path: "/api/v1/users/{username}/add_facility/", method: "PUT", - TBody: Type<{ facility: string }>(), TRes: Type>(), + TBody: Type<{ facility: string }>(), }, addUserSkill: { From 3bfc84eb829f1550e69466e38244655777e5cbb6 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Sat, 25 Nov 2023 08:56:31 +0530 Subject: [PATCH 24/26] fix http 301 redirect due to missing trailing slash --- src/Redux/api.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index dd61affe816..8e1997e9edb 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -228,7 +228,7 @@ const routes = { }, deleteUser: { - path: "/api/v1/users/{username}", + path: "/api/v1/users/{username}/", method: "DELETE", TRes: Type>(), }, From de5144b46edf8a368011b03db1a89687bcb2f5a1 Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh <63492939+thedevildude@users.noreply.github.com> Date: Thu, 30 Nov 2023 10:31:52 +0530 Subject: [PATCH 25/26] Update TRes of userListFacility in src/Redux/api.tsx Co-authored-by: Rithvik Nishad --- src/Redux/api.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index f9b64ca7be1..c322672864c 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -177,7 +177,7 @@ const routes = { userListFacility: { path: "/api/v1/users/{username}/get_facilities/", method: "GET", - TRes: Type(), + TRes: Type(), }, addUserFacility: { From 7cc2c7545a38f666341930dfb838d5d9e2fdd4cf Mon Sep 17 00:00:00 2001 From: Devdeep Ghosh <63492939+thedevildude@users.noreply.github.com> Date: Thu, 30 Nov 2023 05:12:10 +0000 Subject: [PATCH 26/26] resolved imports --- src/Redux/api.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index c322672864c..2a64d921792 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -43,6 +43,8 @@ import { IUserFacilityRequest, PatientStatsModel, WardModel, + LocationModel, + StateModel, } from "../Components/Facility/models"; import { IDeleteExternalResult,