diff --git a/src/components/form/index.tsx b/src/components/form/index.tsx index 60ca0cc7..eb9a87d5 100644 --- a/src/components/form/index.tsx +++ b/src/components/form/index.tsx @@ -12,7 +12,7 @@ import { syncCaseDetail } from '../../action/dataActions'; import { CLICKSTREAM_EVENT_NAMES } from '../../common/Constants'; import { useAppDispatch, useAppSelector } from '../../hooks'; import useIsOnline from '../../hooks/useIsOnline'; -import { getUpdatedCollectionCaseDetail, updateCaseDetail } from '../../reducer/allCasesSlice'; +import {getUpdatedCollectionCaseDetail, setIsFeedbackSubmitting, updateCaseDetail} from '../../reducer/allCasesSlice'; import { deleteInteraction, deleteJourney, updateInteraction } from '../../reducer/caseReducer'; import { CaseAllocationType } from '../../screens/allCases/interface'; import { getUnSyncedCase } from '../../screens/caseDetails/interactionsHandler'; @@ -63,7 +63,6 @@ const Widget: React.FC = (props) => { NUDGE_BOTTOM_SHEET_DEFAULT_STATE ); const isOnline = useIsOnline(); - const [isSubmitting, setIsSubmitting] = useState(false); const { params } = props.route; const { caseId, journey, handleCloseRouting } = params; const caseKey = useRef(''); @@ -74,6 +73,7 @@ const Widget: React.FC = (props) => { const caseData = useAppSelector((state) => state.allCases?.caseDetails?.[caseId]); const dataToBeValidated = useAppSelector((state) => state.case?.caseForm?.[caseId]?.[journey]); const intermediateDocsToBeUploaded = useAppSelector((state) => state.feedbackImages?.intermediateDocsToBeUploaded); + const isFeedbackSubmitting = useAppSelector((state) => state?.allCases?.isFeedbackSubmitting); const name = getWidgetNameFromRoute(props.route.name, caseType); const { sections, conditionActions: widgetConditionActions, isLeaf } = templateData.widget[name]; @@ -194,7 +194,7 @@ const Widget: React.FC = (props) => { }; const onSuccessfulSubmit = (data: any, interactionId: string, nextActions?: any) => { - setIsSubmitting(false); + dispatch(setIsFeedbackSubmitting(false)); setNudgeBottomSheetDetails(NUDGE_BOTTOM_SHEET_DEFAULT_STATE); navigateToScreen(CaseDetailStackEnum.COLLECTION_CASE_DETAIL, { journey: journey, @@ -220,6 +220,7 @@ const Widget: React.FC = (props) => { } const submitJourneyWithGeoLocation = (data: any, _: any, submitViaNudge?: boolean) => { + dispatch(setIsFeedbackSubmitting(true)); addClickstreamEvent( submitViaNudge ? CLICKSTREAM_EVENT_NAMES.FA_SUBMIT_ANYWAYS_CLICKED @@ -238,7 +239,7 @@ const Widget: React.FC = (props) => { }; const onErrorSubmit = (errObj: GenericType, data?: GenericType, interactionId?: string) => { - setIsSubmitting(false); + dispatch(setIsFeedbackSubmitting(false)); if (nudgeBottomSheetDetails?.showNudgeBottomSheet) { addClickstreamEvent(CLICKSTREAM_EVENT_NAMES.FA_SUBMIT_ANYWAYS_FAILED, { caseId, @@ -273,7 +274,6 @@ const Widget: React.FC = (props) => { templateData, }); if (isOnline) { - setIsSubmitting(true); const unSyncedCase = getUnSyncedCase(updatedCase); const transformedPayload = await getTransformedCollectionCaseItem( unSyncedCase, @@ -414,15 +414,15 @@ const Widget: React.FC = (props) => { style={[styles.autoFlex, styles.mH16]} title={'Back'} testID={'test_back'} - disabled={isLeaf && isSubmitting} + disabled={isLeaf && isFeedbackSubmitting} onPress={handleBackButton} leftIcon={} />