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

cleanup fireRequests and remove axios #6003

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
46 changes: 2 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"@sentry/browser": "^7.57.0",
"@storybook/builder-vite": "^7.0.26",
"@yaireo/ui-range": "^2.1.15",
"axios": "^1.4.0",
"browser-image-compression": "^2.0.2",
"cross-env": "^7.0.3",
"date-fns": "^2.30.0",
Expand Down
31 changes: 14 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IConfig } from "./Common/hooks/useConfig";
import { LocalStorageKeys } from "./Common/constants";
import Plausible from "./Components/Common/Plausible";
import SessionRouter from "./Router/SessionRouter";
import axios from "axios";
import loadable from "@loadable/component";

const Loading = loadable(() => import("./Components/Common/Loading"));
Expand Down Expand Up @@ -40,23 +39,21 @@ const App: React.FC = () => {

const updateRefreshToken = () => {
const refresh = localStorage.getItem(LocalStorageKeys.refreshToken);
// const access = localStorage.getItem(LocalStorageKeys.accessToken);
// if (!access && refresh) {
// localStorage.removeItem(LocalStorageKeys.refreshToken);
// document.location.reload();
// return;
// }
if (!refresh) {
return;
}
axios
.post("/api/v1/auth/token/refresh/", {
refresh,
if (refresh) {
fetch("/api/v1/auth/token/refresh/", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ refresh }),
})
.then((resp) => {
localStorage.setItem(LocalStorageKeys.accessToken, resp.data.access);
localStorage.setItem(LocalStorageKeys.refreshToken, resp.data.refresh);
});
.then((res) => res.json())
.then((resp) => {
localStorage.setItem(LocalStorageKeys.accessToken, resp.access);
localStorage.setItem(LocalStorageKeys.refreshToken, resp.refresh);
});
}
};
useEffect(() => {
updateRefreshToken();
Expand Down
13 changes: 8 additions & 5 deletions src/Common/hooks/useMSEplayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useRef } from "react";
import axios from "axios";

export interface IAsset {
middlewareHostname: string;
Expand Down Expand Up @@ -59,10 +58,14 @@ const stopStream =
(payload: { id: string }, options: IOptions) => {
const { id } = payload;
ws?.close();
axios
.post(`https://${middlewareHostname}/stop`, {
id,
})
fetch(`https://${middlewareHostname}/stop`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ id }),
})
.then((res) => options?.onSuccess && options.onSuccess(res))
.catch((err) => options.onError && options.onError(err));
};
Expand Down
11 changes: 6 additions & 5 deletions src/Components/Assets/AssetType/ONVIFCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from "../../../Redux/actions";
import * as Notification from "../../../Utils/Notifications.js";
import { BedModel } from "../../Facility/models";
import axios from "axios";
import { getCameraConfig } from "../../../Utils/transformUtils";
import CameraConfigure from "../configure/CameraConfigure";
import Loading from "../../Common/Loading";
Expand Down Expand Up @@ -110,13 +109,15 @@ const ONVIFCamera = (props: ONVIFCameraProps) => {
};
try {
setLoadingAddPreset(true);
const presetData = await axios.get(
`https://${facilityMiddlewareHostname}/status?hostname=${config.hostname}&port=${config.port}&username=${config.username}&password=${config.password}`
);
const preset = await fetch(
`https://${facilityMiddlewareHostname}/preset?hostname=${config.hostname}\
&port=${config.port}&username=${config.username}&password=${config.password}\
&preset_name=${newPreset}`
).then((res) => res.json());
const res: any = await Promise.resolve(
dispatch(
createAssetBed(
{ meta: { ...data, ...presetData.data } },
{ meta: { ...data, ...preset.data } },
assetId,
bed?.id as string
)
Expand Down
6 changes: 3 additions & 3 deletions src/Components/CriticalCareRecording/CriticalCare__API.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { fireRequestV2 } from "../../Redux/fireRequest";
import { legacyFireRequest } from "../../Redux/fireRequest";

export const loadDailyRound = (
consultationId: string,
id: string,
successCB: any = () => null,
errorCB: any = () => null
) => {
fireRequestV2("getDailyReport", [], {}, successCB, errorCB, {
legacyFireRequest("getDailyReport", [], {}, successCB, errorCB, {
consultationId,
id,
});
Expand All @@ -19,7 +19,7 @@ export const updateDailyRound = (
successCB: any = () => null,
errorCB: any = () => null
) => {
fireRequestV2("updateDailyRound", [], params, successCB, errorCB, {
legacyFireRequest("updateDailyRound", [], params, successCB, errorCB, {
consultationId,
id,
});
Expand Down
8 changes: 3 additions & 5 deletions src/Components/Facility/Consultations/LiveFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import { useFeedPTZ } from "../../../Common/hooks/useFeedPTZ";
import * as Notification from "../../../Utils/Notifications.js";
import { FeedCameraPTZHelpButton } from "./Feed";
import { AxiosError } from "axios";
import { BedSelect } from "../../Common/BedSelect";
import { BedModel } from "../models";
import useWindowDimensions from "../../../Common/hooks/useWindowDimensions";
Expand Down Expand Up @@ -93,10 +92,9 @@ const LiveFeed = (props: any) => {
setPresets(resp);
},
onError: (resp) => {
resp instanceof AxiosError &&
Notification.Error({
msg: "Camera is offline",
});
Notification.Error({
msg: "Camera is offline",
});
},
});

Expand Down
8 changes: 4 additions & 4 deletions src/Components/Facility/CoverImageEditModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import {
ChangeEventHandler,
useCallback,
Expand Down Expand Up @@ -110,17 +109,18 @@ const CoverImageEditModal = ({

setIsUploading(true);
try {
const response = await axios.post(
const response = await fetch(
`/api/v1/facility/${facility.id}/cover_image/`,
formData,
{
method: "POST",
headers: {
"Content-Type": "multipart/form-data",
Authorization:
"Bearer " + localStorage.getItem(LocalStorageKeys.accessToken),
},
body: formData,
}
);
)
if (response.status === 200) {
Success({ msg: "Cover image updated." });
window.location.reload();
Expand Down
21 changes: 3 additions & 18 deletions src/Components/Patient/FileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import CircularProgress from "../Common/components/CircularProgress";
import loadable from "@loadable/component";
import React, { useCallback, useState, useEffect, useRef } from "react";
Expand Down Expand Up @@ -32,6 +31,7 @@ import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import AuthorizedChild from "../../CAREUI/misc/AuthorizedChild";
import Page from "../Common/components/Page";
import FilePreviewDialog from "../Common/FilePreviewDialog";
import { uploadFile } from "../../Redux/fireRequest";

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

Expand Down Expand Up @@ -928,24 +928,10 @@ export const FileUpload = (props: FileUploadProps) => {
if (!f) return;
const newFile = new File([f], `${internal_name}`);

const config = {
headers: {
"Content-type": contentType,
"Content-disposition": "inline",
},
onUploadProgress: (progressEvent: any) => {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
setUploadPercent(percentCompleted);
},
};
return new Promise<void>((resolve, reject) => {
axios
.put(url, newFile, config)
uploadFile(url, newFile, contentType, setUploadPercent)
.then(() => {
setUploadStarted(false);
// setUploadSuccess(true);
setFile(null);
setUploadFileName("");
setReload(!reload);
Expand Down Expand Up @@ -1049,8 +1035,7 @@ export const FileUpload = (props: FileUploadProps) => {
},
};

axios
.put(url, newFile, config)
uploadFile(url, newFile, "audio/mpeg", setUploadPercent)
.then(() => {
setAudioUploadStarted(false);
// setUploadSuccess(true);
Expand Down
51 changes: 18 additions & 33 deletions src/Components/Patient/UpdateStatusDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useEffect, useState, useReducer } from "react";
import axios from "axios";
import {
SAMPLE_TEST_STATUS,
SAMPLE_TEST_RESULT,
Expand All @@ -9,7 +8,7 @@ import { SampleTestModel } from "./models";
import * as Notification from "../../Utils/Notifications.js";
import { createUpload, editUpload } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { header_content_type, LinearProgressWithLabel } from "./FileUpload";
import { FileUpload, header_content_type, LinearProgressWithLabel } from "./FileUpload";
import { Submit } from "../Common/components/ButtonV2";
import CareIcon from "../../CAREUI/icons/CareIcon";
import ConfirmDialog from "../Common/ConfirmDialog";
Expand All @@ -18,6 +17,7 @@ import { FieldChangeEvent } from "../Form/FormFields/Utils";
import TextFormField from "../Form/FormFields/TextFormField";
import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField";
import { useTranslation } from "react-i18next";
import { uploadFile } from "../../Redux/fireRequest";

interface Props {
sample: SampleTestModel;
Expand Down Expand Up @@ -105,38 +105,23 @@ const UpdateStatusDialog = (props: Props) => {
if (f === undefined) return;
const newFile = new File([f], `${internal_name}`);

const config = {
headers: {
"Content-type": contentType,
"Content-disposition": "inline",
},
onUploadProgress: (progressEvent: any) => {
const percentCompleted = Math.round(
(progressEvent.loaded * 100) / progressEvent.total
);
setUploadPercent(percentCompleted);
},
};
axios
.put(url, newFile, config)
.then(() => {
setUploadStarted(false);
setUploadDone(true);
redux_dispatch(
editUpload(
{ upload_completed: true },
response.data.id,
"SAMPLE_MANAGEMENT",
sample.id?.toString() ?? ""
)
);
Notification.Success({
msg: "File Uploaded Successfully",
});
})
.catch(() => {
setUploadStarted(false);
uploadFile(url, newFile, contentType, setUploadPercent).then(() => {
setUploadStarted(false);
setUploadDone(true);
redux_dispatch(
editUpload(
{ upload_completed: true },
response.data.id,
"SAMPLE_MANAGEMENT",
sample.id?.toString() ?? ""
)
);
Notification.Success({
msg: "File Uploaded Successfully",
});
}).catch(() => {
setUploadStarted(false);
});
};

const onFileChange = (e: React.ChangeEvent<HTMLInputElement>): any => {
Expand Down
Loading
Loading