Skip to content

Commit

Permalink
Move basePath and mock server option to env
Browse files Browse the repository at this point in the history
  • Loading branch information
alefalezza committed Aug 9, 2022
1 parent 2496995 commit cbb742a
Show file tree
Hide file tree
Showing 31 changed files with 181 additions and 246 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_USE_MOCK_API=
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_USE_MOCK_API=true
16 changes: 9 additions & 7 deletions .env.docker
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
GITHUB_ORG=intesys
OH_CORE_BRANCH=staging3Test
OH_API_BRANCH=staging3Test
API_VERSION=0.0.1
API_PORT:8080

MYSQL_TAG=8.0.25
MYSQL_DATABASE=oh
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_USER=isf
MYSQL_PASSWORD=isf123

GITHUB_ORG=intesys
OH_CORE_BRANCH=staging3Test
OH_API_BRANCH=staging3Test
API_VERSION=0.0.1
API_PORT:8080

NODE_ENV=development
PUBLIC_URL=/
REACT_APP_USE_MOCK_API=
REACT_APP_BASE_PATH=http://localhost:8080/oh-api
3 changes: 2 additions & 1 deletion .env.gh-pages
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PUBLIC_URL=/openhospital-ui
PUBLIC_URL=/openhospital-ui
REACT_APP_USE_MOCK_API=
3 changes: 2 additions & 1 deletion .env.staging
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PUBLIC_URL=/oh20
PUBLIC_URL=/oh20
REACT_APP_USE_MOCK_API=
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_USE_MOCK_API=true
5 changes: 3 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
build:
context: ./
dockerfile: ./docker/Dockerfile.frontend
args:
PUBLIC_URL: /
env_file:
- .env.docker
ports:
- 3000:3000
volumes:
Expand All @@ -19,6 +19,7 @@ services:
networks:
- openhospital
stdin_open: true

backend:
build:
context: ./docker
Expand Down
9 changes: 3 additions & 6 deletions docker/Dockerfile.frontend
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
FROM node:lts

ARG PUBLIC_URL

ENV NODE_ENV=development
ENV PUBLIC_URL=/
ENV REACT_APP_USE_MOCK_API=
ENV REACT_APP_BASE_PATH=/

VOLUME /oh

WORKDIR /oh

COPY ../package*.json /oh

RUN npm ci --legacy-peer-deps

CMD npm start
Expand Down
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import diseaseTypes from "./state/diseaseTypes/reducer";
import examTypes from "./state/examTypes/reducer";
import ageTypes from "./state/ageTypes/reducer";

if (process.env.NODE_ENV === "development") {
if (process.env.REACT_APP_USE_MOCK_API) {
console.log("Using mocked api");
makeServer();
}

Expand Down
13 changes: 13 additions & 0 deletions src/libraries/apiUtils/configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { BASE_PATH, Configuration } from "../../generated";
import { applyTokenMiddleware } from "./applyTokenMiddleware";

const basePath = process.env.REACT_APP_BASE_PATH || BASE_PATH;

export const customConfiguration = (authenticated = true) => {
return authenticated
? new Configuration({
basePath,
middleware: [applyTokenMiddleware],
})
: new Configuration({ basePath });
};
10 changes: 3 additions & 7 deletions src/state/admissionTypes/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Dispatch } from "redux";
import {
Configuration,
AdmissionDTO,
AdmissionTypeControllerApi,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { AdmissionDTO, AdmissionTypeControllerApi } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
GET_ADMISSIONTYPE_FAIL,
Expand All @@ -14,7 +10,7 @@ import {
} from "./consts";

const admissionTypeControllerApi = new AdmissionTypeControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
customConfiguration()
);

