Skip to content

Commit

Permalink
fix(Intermediate): Disabled the Back button if activity record has be…
Browse files Browse the repository at this point in the history
  • Loading branch information
BamMironov authored May 27, 2024
1 parent 520f9fe commit 74e5099
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/widgets/survey/lib/storageHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 13 additions & 4 deletions src/widgets/survey/ui/Intermediate.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -236,13 +245,13 @@ function Intermediate({
</Button>

<Text
color="$blue"
color={canNotGoBack ? '$lightGrey' : '$blue'}
accessibilityLabel="back-button"
textAlign="center"
fontSize={17}
fontWeight="bold"
onPress={onClose}
disabled={isLoading && !isCompleted && !isPostponed && !isError}
disabled={canNotGoBack}
>
{t('activity_navigation:back')}
</Text>
Expand Down

0 comments on commit 74e5099

Please sign in to comment.