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

(refactor) Replace usages of /ws/rest/v1 with restBaseUrl #73

Merged
merged 1 commit into from
Mar 8, 2024
Merged
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
8 changes: 6 additions & 2 deletions src/hooks/useForm.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { type FetchResponse, openmrsFetch } from "@openmrs/esm-framework";
import {
type FetchResponse,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";
import useSWR from "swr";
import { SpecificQuestion, SpecificQuestionConfig } from "../types";
import { useMemo } from "react";

const formUrl = "/ws/rest/v1/o3/forms";
const formUrl = `${restBaseUrl}/o3/forms`;

export const useSpecificQuestions = (
formUuid: string,
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useGetAllForms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import {
openmrsFetch,
userHasAccess,
useSession,
restBaseUrl,
} from "@openmrs/esm-framework";
import useSWR from "swr";

const customFormRepresentation =
"(uuid,name,display,encounterType:(uuid,name,viewPrivilege,editPrivilege),version,published,retired,resources:(uuid,name,dataType,valueReference))";

const formEncounterUrl = `/ws/rest/v1/form?v=custom:${customFormRepresentation}`;
const formEncounterUrlPoc = `/ws/rest/v1/form?v=custom:${customFormRepresentation}&q=poc`;
const formEncounterUrl = `${restBaseUrl}/form?v=custom:${customFormRepresentation}`;
const formEncounterUrlPoc = `${restBaseUrl}/form?v=custom:${customFormRepresentation}&q=poc`;

export function useGetAllForms(cachedOfflineFormsOnly = false) {
const session = useSession();
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGetEncounter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { openmrsFetch } from "@openmrs/esm-framework";
import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework";
import useSWR from "swr";

const encounterUrl = "/ws/rest/v1/encounter/";
const encounterUrl = `${restBaseUrl}/encounter/`;

const useGetEncounter = (encounterUuid) => {
const url = `${encounterUrl}${encounterUuid}`;
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGetSystemSetting.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from "react";
import { openmrsFetch } from "@openmrs/esm-framework";
import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework";

const useGetSystemSetting = (settingId) => {
const [isSubmitting, setIsSubmitting] = useState(false);
Expand All @@ -19,7 +19,7 @@ const useGetSystemSetting = (settingId) => {
}, []);

const getSetting = useCallback(() => {
openmrsFetch(`/ws/rest/v1/systemsetting?q=${settingId}&v=default`)
openmrsFetch(`${restBaseUrl}/systemsetting?q=${settingId}&v=default`)
.then(onResult)
.catch(onError);
}, [onError, onResult, settingId]);
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/usePostEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { openmrsFetch } from "@openmrs/esm-framework";
import { openmrsFetch, restBaseUrl } from "@openmrs/esm-framework";
import { useCallback, useState } from "react";

const usePostEndpoint = ({ endpointUrl }) => {
Expand Down Expand Up @@ -66,11 +66,11 @@ const usePostEndpoint = ({ endpointUrl }) => {
};

const usePostVisit = () => {
return usePostEndpoint({ endpointUrl: "/ws/rest/v1/visit" });
return usePostEndpoint({ endpointUrl: `${restBaseUrl}/visit` });
};

const usePostCohort = () => {
return usePostEndpoint({ endpointUrl: "/ws/rest/v1/cohortm/cohort" });
return usePostEndpoint({ endpointUrl: `${restBaseUrl}/cohortm/cohort` });
};

export { usePostEndpoint, usePostVisit, usePostCohort };
8 changes: 6 additions & 2 deletions src/hooks/useSearchEndpoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { openmrsFetch, FetchResponse } from "@openmrs/esm-framework";
import {
openmrsFetch,
FetchResponse,
restBaseUrl,
} from "@openmrs/esm-framework";
import { useCallback, useMemo } from "react";
import useSWRInfinite from "swr/infinite";

Expand Down Expand Up @@ -111,7 +115,7 @@ const useSearchCohortInfinite = ({
...props
}: SearchInfiniteProps): SearchResponse => {
return useSearchEndpointInfinite({
baseUrl: "/ws/rest/v1/cohortm/cohort",
baseUrl: `${restBaseUrl}/cohortm/cohort`,
resultsToFetch: 10,
...props,
});
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useStartVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
showNotification,
showToast,
openmrsFetch,
restBaseUrl,
} from "@openmrs/esm-framework";

const useStartVisit = ({
Expand Down Expand Up @@ -61,7 +62,7 @@ const useStartVisit = ({
visitType: data.visitType,
location: data.location,
};
openmrsFetch("/ws/rest/v1/visit", {
openmrsFetch(`${restBaseUrl}/visit`, {
method: "POST",
body: payload,
headers: { "Content-Type": "application/json" },
Expand All @@ -73,7 +74,7 @@ const useStartVisit = ({
);

const updateEncounter = useCallback((data) => {
openmrsFetch("/ws/rest/v1/encounter/" + data.uuid, {
openmrsFetch(`${restBaseUrl}/encounter/` + data.uuid, {
method: "POST",
body: { visit: data.visit },
headers: { "Content-Type": "application/json" },
Expand Down
Loading