export const getAdmissionTypes =
Expand Down
28 changes: 12 additions & 16 deletions src/state/admissions/actions.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
import { isEmpty } from "lodash";
import { Dispatch } from "redux";
import {
Configuration,
AdmissionDTO,
AdmissionControllerApi,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { AdmissionControllerApi, AdmissionDTO } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
CREATE_ADMISSION_FAIL,
CREATE_ADMISSION_LOADING,
CREATE_ADMISSION_RESET,
CREATE_ADMISSION_SUCCESS,
UPDATE_ADMISSION_FAIL,
UPDATE_ADMISSION_LOADING,
UPDATE_ADMISSION_RESET,
UPDATE_ADMISSION_SUCCESS,
DISCHARGE_PATIENT_FAIL,
DISCHARGE_PATIENT_LOADING,
DISCHARGE_PATIENT_RESET,
DISCHARGE_PATIENT_SUCCESS,
GET_ADMISSION_FAIL,
GET_ADMISSION_LOADING,
GET_ADMISSION_SUCCESS,
GET_ADMISSION_SUCCESS_EMPTY,
GET_CURRENTADMISSION_EMPTY,
GET_CURRENTADMISSION_FAIL,
GET_CURRENTADMISSION_LOADING,
GET_CURRENTADMISSION_SUCCESS,
GET_CURRENTADMISSION_EMPTY,
DISCHARGE_PATIENT_LOADING,
DISCHARGE_PATIENT_SUCCESS,
DISCHARGE_PATIENT_FAIL,
DISCHARGE_PATIENT_RESET,
UPDATE_ADMISSION_FAIL,
UPDATE_ADMISSION_LOADING,
UPDATE_ADMISSION_RESET,
UPDATE_ADMISSION_SUCCESS,
} from "./consts";

const admissionControllerApi = new AdmissionControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
customConfiguration()
);

export const createAdmission =
Expand Down
12 changes: 3 additions & 9 deletions src/state/ageTypes/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Dispatch } from "redux";
import {
Configuration,
AdmissionDTO,
AgeTypeControllerApi,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { AdmissionDTO, AgeTypeControllerApi } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
GET_AGETYPES_FAIL,
Expand All @@ -13,9 +9,7 @@ import {
GET_AGETYPES_SUCCESS_EMPTY,
} from "./consts";

const ageTypeControllerApi = new AgeTypeControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
);
const ageTypeControllerApi = new AgeTypeControllerApi(customConfiguration());

export const getAgeTypes =
() =>
Expand Down
67 changes: 32 additions & 35 deletions src/state/bills/actions.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,56 @@
import { Dispatch } from "redux";
import { map, catchError, switchMap } from "rxjs/operators";
import { of, Observable, forkJoin } from "rxjs";
import isEmpty from "lodash.isempty";
import { Dispatch } from "redux";
import { forkJoin, Observable, of } from "rxjs";
import { catchError, map, switchMap } from "rxjs/operators";
import { TFilterValues } from "../../components/accessories/billTable/types";
import {
Configuration,
BillControllerApi,
BillDTO,
FullBillDTO,
BillItemsDTO,
BillPaymentsDTO,
FullBillDTO,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
CLOSE_BILL_FAIL,
CLOSE_BILL_LOADING,
CLOSE_BILL_RESET,
CLOSE_BILL_SUCCESS,
DELETE_BILL_FAIL,
DELETE_BILL_LOADING,
DELETE_BILL_RESET,
DELETE_BILL_SUCCESS,
EDIT_BILL_FAIL,
EDIT_BILL_LOADING,
EDIT_BILL_RESET,
EDIT_BILL_SUCCESS,
GET_BILL_FAIL,
GET_BILL_LOADING,
GET_BILL_SUCCESS,
NEW_BILL_FAIL,
NEW_BILL_LOADING,
NEW_BILL_SUCCESS,
NEW_BILL_RESET,
NEW_BILL_SUCCESS,
PENDING_BILL_FAIL,
PENDING_BILL_LOADING,
PENDING_BILL_SUCCESS,
SEARCH_BILLS_BY_YEAR_FAIL,
SEARCH_BILLS_BY_YEAR_LOADING,
SEARCH_BILLS_BY_YEAR_SUCCESS,
SEARCH_BILL_FAIL,
SEARCH_BILL_LOADING,
SEARCH_BILL_SUCCESS,
GET_BILL_LOADING,
GET_BILL_SUCCESS,
GET_BILL_FAIL,
PENDING_BILL_SUCCESS,
PENDING_BILL_FAIL,
PENDING_BILL_LOADING,
SEARCH_PAYMENTS_SUCCESS,
SEARCH_PAYMENTS_FAIL,
SEARCH_PAYMENTS_LOADING,
DELETE_BILL_FAIL,
DELETE_BILL_LOADING,
DELETE_BILL_SUCCESS,
DELETE_BILL_RESET,
EDIT_BILL_LOADING,
EDIT_BILL_SUCCESS,
EDIT_BILL_FAIL,
EDIT_BILL_RESET,
CLOSE_BILL_FAIL,
CLOSE_BILL_SUCCESS,
CLOSE_BILL_LOADING,
CLOSE_BILL_RESET,
UPDATE_BILL_LOADING,
UPDATE_BILL_SUCCESS,
SEARCH_PAYMENTS_SUCCESS,
UPDATE_BILL_FAIL,
UPDATE_BILL_LOADING,
UPDATE_BILL_RESET,
SEARCH_BILLS_BY_YEAR_LOADING,
SEARCH_BILLS_BY_YEAR_SUCCESS,
SEARCH_BILLS_BY_YEAR_FAIL,
UPDATE_BILL_SUCCESS,
} from "./consts";
import { TFilterValues } from "../../components/accessories/billTable/types";

