diff --git a/src/common/TrackingComponent.tsx b/src/common/TrackingComponent.tsx index dd01ba5e..9af7b795 100644 --- a/src/common/TrackingComponent.tsx +++ b/src/common/TrackingComponent.tsx @@ -57,6 +57,8 @@ import { getSyncUrl } from '@services/syncJsonDataToBe'; import { handleCheckAndUpdatePullToRefreshStateForNearbyCases } from '@screens/allCases/utils'; import { getWifiDetailsSyncUrl } from '@components/utlis/WifiDetails'; import useFirestoreUpdates from '@hooks/useFirestoreUpdates'; +import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions'; +import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; export enum FOREGROUND_TASKS { GEOLOCATION = 'GEOLOCATION', @@ -105,6 +107,7 @@ const TrackingComponent: React.FC = ({ children }) => { const isTimeDifferenceLess = isTimeDifferenceWithinRange(timestamp, 5); dispatch(setIsTimeSynced(isTimeDifferenceLess)); } + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); } catch (e: any) { logError(e, 'Error during fetching timestamp from server.'); } diff --git a/src/components/form/components/GeolocationAddress.tsx b/src/components/form/components/GeolocationAddress.tsx index bbfa07ab..00a28f3a 100644 --- a/src/components/form/components/GeolocationAddress.tsx +++ b/src/components/form/components/GeolocationAddress.tsx @@ -32,8 +32,9 @@ import Tag, { TagVariant } from '@rn-ui-lib/components/Tag'; import ArrowSolidIcon from '@rn-ui-lib/icons/ArrowSolidIcon'; import { CaseDetailStackEnum } from '@screens/caseDetails/CaseDetailStack'; import { handleClickPostOperativeHours } from '@screens/addressGeolocation/utils/operativeHourUtils'; -import { handleTimeSync } from '@screens/caseDetails/utils/postOperationalHourActions'; +import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions'; import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; +import { getSyncTime } from '@hooks/capturingApi'; interface IGeolocationAddress { address: IGeolocation; @@ -111,17 +112,15 @@ const GeolocationAddress: React.FC = ({ (state) => state.postOperationalHourRestrictionsSlice.postOperationalHourRestrictions ); const handleCloseRouting = () => handlePageRouting?.(CaseDetailStackEnum.ADDRESS_GEO); + useEffect(() => { const syncTime = async () => { - const getCurrentTime = await handleTimeSync(); - if (getCurrentTime?.isPostOperational) { - dispatch(setPostOperationalHourRestrictions(getCurrentTime?.isPostOperational)); - } + const timestamp = await getSyncTime(); + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); }; syncTime(); - const intervalId = setInterval(syncTime, 180000); - return () => clearInterval(intervalId); }, []); + const handleAddFeedback = () => { if (!caseId) { return; diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index 1b19d488..5d546835 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -44,8 +44,9 @@ import { NUDGE_BOTTOM_SHEET_DEFAULT_STATE } from './constants'; import {useBackHandler} from "@hooks/useBackHandler"; import { CALLING_NUDGE } from '@screens/caseDetails/CallingFlow/constants'; import { isFunction } from '@components/utlis/commonFunctions'; -import { handleTimeSync } from '@screens/caseDetails/utils/postOperationalHourActions'; +import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions'; import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; +import { getSyncTime } from '@hooks/capturingApi'; interface IWidget { route: { @@ -103,17 +104,15 @@ const Widget: React.FC = (props) => { const addingNewFeedbackDisabled = useAppSelector((state) => state.postOperationalHourRestrictionsSlice.postOperationalHourRestrictions); const [isSubmitButtonDiabled, setIsSubmitButtonDiabled] = useState(false); + useEffect(() => { const syncTime = async () => { - const getCurrentTime = await handleTimeSync(); - if (getCurrentTime?.isPostOperational) { - dispatch(setPostOperationalHourRestrictions(getCurrentTime?.isPostOperational)); - } + const timestamp = await getSyncTime(); + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); }; syncTime(); - const intervalId = setInterval(syncTime, 15000); - return () => clearInterval(intervalId); }, []); + const handleBackPress = useCallback(() => { if (isSubmitting && ! addingNewFeedbackDisabled) { toast({ diff --git a/src/screens/addressGeolocation/AddressItem.tsx b/src/screens/addressGeolocation/AddressItem.tsx index 43ce5a21..129ba35c 100644 --- a/src/screens/addressGeolocation/AddressItem.tsx +++ b/src/screens/addressGeolocation/AddressItem.tsx @@ -20,8 +20,9 @@ import { CLICKSTREAM_EVENT_NAMES } from '@common/Constants'; import CopyIcon from '@rn-ui-lib/icons/CopyIcon'; import { copyAddressToClipboard } from './utils/copyAddressText'; import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; -import { handleTimeSync } from '@screens/caseDetails/utils/postOperationalHourActions'; +import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions'; import { handleClickPostOperativeHours } from './utils/operativeHourUtils'; +import { getSyncTime } from '@hooks/capturingApi'; interface IAddressItem { addressItem: IAddress; @@ -76,14 +77,10 @@ function AddressItem({ ); useEffect(() => { const syncTime = async () => { - const getCurrentTime = await handleTimeSync(); - if (getCurrentTime?.isPostOperational) { - dispatch(setPostOperationalHourRestrictions(getCurrentTime?.isPostOperational)); - } + const timestamp = await getSyncTime(); + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); }; syncTime(); - const intervalId = setInterval(syncTime, 180000); - return () => clearInterval(intervalId); }, []); const handleAddFeedback = () => { diff --git a/src/screens/addressGeolocation/SimilarAddressItem.tsx b/src/screens/addressGeolocation/SimilarAddressItem.tsx index 9002609a..826a442b 100644 --- a/src/screens/addressGeolocation/SimilarAddressItem.tsx +++ b/src/screens/addressGeolocation/SimilarAddressItem.tsx @@ -24,9 +24,10 @@ import AddressSource from './AddressSource'; import relativeDistanceFormatter from './utils/relativeDistanceFormatter'; import CopyIcon from '@rn-ui-lib/icons/CopyIcon'; import { copyAddressToClipboard } from './utils/copyAddressText'; -import { handleTimeSync } from '@screens/caseDetails/utils/postOperationalHourActions'; +import { handlePostOperativeHourActivity } from '@screens/caseDetails/utils/postOperationalHourActions'; import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; import { handleClickPostOperativeHours } from './utils/operativeHourUtils'; +import { getSyncTime } from '@hooks/capturingApi'; interface IAddressItem { addressItem: IAddress; @@ -122,16 +123,13 @@ function SimilarAddressItem({ } }; const addingNewFeedbackDisabled = useAppSelector((state) => state.postOperationalHourRestrictionsSlice.postOperationalHourRestrictions); + useEffect(() => { const syncTime = async () => { - const getCurrentTime = await handleTimeSync(); - if (getCurrentTime?.isPostOperational) { - dispatch(setPostOperationalHourRestrictions(getCurrentTime?.isPostOperational)); - } + const timestamp = await getSyncTime(); + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); }; syncTime(); - const intervalId = setInterval(syncTime, 180000); - return () => clearInterval(intervalId); }, []); const copyAddress = () => { diff --git a/src/screens/addressGeolocation/utils/operativeHourUtils.ts b/src/screens/addressGeolocation/utils/operativeHourUtils.ts index 9c3e4f70..1cbe2ba8 100644 --- a/src/screens/addressGeolocation/utils/operativeHourUtils.ts +++ b/src/screens/addressGeolocation/utils/operativeHourUtils.ts @@ -1,9 +1,9 @@ import { toast } from "@rn-ui-lib/components/toast"; - export const handleClickPostOperativeHours = () => { + toast({ - type: 'error', + type: 'warn', text1: 'You will be able to add feedback only during work hours (8 AM to 7 PM).', }); return; diff --git a/src/screens/caseDetails/CollectionCaseDetailFooter.tsx b/src/screens/caseDetails/CollectionCaseDetailFooter.tsx index c3864ce3..604f4caa 100644 --- a/src/screens/caseDetails/CollectionCaseDetailFooter.tsx +++ b/src/screens/caseDetails/CollectionCaseDetailFooter.tsx @@ -14,9 +14,10 @@ import React, { useEffect } from 'react'; import { StyleSheet, View } from 'react-native'; import { CaseDetailStackEnum } from './CaseDetailStack'; import { captureLatestDeviceLocation } from '@components/form/services/geoLocation.service'; -import { handleTimeSync } from './utils/postOperationalHourActions'; +import { handlePostOperativeHourActivity } from './utils/postOperationalHourActions'; import { handleClickPostOperativeHours } from '@screens/addressGeolocation/utils/operativeHourUtils'; import { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; +import { getSyncTime } from '@hooks/capturingApi'; interface ICollectionCaseDetailFooter { caseId: string; @@ -84,14 +85,10 @@ const CollectionCaseDetailFooter = ({ caseId, notificationId }: ICollectionCaseD }; useEffect(() => { const syncTime = async () => { - const getCurrentTime = await handleTimeSync(); - if (getCurrentTime?.isPostOperational) { - dispatch(setPostOperationalHourRestrictions(getCurrentTime?.isPostOperational)); - } + const timestamp = await getSyncTime(); + dispatch(setPostOperationalHourRestrictions(handlePostOperativeHourActivity(timestamp))); }; syncTime(); - const intervalId = setInterval(syncTime, 180000); - return () => clearInterval(intervalId); }, []); useEffect(() => { @@ -122,7 +119,7 @@ const CollectionCaseDetailFooter = ({ caseId, notificationId }: ICollectionCaseD testID={'test_call_customer'} />