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: Consultations #6372 #6484

Merged
merged 22 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
330c7d9
PaginatedList: fix `offset` not included in qParams
rithviknishad Oct 18, 2023
7302798
fix error message
rithviknishad Oct 18, 2023
4af705a
Merge remote-tracking branch 'upstream/fix-pagination' into Fix#6372-new
AshrafMd-1 Oct 24, 2023
48aff69
convert dispatch to useQuery and request
AshrafMd-1 Oct 24, 2023
62cd937
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Oct 25, 2023
2537a50
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Oct 25, 2023
92dda5f
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Oct 27, 2023
22dbb11
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Oct 30, 2023
18424ce
merge develop
AshrafMd-1 Nov 1, 2023
2aeaad2
change components based on suggestions
AshrafMd-1 Nov 6, 2023
5fdefc5
Merge branch 'develop' into Fix#6372-new
AshrafMd-1 Nov 6, 2023
4c9c27a
change api model to paginated api
AshrafMd-1 Nov 6, 2023
70fca2f
resolve merge conflict
AshrafMd-1 Nov 9, 2023
6301e19
Merge branch 'develop' into Fix#6372-new
AshrafMd-1 Nov 9, 2023
9c2fdf3
format code with prettier
AshrafMd-1 Nov 9, 2023
a5534df
Merge branch 'develop' into Fix#6372-new
AshrafMd-1 Nov 11, 2023
1b678ff
fix paginatedlist
AshrafMd-1 Nov 12, 2023
0c0fb5c
edit previous round
AshrafMd-1 Nov 13, 2023
88641c8
Merge branch 'develop' into Fix#6372-new
AshrafMd-1 Nov 14, 2023
304066b
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Nov 14, 2023
a19f10b
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Nov 15, 2023
32b8660
Merge branch 'coronasafe:develop' into Fix#6372-new
AshrafMd-1 Nov 16, 2023
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
6 changes: 3 additions & 3 deletions src/CAREUI/misc/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ PaginatedList.Refresh = Refresh;