const billControllerApi = new BillControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
);
const billControllerApi = new BillControllerApi(customConfiguration());

export const newBill =
(newBillDto: FullBillDTO) =>
Expand Down
10 changes: 3 additions & 7 deletions src/state/dischargeTypes/actions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Dispatch } from "redux";
import {
Configuration,
AdmissionDTO,
DischargeTypeControllerApi,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { AdmissionDTO, DischargeTypeControllerApi } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
GET_DISCHARGETYPE_FAIL,
Expand All @@ -14,7 +10,7 @@ import {
} from "./consts";

const dischargeTypeControllerApi = new DischargeTypeControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
customConfiguration()
);

export const getDischargeTypes =
Expand Down
12 changes: 3 additions & 9 deletions src/state/diseaseTypes/actions.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import isEmpty from "lodash.isempty";
import { Dispatch } from "redux";
import {
Configuration,
DiseaseControllerApi,
DiseaseDTO,
DiseaseTypeControllerApi,
DiseaseTypeDTO,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { DiseaseTypeControllerApi, DiseaseTypeDTO } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
GET_DISEASETYPE_FAIL,
Expand All @@ -16,7 +10,7 @@ import {
} from "./consts";

const desaseTypeControllerApi = new DiseaseTypeControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
customConfiguration()
);

export const getDiseaseTypes =
Expand Down
20 changes: 7 additions & 13 deletions src/state/diseases/actions.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import isEmpty from "lodash.isempty";
import { Dispatch } from "redux";
import {
Configuration,
DiseaseControllerApi,
DiseaseDTO,
} from "../../generated";
import { applyTokenMiddleware } from "../../libraries/apiUtils/applyTokenMiddleware";
import { DiseaseControllerApi, DiseaseDTO } from "../../generated";
import { customConfiguration } from "../../libraries/apiUtils/configuration";
import { IAction } from "../types";
import {
GET_DISEASE_FAIL,
GET_DISEASE_LOADING,
GET_DISEASE_SUCCESS,
GET_DISEASEIPDIN_FAIL,
GET_DISEASEIPDIN_LOADING,
GET_DISEASEIPDIN_SUCCESS,
GET_DISEASEIPDOUT_FAIL,
GET_DISEASEIPDOUT_SUCCESS,
GET_DISEASEIPDOUT_LOADING,
GET_DISEASEIPDOUT_SUCCESS,
GET_DISEASE_FAIL,
GET_DISEASE_LOADING,
GET_DISEASE_SUCCESS,
} from "./consts";

const desaseControllerApi = new DiseaseControllerApi(
new Configuration({ middleware: [applyTokenMiddleware] })
);
const desaseControllerApi = new DiseaseControllerApi(customConfiguration());

export const getDiseasesOpd =
() =>
Expand Down
Loading

0 comments on commit cbb742a

Please sign in to comment.