From bf8b70730f961291b39955e3021b513f1166b379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cec=C3=ADlia=20Rom=C3=A3o?= Date: Tue, 31 Oct 2023 14:40:30 -0300 Subject: [PATCH] feat: sdp tenant name headers --- src/api/getDisbursementDetails.ts | 2 ++ src/api/getDisbursementDrafts.ts | 2 ++ src/api/getDisbursementInstructions.ts | 2 ++ src/api/getDisbursementReceivers.ts | 2 ++ src/api/getDisbursements.ts | 2 ++ src/api/getOrgInfo.ts | 2 ++ src/api/getProfileInfo.ts | 2 ++ src/api/patchDisbursementStatus.ts | 2 ++ src/api/patchOrgInfo.ts | 2 ++ src/api/patchProfileInfo.ts | 2 ++ src/api/patchUserRole.ts | 2 ++ src/api/postDisbursement.ts | 2 ++ src/api/postDisbursementFile.ts | 2 ++ src/api/refreshToken.ts | 2 ++ src/helpers/fetchApi.ts | 2 ++ src/helpers/getSdpTenantName.ts | 1 + src/pages/MFAuth.tsx | 3 +++ src/pages/SignIn.tsx | 2 ++ webpack.dev.js | 1 + 19 files changed, 37 insertions(+) create mode 100644 src/helpers/getSdpTenantName.ts diff --git a/src/api/getDisbursementDetails.ts b/src/api/getDisbursementDetails.ts index 05cf232..5eefcfa 100644 --- a/src/api/getDisbursementDetails.ts +++ b/src/api/getDisbursementDetails.ts @@ -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 ( @@ -11,6 +12,7 @@ export const getDisbursementDetails = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }); diff --git a/src/api/getDisbursementDrafts.ts b/src/api/getDisbursementDrafts.ts index 4a46008..02cb938 100644 --- a/src/api/getDisbursementDrafts.ts +++ b/src/api/getDisbursementDrafts.ts @@ -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 ( @@ -13,6 +14,7 @@ export const getDisbursementDrafts = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }, ); diff --git a/src/api/getDisbursementInstructions.ts b/src/api/getDisbursementInstructions.ts index e4c3bd0..16c7e0f 100644 --- a/src/api/getDisbursementInstructions.ts +++ b/src/api/getDisbursementInstructions.ts @@ -1,4 +1,5 @@ import { API_URL, SESSION_EXPIRED } from "constants/settings"; +import { getSdpTenantName } from "helpers/getSdpTenantName"; export const getDisbursementInstructions = async ( token: string, @@ -10,6 +11,7 @@ export const getDisbursementInstructions = async ( method: "GET", headers: { Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }, ); diff --git a/src/api/getDisbursementReceivers.ts b/src/api/getDisbursementReceivers.ts index 49a7c9d..9085d23 100644 --- a/src/api/getDisbursementReceivers.ts +++ b/src/api/getDisbursementReceivers.ts @@ -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 ( @@ -17,6 +18,7 @@ export const getDisbursementReceivers = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }, ); diff --git a/src/api/getDisbursements.ts b/src/api/getDisbursements.ts index f59396a..51e3b4b 100644 --- a/src/api/getDisbursements.ts +++ b/src/api/getDisbursements.ts @@ -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 ( @@ -22,6 +23,7 @@ export const getDisbursements = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }); diff --git a/src/api/getOrgInfo.ts b/src/api/getOrgInfo.ts index 761fb2b..633bdb6 100644 --- a/src/api/getOrgInfo.ts +++ b/src/api/getOrgInfo.ts @@ -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 => { @@ -8,6 +9,7 @@ export const getOrgInfo = async (token: string): Promise => { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }); diff --git a/src/api/getProfileInfo.ts b/src/api/getProfileInfo.ts index 700faae..820db0b 100644 --- a/src/api/getProfileInfo.ts +++ b/src/api/getProfileInfo.ts @@ -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 ( @@ -10,6 +11,7 @@ export const getProfileInfo = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }); diff --git a/src/api/patchDisbursementStatus.ts b/src/api/patchDisbursementStatus.ts index 1a17ee9..9c36129 100644 --- a/src/api/patchDisbursementStatus.ts +++ b/src/api/patchDisbursementStatus.ts @@ -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 ( @@ -14,6 +15,7 @@ export const patchDisbursementStatus = async ( headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, body: JSON.stringify({ status, diff --git a/src/api/patchOrgInfo.ts b/src/api/patchOrgInfo.ts index 9eb8432..6c15d22 100644 --- a/src/api/patchOrgInfo.ts +++ b/src/api/patchOrgInfo.ts @@ -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"; @@ -45,6 +46,7 @@ export const patchOrgInfo = async ( method: "PATCH", headers: { Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, body: formData, }); diff --git a/src/api/patchProfileInfo.ts b/src/api/patchProfileInfo.ts index a5d9b16..76738ab 100644 --- a/src/api/patchProfileInfo.ts +++ b/src/api/patchProfileInfo.ts @@ -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 ( @@ -24,6 +25,7 @@ export const patchProfileInfo = async ( method: "PATCH", headers: { Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, body: JSON.stringify(fieldsToSubmit), }); diff --git a/src/api/patchUserRole.ts b/src/api/patchUserRole.ts index 5d6405e..e490bf1 100644 --- a/src/api/patchUserRole.ts +++ b/src/api/patchUserRole.ts @@ -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 ( @@ -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, diff --git a/src/api/postDisbursement.ts b/src/api/postDisbursement.ts index 2085e6f..c4b82ce 100644 --- a/src/api/postDisbursement.ts +++ b/src/api/postDisbursement.ts @@ -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 ( @@ -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, diff --git a/src/api/postDisbursementFile.ts b/src/api/postDisbursementFile.ts index 131649d..a2ab499 100644 --- a/src/api/postDisbursementFile.ts +++ b/src/api/postDisbursementFile.ts @@ -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, @@ -15,6 +16,7 @@ export const postDisbursementFile = async ( method: "POST", headers: { Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, body: formData, }, diff --git a/src/api/refreshToken.ts b/src/api/refreshToken.ts index 7a3028f..56fe068 100644 --- a/src/api/refreshToken.ts +++ b/src/api/refreshToken.ts @@ -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 => { const jwt = parseJwt(token); @@ -15,6 +16,7 @@ export const refreshToken = async (token: string): Promise => { headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), }, }); diff --git a/src/helpers/fetchApi.ts b/src/helpers/fetchApi.ts index fc4c4a4..9abfa0b 100644 --- a/src/helpers/fetchApi.ts +++ b/src/helpers/fetchApi.ts @@ -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; @@ -42,6 +43,7 @@ export const fetchApi = async ( config.headers = { ...config.headers, Authorization: `Bearer ${token}`, + SDP_TENANT_NAME: getSdpTenantName(), ...(!options?.omitContentType ? { "Content-Type": diff --git a/src/helpers/getSdpTenantName.ts b/src/helpers/getSdpTenantName.ts new file mode 100644 index 0000000..d7028f5 --- /dev/null +++ b/src/helpers/getSdpTenantName.ts @@ -0,0 +1 @@ +export const getSdpTenantName = () => window.location.hostname.split(".")[0]; diff --git a/src/pages/MFAuth.tsx b/src/pages/MFAuth.tsx index a6498a4..d941f73 100644 --- a/src/pages/MFAuth.tsx +++ b/src/pages/MFAuth.tsx @@ -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(); @@ -73,6 +74,7 @@ export const MFAuth = () => { const headers = { "Device-ID": deviceId, + SDP_TENANT_NAME: getSdpTenantName(), }; dispatch(mfaAction({ mfaCode, rememberMe, recaptchaToken, headers })); @@ -88,6 +90,7 @@ export const MFAuth = () => { const headers = { "Device-ID": deviceId, + SDP_TENANT_NAME: getSdpTenantName(), }; if (email && password) { diff --git a/src/pages/SignIn.tsx b/src/pages/SignIn.tsx index e2ce17d..e1e2bc0 100644 --- a/src/pages/SignIn.tsx +++ b/src/pages/SignIn.tsx @@ -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(); @@ -88,6 +89,7 @@ export const SignIn = () => { const headers = { "Device-ID": deviceId, + SDP_TENANT_NAME: getSdpTenantName(), }; dispatch(signInAction({ email, password, recaptchaToken, headers })); diff --git a/webpack.dev.js b/webpack.dev.js index 6c455c5..8f7f8b7 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -11,5 +11,6 @@ module.exports = merge(common, { port: 3000, open: true, hot: true, + allowedHosts: "all", }, });