From 72cce0249f563ed9b99b708fac441a38a6a19559 Mon Sep 17 00:00:00 2001 From: "aishwarya.srivastava" Date: Wed, 27 Nov 2024 03:23:21 +0530 Subject: [PATCH 01/12] NTP-14132| restrict feedback post operative hours --- src/action/dataActions.ts | 1 + .../form/components/GeolocationAddress.tsx | 32 ++++++++++++--- src/components/form/index.tsx | 40 +++++++++++++++---- .../postOperationalHourRestrictionsSlice.ts | 24 +++++++++++ .../addressGeolocation/AddressItem.tsx | 31 ++++++++++++-- .../addressGeolocation/SimilarAddressItem.tsx | 28 +++++++++++-- .../utils/operativeHourUtils.ts | 10 +++++ .../CollectionCaseDetailFooter.tsx | 21 +++++++++- .../utils/postOperationalHourActions.tsx | 28 +++++++++++++ src/store/store.ts | 2 + 10 files changed, 195 insertions(+), 22 deletions(-) create mode 100644 src/reducer/postOperationalHourRestrictionsSlice.ts create mode 100644 src/screens/addressGeolocation/utils/operativeHourUtils.ts create mode 100644 src/screens/caseDetails/utils/postOperationalHourActions.tsx diff --git a/src/action/dataActions.ts b/src/action/dataActions.ts index ad044591..d58eefef 100644 --- a/src/action/dataActions.ts +++ b/src/action/dataActions.ts @@ -106,6 +106,7 @@ export const syncCaseDetail = type: 'success', text1: ToastMessages.FEEDBACK_SUCCESSFUL, }); + //TODO: Aishwarya if (callbacks?.onSuccessCB != null && typeof callbacks?.onSuccessCB === 'function') { callbacks?.onSuccessCB(payload.data.answers, interactionId); } diff --git a/src/components/form/components/GeolocationAddress.tsx b/src/components/form/components/GeolocationAddress.tsx index 5437a3de..bbfa07ab 100644 --- a/src/components/form/components/GeolocationAddress.tsx +++ b/src/components/form/components/GeolocationAddress.tsx @@ -1,5 +1,5 @@ import { Linking, StyleSheet, TouchableOpacity, View } from 'react-native'; -import React, { useMemo } from 'react'; +import React, { useEffect, useMemo } from 'react'; import { GeolocationSource, GeolocationSourceMap, @@ -31,6 +31,9 @@ import { IAddressFeedback } from '../../../reducer/addressSlice'; 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 { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; interface IGeolocationAddress { address: IGeolocation; @@ -104,9 +107,21 @@ const GeolocationAddress: React.FC = ({ ); return { addressDate, addressTime, lastFeedbackTimestampDate }; }, [lastFeedbackForGeolocation, timestamp]); - + const addingNewFeedbackDisabled = useAppSelector( + (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)); + } + }; + syncTime(); + const intervalId = setInterval(syncTime, 180000); + return () => clearInterval(intervalId); + }, []); const handleAddFeedback = () => { if (!caseId) { return; @@ -297,10 +312,10 @@ const GeolocationAddress: React.FC = ({ {showAddFeedback ? ( - + Add feedback @@ -364,6 +379,13 @@ const styles = StyleSheet.create({ tagText: { lineHeight: 18, }, + disabledButton: { + fontSize: 13, + lineHeight: 20, + color: COLORS.TEXT.BLUE, + paddingVertical: 4, + opacity: 0.5 + }, }); export default GeolocationAddress; diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index a8e46e27..1b19d488 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -1,4 +1,4 @@ -import React, {useCallback, useEffect, useRef, useState} from 'react'; +import React, { useCallback, useEffect, useRef, useState } from 'react'; import { useForm } from 'react-hook-form'; import { ScrollView, StyleSheet, View } from 'react-native'; import Geolocation from 'react-native-geolocation-service'; @@ -44,6 +44,8 @@ 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 { setPostOperationalHourRestrictions } from '@reducers/postOperationalHourRestrictionsSlice'; interface IWidget { route: { @@ -98,9 +100,22 @@ const Widget: React.FC = (props) => { } setIsJourneyFirstScreen(isFirst); }, [templateData, name]); - + + 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)); + } + }; + syncTime(); + const intervalId = setInterval(syncTime, 15000); + return () => clearInterval(intervalId); + }, []); const handleBackPress = useCallback(() => { - if (isSubmitting) { + if (isSubmitting && ! addingNewFeedbackDisabled) { toast({ type: 'info', text1: ToastMessages.FEEDBACK_SUBMISSION_UNDER_PROCESS, @@ -112,6 +127,13 @@ const Widget: React.FC = (props) => { }, [isSubmitting]); useBackHandler(handleBackPress); + const handleDisabledButtonClick = () => { + setIsSubmitButtonDiabled(true); + toast({ + type: 'error', + text1: 'Submission failed! You can add feedback only during work hours (8 AM to 7 PM)', + }) + }; const { control, @@ -366,7 +388,7 @@ const Widget: React.FC = (props) => { }, []); const handleCloseIconPress = () => { - if (isSubmitting) { + if (isSubmitting && !addingNewFeedbackDisabled) { toast({ type: 'info', text1: ToastMessages.FEEDBACK_SUBMISSION_UNDER_PROCESS, @@ -464,11 +486,13 @@ const Widget: React.FC = (props) => {