Skip to content

Commit

Permalink
feat: sdp tenant name headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaromao committed Oct 31, 2023
1 parent 1ae0155 commit bf8b707
Show file tree
Hide file tree
Showing 19 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api/getDisbursementDetails.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiDisbursement } from "types";

export const getDisbursementDetails = async (
Expand All @@ -11,6 +12,7 @@ export const getDisbursementDetails = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/api/getDisbursementDrafts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL, UI_STATUS_DISBURSEMENT_DRAFT } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiDisbursements } from "types";

export const getDisbursementDrafts = async (
Expand All @@ -13,6 +14,7 @@ export const getDisbursementDrafts = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/api/getDisbursementInstructions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { API_URL, SESSION_EXPIRED } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";

export const getDisbursementInstructions = async (
token: string,
Expand All @@ -10,6 +11,7 @@ export const getDisbursementInstructions = async (
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/api/getDisbursementReceivers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { handleApiResponse } from "api/handleApiResponse";
import { handleSearchParams } from "api/handleSearchParams";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiDisbursementReceivers, PaginationParams } from "types";

export const getDisbursementReceivers = async (
Expand All @@ -17,6 +18,7 @@ export const getDisbursementReceivers = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
},
);
Expand Down
2 changes: 2 additions & 0 deletions src/api/getDisbursements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { handleApiResponse } from "api/handleApiResponse";
import { handleSearchParams } from "api/handleSearchParams";
import { API_URL, UI_STATUS_DISBURSEMENT } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiDisbursements, PaymentsSearchParams } from "types";

export const getDisbursements = async (
Expand All @@ -22,6 +23,7 @@ export const getDisbursements = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/api/getOrgInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiOrgInfo } from "types";

export const getOrgInfo = async (token: string): Promise<ApiOrgInfo> => {
Expand All @@ -8,6 +9,7 @@ export const getOrgInfo = async (token: string): Promise<ApiOrgInfo> => {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/api/getProfileInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiProfileInfo } from "types";

export const getProfileInfo = async (
Expand All @@ -10,6 +11,7 @@ export const getProfileInfo = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/api/patchDisbursementStatus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { DisbursementStatus } from "types";

export const patchDisbursementStatus = async (
Expand All @@ -14,6 +15,7 @@ export const patchDisbursementStatus = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: JSON.stringify({
status,
Expand Down
2 changes: 2 additions & 0 deletions src/api/patchOrgInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { sanitizeObject } from "helpers/sanitizeObject";
import { OrgUpdateInfo } from "types";

Expand Down Expand Up @@ -45,6 +46,7 @@ export const patchOrgInfo = async (
method: "PATCH",
headers: {
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: formData,
});
Expand Down
2 changes: 2 additions & 0 deletions src/api/patchProfileInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { sanitizeObject } from "helpers/sanitizeObject";

export const patchProfileInfo = async (
Expand All @@ -24,6 +25,7 @@ export const patchProfileInfo = async (
method: "PATCH",
headers: {
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: JSON.stringify(fieldsToSubmit),
});
Expand Down
2 changes: 2 additions & 0 deletions src/api/patchUserRole.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { UserRole } from "types";

export const patchUserRole = async (
Expand All @@ -12,6 +13,7 @@ export const patchUserRole = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: JSON.stringify({
user_id: userId,
Expand Down
2 changes: 2 additions & 0 deletions src/api/postDisbursement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";
import { ApiDisbursement, Disbursement } from "types";

export const postDisbursement = async (
Expand All @@ -11,6 +12,7 @@ export const postDisbursement = async (
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: JSON.stringify({
name: disbursement.name,
Expand Down
2 changes: 2 additions & 0 deletions src/api/postDisbursementFile.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { handleApiResponse } from "api/handleApiResponse";
import { API_URL } from "constants/settings";
import { getSdpTenantName } from "helpers/getSdpTenantName";

export const postDisbursementFile = async (
token: string,
Expand All @@ -15,6 +16,7 @@ export const postDisbursementFile = async (
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
body: formData,
},
Expand Down
2 changes: 2 additions & 0 deletions src/api/refreshToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { differenceInMinutes, fromUnixTime } from "date-fns";
import { API_URL, SESSION_EXPIRED } from "constants/settings";
import { parseJwt } from "helpers/parseJwt";
import { getSdpTenantName } from "helpers/getSdpTenantName";

export const refreshToken = async (token: string): Promise<string> => {
const jwt = parseJwt(token);
Expand All @@ -15,6 +16,7 @@ export const refreshToken = async (token: string): Promise<string> => {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/helpers/fetchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { localStorageSessionToken } from "helpers/localStorageSessionToken";
import { parseJwt } from "helpers/parseJwt";
import { normalizeApiError } from "helpers/normalizeApiError";
import { AnyObject } from "types";
import { getSdpTenantName } from "./getSdpTenantName";

type FetchApiOptions = {
withoutAuth?: boolean;
Expand Down Expand Up @@ -42,6 +43,7 @@ export const fetchApi = async (
config.headers = {
...config.headers,
Authorization: `Bearer ${token}`,
SDP_TENANT_NAME: getSdpTenantName(),
...(!options?.omitContentType
? {
"Content-Type":
Expand Down
1 change: 1 addition & 0 deletions src/helpers/getSdpTenantName.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const getSdpTenantName = () => window.location.hostname.split(".")[0];
3 changes: 3 additions & 0 deletions src/pages/MFAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "constants/settings";
import { useRedux } from "hooks/useRedux";
import { mfaAction, signInAction } from "store/ducks/userAccount";
import { getSdpTenantName } from "helpers/getSdpTenantName";

export const MFAuth = () => {
const dispatch: AppDispatch = useDispatch();
Expand Down Expand Up @@ -73,6 +74,7 @@ export const MFAuth = () => {

const headers = {
"Device-ID": deviceId,
SDP_TENANT_NAME: getSdpTenantName(),
};

dispatch(mfaAction({ mfaCode, rememberMe, recaptchaToken, headers }));
Expand All @@ -88,6 +90,7 @@ export const MFAuth = () => {

const headers = {
"Device-ID": deviceId,
SDP_TENANT_NAME: getSdpTenantName(),
};

if (email && password) {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from "constants/settings";
import { useRedux } from "hooks/useRedux";
import { signInRedirect } from "helpers/singleSingOn";
import { getSdpTenantName } from "helpers/getSdpTenantName";

export const SignIn = () => {
const dispatch: AppDispatch = useDispatch();
Expand Down Expand Up @@ -88,6 +89,7 @@ export const SignIn = () => {

const headers = {
"Device-ID": deviceId,
SDP_TENANT_NAME: getSdpTenantName(),
};

dispatch(signInAction({ email, password, recaptchaToken, headers }));
Expand Down
1 change: 1 addition & 0 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = merge(common, {
port: 3000,
open: true,
hot: true,
allowedHosts: "all",
},
});

0 comments on commit bf8b707

Please sign in to comment.