Skip to content

Commit

Permalink
fix: add back to workspace confirmation page
Browse files Browse the repository at this point in the history
  • Loading branch information
daledah committed Feb 14, 2025
1 parent 4be1590 commit cfbe10f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,7 @@ type SettingsSplitNavigatorParamList = {
type WorkspaceSplitNavigatorParamList = {
[SCREENS.WORKSPACE.INITIAL]: {
policyID: string;
backTo?: Routes;
};
[SCREENS.WORKSPACE.PROFILE]: {
policyID: string;
Expand Down
14 changes: 6 additions & 8 deletions src/pages/workspace/WorkspaceConfirmationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import {useRoute} from '@react-navigation/native';
import React from 'react';
import ScreenWrapper from '@components/ScreenWrapper';
import WorkspaceConfirmationForm from '@components/WorkspaceConfirmationForm';
import type {WorkspaceConfirmationSubmitFunctionParams} from '@components/WorkspaceConfirmationForm';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import {createWorkspaceWithPolicyDraftAndNavigateToIt} from '@libs/actions/App';
import {generatePolicyID} from '@libs/actions/Policy/Policy';
import getCurrentUrl from '@libs/Navigation/currentUrl';
import ROUTES from '@src/ROUTES';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {WorkspaceConfirmationNavigatorParamList} from '@libs/Navigation/types';
import type SCREENS from '@src/SCREENS';

function WorkspaceConfirmationPage() {
// It is necessary to use here isSmallScreenWidth because on a wide layout we should always navigate to ROUTES.WORKSPACE_PROFILE.
// shouldUseNarrowLayout cannot be used to determine that as this screen is displayed in RHP and shouldUseNarrowLayout always returns true.
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth} = useResponsiveLayout();
const route = useRoute<PlatformStackRouteProp<WorkspaceConfirmationNavigatorParamList, typeof SCREENS.WORKSPACE_CONFIRMATION.ROOT>>();

const onSubmit = (params: WorkspaceConfirmationSubmitFunctionParams) => {
const policyID = params.policyID || generatePolicyID();
const routeToNavigate = isSmallScreenWidth ? ROUTES.WORKSPACE_INITIAL.getRoute(policyID) : ROUTES.WORKSPACE_PROFILE.getRoute(policyID);
createWorkspaceWithPolicyDraftAndNavigateToIt('', params.name, false, false, '', policyID, params.currency, params.avatarFile as File, routeToNavigate);
createWorkspaceWithPolicyDraftAndNavigateToIt('', params.name, false, false, route.params?.backTo, policyID, params.currency, params.avatarFile as File);
};
const currentUrl = getCurrentUrl();
// Approved Accountants and Guides can enter a flow where they make a workspace for other users,
Expand Down
8 changes: 7 additions & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,13 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
>
<HeaderWithBackButton
title={policyName}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)}
onBackButtonPress={() => {
if (route.params.backTo) {
Navigation.navigate(route.params.backTo);
return;
}
Navigation.goBack(ROUTES.SETTINGS_WORKSPACES);
}}
policyAvatar={policyAvatar}
style={styles.headerBarDesktopHeight}
/>
Expand Down

0 comments on commit cfbe10f

Please sign in to comment.