interface ItemsProps<TItem> {
className?: string;
children: (item: TItem) => JSX.Element | JSX.Element[];
children: (item: TItem, items: TItem[]) => JSX.Element | JSX.Element[];
shimmer?: JSX.Element;
shimmerCount?: number;
}
Expand All @@ -137,9 +137,9 @@ const Items = <TItem extends object>(props: ItemsProps<TItem>) => {
{props.shimmer}
</li>
))
: items.map((item, index) => (
: items.map((item, index, items) => (
<li key={index} className="w-full">
{props.children(item)}
{props.children(item, items)}
</li>
))}
</ul>
Expand Down
71 changes: 30 additions & 41 deletions src/Components/Facility/Consultations/ABGPlots.tsx
Original file line number Diff line number Diff line change
@@ -1,56 +1,45 @@
import { useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { dailyRoundsAnalyse } from "../../../Redux/actions";
import { useEffect, useState } from "react";
import { LinePlot } from "./components/LinePlot";
import Pagination from "../../Common/Pagination";
import { PAGINATION_LIMIT } from "../../../Common/constants";
import { formatDateTime } from "../../../Utils/utils";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";

export const ABGPlots = (props: any) => {
const { consultationId } = props;
const dispatch: any = useDispatch();
const [results, setResults] = useState({});
const [currentPage, setCurrentPage] = useState(1);
const [totalCount, setTotalCount] = useState(0);

const fetchDailyRounds = useCallback(
async (status: statusType) => {
const res = await dispatch(
dailyRoundsAnalyse(
{
page: currentPage,
fields: [
"ph",
"pco2",
"po2",
"hco3",
"base_excess",
"lactate",
"sodium",
"potassium",
"ventilator_fi02",
],
},
{ consultationId }
)
);
if (!status.aborted) {
if (res?.data) {
setResults(res.data.results);
setTotalCount(res.data.count);
}
useEffect(() => {
const fetchDailyRounds = async (currentPage: number) => {
const { res, data } = await request(routes.dailyRoundsAnalyse, {
body: {
page: currentPage,
fields: [
"ph",
"pco2",
"po2",
"hco3",
"base_excess",
"lactate",
"sodium",
"potassium",
"ventilator_fi02",
],
},
pathParams: {
consultationId,
},
});
if (res?.ok && data) {
setResults(data.results);
setTotalCount(data.count);
}
},
[consultationId, dispatch, currentPage]
);

useAbortableEffect(
(status: statusType) => {
fetchDailyRounds(status);
},
[currentPage]
);
};
fetchDailyRounds(currentPage);
}, [currentPage, consultationId]);

const handlePagination = (page: number, _limit: number) => {
setCurrentPage(page);
Expand Down
69 changes: 26 additions & 43 deletions src/Components/Facility/Consultations/Beds.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import * as Notification from "../../../Utils/Notifications.js";

import { BedModel, CurrentBed } from "../models";
import { Dispatch, SetStateAction, useCallback, useState } from "react";
import {
createConsultationBed,
listConsultationBeds,
} from "../../../Redux/actions";
import { statusType, useAbortableEffect } from "../../../Common/utils";
import { Dispatch, SetStateAction, useState } from "react";
import routes from "../../../Redux/api";
import request from "../../../Utils/request/request";
import useQuery from "../../../Utils/request/useQuery";

import { BedSelect } from "../../Common/BedSelect";
import ButtonV2 from "../../Common/components/ButtonV2";
Expand All @@ -16,15 +14,14 @@ import { FieldLabel } from "../../Form/FormFields/FormField";
import Loading from "../../Common/Loading";
import TextFormField from "../../Form/FormFields/TextFormField";
import { formatDateTime } from "../../../Utils/utils";
import { useDispatch } from "react-redux";
import dayjs from "../../../Utils/dayjs";
import { AssetSelect } from "../../Common/AssetSelect.js";
import DialogModal from "../../Common/Dialog.js";
import { Link } from "raviger";
import {
AssetClass,
AssetData,
assetClassProps,
AssetData,
} from "../../Assets/AssetTypes.js";
import Chip from "../../../CAREUI/display/Chip.js";

Expand All @@ -40,45 +37,30 @@ interface BedsProps {
}

const Beds = (props: BedsProps) => {
const dispatch = useDispatch<any>();
const { facilityId, consultationId, discharged } = props;
const [bed, setBed] = useState<BedModel>({});
const [startDate, setStartDate] = useState<string>(
dayjs().format("YYYY-MM-DDTHH:mm")
);
const [assets, setAssets] = useState<any[]>([]);
const [consultationBeds, setConsultationBeds] = useState<CurrentBed[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [key, setKey] = useState(0);
const [showBedDetails, setShowBedDetails] = useState<CurrentBed | null>(null);

const fetchData = useCallback(
async (status: statusType) => {
setIsLoading(true);
const [bedsData]: any = await Promise.all([
dispatch(listConsultationBeds({ consultation: consultationId })),
]);
if (!status.aborted) {
setIsLoading(false);
if (!bedsData?.data)
Notification.Error({
msg: "Something went wrong..!",
});
else {
setConsultationBeds(bedsData.data.results);
setBed(bedsData.data.results[0]?.bed_object || {});
setAssets(bedsData.data.results[0]?.assets_objects || []);
}
const { loading } = useQuery(routes.listConsultationBeds, {
query: { consultation: consultationId },
onResponse: ({ res, data }) => {
if (res && res.status === 200 && data?.results) {
setConsultationBeds(data.results);
setBed(data?.results[0]?.bed_object || {});
setAssets(data?.results[0]?.assets_objects || []);
} else {
Notification.Error({
msg: "Something went wrong..!",
});
}
},
[consultationId, dispatch]
);
useAbortableEffect(
(status: statusType) => {
fetchData(status);
},
[dispatch, fetchData, key]
);
});

const handleSubmit = async (e: React.SyntheticEvent) => {
e.preventDefault();
Expand All @@ -88,13 +70,14 @@ const Beds = (props: BedsProps) => {
msg: "Please select a bed first..!",
});

const res: any = await dispatch(
createConsultationBed(
{ start_date: startDate, assets: assets.map((asset) => asset.id) },
consultationId,
bed?.id
)
);
const { res } = await request(routes.createConsultationBed, {
body: {
start_date: startDate,
assets: assets.map((asset) => asset.id),
consultation: consultationId,
bed: bed?.id,
},
});

if (res && res.status === 201) {
Notification.Success({
Expand All @@ -106,7 +89,7 @@ const Beds = (props: BedsProps) => {
}
};

if (isLoading) {
if (loading) {
if (props.smallLoader && props.smallLoader === true) {
return (
<div className="flex w-full items-center justify-center p-5 px-10">
Expand Down
Loading
Loading