Skip to content

Commit a1142bc

Browse files
authored
Merge pull request #49 from software-mansion-labs/@kosmydel/ideal-nav-issues-v7
ideal nav issues v7
2 parents b33e251 + 73c6c75 commit a1142bc

26 files changed

+76
-71
lines changed

src/components/AttachmentModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function AttachmentModal({
281281
const deleteAndCloseModal = useCallback(() => {
282282
IOU.detachReceipt(transaction?.transactionID);
283283
setIsDeleteReceiptConfirmModalVisible(false);
284-
Navigation.dismissModalWithReportID(report?.reportID ?? '');
284+
Navigation.dismissModal(report?.reportID);
285285
}, [transaction, report]);
286286

287287
const isValidFile = useCallback((fileObject: FileObject) => {

src/components/ReportHeaderSkeletonView.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function ReportHeaderSkeletonView({shouldAnimate = true, onBackButtonPress = ()
2525

2626
return (
2727
<View style={[styles.appContentHeader]}>
28-
<View style={[styles.appContentHeaderTitle, !isSmallScreenWidth && styles.pl5]}>
28+
<View style={[styles.appContentHeaderTitle]}>
2929
{isSmallScreenWidth && (
3030
<PressableWithFeedback
3131
onPress={onBackButtonPress}
@@ -48,18 +48,18 @@ function ReportHeaderSkeletonView({shouldAnimate = true, onBackButtonPress = ()
4848
>
4949
<Circle
5050
cx="20"
51-
cy="33"
51+
cy="40"
5252
r="20"
5353
/>
5454
<Rect
5555
x="55"
56-
y="20"
56+
y="28"
5757
width="30%"
5858
height="8"
5959
/>
6060
<Rect
6161
x="55"
62-
y="40"
62+
y="48"
6363
width="40%"
6464
height="8"
6565
/>

src/libs/Navigation/Navigation.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import linkingConfig from './linkingConfig';
1818
import linkTo from './linkTo';
1919
import navigationRef from './navigationRef';
2020
import switchPolicyID from './switchPolicyID';
21-
import type {State, StateOrRoute, switchPolicyIDParams} from './types';
21+
import type {State, StateOrRoute, SwitchPolicyIDParams} from './types';
2222

2323
let resolveNavigationIsReadyPromise: () => void;
2424
const navigationIsReadyPromise = new Promise<void>((resolve) => {
@@ -51,17 +51,20 @@ const getTopmostReportId = (state = navigationRef.getState()) => originalGetTopm
5151
const getTopmostReportActionId = (state = navigationRef.getState()) => originalGetTopmostReportActionId(state);
5252

5353
// Re-exporting the dismissModal here to fill in default value for navigationRef. The dismissModal isn't defined in this file to avoid cyclic dependencies.
54-
const dismissModal = (ref = navigationRef) => originalDismissModal(ref);
54+
const dismissModal = (reportID?: string, ref = navigationRef) => {
55+
if (!reportID) {
56+
originalDismissModal(ref);
57+
return;
58+
}
59+
const report = getReport(reportID);
60+
originalDismissModalWithReport({reportID, ...report}, ref);
61+
};
5562

5663
// Re-exporting the dismissModalWithReport here to fill in default value for navigationRef. The dismissModalWithReport isn't defined in this file to avoid cyclic dependencies.
5764
// This method is needed because it allows to dismiss the modal and then open the report. Within this method is checked whether the report belongs to a specific workspace. Sometimes the report we want to check, hasn't been added to the Onyx yet.
5865
// Then we can pass the report as a param without getting it from the Onyx.
5966
const dismissModalWithReport = (report: Report | EmptyObject, ref = navigationRef) => originalDismissModalWithReport(report, ref);
6067

61-
const dismissModalWithReportID = (reportID: string, ref = navigationRef) => {
62-
const report = getReport(reportID);
63-
originalDismissModalWithReport({reportID, ...report}, ref);
64-
};
6568
/** Method for finding on which index in stack we are. */
6669
function getActiveRouteIndex(stateOrRoute: StateOrRoute, index?: number): number | undefined {
6770
if ('routes' in stateOrRoute && stateOrRoute.routes) {
@@ -323,7 +326,7 @@ function waitForProtectedRoutes() {
323326
});
324327
}
325328

326-
function navigateWithSwitchPolicyID(params: switchPolicyIDParams) {
329+
function navigateWithSwitchPolicyID(params: SwitchPolicyIDParams) {
327330
if (!canNavigate('navigateWithSwitchPolicyID')) {
328331
return;
329332
}
@@ -337,7 +340,6 @@ export default {
337340
setParams,
338341
dismissModal,
339342
dismissModalWithReport,
340-
dismissModalWithReportID,
341343
isActiveRoute,
342344
getActiveRoute,
343345
getActiveRouteWithoutParams,

src/libs/Navigation/switchPolicyID.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {getActionFromState} from '@react-navigation/core';
22
import type {NavigationAction, NavigationContainerRef, NavigationState, PartialState} from '@react-navigation/native';
33
import {getPathFromState} from '@react-navigation/native';
4-
import type {Writable} from 'type-fest';
4+
import type {ValueOf, Writable} from 'type-fest';
55
import getIsSmallScreenWidth from '@libs/getIsSmallScreenWidth';
66
import CONST from '@src/CONST';
77
import NAVIGATORS from '@src/NAVIGATORS';
@@ -11,7 +11,7 @@ import getStateFromPath from './getStateFromPath';
1111
import getTopmostCentralPaneRoute from './getTopmostCentralPaneRoute';
1212
import linkingConfig from './linkingConfig';
1313
import TAB_TO_CENTRAL_PANE_MAPPING from './linkingConfig/TAB_TO_CENTRAL_PANE_MAPPING';
14-
import type {NavigationRoot, RootStackParamList, StackNavigationAction, State, switchPolicyIDParams} from './types';
14+
import type {NavigationRoot, RootStackParamList, StackNavigationAction, State, SwitchPolicyIDParams} from './types';
1515

1616
type ActionPayloadParams = {
1717
screen?: string;
@@ -60,7 +60,7 @@ function getActionForBottomTabNavigator(action: StackNavigationAction, state: Na
6060
};
6161
}
6262

63-
export default function switchPolicyID(navigation: NavigationContainerRef<RootStackParamList> | null, {policyID, route}: switchPolicyIDParams) {
63+
export default function switchPolicyID(navigation: NavigationContainerRef<RootStackParamList> | null, {policyID, route, isPolicyAdmin = false}: SwitchPolicyIDParams) {
6464
if (!navigation) {
6565
throw new Error("Couldn't find a navigation object. Is your component inside a screen in a navigator?");
6666
}
@@ -110,15 +110,21 @@ export default function switchPolicyID(navigation: NavigationContainerRef<RootSt
110110
const topmostCentralPaneRoute = getTopmostCentralPaneRoute(rootState);
111111
let screen = topmostCentralPaneRoute?.name;
112112
const params: CentralPaneRouteParams = {...topmostCentralPaneRoute?.params};
113+
const isWorkspaceScreen = screen && Object.values(SCREENS.WORKSPACE).includes(screen as ValueOf<typeof SCREENS.WORKSPACE>);
113114

114115
// Only workspace settings screens have to store the policyID in the params.
115116
// In other case, the policyID is read from the BottomTab params.
116-
if (!screen?.startsWith('Workspace_')) {
117+
if (!isWorkspaceScreen) {
117118
delete params.policyID;
118119
} else {
119120
params.policyID = policyID;
120121
}
121122

123+
// We need to redirect non admin users to overview screen, when switching workspace.
124+
if (!isPolicyAdmin && isWorkspaceScreen && screen !== SCREENS.WORKSPACE.OVERVIEW) {
125+
screen = SCREENS.WORKSPACE.OVERVIEW;
126+
}
127+
122128
// If the user is on the home page and changes the current workspace, then should be displayed a report from the selected workspace.
123129
// To achieve that, it's necessary to navigate without the reportID param.
124130
if (checkIfActionPayloadNameIsEqual(actionForBottomTabNavigator, SCREENS.HOME)) {

src/libs/Navigation/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,10 @@ type CentralPaneName = keyof CentralPaneNavigatorParamList;
470470

471471
type FullScreenName = keyof SettingsCentralPaneNavigatorParamList;
472472

473-
type switchPolicyIDParams = {
473+
type SwitchPolicyIDParams = {
474474
policyID?: string;
475475
route?: Routes;
476+
isPolicyAdmin?: boolean;
476477
};
477478

478479
export type {
@@ -519,5 +520,5 @@ export type {
519520
ReimbursementAccountNavigatorParamList,
520521
State,
521522
WorkspaceSwitcherNavigatorParamList,
522-
switchPolicyIDParams,
523+
SwitchPolicyIDParams,
523524
};

src/libs/actions/IOU.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ function createDistanceRequest(report, participant, comment, created, category,
936936
},
937937
onyxData,
938938
);
939-
Navigation.dismissModalWithReportID(isMoneyRequestReport ? report.reportID : chatReport.reportID);
939+
Navigation.dismissModal(isMoneyRequestReport ? report.reportID : chatReport.reportID);
940940
Report.notifyNewAction(chatReport.reportID, userAccountID);
941941
}
942942

@@ -1364,7 +1364,7 @@ function requestMoney(
13641364
onyxData,
13651365
);
13661366
resetMoneyRequestInfo();
1367-
Navigation.dismissModalWithReportID(activeReportID);
1367+
Navigation.dismissModal(activeReportID);
13681368
Report.notifyNewAction(activeReportID, payeeAccountID);
13691369
}
13701370

@@ -1806,7 +1806,7 @@ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccou
18061806
);
18071807

18081808
resetMoneyRequestInfo();
1809-
Navigation.dismissModalWithReportID(splitData.chatReportID);
1809+
Navigation.dismissModal(splitData.chatReportID);
18101810
Report.notifyNewAction(splitData.chatReportID, currentUserAccountID);
18111811
}
18121812

@@ -2288,7 +2288,7 @@ function completeSplitBill(chatReportID, reportAction, updatedTransaction, sessi
22882288
},
22892289
{optimisticData, successData, failureData},
22902290
);
2291-
Navigation.dismissModalWithReportID(chatReportID);
2291+
Navigation.dismissModal(chatReportID);
22922292
Report.notifyNewAction(chatReportID, sessionAccountID);
22932293
}
22942294

@@ -3244,7 +3244,7 @@ function sendMoneyElsewhere(report, amount, currency, comment, managerID, recipi
32443244
API.write('SendMoneyElsewhere', params, {optimisticData, successData, failureData});
32453245

32463246
resetMoneyRequestInfo();
3247-
Navigation.dismissModalWithReportID(params.chatReportID);
3247+
Navigation.dismissModal(params.chatReportID);
32483248
Report.notifyNewAction(params.chatReportID, managerID);
32493249
}
32503250

@@ -3262,7 +3262,7 @@ function sendMoneyWithWallet(report, amount, currency, comment, managerID, recip
32623262
API.write('SendMoneyWithWallet', params, {optimisticData, successData, failureData});
32633263

32643264
resetMoneyRequestInfo();
3265-
Navigation.dismissModalWithReportID(params.chatReportID);
3265+
Navigation.dismissModal(params.chatReportID);
32663266
Report.notifyNewAction(params.chatReportID, managerID);
32673267
}
32683268

src/libs/actions/Report.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ function addPolicyReport(policyReport: ReportUtils.OptimisticChatReport) {
16411641
};
16421642

16431643
API.write(WRITE_COMMANDS.ADD_WORKSPACE_ROOM, parameters, {optimisticData, successData, failureData});
1644-
Navigation.dismissModalWithReportID(policyReport.reportID);
1644+
Navigation.dismissModal(policyReport.reportID);
16451645
}
16461646

16471647
/** Deletes a report, along with its reportActions, any linked reports, and any linked IOU report. */

src/libs/actions/Task.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function createTaskAndNavigate(
244244

245245
API.write(WRITE_COMMANDS.CREATE_TASK, parameters, {optimisticData, successData, failureData});
246246

247-
Navigation.dismissModalWithReportID(parentReportID);
247+
Navigation.dismissModal(parentReportID);
248248
}
249249

250250
/**

src/libs/actions/TeachersUnite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function referTeachersUniteVolunteer(partnerUserID: string, firstName: string, l
6161
};
6262

6363
API.write(WRITE_COMMANDS.REFER_TEACHERS_UNITE_VOLUNTEER, parameters, {optimisticData});
64-
Navigation.dismissModalWithReportID(publicRoomReportID);
64+
Navigation.dismissModal(publicRoomReportID);
6565
}
6666

6767
/**
@@ -181,7 +181,7 @@ function addSchoolPrincipal(firstName: string, partnerUserID: string, lastName:
181181
};
182182

183183
API.write(WRITE_COMMANDS.ADD_SCHOOL_PRINCIPAL, parameters, {optimisticData, successData, failureData});
184-
Navigation.dismissModalWithReportID(expenseChatReportID);
184+
Navigation.dismissModal(expenseChatReportID);
185185
}
186186

187187
export default {referTeachersUniteVolunteer, addSchoolPrincipal};

src/pages/AddPersonalBankAccountPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function AddPersonalBankAccountPage({personalBankAccount, plaidData}: AddPersona
4747
const onSuccessFallbackRoute = personalBankAccount?.onSuccessFallbackRoute ?? '';
4848

4949
if (exitReportID) {
50-
Navigation.dismissModalWithReportID(exitReportID);
50+
Navigation.dismissModal(exitReportID);
5151
} else if (shouldContinue && onSuccessFallbackRoute) {
5252
PaymentMethods.continueSetup(onSuccessFallbackRoute);
5353
} else {

src/pages/EditRequestDistancePage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup}
6060
// When the loading goes from true to false, then we know the transaction has just been
6161
// saved to the server. Check for errors. If there are no errors, then the modal can be closed.
6262
if (prevIsLoading && !transaction.isLoading && !hasWaypointError.current) {
63-
Navigation.dismissModalWithReportID(report.reportID);
63+
Navigation.dismissModal(report.reportID);
6464
}
6565
}, [transaction, prevIsLoading, report]);
6666

@@ -75,7 +75,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup}
7575
const oldAddresses = _.mapObject(oldWaypoints, (waypoint) => _.pick(waypoint, 'address'));
7676
const addresses = _.mapObject(waypoints, (waypoint) => _.pick(waypoint, 'address'));
7777
if (_.isEqual(oldAddresses, addresses)) {
78-
Navigation.dismissModalWithReportID(report.reportID);
78+
Navigation.dismissModal(report.reportID);
7979
return;
8080
}
8181

@@ -84,7 +84,7 @@ function EditRequestDistancePage({report, route, transaction, transactionBackup}
8484
// If the client is offline, then the modal can be closed as well (because there are no errors or other feedback to show them
8585
// until they come online again and sync with the server).
8686
if (isOffline) {
87-
Navigation.dismissModalWithReportID(report.reportID);
87+
Navigation.dismissModal(report.reportID);
8888
}
8989
};
9090

src/pages/SearchPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function SearchPage({betas, personalDetails, reports, isSearchingForReports, nav
155155
return;
156156
}
157157
if (option.reportID) {
158-
Navigation.dismissModalWithReportID(option.reportID);
158+
Navigation.dismissModal(option.reportID);
159159
} else {
160160
Report.navigateToAndOpenReport([option.login]);
161161
}

src/pages/SearchPage/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function SearchPage({betas, reports}) {
123123

124124
if (option.reportID) {
125125
setSearchValue('');
126-
Navigation.dismissModalWithReportID(option.reportID);
126+
Navigation.dismissModal(option.reportID);
127127
} else {
128128
Report.navigateToAndOpenReport([option.login]);
129129
}

src/pages/ShareCodePage.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,8 @@ class ShareCodePage extends React.Component {
9090
shouldShowBackButton={isReport || this.props.isSmallScreenWidth}
9191
/>
9292

93-
<ScrollView style={[this.props.themeStyles.flex1, this.props.themeStyles.mt3]}>
94-
<View
95-
style={[
96-
this.props.themeStyles.shareCodePage,
97-
this.props.isSmallScreenWidth ? this.props.themeStyles.workspaceSectionMobile : this.props.themeStyles.workspaceSection,
98-
]}
99-
>
93+
<ScrollView style={[this.props.themeStyles.flex1]}>
94+
<View style={[this.props.isSmallScreenWidth ? this.props.themeStyles.workspaceSectionMobile : this.props.themeStyles.workspaceSection, this.props.themeStyles.ph4]}>
10095
<QRShareWithDownload
10196
ref={this.qrCodeRef}
10297
url={url}

src/pages/WorkspaceSwitcherPage.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ function WorkspaceSwitcherPage({policies}) {
110110
[unreadStatusesForPolicies],
111111
);
112112

113-
const selectPolicy = useCallback((option) => {
114-
const policyID = option.policyID;
113+
const selectPolicy = (option) => {
114+
const {policyID, isPolicyAdmin} = option;
115115

116116
if (policyID) {
117117
setSelectedOption(option);
@@ -121,13 +121,9 @@ function WorkspaceSwitcherPage({policies}) {
121121
setActiveWorkspaceID(policyID);
122122
Navigation.goBack();
123123
if (policyID !== activeWorkspaceID) {
124-
Navigation.navigateWithSwitchPolicyID({policyID});
124+
Navigation.navigateWithSwitchPolicyID({policyID, isPolicyAdmin});
125125
}
126-
}, []);
127-
128-
const onChangeText = useCallback((newSearchTerm) => {
129-
setSearchTerm(newSearchTerm);
130-
}, []);
126+
};
131127

132128
const usersWorkspaces = useMemo(
133129
() =>
@@ -147,6 +143,7 @@ function WorkspaceSwitcherPage({policies}) {
147143
],
148144
boldStyle: hasUnreadData(policy.id),
149145
keyForList: policy.id,
146+
isPolicyAdmin: PolicyUtils.isPolicyAdmin(policy),
150147
}))
151148
.value(),
152149
[policies, getIndicatorTypeForPolicy, hasUnreadData],
@@ -247,7 +244,7 @@ function WorkspaceSwitcherPage({policies}) {
247244
sections={[usersWorkspacesSectionData]}
248245
value={searchTerm}
249246
shouldShowTextInput={usersWorkspaces.length >= CONST.WORKSPACE_SWITCHER.MINIMUM_WORKSPACES_TO_SHOW_SEARCH}
250-
onChangeText={onChangeText}
247+
onChangeText={(newSearchTerm) => setSearchTerm(newSearchTerm)}
251248
selectedOptions={selectedOption ? [selectedOption] : []}
252249
onSelectRow={selectPolicy}
253250
shouldPreventDefaultFocusOnSelectRow
@@ -269,7 +266,7 @@ function WorkspaceSwitcherPage({policies}) {
269266
)}
270267
</>
271268
),
272-
[inputCallbackRef, onChangeText, searchTerm, selectPolicy, selectedOption, styles, theme.textSupporting, translate, usersWorkspaces.length, usersWorkspacesSectionData],
269+
[inputCallbackRef, setSearchTerm, searchTerm, selectPolicy, selectedOption, styles, theme.textSupporting, translate, usersWorkspaces.length, usersWorkspacesSectionData],
273270
);
274271

275272
useEffect(() => {

src/pages/home/HeaderView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function HeaderView(props) {
227227
dataSet={{dragArea: true}}
228228
>
229229
<View style={[styles.appContentHeader]}>
230-
<View style={[styles.appContentHeaderTitle, !isSmallScreenWidth && !isLoading && styles.pl5]}>
230+
<View style={[styles.appContentHeaderTitle, !isSmallScreenWidth && styles.pl5]}>
231231
{isLoading ? (
232232
<ReportHeaderSkeletonView onBackButtonPress={props.onNavigationMenuButtonClicked} />
233233
) : (

src/pages/settings/Preferences/ThemePage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function ThemePage(props) {
4141
title={translate('themePage.theme')}
4242
shouldShowBackButton
4343
onBackButtonPress={() => Navigation.goBack()}
44-
onCloseButtonPress={() => Navigation.dismissModal(true)}
44+
onCloseButtonPress={() => Navigation.dismissModal()}
4545
/>
4646

4747
<Text style={[styles.mh5, styles.mv4]}>{translate('themePage.chooseThemeBelowOrSync')}</Text>

0 commit comments

Comments
 (0)