From 1d52ed7c14d35a0642d42efb70ddb70714091b2a Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Wed, 6 Mar 2024 18:59:18 +0530 Subject: [PATCH 01/10] Improve District filter in User Management --- src/Components/Users/ManageUsers.tsx | 24 +++++++---- src/Components/Users/UserFilter.tsx | 61 ++++++++++++---------------- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index cb0caaec950..dbfca3a815a 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -1,6 +1,6 @@ import dayjs from "dayjs"; import { navigate } from "raviger"; -import { lazy, useState } from "react"; +import { lazy, useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import CountBlock from "../../CAREUI/display/Count"; import CareIcon from "../../CAREUI/icons/CareIcon"; @@ -73,8 +73,7 @@ export default function ManageUsers() { const [weeklyHoursError, setWeeklyHoursError] = useState(""); const extremeSmallScreenBreakpoint = 320; - const isExtremeSmallScreen = - width <= extremeSmallScreenBreakpoint ? true : false; + const isExtremeSmallScreen = width <= extremeSmallScreenBreakpoint; const { data: userListData, @@ -92,15 +91,24 @@ export default function ManageUsers() { phone_number: qParams.phone_number, alt_phone_number: qParams.alt_phone_number, user_type: qParams.user_type, - district_id: qParams.district_id, + district_id: qParams.district, }, }); + useEffect(() => { + if (!qParams.state && qParams.district) { + advancedFilter.removeFilters(["district"]); + } + if (!qParams.district && qParams.state) { + advancedFilter.removeFilters(["state"]); + } + }, [advancedFilter, qParams]); + const { data: districtData, loading: districtDataLoading } = useQuery( routes.getDistrict, { - prefetch: !!qParams.district_id, - pathParams: { id: qParams.district_id }, + prefetch: !!qParams.district, + pathParams: { id: qParams.district }, } ); @@ -535,8 +543,8 @@ export default function ManageUsers() { badge("Role", "user_type"), value( "District", - "district_id", - qParams.district_id ? districtData?.name || "" : "" + "district", + qParams.district ? districtData?.name || "" : "" ), ]} /> diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index f2ce3be914c..92f1bd2ed2f 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -1,4 +1,3 @@ -import DistrictSelect from "../Facility/FacilityFilter/DistrictSelect"; import { parsePhoneNumber } from "../../Utils/utils"; import TextFormField from "../Form/FormFields/TextFormField"; import SelectMenuV2 from "../Form/SelectMenuV2"; @@ -7,8 +6,9 @@ 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"; +import DistrictAutocompleteFormField from "../Common/DistrictAutocompleteFormField"; +import StateAutocompleteFormField from "../Common/StateAutocompleteFormField"; +import { useTranslation } from "react-i18next"; const parsePhoneNumberForFilterParam = (phoneNumber: string) => { if (!phoneNumber) return ""; @@ -18,6 +18,7 @@ const parsePhoneNumberForFilterParam = (phoneNumber: string) => { }; export default function UserFilter(props: any) { + const { t } = useTranslation(); const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ first_name: filter.first_name || "", @@ -25,17 +26,10 @@ export default function UserFilter(props: any) { phone_number: filter.phone_number || "+91", alt_phone_number: filter.alt_phone_number || "+91", user_type: filter.user_type || "", - district_id: filter.district_id || "", - district_ref: null, + district: filter.district || "", + state: filter.state || "", }); - const setDistrict = (selected: any) => { - const filterData: any = { ...filterState }; - filterData["district_ref"] = selected; - filterData["district_id"] = (selected || {}).id; - setFilterState(filterData); - }; - const applyFilter = () => { const { first_name, @@ -43,7 +37,8 @@ export default function UserFilter(props: any) { phone_number, alt_phone_number, user_type, - district_id, + district, + state, } = filterState; const data = { first_name: first_name || "", @@ -51,22 +46,24 @@ export default function UserFilter(props: any) { phone_number: parsePhoneNumberForFilterParam(phone_number), alt_phone_number: parsePhoneNumberForFilterParam(alt_phone_number), user_type: user_type || "", - district_id: district_id || "", + district: district || "", + state: district ? state || "" : "", }; onChange(data); }; - 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 }); - }, - }); + const handleChange = ({ name, value }: any) => { + if (name === "state" && !value) + setFilterState({ ...filterState, state: value, district: undefined }); + else setFilterState({ ...filterState, [name]: value }); + }; - const handleChange = ({ name, value }: any) => - setFilterState({ ...filterState, [name]: value }); + const field = (name: string) => ({ + name, + label: t(name), + value: filterState[name], + onChange: handleChange, + }); return ( -
- District - -
+ +
Date: Thu, 7 Mar 2024 02:22:49 +0530 Subject: [PATCH 02/10] Fix Cypress --- cypress/e2e/users_spec/user_homepage.cy.ts | 1 + cypress/pageobject/Users/UserSearch.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/cypress/e2e/users_spec/user_homepage.cy.ts b/cypress/e2e/users_spec/user_homepage.cy.ts index 3a633bd65a4..1a0bec587a7 100644 --- a/cypress/e2e/users_spec/user_homepage.cy.ts +++ b/cypress/e2e/users_spec/user_homepage.cy.ts @@ -28,6 +28,7 @@ describe("User Homepage", () => { userPage.typeInFirstName("Dev"); userPage.typeInLastName("Doctor"); userPage.selectRole("Doctor"); + userPage.selectState("Kerala"); userPage.selectDistrict("Ernakulam"); userPage.typeInPhoneNumber(phone_number); userPage.typeInAltPhoneNumber(alt_phone_number); diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 12ac64c51b3..52f3c06c08f 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -62,6 +62,11 @@ export class UserPage { cy.get("[role='option']").contains(role).click(); } + selectState(state: string) { + cy.get("input[name='state']").click().type(state); + cy.get("[role='option']").contains(state).click(); + } + selectDistrict(district: string) { cy.get("input[name='district']").click().type(district); cy.get("[role='option']").contains(district).click(); From 5dd77e47d69bec37153159ee1e3a0b8d4de7dd77 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 7 Mar 2024 02:35:04 +0530 Subject: [PATCH 03/10] Fix cypress --- src/Components/Facility/ConsultationForm.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Components/Facility/ConsultationForm.tsx b/src/Components/Facility/ConsultationForm.tsx index 66dbb711afa..a063ce91a8d 100644 --- a/src/Components/Facility/ConsultationForm.tsx +++ b/src/Components/Facility/ConsultationForm.tsx @@ -694,7 +694,7 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { const validated = validateForm(); if (validated) { setIsLoading(true); - const data = { + const data: any = { symptoms: state.form.symptoms, other_symptoms: isOtherSymptomsSelected ? state.form.other_symptoms @@ -713,7 +713,6 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { history_of_present_illness: state.form.history_of_present_illness, treatment_plan: state.form.treatment_plan, discharge_date: state.form.discharge_date, - patient_no: state.form.patient_no, create_diagnoses: isUpdate ? undefined : state.form.create_diagnoses, treating_physician: state.form.treating_physician, investigation: state.form.InvestigationAdvice, @@ -764,6 +763,8 @@ export const ConsultationForm = ({ facilityId, patientId, id }: Props) => { bed: bed && bed instanceof Array ? bed[0]?.id : bed?.id, }; + if (state.form.patient_no) data["patient_no"] = state.form.patient_no; + const res = await dispatchAction( id ? updateConsultation(id!, data) : createConsultation(data) ); From ea5147f12955c5e7114f97562d138affb8a13dcb Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 7 Mar 2024 02:44:00 +0530 Subject: [PATCH 04/10] Fix input selectors in UserSearch.ts --- cypress/pageobject/Users/UserSearch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 52f3c06c08f..d98892494b5 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -63,12 +63,12 @@ export class UserPage { } selectState(state: string) { - cy.get("input[name='state']").click().type(state); + cy.get("'#state input").click().type(state); cy.get("[role='option']").contains(state).click(); } selectDistrict(district: string) { - cy.get("input[name='district']").click().type(district); + cy.get("'#district input").click().type(district); cy.get("[role='option']").contains(district).click(); } From 4a2e86f15e760ff1c697b45074bfecfb0ad0aac5 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Thu, 7 Mar 2024 03:07:16 +0530 Subject: [PATCH 05/10] Fix input selectors in UserSearch.ts --- cypress/pageobject/Users/UserSearch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index d98892494b5..f1c5d16b0d9 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -63,12 +63,12 @@ export class UserPage { } selectState(state: string) { - cy.get("'#state input").click().type(state); + cy.get("#state input").click().type(state); cy.get("[role='option']").contains(state).click(); } selectDistrict(district: string) { - cy.get("'#district input").click().type(district); + cy.get("#district input").click().type(district); cy.get("[role='option']").contains(district).click(); } From 9e3d20d7106c5432df2a3c14d26467efb893f645 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:37:08 +0530 Subject: [PATCH 06/10] Update district_id to district in UserSearch.ts --- cypress/pageobject/Users/UserSearch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index f1c5d16b0d9..7350432db8d 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -29,7 +29,7 @@ export class UserPage { .and("include", "phone_number=%2B919876543219") .and("include", "alt_phone_number=%2B919876543219") .and("include", "user_type=Doctor") - .and("include", "district_id=7"); + .and("include", "district=7"); } checkUsernameText(username: string) { From 1663bd77c38d851856b7a2bd8268907f67fc8e7f Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:31:43 +0530 Subject: [PATCH 07/10] Add district validation when state is selected --- src/Components/Users/UserFilter.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 92f1bd2ed2f..758d8dcf6e4 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -9,6 +9,7 @@ import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import DistrictAutocompleteFormField from "../Common/DistrictAutocompleteFormField"; import StateAutocompleteFormField from "../Common/StateAutocompleteFormField"; import { useTranslation } from "react-i18next"; +import * as Notify from "../../Utils/Notifications"; const parsePhoneNumberForFilterParam = (phoneNumber: string) => { if (!phoneNumber) return ""; @@ -49,6 +50,12 @@ export default function UserFilter(props: any) { district: district || "", state: district ? state || "" : "", }; + if (state && !district) { + Notify.Warn({ + msg: "District is required when state is selected", + }); + return; + } onChange(data); }; From 1ac3412671cba4174dba2c91e2a551baa7b39288 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:06:54 +0530 Subject: [PATCH 08/10] Refactor code to use searchAndSelectOption function for selecting state and district --- cypress/pageobject/Users/UserSearch.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 7350432db8d..201d81721e1 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -63,13 +63,11 @@ export class UserPage { } selectState(state: string) { - cy.get("#state input").click().type(state); - cy.get("[role='option']").contains(state).click(); + cy.searchAndSelectOption("#state", state); } selectDistrict(district: string) { - cy.get("#district input").click().type(district); - cy.get("[role='option']").contains(district).click(); + cy.searchAndSelectOption("#district", district); } typeInPhoneNumber(phone: string) { From 2c924bc7fa90c8520929d78a1fe49b69138f322c Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 12 Mar 2024 12:43:01 +0530 Subject: [PATCH 09/10] Refactor UserFilter component --- src/Components/Users/UserFilter.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 758d8dcf6e4..d89a79c03ee 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -111,13 +111,13 @@ export default function UserFilter(props: any) { />
- + -
+
Date: Tue, 12 Mar 2024 13:00:36 +0530 Subject: [PATCH 10/10] Update element selectors in UserSearch.ts --- cypress/pageobject/Users/UserSearch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 201d81721e1..6f83718e9b8 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -63,11 +63,11 @@ export class UserPage { } selectState(state: string) { - cy.searchAndSelectOption("#state", state); + cy.searchAndSelectOption("#state input", state); } selectDistrict(district: string) { - cy.searchAndSelectOption("#district", district); + cy.searchAndSelectOption("#district input", district); } typeInPhoneNumber(phone: string) {