Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🛠️ Replace useDispatch w. useQuery/request: Facility (Part 1, A-D) (src/Components/Facility/[A-D]*.tsx #6452

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions src/Components/Facility/DoctorVideoSlideover.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
import { useEffect, useState } from "react";
import { useDispatch } from "react-redux";
import SlideOver from "../../CAREUI/interactive/SlideOver";
import { getFacilityUsers } from "../../Redux/actions";
import { UserAssignedModel } from "../Users/models";
import { SkillObjectModel } from "../Users/models";
import CareIcon from "../../CAREUI/icons/CareIcon";
import { relativeTime } from "../../Utils/utils";
import useQuery from "../../Utils/request/useQuery";
import routes from "../../Redux/api";

export default function DoctorVideoSlideover(props: {
show: boolean;
facilityId: string;
setShow: (show: boolean) => void;
}) {
const { show, facilityId, setShow } = props;
const [doctors, setDoctors] = useState<UserAssignedModel[]>([]);

const dispatchAction: any = useDispatch();
useEffect(() => {
const fetchUsers = async () => {
if (facilityId) {
const res = await dispatchAction(
getFacilityUsers(facilityId, { limit: 50 })
);
if (res && res.data) {
setDoctors(
res.data.results
.filter((user: any) => user.alt_phone_number)
.sort((a: any, b: any) => {
return Number(a.last_login) - Number(b.last_login);
})
);
}
} else {
setDoctors([]);
}
};
if (show) {
fetchUsers();
}
}, [show, facilityId]);
const { data } = useQuery(routes.getFacilityUsers, {
pathParams: { facility_id: facilityId },
query: {
limit: 50,
},
});

return (
<SlideOver
Expand Down Expand Up @@ -78,7 +58,11 @@ export default function DoctorVideoSlideover(props: {
id="options"
role="listbox"
>
{doctors
{data?.results
.filter((user) => user.alt_phone_number)
.sort((a, b) => {
return Number(a.last_login) - Number(b.last_login);
})
.filter((doc) => {
const isHomeUser =
(doc.home_facility_object?.id || "") === facilityId;
Expand Down
4 changes: 3 additions & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IConfig } from "../Common/hooks/useConfig";
import { AssetData } from "../Components/Assets/AssetTypes";
import { LocationModel } from "../Components/Facility/models";
import { Prescription } from "../Components/Medicine/models";
import { UserModel } from "../Components/Users/models";
import { UserAssignedModel, UserModel } from "../Components/Users/models";
import { PaginatedResponse } from "../Utils/request/types";

/**
Expand Down Expand Up @@ -212,6 +212,8 @@ const routes = {

getFacilityUsers: {
path: "/api/v1/facility/{facility_id}/get_users/",
methood: "GET",
TRes: Type<PaginatedResponse<UserAssignedModel>>(),
},

listFacilityAssetLocation: {
Expand Down
Loading