import { NavigationProp } from "@react-navigation/native"; import { AnalyticsEventNameConstants, AnalyticsMethodNameConstant, NAVIGATION_ERROR, } from "../constants"; import { sendAsAnalyticsEvent } from "../hooks/useAnalyticsEvent"; import { AnalyticsEvent, CtaData, CtaType } from "../interface"; import { NativeDeeplinkNavigatorModule } from "../native-module/NativeModules"; import { CtaNavigator } from "../navigator/NavigationRouter"; export const globalHandleClick = ( navigation: NavigationProp, cta?: CtaData, screenName?: string, ) => { if (!cta) { const errorEvent: AnalyticsEvent = { name: AnalyticsEventNameConstants.HI_INVALID_SCREEN_CTA, properties: { screenName: screenName || "", methodName: AnalyticsMethodNameConstant.HANDLE_CTA_CLICK, }, }; sendAsAnalyticsEvent(errorEvent); return; } try { switch (cta.type) { case CtaType.DEEP_LINK: case CtaType.USE_ROOT_DEEPLINK_NAVIGATOR: NativeDeeplinkNavigatorModule.navigateToNaviInsuranceDeeplinkNavigator( JSON.stringify(cta), ); break; case CtaType.RN_NAVIGATOR: case CtaType.RN_PUSH: CtaNavigator.push(navigation, cta); break; case CtaType.RN_NAVIGATE: CtaNavigator.navigate(navigation, cta); break; case CtaType.GO_BACK: CtaNavigator.goBack(navigation, cta); break; default: NativeDeeplinkNavigatorModule.navigateToNaviDeeplinkNavigator( JSON.stringify(cta), ); break; } } catch (error) { const errorEvent: AnalyticsEvent = { name: AnalyticsEventNameConstants.HI_INVALID_SCREEN_CTA, properties: { screenName: screenName || "", methodName: AnalyticsMethodNameConstant.HANDLE_CTA_CLICK, reason: error?.toString() || NAVIGATION_ERROR, }, }; sendAsAnalyticsEvent(errorEvent); } };