diff --git a/src/widgets/survey/lib/storageHelpers.ts b/src/widgets/survey/lib/storageHelpers.ts index 38bc49812..de9b276d5 100644 --- a/src/widgets/survey/lib/storageHelpers.ts +++ b/src/widgets/survey/lib/storageHelpers.ts @@ -30,6 +30,17 @@ export const getActivityRecord = ( return !json ? null : (JSON.parse(json) as ActivityState); }; +export const activityRecordExists = ( + appletId: string, + activityId: string, + eventId: string, + order: number, +): boolean => { + const record = getActivityRecord(appletId, activityId, eventId, order); + + return !!record; +}; + export const clearActivityStorageRecord = ( appletId: string, activityId: string, diff --git a/src/widgets/survey/ui/Intermediate.tsx b/src/widgets/survey/ui/Intermediate.tsx index 968423422..8c0ea4ed5 100644 --- a/src/widgets/survey/ui/Intermediate.tsx +++ b/src/widgets/survey/ui/Intermediate.tsx @@ -1,4 +1,4 @@ -import { useCallback, useEffect } from 'react'; +import { useCallback, useEffect, useMemo } from 'react'; import { styled } from '@tamagui/core'; import { useQueryClient } from '@tanstack/react-query'; @@ -20,7 +20,7 @@ import { import { badge } from '@assets/images'; import { Center, YStack, Text, Button, Image, XStack } from '@shared/ui'; -import { useFlowStorageRecord } from '../lib'; +import { activityRecordExists, useFlowStorageRecord } from '../lib'; import { StepperPipelineItem, useAutoCompletion, @@ -116,6 +116,15 @@ function Intermediate({ return new QueryDataUtils(queryClient).getAppletDto(appletId)?.displayName; }, [appletId, queryClient]); + const activityRecordRemoved = useMemo( + () => !activityRecordExists(appletId, activityId, eventId, order), + [activityId, appletId, eventId, order], + ); + + const canNotGoBack = + activityRecordRemoved || + (isLoading && !isCompleted && !isPostponed && !isError); + const changeActivity = useCallback(() => { const appletName = getAppletName(); @@ -236,13 +245,13 @@ function Intermediate({ {t('activity_navigation:back')}