Skip to content

Commit

Permalink
Merge branch 'develop' into issue#6855
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Dec 19, 2023
2 parents eff3ac4 + 1f5ea20 commit 6f62d27
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 111 deletions.
14 changes: 12 additions & 2 deletions src/Components/ABDM/LinkABHANumberModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import TextFormField from "../Form/FormFields/TextFormField";
import { classNames } from "../../Utils/utils";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";
import { ABDMError } from "./models";

export const validateRule = (
condition: boolean,
Expand Down Expand Up @@ -423,10 +424,11 @@ const VerifyAadhaarSection = ({
if (!validateAadhaar() || !txnId) return;

setIsSendingOtp(true);
const { res, data } = await request(routes.abha.generateAadhaarOtp, {
const { res, data } = await request(routes.abha.resendAadhaarOtp, {
body: {
txnId: txnId,
},
silent: true,
});
setIsSendingOtp(false);

Expand All @@ -436,7 +438,15 @@ const VerifyAadhaarSection = ({
msg: "OTP has been resent to the mobile number registered with the Aadhar number.",
});
} else {
Notify.Error({ msg: JSON.stringify(data) });
Notify.Error({
msg:
(data as unknown as ABDMError).details
?.map((detail) => detail.message)
.join(", ")
.trim() ||
(data as unknown as ABDMError).message ||
"OTP resend failed",
});
}
};

Expand Down
9 changes: 9 additions & 0 deletions src/Components/ABDM/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export interface IHealthId {
authMethods?: string[];
}

export interface ABDMError {
code: string;
details?: {
code: string;
message: string;
}[];
message: string;
}

export interface IAadhaarOtp {
txnId: string;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Diagnosis/LegacyDiagnosesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./types";
import { useTranslation } from "react-i18next";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { compareBy } from "../../Utils/utils";

interface Props {
diagnoses: ConsultationDiagnosis[];
Expand All @@ -22,7 +23,7 @@ function groupDiagnoses(diagnoses: ConsultationDiagnosis[]) {
for (const status of ActiveConditionVerificationStatuses) {
groupedDiagnoses[status] = diagnoses
.filter((d) => d.verification_status === status)
.sort((a, b) => Number(b.is_principal) - Number(a.is_principal));
.sort(compareBy("is_principal"));
}

return groupedDiagnoses;
Expand Down
100 changes: 43 additions & 57 deletions src/Components/ExternalResult/ListFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import TextFormField from "../Form/FormFields/TextFormField";
import { MultiSelectFormField } from "../Form/FormFields/SelectFormField";
import DateRangeFormField from "../Form/FormFields/DateRangeFormField";
import dayjs from "dayjs";
import { dateQueryString } from "../../Utils/utils";
import { dateQueryString, compareBy } from "../../Utils/utils";
import useAuthUser from "../../Common/hooks/useAuthUser";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";
import Loading from "../Common/Loading";
import { LocalBodyModel, WardModel } from "../Facility/models";

const clearFilterState = {
created_date_before: "",
Expand All @@ -27,10 +28,10 @@ const getDate = (value: any) =>

export default function ListFilter(props: any) {
const { filter, onChange, closeFilter, dataList, removeFilters } = props;
const [wardList, setWardList] = useState<any[]>([]);
const [lsgList, setLsgList] = useState<any[]>([]);
const [wards, setWards] = useState<any[]>([]);
const [selectedLsgs, setSelectedLsgs] = useState<any[]>([]);
const [wardList, setWardList] = useState<WardModel[]>([]);
const [lsgList, setLsgList] = useState<LocalBodyModel[]>([]);
const [wards, setWards] = useState<WardModel[]>([]);
const [selectedLsgs, setSelectedLsgs] = useState<LocalBodyModel[]>([]);
const authUser = useAuthUser();
const [filterState, setFilterState] = useMergeState({
created_date_before: filter.created_date_before || null,
Expand All @@ -47,32 +48,32 @@ export default function ListFilter(props: any) {
pathParams: { id: String(authUser.district) },
onResponse: ({ res, data }) => {
if (res && data) {
let allWards: any[] = [];
let allLsgs: any[] = [];
const allWards: any[] = [];
const allLsgs: any[] = [];

if (res && data) {
data.forEach((local: any) => {
allLsgs = [...allLsgs, { id: local.id, name: local.name }];
allLsgs.push({ id: local.id, name: local.name });
if (local.wards) {
local.wards.forEach((ward: any) => {
allWards = [
...allWards,
{
id: ward.id,
name: ward.number + ": " + ward.name,
panchayath: local.name,
number: ward.number,
local_body_id: local.id,
},
];
allWards.push({
id: ward.id,
name: ward.number + ": " + ward.name,
panchayath: local.name,
number: ward.number,
local_body_id: local.id,
});
});
}
});
}

sortByName(allWards);
sortByName(allLsgs);
setWardList(allWards || []);
setLsgList(allLsgs || []);
allWards.sort(compareBy("number"));
allLsgs.sort(compareBy("name"));

setWardList(allWards);
setLsgList(allLsgs);

const filteredWard = filter?.wards?.split(",").map(Number);
const selectedWards: any =
filteredWard && allWards
Expand Down Expand Up @@ -106,13 +107,6 @@ export default function ListFilter(props: any) {
setFilterState(filterData);
};

const handleWardChange = (value: any) => {
setWards(value);
};
const handleLsgChange = (value: any) => {
setSelectedLsgs(value);
};

const field = (name: string) => ({
name,
label: t(name),
Expand Down Expand Up @@ -161,12 +155,6 @@ export default function ListFilter(props: any) {
dataList(selectedLsgs, wards);
};

const sortByName = (items: any) => {
items.sort(function (a: any, b: any) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
});
};

const filterWards = () => {
const selectedLsgIds: any = selectedLsgs.map((e) => {
return e.id;
Expand Down Expand Up @@ -205,29 +193,27 @@ export default function ListFilter(props: any) {
closeFilter();
}}
>
<div>
<MultiSelectFormField
name="local_bodies"
options={lsgList}
label={t("Local Body")}
placeholder={t("select_local_body")}
value={selectedLsgs}
optionLabel={(option: any) => option.name}
onChange={(e: any) => handleLsgChange(e.value)}
/>
</div>
<MultiSelectFormField
name="local_bodies"
options={lsgList}
label={t("Local Body")}
placeholder={t("select_local_body")}
value={selectedLsgs}
optionLabel={(option) => option.name}
optionDescription={(option) => option.localbody_code}
onChange={({ value }) => setSelectedLsgs(value)}
/>

<div>
<MultiSelectFormField
name="wards"
options={filterWards()}
label={t("Ward")}
placeholder={t("select_wards")}
value={wards}
optionLabel={(option: any) => option.name}
onChange={(e: any) => handleWardChange(e.value)}
/>
</div>
<MultiSelectFormField
name="wards"
options={filterWards() as WardModel[]}
label={t("Ward")}
placeholder={t("select_wards")}
value={wards}
optionLabel={(option) => option.name}
optionDescription={(option) => option.panchayath}
onChange={({ value }) => setWards(value)}
/>
<DateRangeFormField
name="created_date"
id="created_date"
Expand Down
9 changes: 4 additions & 5 deletions src/Components/ExternalResult/ResultUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Page from "../Common/components/Page.js";
import useQuery from "../../Utils/request/useQuery.js";
import routes from "../../Redux/api.js";
import request from "../../Utils/request/request.js";
import { compareBy } from "../../Utils/utils.js";

const Loading = lazy(() => import("../Common/Loading"));

Expand Down Expand Up @@ -265,11 +266,9 @@ export default function UpdateResult(props: any) {
name="ward"
label="Ward/Division of respective LSGI"
required
options={ward
.sort((a, b) => a.number - b.number)
.map((e) => {
return { id: e.id, name: e.number + ": " + e.name };
})}
options={ward.sort(compareBy("number")).map((e) => {
return { id: e.id, name: e.number + ": " + e.name };
})}
value={state.form.ward}
optionLabel={(ward) => ward.name}
optionValue={(ward) => ward.id}
Expand Down
4 changes: 3 additions & 1 deletion src/Components/Facility/AddBedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Cancel, Submit } from "../Common/components/ButtonV2";
import TextFormField from "../Form/FormFields/TextFormField";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import Page from "../Common/components/Page";

const Loading = lazy(() => import("../Common/Loading"));

interface BedFormProps {
Expand Down Expand Up @@ -73,6 +74,7 @@ export const AddBedForm = (props: BedFormProps) => {
}
setIsLoading(false);
}

fetchFacilityLocationAndBed();
}, [dispatchAction, facilityId, locationId]);

Expand Down Expand Up @@ -125,7 +127,7 @@ export const AddBedForm = (props: BedFormProps) => {
name,
description,
bed_type: bedType,
number_of_beds: numberOfBeds,
number_of_beds: bedId ? 1 : numberOfBeds,
};

if (!validateInputs(data)) return;
Expand Down
41 changes: 19 additions & 22 deletions src/Components/Facility/FacilityCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import * as Notification from "../../Utils/Notifications.js";

import ButtonV2, { Cancel, Submit } from "../Common/components/ButtonV2";
import { CapacityModal, DoctorModal } from "./models";
import {
CapacityModal,
DistrictModel,
DoctorModal,
LocalBodyModel,
StateModel,
WardModel,
} from "./models";
import { DraftSection, useAutoSaveReducer } from "../../Utils/AutoSave.js";
import {
FACILITY_FEATURE_TYPES,
Expand Down Expand Up @@ -30,6 +37,7 @@ import {
getPincodeDetails,
includesIgnoreCase,
parsePhoneNumber,
compareBy,
} from "../../Utils/utils";
import {
phonePreg,
Expand Down Expand Up @@ -67,15 +75,6 @@ interface FacilityProps {
facilityId?: string;
}

interface StateObj {
id: number;
name: string;
}

interface WardObj extends StateObj {
number: number;
}

type FacilityForm = {
facility_type: string;
name: string;
Expand Down Expand Up @@ -162,10 +161,10 @@ export const FacilityCreate = (props: FacilityProps) => {
const [isDistrictLoading, setIsDistrictLoading] = useState(false);
const [isLocalbodyLoading, setIsLocalbodyLoading] = useState(false);
const [isWardLoading, setIsWardLoading] = useState(false);
const [states, setStates] = useState<StateObj[]>([]);
const [districts, setDistricts] = useState<StateObj[]>([]);
const [localBodies, setLocalBodies] = useState<StateObj[]>([]);
const [ward, setWard] = useState<WardObj[]>([]);
const [states, setStates] = useState<StateModel[]>([]);
const [districts, setDistricts] = useState<DistrictModel[]>([]);
const [localBodies, setLocalBodies] = useState<LocalBodyModel[]>([]);
const [ward, setWard] = useState<WardModel[]>([]);
const [currentStep, setCurrentStep] = useState(1);
const [createdFacilityId, setCreatedFacilityId] = useState("");
const [showAutoFilledPincode, setShowAutoFilledPincode] = useState(false);
Expand Down Expand Up @@ -855,14 +854,12 @@ export const FacilityCreate = (props: FacilityProps) => {
className={isWardLoading ? "animate-pulse" : ""}
disabled={isWardLoading}
placeholder="Choose Ward"
options={ward
.sort((a, b) => a.number - b.number)
.map((e) => {
return {
id: e.id,
name: e.number + ": " + e.name,
};
})}
options={ward.sort(compareBy("number")).map((e) => {
return {
id: e.id,
name: e.number + ": " + e.name,
};
})}
optionLabel={(o) => o.name}
optionValue={(o) => o.id}
/>
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Facility/models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface WardModel {
id: number;
name: string;
number: number;
local_body: number;
panchayath: string;
local_body_id: LocalBodyModel["id"];
}

export interface FacilityModel {
Expand Down
5 changes: 2 additions & 3 deletions src/Components/Form/FormFields/RangeAutocompleteFormField.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from "react";
import AutocompleteFormField from "./Autocomplete";
import { FormFieldBaseProps } from "./Utils";
import { classNames } from "../../../Utils/utils";
import { classNames, compareBy } from "../../../Utils/utils";
import ButtonV2 from "../../Common/components/ButtonV2";

interface Threshold {
Expand All @@ -23,8 +23,7 @@ type Props = FormFieldBaseProps<number> & {

export default function RangeAutocompleteFormField(props: Props) {
const options = useMemo(() => {
const sortedThresholds =
props.thresholds?.sort((a, b) => a.value - b.value) || [];
const sortedThresholds = props.thresholds?.sort(compareBy("value")) || [];

const getThreshold = (value: number) => {
const threshold = sortedThresholds.findLast(
Expand Down
Loading

0 comments on commit 6f62d27

Please sign in to comment.