TP-62646 | RN Quote | API unification (POST + GET) (#10942)
This commit is contained in:
committed by
GitHub
parent
eb0c48c6c5
commit
c3ec7e8548
@@ -173,7 +173,7 @@ const QuoteOfferScreen = ({
|
||||
postApiCalled === "true"
|
||||
? ScreenActionTypes.FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND
|
||||
: preQuoteId
|
||||
? ScreenActionTypes.FETCH_QUOTE_V3
|
||||
? ScreenActionTypes.FETCH_QUOTE_V4
|
||||
: ScreenActionTypes.FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND;
|
||||
const data: QuoteOfferRequest = {
|
||||
preQuoteId: preQuoteId ? preQuoteId : undefined,
|
||||
|
||||
@@ -24,6 +24,7 @@ export const AnalyticsModuleNameConstant = {
|
||||
export const AnalyticsMethodNameConstant = {
|
||||
FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND: "fetchInsuranceQuotePageFromBackend",
|
||||
FETCH_QUOTE_V3: "fetchQuoteV3",
|
||||
FETCH_QUOTE_V4: "fetchQuoteV4",
|
||||
FINAL_PATCH_CALL: "finalPatchCall",
|
||||
COMPARE_PLAN_LIST : "comparePlanList",
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { CtaData } from "../..";
|
||||
import { AnalyticsEvent, CtaData } from "../..";
|
||||
import { Widget } from "../Widget";
|
||||
|
||||
export interface ScreenMetaData {
|
||||
@@ -6,6 +6,7 @@ export interface ScreenMetaData {
|
||||
redirectionCta?: CtaData;
|
||||
floatingWidgets?: Widget[];
|
||||
screenProperties?: Array<LineItem>;
|
||||
analyticsEvent?: AnalyticsEvent;
|
||||
}
|
||||
|
||||
type LineItem = {
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
import { ActionMetaData, BaseActionTypes } from "../actions/GenericAction";
|
||||
import { ScreenData } from "../interface/widgets/screenData/ScreenData";
|
||||
import { ScreenActionTypes } from "./ScreenActionTypes";
|
||||
import { Dispatch, SetStateAction } from "react";
|
||||
import { post, get } from "../../../network/NetworkService";
|
||||
import { CtaData } from "../interface";
|
||||
import { getXTargetHeaderInfo } from "../../../network/ApiClient";
|
||||
import { GI } from "../constants/NavigationHandlerConstants";
|
||||
import { ScreenState } from "./BaseScreen";
|
||||
import { BASE_SCREEN } from "../constants/ScreenNameConstants";
|
||||
import { logToSentry } from "../hooks/useSentryLogging";
|
||||
import {
|
||||
sendAsAnalyticsEvent,
|
||||
sendAsGlobalErrorEvent,
|
||||
} from "../hooks/useAnalyticsEvent";
|
||||
getAcceptHeaderInfo,
|
||||
getXTargetHeaderInfo,
|
||||
} from "../../../network/ApiClient";
|
||||
import { GZIP } from "../../../network/NetworkConstant";
|
||||
import { get, post } from "../../../network/NetworkService";
|
||||
import { mergeHeaders } from "../../../network/NetworkUtils";
|
||||
import { ActionMetaData, BaseActionTypes } from "../actions/GenericAction";
|
||||
import { BASE_SCREEN, GI, QUOTE_ID } from "../constants";
|
||||
import {
|
||||
AnalyticsFlowNameConstant,
|
||||
AnalyticsGlobalErrorTypeConstant,
|
||||
AnalyticsMethodNameConstant,
|
||||
AnalyticsModuleNameConstant,
|
||||
} from "../constants/AnalyticsEventsConstant";
|
||||
import {
|
||||
sendAsAnalyticsEvent,
|
||||
sendAsGlobalErrorEvent,
|
||||
} from "../hooks/useAnalyticsEvent";
|
||||
import { logToSentry } from "../hooks/useSentryLogging";
|
||||
import { CtaData } from "../interface";
|
||||
import { ScreenData } from "../interface/widgets/screenData/ScreenData";
|
||||
import {
|
||||
getStringPreference,
|
||||
setStringPreference,
|
||||
} from "../utilities/SharedPreferenceUtils";
|
||||
import { ScreenState } from "./BaseScreen";
|
||||
import { ScreenActionTypes } from "./ScreenActionTypes";
|
||||
|
||||
export const ScreenActionHandler = {
|
||||
handleScreenAction: (
|
||||
@@ -140,6 +144,69 @@ export const ScreenActionHandler = {
|
||||
);
|
||||
});
|
||||
}
|
||||
case ScreenActionTypes.FETCH_QUOTE_V4: {
|
||||
const acceptHeader = getAcceptHeaderInfo(GZIP);
|
||||
const xTargetHeader = getXTargetHeaderInfo(GI.toLocaleUpperCase());
|
||||
return post<ApiResponse<CtaData>>(
|
||||
"v4/quotes",
|
||||
screenMetaData.data,
|
||||
mergeHeaders({ configs: [acceptHeader, xTargetHeader] }),
|
||||
)
|
||||
.then(response => {
|
||||
if (screenData?.screenState) {
|
||||
setScreenData({
|
||||
...screenData,
|
||||
screenState: ScreenState.LOADING,
|
||||
});
|
||||
}
|
||||
setPostApiData();
|
||||
if (response) {
|
||||
const updatedScreenData: ScreenData = {
|
||||
...(response.data as ScreenData),
|
||||
screenState: ScreenState.LOADED,
|
||||
};
|
||||
let quoteId;
|
||||
updatedScreenData?.screenMetaData?.screenProperties?.forEach(
|
||||
item => {
|
||||
if (item.key === QUOTE_ID) {
|
||||
quoteId = item.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
if (!!quoteId) {
|
||||
storeQuoteId(quoteId);
|
||||
}
|
||||
// If redirectionCta is present and screenWidgets is not present then navigate to Base screen to get routed to specific screenName based on Cta
|
||||
if (
|
||||
!!updatedScreenData.screenMetaData?.redirectionCta &&
|
||||
!updatedScreenData.screenWidgets
|
||||
) {
|
||||
const cta = updatedScreenData.screenMetaData?.redirectionCta;
|
||||
// By default routing is happening via Base screen hence below navigate sends the cta there to get routed to specific screenName based on Cta
|
||||
if (!!cta.analyticsEventProperties) {
|
||||
sendAsAnalyticsEvent(cta.analyticsEventProperties);
|
||||
}
|
||||
navigation.navigate(BASE_SCREEN, { ctaData: cta });
|
||||
} else {
|
||||
if (updatedScreenData?.screenMetaData?.analyticsEvent) {
|
||||
sendAsAnalyticsEvent(
|
||||
updatedScreenData.screenMetaData.analyticsEvent,
|
||||
);
|
||||
}
|
||||
setScreenData(updatedScreenData);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
handleErrorData(
|
||||
error,
|
||||
setScreenData,
|
||||
screenMetaData,
|
||||
AnalyticsMethodNameConstant.FETCH_QUOTE_V4,
|
||||
ScreenActionTypes.FETCH_QUOTE_V4,
|
||||
);
|
||||
});
|
||||
}
|
||||
case ScreenActionTypes.SHOW_LOADER: {
|
||||
const updatedScreenData: ScreenData = {
|
||||
...screenData,
|
||||
|
||||
@@ -2,6 +2,7 @@ export const ScreenActionTypes = {
|
||||
FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND:
|
||||
"FETCH_INSURANCE_QUOTE_PAGE_FROM_BACKEND",
|
||||
FETCH_QUOTE_V3: "FETCH_QUOTE_V3",
|
||||
FETCH_QUOTE_V4: "FETCH_QUOTE_V4",
|
||||
SHOW_LOADER: "SHOW_LOADER",
|
||||
FETCH_COMPARE_PLAN_LIST: "FETCH_COMPARE_PLAN_LIST",
|
||||
};
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import { QUOTE_ID } from "../constants/StringConstant";
|
||||
import { QUOTE_ID } from "../constants";
|
||||
import { CtaData } from "../interface";
|
||||
import { ScreenMetaData } from "../interface/widgets/screenData/ScreenMetaData";
|
||||
|
||||
export const getQuoteIdFromCta = (ctaData?: CtaData) => {
|
||||
let quoteId;
|
||||
ctaData?.parameters?.forEach(item => {
|
||||
if (item.key === QUOTE_ID) {
|
||||
quoteId = item.value;
|
||||
return;
|
||||
}
|
||||
});
|
||||
return quoteId;
|
||||
const quoteObj = ctaData?.parameters?.find(item => item.key === QUOTE_ID);
|
||||
return quoteObj?.value;
|
||||
};
|
||||
|
||||
export const getQuoteIdFromScreenMetaData = (
|
||||
screenMetaData?: ScreenMetaData,
|
||||
) => {
|
||||
const quoteObj = screenMetaData?.screenProperties?.find(
|
||||
item => item.key === QUOTE_ID,
|
||||
);
|
||||
return quoteObj?.value;
|
||||
};
|
||||
|
||||
@@ -25,7 +25,7 @@ import { ScreenData } from "../../interface/widgets/screenData/ScreenData";
|
||||
import { FinalPatchCallRequestBody } from "../../interface/widgets/widgetData/FooterWithCardWidgetData";
|
||||
import { NativeDeeplinkNavigatorModule } from "../../native-module/NativeModules";
|
||||
import { ScreenState } from "../../screen/BaseScreen";
|
||||
import { getQuoteIdFromCta } from "../../utilities/CtaParamsUtils";
|
||||
import { getQuoteIdFromCta, getQuoteIdFromScreenMetaData } from "../../utilities/CtaParamsUtils";
|
||||
import { updateValueByKeyPath } from "../../utilities/MiscUtils";
|
||||
import { parseValue } from "../../utilities/SerializerUtil";
|
||||
import { WidgetActionTypes } from "./WidgetActionTypes";
|
||||
@@ -134,7 +134,7 @@ const WidgetActionHandler = {
|
||||
}
|
||||
|
||||
case WidgetActionTypes.PATCH_QUOTE_V2: {
|
||||
let quoteId = getQuoteIdFromCta(ctaData);
|
||||
let quoteId = getQuoteIdFromCta(ctaData) ?? getQuoteIdFromScreenMetaData(screenData?.screenMetaData);
|
||||
const requestData: SumInsuredRequestData = widgetMetaData.data;
|
||||
if (!quoteId) {
|
||||
getQuoteIdFromCache().then((value) => {
|
||||
@@ -170,7 +170,7 @@ const WidgetActionHandler = {
|
||||
screenState: ScreenState.OVERLAY,
|
||||
});
|
||||
invalidatePostApiData();
|
||||
let quoteId = getQuoteIdFromCta(ctaData);
|
||||
let quoteId = getQuoteIdFromCta(ctaData) ?? getQuoteIdFromScreenMetaData(screenData?.screenMetaData);
|
||||
const requestData: SumInsuredRequestData = (
|
||||
widgetMetaData?.data as FinalPatchCallRequestBody
|
||||
).requestData;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosHeaders, AxiosResponse } from "axios";
|
||||
import { BASE_URL } from "./NetworkConstant";
|
||||
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import { NetworkConnectorModule } from "../App/common/native-module/NativeModules";
|
||||
import { AxiosRequestConfig } from "axios";
|
||||
import { BASE_URL } from "./NetworkConstant";
|
||||
|
||||
|
||||
export const getDefaultHeaderData = async () => {
|
||||
try {
|
||||
@@ -23,6 +23,15 @@ export const getXTargetHeaderInfo = (
|
||||
};
|
||||
};
|
||||
|
||||
export const getAcceptHeaderInfo = (acceptType: string): AxiosRequestConfig => {
|
||||
return {
|
||||
decompress: true,
|
||||
headers: {
|
||||
"Accept-Encoding": acceptType,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const ApiClient = axios.create({
|
||||
baseURL: BASE_URL,
|
||||
timeout: 10000,
|
||||
|
||||
@@ -3,3 +3,4 @@ export const APPLICATION_ID_PATH = "/arc-warden/api/v2/application";
|
||||
export const FILL_APPLICATION_PATH =
|
||||
"/arc-warden/api/v2/application/:applicationId/fill";
|
||||
export const BUNDLE_VERSION = "x-rn-bundle-version";
|
||||
export const GZIP = "gzip";
|
||||
@@ -1,7 +1,11 @@
|
||||
import {
|
||||
AxiosInstance,
|
||||
AxiosRequestConfig,
|
||||
RawAxiosRequestHeaders,
|
||||
} from "axios";
|
||||
import { getStringPreference } from "../App/common/utilities/SharedPreferenceUtils";
|
||||
import packageJson from "../package.json";
|
||||
import { BUNDLE_VERSION } from "./NetworkConstant";
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
const getSessionToken = async () => {
|
||||
return await getStringPreference("SESSION_TOKEN", "string");
|
||||
@@ -18,4 +22,19 @@ const addBundleVersionToHeader = (axiosInstance: AxiosInstance) => {
|
||||
});
|
||||
};
|
||||
|
||||
export { getSessionToken, getDeviceId, addBundleVersionToHeader };
|
||||
const mergeHeaders = ({
|
||||
configs,
|
||||
}: {
|
||||
configs: AxiosRequestConfig[];
|
||||
}): AxiosRequestConfig => {
|
||||
const mergedHeaders = configs.reduce((acc, config) => {
|
||||
const headers = config.headers as RawAxiosRequestHeaders;
|
||||
return { ...acc, ...headers };
|
||||
}, {} as RawAxiosRequestHeaders);
|
||||
|
||||
return {
|
||||
headers: mergedHeaders,
|
||||
};
|
||||
};
|
||||
|
||||
export { addBundleVersionToHeader, getDeviceId, getSessionToken, mergeHeaders };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "NaviApp",
|
||||
"version": "0.1.0",
|
||||
"versionCode": 1,
|
||||
"version": "0.1.1",
|
||||
"versionCode": 2,
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "yarn react-native start",
|
||||
|
||||
Reference in New Issue
Block a user