TP-69871 | longhorn block pr fixes

This commit is contained in:
varnit-goyal_navi
2024-08-26 16:47:07 +05:30
parent 1b5b4bf95b
commit 63a717fbcc
4 changed files with 30 additions and 16 deletions

View File

@@ -73,6 +73,7 @@ import { initialize } from 'react-native-clarity';
import { getPermissionsToRequest } from '@components/utlis/PermissionUtils';
import { syncToLonghorn } from '../miniModules/callingAgents/screens/homeScreen/action';
import { updateImageUploadComponent } from '@components/form/services/formComponents';
import React from "react";
export enum FOREGROUND_TASKS {
GEOLOCATION = 'GEOLOCATION',
@@ -275,7 +276,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
const taskSyncToLonghorn = async () => {
const allPermissionsGranted = await checkPermissions();
await syncToLonghorn(allPermissionsGranted, agentId, appVersion);
await syncToLonghorn({allPermissionsGranted, agentId, appVersion, isSyncToastEnabled: false});
};
const tasks: IForegroundTask[] = [
@@ -346,12 +347,6 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
delay: 3 * MILLISECONDS_IN_A_MINUTE, // 3 minutes
onLoop: true,
},
{
taskId: FOREGROUND_TASKS.COSMOS_SYNC_WITH_LONGHORN,
task: taskSyncToLonghorn,
delay: 5 * MILLISECONDS_IN_A_SECOND,
onLoop: true,
}
];
if (!isTeamLead) {
@@ -362,7 +357,6 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
onLoop: true,
});
}
const handleDataSync = () => {
if (!isOnline) {
return;
@@ -382,6 +376,17 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
});
}
if(GLOBAL?.BUILD_FLAVOUR === 'callingAgents') {
tasks.push({
taskId: FOREGROUND_TASKS.COSMOS_SYNC_WITH_LONGHORN,
task: taskSyncToLonghorn,
delay: 5 * MILLISECONDS_IN_A_SECOND,
onLoop: true,
});
}
const userActivityUpdateOnBackground = async () => {
const foregroundTimestamp = await getItem(StorageKeys.APP_FOREGROUND_TIMESTAMP);
const backgroundTimestamp = await getItem(StorageKeys.APP_BACKGROUND_TIMESTAMP);
@@ -427,6 +432,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
MS_CLARITY_PROJECT_ID &&
!GLOBAL.MS_CLARITY_INITIALIZED &&
msClarityResponse &&
//@ts-expect-error - The configuration will change at runtime
ENV === 'prod'
) {
addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.MS_CLARITY_INITIALIZED, {
@@ -464,8 +470,7 @@ const TrackingComponent: React.FC<ITrackingComponent> = ({ children }) => {
}, []);
useEffect(() => {
let appStateSubscription: NativeEventSubscription;
appStateSubscription = AppState.addEventListener('change', handleAppStateChange);
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);
CosmosForegroundService.start(tasks);
return () => {
appStateSubscription?.remove();

View File

@@ -21,6 +21,7 @@ export const GLOBAL = {
} as unknown as IGlobalUserData;
interface IGlobalUserData {
MS_CLARITY_INITIALIZED: boolean;
token?: string;
deviceId?: string;
agentId?: string;

View File

@@ -1,12 +1,20 @@
import axiosInstance, { ApiKeys, getApiUrl } from "@components/utlis/apiHelper";
import { toast } from "@rn-ui-lib/components/toast";
export const syncToLonghorn = async (
type SyncToLonghornParams = {
allPermissionsGranted: boolean,
agentId: string,
appVersion: string,
showSyncToast ?: boolean
) => {
isSyncToastEnabled ?: boolean
}
export const syncToLonghorn = async ({
allPermissionsGranted,
agentId,
appVersion,
isSyncToastEnabled
}:SyncToLonghornParams) => {
const url = getApiUrl(ApiKeys.SYNC_COSMOS_TO_LONGHORN);
const payload = {
allPermissionsGranted,
@@ -16,6 +24,6 @@ export const syncToLonghorn = async (
try {
await axiosInstance.post(url, payload , { headers: { donotHandleError: true } });
} catch {
showSyncToast && toast({ type: 'error', text1: 'Could not sync. Please try again' });
isSyncToastEnabled && toast({ type: 'error', text1: 'Could not sync. Please try again' });
}
}

View File

@@ -24,7 +24,7 @@ const CallingAgentHomeScreen = () => {
const appVersion = getAppVersion();
const handleOnPress = async () => {
const allPermissionsGranted = await checkPermissions();
await syncToLonghorn(allPermissionsGranted, agentId, appVersion, true);
await syncToLonghorn({allPermissionsGranted, agentId, appVersion, isSyncToastEnabled:true});
};
return (
@@ -55,7 +55,7 @@ const CallingAgentHomeScreen = () => {
<View style={GenericStyles.mt16}>
<Button
variant="primaryText"
title="Sync instantly to longhorn"
title="Sync instantly to Longhorn"
leftIcon={
<View style={styles.iconGap}>
<RefreshIcon />