Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2759,14 +2759,6 @@ const CONST = {
CONFIRM: 'confirm',
},
},

SUBSCRIPTION_SIZE: {
PAGE_NAME: {
SIZE: 'size',
CONFIRM: 'confirm',
},
},

MISSING_PERSONAL_DETAILS_INDEXES: {
MAPPING: {
LEGAL_NAME: 0,
Expand Down
10 changes: 2 additions & 8 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,8 @@ const ROUTES = {
getRoute: (backTo?: string) => getUrlWithBackToParam('settings/subscription', backTo),
},
SETTINGS_SUBSCRIPTION_SIZE: {
route: 'settings/subscription/subscription-size/:subPage?',
getRoute: (canChangeSize?: 0 | 1, subPage?: string) => {
const baseRoute = 'settings/subscription/subscription-size';
const subPageParam = subPage ? `/${subPage}` : '';
const canChangeSizeParam = canChangeSize !== undefined ? `?canChangeSize=${canChangeSize as number}` : '';

return `${baseRoute}${subPageParam}${canChangeSizeParam}` as const;
},
route: 'settings/subscription/subscription-size',
getRoute: (canChangeSize: 0 | 1) => `settings/subscription/subscription-size?canChangeSize=${canChangeSize as number}` as const,
},
SETTINGS_SUBSCRIPTION_SETTINGS_DETAILS: 'settings/subscription/details',
SETTINGS_SUBSCRIPTION_ADD_PAYMENT_CARD: 'settings/subscription/add-payment-card',
Expand Down
2 changes: 0 additions & 2 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,6 @@ type SettingsNavigatorParamList = {
};
[SCREENS.SETTINGS.SUBSCRIPTION.SIZE]: {
canChangeSize: 0 | 1;
subPage?: string;
action?: 'edit';
};
[SCREENS.SETTINGS.SUBSCRIPTION.SETTINGS_DETAILS]: undefined;
[SCREENS.SETTINGS.SUBSCRIPTION.ADD_PAYMENT_CARD]: undefined;
Expand Down
30 changes: 11 additions & 19 deletions src/pages/settings/Subscription/SubscriptionSize/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePrivateSubscription from '@hooks/usePrivateSubscription';
import useSubPage from '@hooks/useSubPage';
import useSubStep from '@hooks/useSubStep';
import type {SubStepProps} from '@hooks/useSubStep/types';
import {clearDraftValues} from '@libs/actions/FormActions';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
Expand All @@ -16,18 +17,14 @@ import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import {updateSubscriptionSize} from '@userActions/Subscription';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/SubscriptionSizeForm';
import Confirmation from './substeps/Confirmation';
import Size from './substeps/Size';

type SubscriptionSizePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.SUBSCRIPTION.SIZE>;
const bodyContent: Array<React.ComponentType<SubStepProps>> = [Size, Confirmation];

const pages = [
{pageName: CONST.SUBSCRIPTION_SIZE.PAGE_NAME.SIZE, component: Size},
{pageName: CONST.SUBSCRIPTION_SIZE.PAGE_NAME.CONFIRM, component: Confirmation},
];
type SubscriptionSizePageProps = PlatformStackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.SUBSCRIPTION.SIZE>;

function SubscriptionSizePage({route}: SubscriptionSizePageProps) {
const privateSubscription = usePrivateSubscription();
Expand All @@ -38,19 +35,14 @@ function SubscriptionSizePage({route}: SubscriptionSizePageProps) {

const onFinished = () => {
updateSubscriptionSize(subscriptionSizeFormDraft ? Number(subscriptionSizeFormDraft[INPUT_IDS.SUBSCRIPTION_SIZE]) : 0, privateSubscription?.userCount ?? 0);
Navigation.goBack(ROUTES.SETTINGS_SUBSCRIPTION_SETTINGS_DETAILS);
Navigation.goBack();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep a fallback route when finishing subscription resize

Switching onFinished to Navigation.goBack() makes the save flow a no-op when this screen is opened directly (for example from a bookmarked/deep link URL) because goBack() returns early when there is no back stack (src/libs/Navigation/Navigation.ts, !canGoBack() branch). The previous goBack(ROUTES.SETTINGS_SUBSCRIPTION_SETTINGS_DETAILS) ensured users always land on subscription settings after saving, so this change can leave users stuck on the confirmation page after pressing Save.

Useful? React with 👍 / 👎.

};

const {CurrentPage, pageIndex, prevPage, nextPage, moveTo, isRedirecting} = useSubPage({
pages,
onFinished,
startFrom,
buildRoute: (pageName) => ROUTES.SETTINGS_SUBSCRIPTION_SIZE.getRoute(route.params?.canChangeSize, pageName),
});
const {componentToRender: SubStep, screenIndex, nextScreen, prevScreen, moveTo} = useSubStep({bodyContent, startFrom, onFinished});

const onBackButtonPress = () => {
if (pageIndex !== 0 && startFrom === 0) {
prevPage();
if (screenIndex !== 0 && startFrom === 0) {
prevScreen();
return;
}

Expand All @@ -68,7 +60,7 @@ function SubscriptionSizePage({route}: SubscriptionSizePageProps) {
return <NotFoundPage />;
}

if (isRedirecting || !privateSubscription) {
if (!privateSubscription) {
return <FullScreenLoadingIndicator />;
}

Expand All @@ -85,9 +77,9 @@ function SubscriptionSizePage({route}: SubscriptionSizePageProps) {
title={translate('subscription.subscriptionSize.title')}
onBackButtonPress={onBackButtonPress}
/>
<CurrentPage
<SubStep
isEditing={canChangeSubscriptionSize}
onNext={nextPage}
onNext={nextScreen}
onMove={moveTo}
/>
</DelegateNoAccessWrapper>
Expand Down
Loading