From c45fe04273dc29060cd7300cb61d240f4d67eccb Mon Sep 17 00:00:00 2001 From: twilight294 Date: Tue, 8 Oct 2024 13:29:43 +0000 Subject: [PATCH 01/18] Add new routes for tags RHP Signed-off-by: GitHub --- src/ROUTES.ts | 76 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index dcda868efb94..05872df290b3 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -154,10 +154,18 @@ const ROUTES = { route: 'settings/wallet/card/:cardID?', getRoute: (cardID: string) => `settings/wallet/card/${cardID}` as const, }, + SETTINGS_DOMAINCARD_DETAIL: { + route: 'settings/card/:cardID?', + getRoute: (cardID: string) => `settings/card/${cardID}` as const, + }, SETTINGS_REPORT_FRAUD: { route: 'settings/wallet/card/:cardID/report-virtual-fraud', getRoute: (cardID: string) => `settings/wallet/card/${cardID}/report-virtual-fraud` as const, }, + SETTINGS_DOMAINCARD_REPORT_FRAUD: { + route: 'settings/card/:cardID/report-virtual-fraud', + getRoute: (cardID: string) => `settings/card/${cardID}/report-virtual-fraud` as const, + }, SETTINGS_WALLET_CARD_GET_PHYSICAL_NAME: { route: 'settings/wallet/card/:domain/get-physical/name', getRoute: (domain: string) => `settings/wallet/card/${domain}/get-physical/name` as const, @@ -429,6 +437,54 @@ const ROUTES = { getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => getUrlWithBackToParam(`${action as string}/${iouType as string}/category/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, + SETTINGS_TAGS_ROOT: { + route: 'settings/:policyID/tags', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags`, backTo), + }, + SETTINGS_TAGS_SETTINGS: { + route: 'settings/:policyID/tags/settings', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags/settings` as const, backTo), + }, + SETTINGS_TAGS_EDIT: { + route: 'settings/:policyID/tags/:orderWeight/edit', + getRoute: (policyID: string, orderWeight: number, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags/${orderWeight}/edit` as const, backTo), + }, + SETTINGS_TAG_CREATE: { + route: 'settings/:policyID/tags/new', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags/new` as const, backTo), + }, + SETTINGS_TAG_EDIT: { + route: 'settings/:policyID/tag/:orderWeight/:tagName/edit', + getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}/edit` as const, backTo), + }, + SETTINGS_TAG_SETTINGS: { + route: 'settings/:policyID/tag/:orderWeight/:tagName', + getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}` as const, backTo), + }, + SETTINGS_TAG_APPROVER: { + route: 'settings/:policyID/tag/:orderWeight/:tagName/approver', + getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${tagName}/approver` as const, backTo), + }, + SETTINGS_TAG_LIST_VIEW: { + route: 'settings/:policyID/tag-list/:orderWeight', + getRoute: (policyID: string, orderWeight: number, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tag-list/${orderWeight}` as const, backTo), + }, + SETTINGS_TAG_GL_CODE: { + route: 'settings/:policyID/tag/:orderWeight/:tagName/gl-code', + getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}/gl-code` as const, backTo), + }, + SETTINGS_TAGS_IMPORT: { + route: 'settings/:policyID/tags/import', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags/import` as const, backTo), + }, + SETTINGS_TAGS_IMPORTED: { + route: 'settings/:policyID/tags/imported', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags/imported` as const, backTo), + }, SETTINGS_CATEGORIES_ROOT: { route: 'settings/:policyID/categories', getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/categories`, backTo), @@ -499,10 +555,6 @@ const ROUTES = { getRoute: (action: IOUAction, iouType: IOUType, orderWeight: number, transactionID: string, reportID: string, backTo = '', reportActionID?: string) => getUrlWithBackToParam(`${action as string}/${iouType as string}/tag/${orderWeight}/${transactionID}/${reportID}${reportActionID ? `/${reportActionID}` : ''}`, backTo), }, - SETTINGS_TAGS_ROOT: { - route: 'settings/:policyID/tags', - getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/tags`, backTo), - }, MONEY_REQUEST_STEP_WAYPOINT: { route: ':action/:iouType/waypoint/:transactionID/:reportID/:pageIndex', getRoute: (action: IOUAction, iouType: IOUType, transactionID: string, reportID?: string, pageIndex = '', backTo = '') => @@ -1015,18 +1067,34 @@ const ROUTES = { route: 'settings/workspaces/:policyID/expensify-card/:cardID', getRoute: (policyID: string, cardID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/expensify-card/${cardID}`, backTo), }, + EXPENSIFY_CARD_DETAILS: { + route: 'settings/:policyID/expensify-card/:cardID', + getRoute: (policyID: string, cardID: string, backTo?: string) => getUrlWithBackToParam(`settings/${policyID}/expensify-card/${cardID}`, backTo), + }, WORKSPACE_EXPENSIFY_CARD_NAME: { route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/name', getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/name` as const, }, + EXPENSIFY_CARD_NAME: { + route: 'settings/:policyID/expensify-card/:cardID/edit/name', + getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/name` as const, + }, WORKSPACE_EXPENSIFY_CARD_LIMIT: { route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/limit', getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/limit` as const, }, + EXPENSIFY_CARD_LIMIT: { + route: 'settings/:policyID/expensify-card/:cardID/edit/limit', + getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/limit` as const, + }, WORKSPACE_EXPENSIFY_CARD_LIMIT_TYPE: { route: 'settings/workspaces/:policyID/expensify-card/:cardID/edit/limit-type', getRoute: (policyID: string, cardID: string) => `settings/workspaces/${policyID}/expensify-card/${cardID}/edit/limit-type` as const, }, + EXPENSIFY_CARD_LIMIT_TYPE: { + route: 'settings/:policyID/expensify-card/:cardID/edit/limit-type', + getRoute: (policyID: string, cardID: string) => `settings/${policyID}/expensify-card/${cardID}/edit/limit-type` as const, + }, WORKSPACE_EXPENSIFY_CARD_ISSUE_NEW: { route: 'settings/workspaces/:policyID/expensify-card/issue-new', getRoute: (policyID: string, backTo?: string) => getUrlWithBackToParam(`settings/workspaces/${policyID}/expensify-card/issue-new`, backTo), From a379e49346b6f18bff3bec0535b892f9aa1ea857 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Tue, 8 Oct 2024 13:44:52 +0000 Subject: [PATCH 02/18] Background report changes to Tags page after clicking Tag pages Signed-off-by: GitHub --- src/SCREENS.ts | 27 +++++- .../ModalStackNavigators/index.tsx | 30 ++++++- src/libs/Navigation/linkingConfig/config.ts | 86 ++++++++++++++++++- src/libs/Navigation/types.ts | 13 +++ src/pages/workspace/tags/EditTagPage.tsx | 20 ++--- src/pages/workspace/tags/ImportTagsPage.tsx | 3 +- src/pages/workspace/tags/ImportedTagsPage.tsx | 3 +- src/pages/workspace/tags/TagGLCodePage.tsx | 9 +- src/pages/workspace/tags/TagSettingsPage.tsx | 17 +++- .../workspace/tags/WorkspaceCreateTagPage.tsx | 27 ++---- .../workspace/tags/WorkspaceEditTagsPage.tsx | 25 ++---- .../workspace/tags/WorkspaceTagsPage.tsx | 26 +++++- .../tags/WorkspaceTagsSettingsPage.tsx | 34 ++++---- .../workspace/tags/WorkspaceViewTagsPage.tsx | 9 ++ 14 files changed, 251 insertions(+), 78 deletions(-) diff --git a/src/SCREENS.ts b/src/SCREENS.ts index 9186c2b58bfa..e22f0877b58a 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -176,6 +176,9 @@ const SCREENS = { SEARCH_ADVANCED_FILTERS: 'SearchAdvancedFilters', SEARCH_SAVED_SEARCH: 'SearchSavedSearch', SETTINGS_CATEGORIES: 'SettingsCategories', + SETTINGS_TAGS: 'SettingsTags', + EXPENSIFY_CARD: 'ExpensifyCard', + DOMAIN_CARD: 'DomainCard', RESTRICTED_ACTION: 'RestrictedAction', REPORT_EXPORT: 'Report_Export', MISSING_PERSONAL_DETAILS: 'MissingPersonalDetails', @@ -244,8 +247,30 @@ const SCREENS = { SETTINGS_CATEGORY_EDIT: 'Settings_Category_Edit', SETTINGS_CATEGORIES_ROOT: 'Settings_Categories', }, + EXPENSIFY_CARD: { + EXPENSIFY_CARD_DETAILS: 'Expensify_Card_Details', + EXPENSIFY_CARD_NAME: 'Expensify_Card_Name', + EXPENSIFY_CARD_LIMIT: 'Expensify_Card_Limit', + EXPENSIFY_CARD_LIMIT_TYPE: 'Expensify_Card_Limit_Type', + }, + DOMAIN_CARD: { + DOMAIN_CARD_DETAIL: 'Domain_Card_Detail', + DOMAIN_CARD_REPORT_FRAUD: 'Domain_Card_Report_Fraud', + }, - SETTINGS_TAGS_ROOT: 'Settings_Tags', + SETTINGS_TAGS: { + SETTINGS_TAGS_ROOT: 'Settings_Tags', + SETTINGS_TAGS_SETTINGS: 'Settings_Tags_Settings', + SETTINGS_TAGS_EDIT: 'Settings_Tags_Edit', + SETTINGS_TAG_CREATE: 'Settings_Tag_Create', + SETTINGS_TAG_EDIT: 'Settings_Tag_Edit', + SETTINGS_TAG_SETTINGS: 'Settings_Tag_Settings', + SETTINGS_TAG_APPROVER: 'Settings_Tag_Approver', + SETTINGS_TAG_LIST_VIEW: 'Settings_Tag_List_View', + SETTINGS_TAG_GL_CODE: 'Settings_Tag_GL_Code', + SETTINGS_TAGS_IMPORT: 'Settings_Tags_Import', + SETTINGS_TAGS_IMPORTED: 'Settings_Tags_Imported', + }, REPORT_SETTINGS: { ROOT: 'Report_Settings_Root', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 5cdfa302ec97..695166a20197 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -87,7 +87,7 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator require('../../../../pages/iou/request/step/IOURequestStepMerchant').default, [SCREENS.MONEY_REQUEST.STEP_PARTICIPANTS]: () => require('../../../../pages/iou/request/step/IOURequestStepParticipants').default, [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_ROOT]: () => require('../../../../pages/workspace/categories/WorkspaceCategoriesPage').default, - [SCREENS.SETTINGS_TAGS_ROOT]: () => require('../../../../pages/workspace/tags/WorkspaceTagsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_ROOT]: () => require('../../../../pages/workspace/tags/WorkspaceTagsPage').default, [SCREENS.MONEY_REQUEST.STEP_SCAN]: () => require('../../../../pages/iou/request/step/IOURequestStepScan').default, [SCREENS.MONEY_REQUEST.STEP_TAG]: () => require('../../../../pages/iou/request/step/IOURequestStepTag').default, [SCREENS.MONEY_REQUEST.STEP_WAYPOINT]: () => require('../../../../pages/iou/request/step/IOURequestStepWaypoint').default, @@ -144,6 +144,31 @@ const CategoriesModalStackNavigator = createModalStackNavigator({ [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS]: () => require('../../../../pages/workspace/categories/CategorySettingsPage').default, }); +const TagsModalStackNavigator = createModalStackNavigator({ + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_SETTINGS]: () => require('../../../../pages/workspace/tags/WorkspaceTagsSettingsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_EDIT]: () => require('../../../../pages/workspace/tags/WorkspaceEditTagsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORT]: () => require('../../../../pages/workspace/tags/ImportTagsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORTED]: () => require('../../../../pages/workspace/tags/ImportedTagsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_SETTINGS]: () => require('../../../../pages/workspace/tags/TagSettingsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: () => require('../../../../pages/workspace/tags/WorkspaceViewTagsPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_CREATE]: () => require('../../../../pages/workspace/tags/WorkspaceCreateTagPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_EDIT]: () => require('../../../../pages/workspace/tags/EditTagPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: () => require('../../../../pages/workspace/tags/TagApproverPage').default, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE]: () => require('../../../../pages/workspace/tags/TagGLCodePage').default, +}); + +const ExpensifyCardModalStackNavigator = createModalStackNavigator({ + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_DETAILS]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceExpensifyCardDetailsPage').default, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_NAME]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceEditCardNamePage').default, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceEditCardLimitPage').default, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT_TYPE]: () => require('../../../../pages/workspace/expensifyCard/WorkspaceEditCardLimitTypePage').default, +}); + +const DomainCardModalStackNavigator = createModalStackNavigator({ + [SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL]: () => require('../../../../pages/settings/Wallet/ExpensifyCardPage').default, + [SCREENS.DOMAIN_CARD.DOMAIN_CARD_REPORT_FRAUD]: () => require('../../../../pages/settings/Wallet/ReportVirtualCardFraudPage').default, +}); + const ReportParticipantsModalStackNavigator = createModalStackNavigator({ [SCREENS.REPORT_PARTICIPANTS.ROOT]: () => require('../../../../pages/ReportParticipantsPage').default, [SCREENS.REPORT_PARTICIPANTS.INVITE]: () => require('../../../../pages/InviteReportParticipantsPage').default, @@ -612,6 +637,9 @@ export { SettingsModalStackNavigator, SignInModalStackNavigator, CategoriesModalStackNavigator, + TagsModalStackNavigator, + ExpensifyCardModalStackNavigator, + DomainCardModalStackNavigator, SplitDetailsModalStackNavigator, TaskModalStackNavigator, WalletStatementStackNavigator, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index d3d575f961a8..fde7cc38bb32 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -927,6 +927,90 @@ const config: LinkingOptions['config'] = { }, }, }, + [SCREENS.RIGHT_MODAL.SETTINGS_TAGS]: { + screens: { + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_SETTINGS]: { + path: ROUTES.SETTINGS_TAGS_SETTINGS.route, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_EDIT]: { + path: ROUTES.SETTINGS_TAGS_EDIT.route, + parse: { + orderWeight: Number, + tagName: (tagName: string) => decodeURIComponent(tagName), + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_CREATE]: { + path: ROUTES.SETTINGS_TAG_CREATE.route, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_EDIT]: { + path: ROUTES.SETTINGS_TAG_EDIT.route, + parse: { + orderWeight: Number, + tagName: (tagName: string) => decodeURIComponent(tagName), + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_SETTINGS]: { + path: ROUTES.SETTINGS_TAG_SETTINGS.route, + parse: { + orderWeight: Number, + tagName: (tagName: string) => decodeURIComponent(tagName), + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_APPROVER]: { + path: ROUTES.SETTINGS_TAG_APPROVER.route, + parse: { + orderWeight: Number, + tagName: (tagName: string) => decodeURIComponent(tagName), + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_LIST_VIEW]: { + path: ROUTES.SETTINGS_TAG_LIST_VIEW.route, + parse: { + orderWeight: Number, + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_GL_CODE]: { + path: ROUTES.SETTINGS_TAG_GL_CODE.route, + parse: { + orderWeight: Number, + tagName: (tagName: string) => decodeURIComponent(tagName), + }, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORT]: { + path: ROUTES.SETTINGS_TAGS_IMPORT.route, + }, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_IMPORTED]: { + path: ROUTES.SETTINGS_TAGS_IMPORTED.route, + }, + }, + }, + + [SCREENS.RIGHT_MODAL.EXPENSIFY_CARD]: { + screens: { + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_DETAILS]: { + path: ROUTES.EXPENSIFY_CARD_DETAILS.route, + }, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_NAME]: { + path: ROUTES.EXPENSIFY_CARD_NAME.route, + }, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT]: { + path: ROUTES.EXPENSIFY_CARD_LIMIT.route, + }, + [SCREENS.EXPENSIFY_CARD.EXPENSIFY_CARD_LIMIT_TYPE]: { + path: ROUTES.EXPENSIFY_CARD_LIMIT_TYPE.route, + }, + }, + }, + [SCREENS.RIGHT_MODAL.DOMAIN_CARD]: { + screens: { + [SCREENS.DOMAIN_CARD.DOMAIN_CARD_DETAIL]: { + path: ROUTES.SETTINGS_DOMAINCARD_DETAIL.route, + }, + [SCREENS.DOMAIN_CARD.DOMAIN_CARD_REPORT_FRAUD]: { + path: ROUTES.SETTINGS_DOMAINCARD_REPORT_FRAUD.route, + }, + }, + }, [SCREENS.RIGHT_MODAL.REPORT_DESCRIPTION]: { screens: { [SCREENS.REPORT_DESCRIPTION_ROOT]: ROUTES.REPORT_DESCRIPTION.route, @@ -1017,7 +1101,7 @@ const config: LinkingOptions['config'] = { }, }, [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_ROOT]: ROUTES.SETTINGS_CATEGORIES_ROOT.route, - [SCREENS.SETTINGS_TAGS_ROOT]: ROUTES.SETTINGS_TAGS_ROOT.route, + [SCREENS.SETTINGS_TAGS.SETTINGS_TAGS_ROOT]: ROUTES.SETTINGS_TAGS_ROOT.route, [SCREENS.MONEY_REQUEST.STEP_SEND_FROM]: ROUTES.MONEY_REQUEST_STEP_SEND_FROM.route, [SCREENS.MONEY_REQUEST.STEP_COMPANY_INFO]: ROUTES.MONEY_REQUEST_STEP_COMPANY_INFO.route, [SCREENS.MONEY_REQUEST.STEP_AMOUNT]: ROUTES.MONEY_REQUEST_STEP_AMOUNT.route, diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 631796401734..544e20c65991 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -257,6 +257,7 @@ type SettingsNavigatorParamList = { }; [SCREENS.WORKSPACE.TAG_CREATE]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.DISTANCE_RATE_DETAILS]: { policyID: string; @@ -276,30 +277,37 @@ type SettingsNavigatorParamList = { }; [SCREENS.WORKSPACE.TAGS_SETTINGS]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAGS_IMPORT]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAGS_IMPORTED]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_SETTINGS]: { policyID: string; orderWeight: number; tagName: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_LIST_VIEW]: { policyID: string; orderWeight: number; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAGS_EDIT]: { policyID: string; orderWeight: number; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_EDIT]: { policyID: string; orderWeight: number; tagName: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_APPROVER]: { policyID: string; @@ -310,6 +318,7 @@ type SettingsNavigatorParamList = { policyID: string; orderWeight: number; tagName: string; + backTo?: Routes; }; [SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: undefined; [SCREENS.SETTINGS.SUBSCRIPTION.SIZE]: { @@ -1252,6 +1261,9 @@ type RightModalNavigatorParamList = { [SCREENS.RIGHT_MODAL.REPORT_DETAILS]: NavigatorScreenParams; [SCREENS.RIGHT_MODAL.REPORT_SETTINGS]: NavigatorScreenParams; [SCREENS.RIGHT_MODAL.SETTINGS_CATEGORIES]: NavigatorScreenParams; + [SCREENS.RIGHT_MODAL.SETTINGS_TAGS]: NavigatorScreenParams; + [SCREENS.RIGHT_MODAL.EXPENSIFY_CARD]: NavigatorScreenParams; + [SCREENS.RIGHT_MODAL.DOMAIN_CARD]: NavigatorScreenParams; [SCREENS.RIGHT_MODAL.REPORT_DESCRIPTION]: NavigatorScreenParams; [SCREENS.RIGHT_MODAL.PARTICIPANTS]: NavigatorScreenParams; [SCREENS.RIGHT_MODAL.ROOM_MEMBERS]: NavigatorScreenParams; @@ -1345,6 +1357,7 @@ type FullScreenNavigatorParamList = { }; [SCREENS.WORKSPACE.TAGS]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAXES]: { policyID: string; diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index c8cef174dbdb..0bf7240d2ca9 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -1,8 +1,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback} from 'react'; import {Keyboard} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -22,16 +21,11 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/WorkspaceTagForm'; -import type {PolicyTagLists} from '@src/types/onyx'; -type EditTagPageOnyxProps = { - /** All policy tags */ - policyTags: OnyxEntry; -}; +type EditTagPageProps = StackScreenProps; -type EditTagPageProps = EditTagPageOnyxProps & StackScreenProps; - -function EditTagPage({route, policyTags}: EditTagPageProps) { +function EditTagPage({route}: EditTagPageProps) { + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); @@ -111,8 +105,4 @@ function EditTagPage({route, policyTags}: EditTagPageProps) { EditTagPage.displayName = 'EditTagPage'; -export default withOnyx({ - policyTags: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`, - }, -})(EditTagPage); +export default EditTagPage; diff --git a/src/pages/workspace/tags/ImportTagsPage.tsx b/src/pages/workspace/tags/ImportTagsPage.tsx index 0dd7c01f0af3..72ddeb8ca958 100644 --- a/src/pages/workspace/tags/ImportTagsPage.tsx +++ b/src/pages/workspace/tags/ImportTagsPage.tsx @@ -9,10 +9,11 @@ type ImportTagsPageProps = StackScreenProps ); diff --git a/src/pages/workspace/tags/ImportedTagsPage.tsx b/src/pages/workspace/tags/ImportedTagsPage.tsx index b2e95edc43a4..1c61ad19e79b 100644 --- a/src/pages/workspace/tags/ImportedTagsPage.tsx +++ b/src/pages/workspace/tags/ImportedTagsPage.tsx @@ -30,6 +30,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) { const {containsHeader = true} = spreadsheet ?? {}; const [isValidationEnabled, setIsValidationEnabled] = useState(false); const policyID = route.params.policyID; + const backTo = route.params.backTo; const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`); const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); const policy = usePolicy(policyID); @@ -126,7 +127,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) { > Navigation.goBack(ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))} /> { - Navigation.goBack(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName)); - }, [orderWeight, route.params.policyID, tagName]); + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName, backTo) + : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName), + ); + }, [orderWeight, route.params.policyID, tagName, backTo]); const editGLCode = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index f5599ed4c269..a9ea25a0ffe2 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -32,7 +32,7 @@ type TagSettingsPageProps = StackScreenProps PolicyUtils.getTagList(policyTags, orderWeight), [policyTags, orderWeight]); @@ -57,7 +57,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const deleteTagAndHideModal = () => { Tag.deletePolicyTags(policyID, [currentPolicyTag.name]); setIsDeleteTagModalOpen(false); - Navigation.goBack(); + Navigation.goBack(backTo); }; const updateWorkspaceTagEnabled = (value: boolean) => { @@ -65,6 +65,10 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { }; const navigateToEditTag = () => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name)); }; @@ -75,10 +79,18 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { ); return; } + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name)); }; const navigateToEditTagApprover = () => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name)); }; @@ -104,6 +116,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS.getRoute(policyID))} /> ; -}; +type CreateTagPageProps = StackScreenProps; -type CreateTagPageProps = WorkspaceCreateTagPageOnyxProps & StackScreenProps; - -function CreateTagPage({route, policyTags}: CreateTagPageProps) { +function CreateTagPage({route}: CreateTagPageProps) { + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); + const backTo = route.params.backTo; const validate = useCallback( (values: FormOnyxValues) => { @@ -63,9 +58,9 @@ function CreateTagPage({route, policyTags}: CreateTagPageProps) { (values: FormOnyxValues) => { Tag.createPolicyTag(route.params.policyID, values.tagName.trim()); Keyboard.dismiss(); - Navigation.goBack(); + Navigation.goBack(backTo); }, - [route.params.policyID], + [route.params.policyID, backTo], ); return ( @@ -82,7 +77,7 @@ function CreateTagPage({route, policyTags}: CreateTagPageProps) { > Navigation.goBack(backTo)} /> ({ - policyTags: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`, - }, -})(CreateTagPage); +export default CreateTagPage; diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index d63799169ca8..f97468f1b9af 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -1,8 +1,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; import InputWrapper from '@components/Form/InputWrapper'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -21,20 +20,16 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/PolicyTagNameForm'; -import type * as OnyxTypes from '@src/types/onyx'; -type WorkspaceEditTagsPageOnyxProps = { - /** Collection of tags attached to a policy */ - policyTags: OnyxEntry; -}; +type WorkspaceEditTagsPageProps = StackScreenProps; -type WorkspaceEditTagsPageProps = WorkspaceEditTagsPageOnyxProps & StackScreenProps; - -function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) { +function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${route?.params?.policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const taglistName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]); const {inputCallbackRef} = useAutoFocusInput(); + const backTo = route.params.backTo; const validateTagName = useCallback( (values: FormOnyxValues) => { @@ -58,9 +53,9 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { Tag.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags, route.params.orderWeight); } - Navigation.goBack(); + Navigation.goBack(backTo); }, - [policyTags, route.params.orderWeight, route.params.policyID, taglistName], + [policyTags, route.params.orderWeight, route.params.policyID, taglistName, backTo], ); return ( @@ -102,8 +97,4 @@ function WorkspaceEditTagsPage({route, policyTags}: WorkspaceEditTagsPageProps) WorkspaceEditTagsPage.displayName = 'WorkspaceEditTagsPage'; -export default withOnyx({ - policyTags: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route.params.policyID}`, - }, -})(WorkspaceEditTagsPage); +export default WorkspaceEditTagsPage; diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 115944ae45c0..c554a613ed7d 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -62,6 +62,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const [isOfflineModalVisible, setIsOfflineModalVisible] = useState(false); const isFocused = useIsFocused(); const policyID = route.params.policyID ?? '-1'; + const backTo = route.params.backTo; const policy = usePolicy(policyID); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`); const {selectionMode} = useMobileSelectionMode(); @@ -70,7 +71,6 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); const canSelectMultiple = !isMultiLevelTags && (shouldUseNarrowLayout ? selectionMode?.isEnabled : true); - const fetchTags = useCallback(() => { Tag.openPolicyTagsPage(policyID); }, [policyID]); @@ -172,18 +172,34 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { }; const navigateToTagsSettings = () => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(policyID, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(policyID)); }; const navigateToCreateTagPage = () => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_CREATE.getRoute(policyID, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(policyID)); }; const navigateToTagSettings = (tag: TagListItem) => { if (tag.orderWeight !== undefined) { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight)); return; } + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value)); }; @@ -304,6 +320,10 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { Modal.close(() => setIsOfflineModalVisible(true)); return; } + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); }, }, @@ -328,7 +348,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { } return menuItems; - }, [translate, hasVisibleTags, isOffline, policyID]); + }, [translate, hasVisibleTags, isOffline, policyID, backTo]); const getHeaderText = () => ( @@ -374,7 +394,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { turnOffMobileSelectionMode(); return; } - Navigation.goBack(); + Navigation.goBack(backTo); }} shouldShowThreeDotsButton={!policy?.hasMultipleTagLists} threeDotsMenuItems={threeDotsMenuItems} diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index b5b527dc4dfa..9973e4d071ae 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -2,7 +2,7 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; -import {withOnyx} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; @@ -27,11 +27,7 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; -type WorkspaceTagsSettingsPageOnyxProps = { - /** Collection of tags attached to a policy */ - policyTags: OnyxEntry; -}; -type WorkspaceTagsSettingsPageProps = WorkspaceTagsSettingsPageOnyxProps & StackScreenProps; +type WorkspaceTagsSettingsPageProps = StackScreenProps; /** * The pending state might be set by either setPolicyBillableMode or disableWorkspaceBillableExpenses. @@ -53,8 +49,10 @@ function toggleBillableExpenses(policy: OnyxEntry) { } } -function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPageProps) { - const policyID = route.params.policyID; +function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { + const policyID = route.params.policyID ?? '-1'; + const backTo = route.params.backTo; + const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); @@ -62,7 +60,6 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag const {isOffline} = useNetwork(); const hasEnabledOptions = OptionsListUtils.hasEnabledOptions(Object.values(policyTags ?? {}).flatMap(({tags}) => Object.values(tags))); const {canUseWorkspaceRules} = usePermissions(); - const updateWorkspaceRequiresTag = useCallback( (value: boolean) => { Tag.setPolicyRequiresTag(policyID, value); @@ -82,7 +79,13 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0))} + onPress={() => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAGS_EDIT.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0, backTo)); + return; + } + Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0)); + }} shouldShowRightIcon /> @@ -128,7 +131,10 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag style={[styles.defaultModalContainer]} testID={WorkspaceTagsSettingsPage.displayName} > - + Navigation.goBack(backTo)} + /> {isOffline && isLoading ? {getTagsSettings(policy)} : getTagsSettings(policy)} )} @@ -138,8 +144,4 @@ function WorkspaceTagsSettingsPage({route, policyTags}: WorkspaceTagsSettingsPag WorkspaceTagsSettingsPage.displayName = 'WorkspaceTagsSettingsPage'; -export default withOnyx({ - policyTags: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${route.params.policyID}`, - }, -})(WorkspaceTagsSettingsPage); +export default WorkspaceTagsSettingsPage; diff --git a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx index a01707a04740..45cd6881114d 100644 --- a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx @@ -53,6 +53,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { const [isDeleteTagsConfirmModalVisible, setIsDeleteTagsConfirmModalVisible] = useState(false); const isFocused = useIsFocused(); const policyID = route.params.policyID ?? '-1'; + const backTo = route.params.backTo; const policy = usePolicy(policyID); const [policyTags] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`); const {selectionMode} = useMobileSelectionMode(); @@ -141,6 +142,10 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { }; const navigateToTagSettings = (tag: TagListItem) => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value)); }; @@ -237,6 +242,10 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { } const navigateToEditTag = () => { + if (backTo) { + Navigation.navigate(ROUTES.SETTINGS_TAGS_EDIT.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0, backTo)); + return; + } Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0)); }; From a51d9b499e9c11dddeef42285d1b23abf92a598b Mon Sep 17 00:00:00 2001 From: twilight294 Date: Tue, 8 Oct 2024 14:29:15 +0000 Subject: [PATCH 03/18] Fix rightModal navigator Signed-off-by: GitHub --- .../AppNavigator/Navigators/RightModalNavigator.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx b/src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx index 0df3ae3f4b92..da1ce32bf747 100644 --- a/src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx +++ b/src/libs/Navigation/AppNavigator/Navigators/RightModalNavigator.tsx @@ -103,6 +103,10 @@ function RightModalNavigator({navigation, route}: RightModalNavigatorProps) { name={SCREENS.RIGHT_MODAL.SETTINGS_CATEGORIES} component={ModalStackNavigators.CategoriesModalStackNavigator} /> + Date: Thu, 10 Oct 2024 20:37:09 +0000 Subject: [PATCH 04/18] Fix navigation issues on all tag screens Signed-off-by: GitHub --- src/libs/Navigation/types.ts | 1 + src/pages/workspace/tags/EditTagPage.tsx | 16 ++++++++-- src/pages/workspace/tags/ImportedTagsPage.tsx | 2 +- src/pages/workspace/tags/TagApproverPage.tsx | 11 +++++-- src/pages/workspace/tags/TagSettingsPage.tsx | 30 ++++++++--------- .../workspace/tags/WorkspaceCreateTagPage.tsx | 3 +- .../workspace/tags/WorkspaceEditTagsPage.tsx | 10 ++++-- .../workspace/tags/WorkspaceTagsPage.tsx | 32 ++++--------------- .../tags/WorkspaceTagsSettingsPage.tsx | 12 +++---- .../workspace/tags/WorkspaceViewTagsPage.tsx | 22 ++++++------- 10 files changed, 72 insertions(+), 67 deletions(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 544e20c65991..54b261ffcfa9 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -313,6 +313,7 @@ type SettingsNavigatorParamList = { policyID: string; orderWeight: number; tagName: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_GL_CODE]: { policyID: string; diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index 0bf7240d2ca9..73f6bbd050a7 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -19,6 +19,7 @@ import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import * as Tag from '@userActions/Policy/Tag'; 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/WorkspaceTagForm'; @@ -26,6 +27,7 @@ type EditTagPageProps = StackScreenProps + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName, backTo) + : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName), + ) + } /> { setIsImportingTags(false); closeImportPage(); - Navigation.navigate(ROUTES.WORKSPACE_TAGS.getRoute(policyID)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); }; return ( diff --git a/src/pages/workspace/tags/TagApproverPage.tsx b/src/pages/workspace/tags/TagApproverPage.tsx index 874754b2cf4b..0d66660ae88b 100644 --- a/src/pages/workspace/tags/TagApproverPage.tsx +++ b/src/pages/workspace/tags/TagApproverPage.tsx @@ -11,18 +11,23 @@ import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import * as Tag from '@userActions/Policy/Tag'; import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; type TagApproverPageProps = StackScreenProps; function TagApproverPage({route}: TagApproverPageProps) { - const {policyID, tagName} = route.params; + const {policyID, tagName, orderWeight, backTo} = route.params; const styles = useThemeStyles(); const {translate} = useLocalize(); const tagApprover = PolicyUtils.getTagApproverRule(policyID, tagName)?.approver; + const goBack = () => { + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName)); + }; + return ( Navigation.goBack()} + onBackButtonPress={goBack} /> { Tag.setPolicyTagApprover(policyID, tagName, email); - Navigation.setNavigationActionToMicrotaskQueue(Navigation.goBack); + Navigation.setNavigationActionToMicrotaskQueue(goBack); }} /> diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index a9ea25a0ffe2..d7f5d1fa6975 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -65,11 +65,11 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { }; const navigateToEditTag = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) + : ROUTES.WORKSPACE_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name), + ); }; const navigateToEditGlCode = () => { @@ -79,19 +79,19 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { ); return; } - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) + : ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name), + ); }; const navigateToEditTagApprover = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) + : ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name), + ); }; const isThereAnyAccountingConnection = Object.keys(policy?.connections ?? {}).length !== 0; diff --git a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx index 3ed9f9a90351..29c73d8ac063 100644 --- a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx +++ b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx @@ -20,6 +20,7 @@ import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import * as Tag from '@userActions/Policy/Tag'; 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/WorkspaceTagForm'; @@ -58,7 +59,7 @@ function CreateTagPage({route}: CreateTagPageProps) { (values: FormOnyxValues) => { Tag.createPolicyTag(route.params.policyID, values.tagName.trim()); Keyboard.dismiss(); - Navigation.goBack(backTo); + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID) : undefined); }, [route.params.policyID, backTo], ); diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index f97468f1b9af..41262dba22d2 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -18,6 +18,7 @@ import type {SettingsNavigatorParamList} from '@navigation/types'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; 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/PolicyTagNameForm'; @@ -53,7 +54,7 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { Tag.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags, route.params.orderWeight); } - Navigation.goBack(backTo); + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID)); }, [policyTags, route.params.orderWeight, route.params.policyID, taglistName, backTo], ); @@ -69,7 +70,12 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { shouldEnableMaxHeight testID={WorkspaceEditTagsPage.displayName} > - + + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID)) + } + /> { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(policyID, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(policyID)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(policyID)); }; const navigateToCreateTagPage = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_CREATE.getRoute(policyID, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_CREATE.getRoute(policyID)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_CREATE.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAG_CREATE.getRoute(policyID)); }; const navigateToTagSettings = (tag: TagListItem) => { if (tag.orderWeight !== undefined) { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight)); - return; + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo) : ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight)); } - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value)); + + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value)); }; const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); @@ -320,11 +304,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { Modal.close(() => setIsOfflineModalVisible(true)); return; } - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); }, }, ]; diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index 9973e4d071ae..45267a08361c 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -80,11 +80,11 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { title={policyTagLists.at(0)?.name ?? ''} description={translate(`workspace.tags.customTagName`)} onPress={() => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAGS_EDIT.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAGS_EDIT.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0, backTo) + : ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0), + ); }} shouldShowRightIcon /> @@ -133,7 +133,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { > Navigation.goBack(backTo)} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : ROUTES.WORKSPACE_TAGS.getRoute(policyID))} /> {isOffline && isLoading ? {getTagsSettings(policy)} : getTagsSettings(policy)} diff --git a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx index 45cd6881114d..889d7f2c3015 100644 --- a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx @@ -142,11 +142,11 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { }; const navigateToTagSettings = (tag: TagListItem) => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value, backTo) + : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value), + ); }; const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); @@ -242,11 +242,11 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { } const navigateToEditTag = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_TAGS_EDIT.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_TAGS_EDIT.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0, backTo) + : ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0), + ); }; const selectionModeHeader = selectionMode?.isEnabled && isSmallScreenWidth; @@ -270,7 +270,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { turnOffMobileSelectionMode(); return; } - Navigation.goBack(); + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : ROUTES.WORKSPACE_TAGS.getRoute(policyID)); }} > {!shouldUseNarrowLayout && getHeaderButtons()} From 671179a93a608154f97ce6cf19743e49698833d0 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Fri, 11 Oct 2024 02:18:42 +0530 Subject: [PATCH 05/18] add backTo as dependency --- src/pages/workspace/tags/EditTagPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index 73f6bbd050a7..149582d8ba4d 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -66,7 +66,7 @@ function EditTagPage({route}: EditTagPageProps) { : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName), ); }, - [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight], + [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight, backTo], ); return ( From 8694a58095ebfb099db95485d8507335c38c56df Mon Sep 17 00:00:00 2001 From: twilight294 Date: Fri, 11 Oct 2024 08:29:22 +0000 Subject: [PATCH 06/18] Fix routes for RHP on categories Signed-off-by: GitHub --- src/ROUTES.ts | 20 +++++++++++++++- src/SCREENS.ts | 4 ++++ .../ModalStackNavigators/index.tsx | 4 ++++ src/libs/Navigation/linkingConfig/config.ts | 18 ++++++++++++++ src/libs/Navigation/types.ts | 4 ++++ .../categories/CategoryGLCodePage.tsx | 15 ++++++++++-- .../categories/CategoryPayrollCodePage.tsx | 15 ++++++++++-- .../categories/CategorySettingsPage.tsx | 24 +++++++++---------- .../categories/CreateCategoryPage.tsx | 8 ++----- .../workspace/categories/EditCategoryPage.tsx | 19 ++++++++------- .../categories/ImportCategoriesPage.tsx | 5 ++-- .../categories/ImportedCategoriesPage.tsx | 5 ++-- .../categories/WorkspaceCategoriesPage.tsx | 22 +++++------------ 13 files changed, 112 insertions(+), 51 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 05872df290b3..8846ec537009 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -503,7 +503,25 @@ const ROUTES = { }, SETTINGS_CATEGORY_EDIT: { route: 'settings/:policyID/category/:categoryName/edit', - getRoute: (policyID: string, categoryName: string, backTo = '') => getUrlWithBackToParam(`settings/workspaces/${policyID}/category/${encodeURIComponent(categoryName)}/edit`, backTo), + getRoute: (policyID: string, categoryName: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/category/${encodeURIComponent(categoryName)}/edit`, backTo), + }, + SETTINGS_CATEGORIES_IMPORT: { + route: 'settings/:policyID/categories/import', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/categories/import` as const, backTo), + }, + SETTINGS_CATEGORIES_IMPORTED: { + route: 'settings/:policyID/categories/imported', + getRoute: (policyID: string, backTo = '') => getUrlWithBackToParam(`settings/${policyID}/categories/imported` as const, backTo), + }, + SETTINGS_CATEGORY_PAYROLL_CODE: { + route: 'settings/:policyID/category/:categoryName/payroll-code', + getRoute: (policyID: string, categoryName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/category/${encodeURIComponent(categoryName)}/payroll-code` as const, backTo), + }, + SETTINGS_CATEGORY_GL_CODE: { + route: 'settings/:policyID/category/:categoryName/gl-code', + getRoute: (policyID: string, categoryName: string, backTo = '') => + getUrlWithBackToParam(`settings/${policyID}/category/${encodeURIComponent(categoryName)}/gl-code` as const, backTo), }, MONEY_REQUEST_STEP_CURRENCY: { route: ':action/:iouType/currency/:transactionID/:reportID/:pageIndex?', diff --git a/src/SCREENS.ts b/src/SCREENS.ts index e22f0877b58a..24bc9e757861 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -246,6 +246,10 @@ const SCREENS = { SETTINGS_CATEGORY_CREATE: 'Settings_Category_Create', SETTINGS_CATEGORY_EDIT: 'Settings_Category_Edit', SETTINGS_CATEGORIES_ROOT: 'Settings_Categories', + SETTINGS_CATEGORIES_IMPORT: 'Settings_Categories_Import', + SETTINGS_CATEGORIES_IMPORTED: 'Settings_Categories_Imported', + SETTINGS_CATEGORY_PAYROLL_CODE: 'Settings_Category_Payroll_Code', + SETTINGS_CATEGORY_GL_CODE: 'Settings_Category_GL_Code', }, EXPENSIFY_CARD: { EXPENSIFY_CARD_DETAILS: 'Expensify_Card_Details', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx index 695166a20197..d37086648930 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx @@ -142,6 +142,10 @@ const CategoriesModalStackNavigator = createModalStackNavigator({ [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_CREATE]: () => require('../../../../pages/workspace/categories/CreateCategoryPage').default, [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_EDIT]: () => require('../../../../pages/workspace/categories/EditCategoryPage').default, [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_SETTINGS]: () => require('../../../../pages/workspace/categories/CategorySettingsPage').default, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORT]: () => require('../../../../pages/workspace/categories/ImportCategoriesPage').default, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORTED]: () => require('../../../../pages/workspace/categories/ImportedCategoriesPage').default, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_PAYROLL_CODE]: () => require('../../../../pages/workspace/categories/CategoryPayrollCodePage').default, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_GL_CODE]: () => require('../../../../pages/workspace/categories/CategoryGLCodePage').default, }); const TagsModalStackNavigator = createModalStackNavigator({ diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 006cf73f5a8e..758f42a161eb 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -925,6 +925,24 @@ const config: LinkingOptions['config'] = { categoryName: (categoryName: string) => decodeURIComponent(categoryName), }, }, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORT]: { + path: ROUTES.SETTINGS_CATEGORIES_IMPORT.route, + }, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORIES_IMPORTED]: { + path: ROUTES.SETTINGS_CATEGORIES_IMPORTED.route, + }, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_PAYROLL_CODE]: { + path: ROUTES.SETTINGS_CATEGORY_PAYROLL_CODE.route, + parse: { + categoryName: (categoryName: string) => decodeURIComponent(categoryName), + }, + }, + [SCREENS.SETTINGS_CATEGORIES.SETTINGS_CATEGORY_GL_CODE]: { + path: ROUTES.SETTINGS_CATEGORY_GL_CODE.route, + parse: { + categoryName: (categoryName: string) => decodeURIComponent(categoryName), + }, + }, }, }, [SCREENS.RIGHT_MODAL.SETTINGS_TAGS]: { diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 54b261ffcfa9..12a09ea27e1f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -210,10 +210,12 @@ type SettingsNavigatorParamList = { [SCREENS.WORKSPACE.CATEGORY_PAYROLL_CODE]: { policyID: string; categoryName: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.CATEGORY_GL_CODE]: { policyID: string; categoryName: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.CATEGORY_DEFAULT_TAX_RATE]: { policyID: string; @@ -251,9 +253,11 @@ type SettingsNavigatorParamList = { }; [SCREENS.WORKSPACE.CATEGORIES_IMPORT]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.CATEGORIES_IMPORTED]: { policyID: string; + backTo?: Routes; }; [SCREENS.WORKSPACE.TAG_CREATE]: { policyID: string; diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 131f17a14242..5984495e914b 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -26,6 +26,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const policyId = route.params.policyID ?? '-1'; + const backTo = route.params.backTo; const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); const categoryName = route.params.categoryName; @@ -38,7 +39,11 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { if (newGLCode !== glCode) { Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode); } - Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName)); + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName, backTo) + : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), + ); }, [categoryName, glCode, route.params.policyID], ); @@ -57,7 +62,13 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { > Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName))} + onBackButtonPress={() => + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) + : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), + ) + } /> Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName))} + onBackButtonPress={() => + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName, backTo) + : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), + ) + } /> { - if (backTo) { - Navigation.goBack(ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo)); - return; - } - Navigation.goBack(); + Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined); }; useEffect(() => { @@ -115,11 +111,7 @@ function CategorySettingsPage({ }; const navigateToEditCategory = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_CATEGORY_EDIT.getRoute(policyID, policyCategory.name, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_EDIT.getRoute(policyID, policyCategory.name)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORY_EDIT.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_EDIT.getRoute(policyID, policyCategory.name)); }; const deleteCategory = () => { @@ -200,7 +192,11 @@ function CategorySettingsPage({ ); return; } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name, backTo) + : ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name), + ); }} shouldShowRightIcon /> @@ -220,7 +216,11 @@ function CategorySettingsPage({ ); return; } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(policyID, policyCategory.name)); + Navigation.navigate( + backTo + ? ROUTES.SETTINGS_CATEGORY_PAYROLL_CODE.getRoute(policyID, policyCategory.name, backTo) + : ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(policyID, policyCategory.name), + ); }} shouldShowRightIcon /> diff --git a/src/pages/workspace/categories/CreateCategoryPage.tsx b/src/pages/workspace/categories/CreateCategoryPage.tsx index 472cba1215af..ef365bac788c 100644 --- a/src/pages/workspace/categories/CreateCategoryPage.tsx +++ b/src/pages/workspace/categories/CreateCategoryPage.tsx @@ -33,11 +33,7 @@ function CreateCategoryPage({route, policyCategories}: CreateCategoryPageProps) const createCategory = useCallback( (values: FormOnyxValues) => { Category.createPolicyCategory(route.params.policyID, values.categoryName.trim()); - if (backTo) { - Navigation.goBack(ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo)); - return; - } - Navigation.goBack(); + Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, [backTo, route.params.policyID], ); @@ -56,7 +52,7 @@ function CreateCategoryPage({route, policyCategories}: CreateCategoryPageProps) > (backTo ? Navigation.goBack(ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo)) : Navigation.goBack())} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined)} /> - backTo - ? Navigation.goBack(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo)) - : Navigation.goBack(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName)) + Navigation.goBack( + backTo + ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) + : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), + ) } /> ); } diff --git a/src/pages/workspace/categories/ImportedCategoriesPage.tsx b/src/pages/workspace/categories/ImportedCategoriesPage.tsx index 041e2b77c91e..869542b729ac 100644 --- a/src/pages/workspace/categories/ImportedCategoriesPage.tsx +++ b/src/pages/workspace/categories/ImportedCategoriesPage.tsx @@ -30,6 +30,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { const {containsHeader = true} = spreadsheet ?? {}; const [isValidationEnabled, setIsValidationEnabled] = useState(false); const policyID = route.params.policyID; + const backTo = route.params.backTo; const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); const policy = usePolicy(policyID); const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0); @@ -120,7 +121,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { const closeImportPageAndModal = () => { setIsImportingCategories(false); closeImportPage(); - Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)); }; return ( @@ -130,7 +131,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { > Navigation.goBack(ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyID))} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyID))} /> { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList)); + Navigation.navigate( + backTo ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList), + ); }; const navigateToCategoriesSettings = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_CATEGORIES_SETTINGS.getRoute(policyId, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES_SETTINGS.getRoute(policyId)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_SETTINGS.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_SETTINGS.getRoute(policyId)); }; const navigateToCreateCategoryPage = () => { - if (backTo) { - Navigation.navigate(ROUTES.SETTINGS_CATEGORY_CREATE.getRoute(policyId, backTo)); - return; - } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORY_CREATE.getRoute(policyId)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORY_CREATE.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORY_CREATE.getRoute(policyId)); }; const dismissError = (item: PolicyOption) => { @@ -312,7 +302,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { Modal.close(() => setIsOfflineModalVisible(true)); return; } - Navigation.navigate(ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyId)); + Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyId)); }, }); } From 92f59907f3238be810eb897b5ed8e9b8122557ad Mon Sep 17 00:00:00 2001 From: twilight294 Date: Fri, 11 Oct 2024 08:37:26 +0000 Subject: [PATCH 07/18] add dependency and use Signed-off-by: GitHub --- .../categories/CategoryGLCodePage.tsx | 2 +- .../categories/CategoryPayrollCodePage.tsx | 2 +- .../categories/CreateCategoryPage.tsx | 20 +++++------------- .../workspace/categories/EditCategoryPage.tsx | 21 +++++-------------- .../categories/WorkspaceCategoriesPage.tsx | 2 +- 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 5984495e914b..551b54f746fc 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -45,7 +45,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, glCode, route.params.policyID], + [categoryName, glCode, route.params.policyID, backTo], ); return ( diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx index d0394246f435..395b8fb1023b 100644 --- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx +++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx @@ -45,7 +45,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, payrollCode, route.params.policyID], + [categoryName, payrollCode, route.params.policyID, backTo], ); return ( diff --git a/src/pages/workspace/categories/CreateCategoryPage.tsx b/src/pages/workspace/categories/CreateCategoryPage.tsx index ef365bac788c..9035242a9dec 100644 --- a/src/pages/workspace/categories/CreateCategoryPage.tsx +++ b/src/pages/workspace/categories/CreateCategoryPage.tsx @@ -1,7 +1,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -15,17 +14,12 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {PolicyCategories} from '@src/types/onyx'; import CategoryForm from './CategoryForm'; -type WorkspaceCreateCategoryPageOnyxProps = { - /** All policy categories */ - policyCategories: OnyxEntry; -}; +type CreateCategoryPageProps = StackScreenProps; -type CreateCategoryPageProps = WorkspaceCreateCategoryPageOnyxProps & StackScreenProps; - -function CreateCategoryPage({route, policyCategories}: CreateCategoryPageProps) { +function CreateCategoryPage({route}: CreateCategoryPageProps) { + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const backTo = route.params?.backTo; @@ -65,8 +59,4 @@ function CreateCategoryPage({route, policyCategories}: CreateCategoryPageProps) CreateCategoryPage.displayName = 'CreateCategoryPage'; -export default withOnyx({ - policyCategories: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route?.params?.policyID}`, - }, -})(CreateCategoryPage); +export default CreateCategoryPage; diff --git a/src/pages/workspace/categories/EditCategoryPage.tsx b/src/pages/workspace/categories/EditCategoryPage.tsx index 4a55e8939c25..7678938e1943 100644 --- a/src/pages/workspace/categories/EditCategoryPage.tsx +++ b/src/pages/workspace/categories/EditCategoryPage.tsx @@ -1,7 +1,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import React, {useCallback} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; +import {useOnyx} from 'react-native-onyx'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -15,17 +14,12 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {PolicyCategories} from '@src/types/onyx'; import CategoryForm from './CategoryForm'; -type WorkspaceEditCategoryPageOnyxProps = { - /** All policy categories */ - policyCategories: OnyxEntry; -}; +type EditCategoryPageProps = StackScreenProps; -type EditCategoryPageProps = WorkspaceEditCategoryPageOnyxProps & StackScreenProps; - -function EditCategoryPage({route, policyCategories}: EditCategoryPageProps) { +function EditCategoryPage({route}: EditCategoryPageProps) { + const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params.policyID}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const currentCategoryName = route.params.categoryName; @@ -59,7 +53,6 @@ function EditCategoryPage({route, policyCategories}: EditCategoryPageProps) { ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ); - return; }, [backTo, currentCategoryName, route.params.categoryName, route.params.policyID], ); @@ -99,8 +92,4 @@ function EditCategoryPage({route, policyCategories}: EditCategoryPageProps) { EditCategoryPage.displayName = 'EditCategoryPage'; -export default withOnyx({ - policyCategories: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route?.params?.policyID}`, - }, -})(EditCategoryPage); +export default EditCategoryPage; diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index 1391f3c82c0c..3ac09cf0802d 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -325,7 +325,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { } return menuItems; - }, [policyId, translate, isOffline, hasVisibleCategories, policy]); + }, [policyId, translate, isOffline, hasVisibleCategories, policy, backTo]); const selectionModeHeader = selectionMode?.isEnabled && shouldUseNarrowLayout; From 5d8e2dfdbdc02003cf43b1e3864cce3b5eea46f0 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 14:39:33 +0000 Subject: [PATCH 08/18] fix navigation issues on tag create and settings Signed-off-by: GitHub --- src/ROUTES.ts | 58 ++++++++++++++++--- src/components/ImportSpreadsheet.tsx | 2 +- src/pages/workspace/tags/ImportTagsPage.tsx | 2 +- src/pages/workspace/tags/TagSettingsPage.tsx | 7 ++- .../workspace/tags/WorkspaceCreateTagPage.tsx | 2 +- .../tags/WorkspaceTagsSettingsPage.tsx | 2 +- 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 8846ec537009..9715f73423b2 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -138,6 +138,14 @@ const ROUTES = { route: 'settings/security/delegate/:login/role/:role', getRoute: (login: string, role?: string) => `settings/security/delegate/${encodeURIComponent(login)}/role/${role}` as const, }, + SETTINGS_UPDATE_DELEGATE_ROLE: { + route: 'settings/security/delegate/:login/update-role/:currentRole', + getRoute: (login: string, currentRole: string) => `settings/security/delegate/${encodeURIComponent(login)}/update-role/${currentRole}` as const, + }, + SETTINGS_UPDATE_DELEGATE_ROLE_MAGIC_CODE: { + route: 'settings/security/delegate/:login/update-role/:role/magic-code', + getRoute: (login: string, role: string) => `settings/security/delegate/${encodeURIComponent(login)}/update-role/${role}/magic-code` as const, + }, SETTINGS_DELEGATE_CONFIRM: { route: 'settings/security/delegate/:login/role/:role/confirm', getRoute: (login: string, role: string) => `settings/security/delegate/${encodeURIComponent(login)}/role/${role}/confirm` as const, @@ -303,8 +311,12 @@ const ROUTES = { }, ATTACHMENTS: { route: 'attachment', - getRoute: (reportID: string, type: ValueOf, url: string, accountID?: number) => - `attachment?source=${encodeURIComponent(url)}&type=${type}${reportID ? `&reportID=${reportID}` : ''}${accountID ? `&accountID=${accountID}` : ''}` as const, + getRoute: (reportID: string, type: ValueOf, url: string, accountID?: number, isAuthTokenRequired?: boolean) => { + const reportParam = reportID ? `&reportID=${reportID}` : ''; + const accountParam = accountID ? `&accountID=${accountID}` : ''; + const authTokenParam = isAuthTokenRequired ? '&isAuthTokenRequired=true' : ''; + return `attachment?source=${encodeURIComponent(url)}&type=${type}${reportParam}${accountParam}${authTokenParam}` as const; + }, }, REPORT_PARTICIPANTS: { route: 'r/:reportID/participants', @@ -466,7 +478,7 @@ const ROUTES = { SETTINGS_TAG_APPROVER: { route: 'settings/:policyID/tag/:orderWeight/:tagName/approver', getRoute: (policyID: string, orderWeight: number, tagName: string, backTo = '') => - getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${tagName}/approver` as const, backTo), + getUrlWithBackToParam(`settings/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}/approver` as const, backTo), }, SETTINGS_TAG_LIST_VIEW: { route: 'settings/:policyID/tag-list/:orderWeight', @@ -720,10 +732,38 @@ const ROUTES = { route: 'settings/workspaces/:policyID/accounting/quickbooks-online/export/date-select', getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/export/date-select` as const, }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense` as const, + }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_ACCOUNT_SELECT: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense/account-select', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/account-select` as const, + }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT_OUT_OF_POCKET_EXPENSES_SELECT: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export/out-of-pocket-expense/entity-select', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export/out-of-pocket-expense/entity-select` as const, + }, POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT: { route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/export', getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/export` as const, }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_MODAL: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/setup-modal', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/setup-modal` as const, + }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_REQUIRED_DEVICE_MODAL: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/setup-required-device', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/setup-required-device` as const, + }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_TRIGGER_FIRST_SYNC: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/trigger-first-sync', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/trigger-first-sync` as const, + }, + POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_IMPORT: { + route: 'settings/workspaces/:policyID/accounting/quickbooks-desktop/import', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-desktop/import` as const, + }, WORKSPACE_PROFILE_NAME: { route: 'settings/workspaces/:policyID/profile/name', getRoute: (policyID: string) => `settings/workspaces/${policyID}/profile/name` as const, @@ -933,7 +973,7 @@ const ROUTES = { }, WORKSPACE_TAG_APPROVER: { route: 'settings/workspaces/:policyID/tag/:orderWeight/:tagName/approver', - getRoute: (policyID: string, orderWeight: number, tagName: string) => `settings/workspaces/${policyID}/tag/${orderWeight}/${tagName}/approver` as const, + getRoute: (policyID: string, orderWeight: number, tagName: string) => `settings/workspaces/${policyID}/tag/${orderWeight}/${encodeURIComponent(tagName)}/approver` as const, }, WORKSPACE_TAG_LIST_VIEW: { route: 'settings/workspaces/:policyID/tag-list/:orderWeight', @@ -1225,9 +1265,13 @@ const ROUTES = { route: 'onboarding/personal-details', getRoute: (backTo?: string) => getUrlWithBackToParam(`onboarding/personal-details`, backTo), }, - ONBOARDING_WORK: { - route: 'onboarding/work', - getRoute: (backTo?: string) => getUrlWithBackToParam(`onboarding/work`, backTo), + ONBOARDING_EMPLOYEES: { + route: 'onboarding/employees', + getRoute: (backTo?: string) => getUrlWithBackToParam(`onboarding/employees`, backTo), + }, + ONBOARDING_ACCOUNTING: { + route: 'onboarding/accounting', + getRoute: (backTo?: string) => getUrlWithBackToParam(`onboarding/accounting`, backTo), }, ONBOARDING_PURPOSE: { route: 'onboarding/purpose', diff --git a/src/components/ImportSpreadsheet.tsx b/src/components/ImportSpreadsheet.tsx index b68c773bc12d..ab0493faa2ff 100644 --- a/src/components/ImportSpreadsheet.tsx +++ b/src/components/ImportSpreadsheet.tsx @@ -167,7 +167,7 @@ function ImportSpreedsheet({backTo, goTo}: ImportSpreedsheetProps) { Navigation.navigate(backTo)} + onBackButtonPress={() => Navigation.goBack(backTo)} /> diff --git a/src/pages/workspace/tags/ImportTagsPage.tsx b/src/pages/workspace/tags/ImportTagsPage.tsx index 72ddeb8ca958..97df6801a658 100644 --- a/src/pages/workspace/tags/ImportTagsPage.tsx +++ b/src/pages/workspace/tags/ImportTagsPage.tsx @@ -14,7 +14,7 @@ function ImportTagsPage({route}: ImportTagsPageProps) { return ( ); } diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index d7f5d1fa6975..5df59a193ee4 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -13,6 +13,7 @@ import Switch from '@components/Switch'; import Text from '@components/Text'; import TextLink from '@components/TextLink'; import useLocalize from '@hooks/useLocalize'; +import usePermissions from '@hooks/usePermissions'; import usePolicy from '@hooks/usePolicy'; import useThemeStyles from '@hooks/useThemeStyles'; import * as ErrorUtils from '@libs/ErrorUtils'; @@ -38,7 +39,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const policyTag = useMemo(() => PolicyUtils.getTagList(policyTags, orderWeight), [policyTags, orderWeight]); const policy = usePolicy(policyID); const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); - + const {canUseCategoryAndTagApprovers} = usePermissions(); const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false); const currentPolicyTag = policyTag.tags[tagName] ?? Object.values(policyTag.tags ?? {}).find((tag) => tag.previousTagName === tagName); @@ -116,7 +117,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS.getRoute(policyID))} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} /> - {policy?.areRulesEnabled && ( + {policy?.areRulesEnabled && canUseCategoryAndTagApprovers && ( <> {translate('workspace.tags.tagRules')} diff --git a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx index 29c73d8ac063..e851ccf964a2 100644 --- a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx +++ b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx @@ -78,7 +78,7 @@ function CreateTagPage({route}: CreateTagPageProps) { > Navigation.goBack(backTo)} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined)} /> Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : ROUTES.WORKSPACE_TAGS.getRoute(policyID))} + onBackButtonPress={() => Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} /> {isOffline && isLoading ? {getTagsSettings(policy)} : getTagsSettings(policy)} From c3e7ca9a42cbd5e8e4b17c2c8e4d5532c933c812 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 14:52:18 +0000 Subject: [PATCH 09/18] correct backTo for workspace upgrade Signed-off-by: GitHub --- src/pages/workspace/categories/CategorySettingsPage.tsx | 4 +++- src/pages/workspace/tags/TagSettingsPage.tsx | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx index 5582ce73887d..2a42abf5642d 100644 --- a/src/pages/workspace/categories/CategorySettingsPage.tsx +++ b/src/pages/workspace/categories/CategorySettingsPage.tsx @@ -189,7 +189,9 @@ function CategorySettingsPage({ ROUTES.WORKSPACE_UPGRADE.getRoute( policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias, - ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name), + backTo + ? ROUTES.SETTINGS_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name, backTo) + : ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name), ), ); return; diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index 5df59a193ee4..795ecd6f15b6 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -76,7 +76,13 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const navigateToEditGlCode = () => { if (!PolicyUtils.isControlPolicy(policy)) { Navigation.navigate( - ROUTES.WORKSPACE_UPGRADE.getRoute(policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias, ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policy?.id ?? '', orderWeight, tagName)), + ROUTES.WORKSPACE_UPGRADE.getRoute( + policyID, + CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias, + backTo + ? ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policy?.id ?? '', orderWeight, tagName, backTo) + : ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policy?.id ?? '', orderWeight, tagName), + ), ); return; } From a531f90cfa0eb53eacb7d17fce92d9b3e9e354de Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 20:26:32 +0530 Subject: [PATCH 10/18] pass backTo route to create tag --- src/pages/workspace/tags/WorkspaceCreateTagPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx index e851ccf964a2..92e7b73e07e1 100644 --- a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx +++ b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx @@ -59,7 +59,7 @@ function CreateTagPage({route}: CreateTagPageProps) { (values: FormOnyxValues) => { Tag.createPolicyTag(route.params.policyID, values.tagName.trim()); Keyboard.dismiss(); - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID) : undefined); + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, [route.params.policyID, backTo], ); From 0478e9c21cdc8f46638016ed0979505730cc77c8 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 15:46:26 +0000 Subject: [PATCH 11/18] add route to category settings and add fallback to delete tag Signed-off-by: GitHub --- .../WorkspaceCategoriesSettingsPage.tsx | 19 +++++++++++++++++-- src/pages/workspace/tags/TagSettingsPage.tsx | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index c70360bd8478..e41090260d31 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -9,6 +9,7 @@ import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import usePermissions from '@hooks/usePermissions'; import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -20,9 +21,19 @@ import {setWorkspaceRequiresCategory} from '@userActions/Policy/Category'; import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import {Routes} from '@src/types/onyx/Transaction'; import SpendCategorySelectorListItem from './SpendCategorySelectorListItem'; -type WorkspaceCategoriesSettingsPageProps = WithPolicyConnectionsProps; +type WorkspaceCategoriesSettingsRouteProps = { + route: { + params: { + backTo: string; + }; + }; +}; + +type WorkspaceCategoriesSettingsPageProps = WorkspaceCategoriesSettingsRouteProps & WithPolicyConnectionsProps; function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSettingsPageProps) { const styles = useThemeStyles(); @@ -30,6 +41,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet const {canUseWorkspaceRules} = usePermissions(); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const policyID = route.params.policyID ?? '-1'; + const backTo = route.params.backTo; const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); const [currentPolicy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`); const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); @@ -90,7 +102,10 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet style={[styles.defaultModalContainer]} testID={WorkspaceCategoriesSettingsPage.displayName} > - + Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined)} + /> { Tag.deletePolicyTags(policyID, [currentPolicyTag.name]); setIsDeleteTagModalOpen(false); - Navigation.goBack(backTo); + Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined); }; const updateWorkspaceTagEnabled = (value: boolean) => { From 7f620515c13161b35944ce3e65144df8f0e9a568 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 21:22:02 +0530 Subject: [PATCH 12/18] remove unused import --- .../workspace/categories/WorkspaceCategoriesSettingsPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index e41090260d31..bdd2dad67b4a 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -22,7 +22,6 @@ import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {Routes} from '@src/types/onyx/Transaction'; import SpendCategorySelectorListItem from './SpendCategorySelectorListItem'; type WorkspaceCategoriesSettingsRouteProps = { From 255249752236b4ca73adab4f720699f794ebe26a Mon Sep 17 00:00:00 2001 From: twilight294 Date: Sat, 12 Oct 2024 21:25:48 +0530 Subject: [PATCH 13/18] fix route mismatch in tags import --- src/pages/workspace/tags/ImportTagsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/tags/ImportTagsPage.tsx b/src/pages/workspace/tags/ImportTagsPage.tsx index 97df6801a658..29a1342a2a31 100644 --- a/src/pages/workspace/tags/ImportTagsPage.tsx +++ b/src/pages/workspace/tags/ImportTagsPage.tsx @@ -14,7 +14,7 @@ function ImportTagsPage({route}: ImportTagsPageProps) { return ( ); } From edcd249c201d5d2f4f7b8e27306e2d8891800615 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Mon, 14 Oct 2024 15:04:35 +0530 Subject: [PATCH 14/18] remove unnecessary `tagName` param Co-authored-by: Pavlo Tsimura --- src/libs/Navigation/linkingConfig/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index ce0d8d380fad..73f640baf767 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -989,7 +989,6 @@ const config: LinkingOptions['config'] = { path: ROUTES.SETTINGS_TAGS_EDIT.route, parse: { orderWeight: Number, - tagName: (tagName: string) => decodeURIComponent(tagName), }, }, [SCREENS.SETTINGS_TAGS.SETTINGS_TAG_CREATE]: { From 887c85ca1a90f93527daae3dbc344eff5ba356c2 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Mon, 14 Oct 2024 11:04:57 +0000 Subject: [PATCH 15/18] add isQuickSettingsFlow const for clarity in ternary operator Signed-off-by: GitHub --- .../workspace/categories/CategoryGLCodePage.tsx | 8 +++++--- .../categories/CategoryPayrollCodePage.tsx | 8 +++++--- .../categories/CategorySettingsPage.tsx | 14 +++++++++----- .../workspace/categories/CreateCategoryPage.tsx | 8 +++++--- .../workspace/categories/EditCategoryPage.tsx | 8 +++++--- .../categories/ImportCategoriesPage.tsx | 6 ++++-- .../categories/ImportedCategoriesPage.tsx | 8 ++++++-- .../categories/WorkspaceCategoriesPage.tsx | 14 +++++++++----- .../WorkspaceCategoriesSettingsPage.tsx | 5 +++-- src/pages/workspace/tags/EditTagPage.tsx | 8 +++++--- src/pages/workspace/tags/ImportTagsPage.tsx | 6 ++++-- src/pages/workspace/tags/ImportedTagsPage.tsx | 4 +++- src/pages/workspace/tags/TagApproverPage.tsx | 6 +++++- src/pages/workspace/tags/TagGLCodePage.tsx | 6 ++++-- src/pages/workspace/tags/TagSettingsPage.tsx | 14 ++++++++------ .../workspace/tags/WorkspaceCreateTagPage.tsx | 8 +++++--- .../workspace/tags/WorkspaceEditTagsPage.tsx | 12 +++++++++--- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 16 ++++++++++------ .../workspace/tags/WorkspaceTagsSettingsPage.tsx | 6 ++++-- .../workspace/tags/WorkspaceViewTagsPage.tsx | 8 +++++--- 20 files changed, 113 insertions(+), 60 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 551b54f746fc..6a15dc5143bb 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -32,6 +33,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { const categoryName = route.params.categoryName; const glCode = policyCategories?.[categoryName]?.['GL Code']; const {inputCallbackRef} = useAutoFocusInput(); + const isQuickSettingsFlow = !isEmpty(backTo); const editGLCode = useCallback( (values: FormOnyxValues) => { @@ -40,12 +42,12 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { Category.setPolicyCategoryGLCode(route.params.policyID, categoryName, newGLCode); } Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, glCode, route.params.policyID, backTo], + [categoryName, glCode, route.params.policyID, isQuickSettingsFlow], ); return ( @@ -64,7 +66,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { title={translate('workspace.categories.glCode')} onBackButtonPress={() => Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ) diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx index 395b8fb1023b..9dd7120f05bb 100644 --- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx +++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -32,6 +33,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { const categoryName = route.params.categoryName; const payrollCode = policyCategories?.[categoryName]?.['Payroll Code']; const {inputCallbackRef} = useAutoFocusInput(); + const isQuickSettingsFlow = !isEmpty(backTo); const editPayrollCode = useCallback( (values: FormOnyxValues) => { @@ -40,12 +42,12 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { Category.setPolicyCategoryPayrollCode(route.params.policyID, categoryName, newPayrollCode); } Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, payrollCode, route.params.policyID, backTo], + [categoryName, payrollCode, route.params.policyID, isQuickSettingsFlow], ); return ( @@ -64,7 +66,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { title={translate('workspace.categories.payrollCode')} onBackButtonPress={() => Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ) diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx index 2a42abf5642d..c8195ed83307 100644 --- a/src/pages/workspace/categories/CategorySettingsPage.tsx +++ b/src/pages/workspace/categories/CategorySettingsPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -53,9 +54,10 @@ function CategorySettingsPage({ const policyCategoryExpenseLimitType = policyCategory?.expenseLimitType ?? CONST.POLICY.EXPENSE_LIMIT_TYPES.EXPENSE; const areCommentsRequired = policyCategory?.areCommentsRequired ?? false; + const isQuickSettingsFlow = !isEmpty(backTo); const navigateBack = () => { - Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined); + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined); }; useEffect(() => { @@ -113,7 +115,9 @@ function CategorySettingsPage({ }; const navigateToEditCategory = () => { - Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORY_EDIT.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_EDIT.getRoute(policyID, policyCategory.name)); + Navigation.navigate( + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_EDIT.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_EDIT.getRoute(policyID, policyCategory.name), + ); }; const deleteCategory = () => { @@ -189,7 +193,7 @@ function CategorySettingsPage({ ROUTES.WORKSPACE_UPGRADE.getRoute( policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glAndPayrollCodes.alias, - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name), ), @@ -197,7 +201,7 @@ function CategorySettingsPage({ return; } Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_GL_CODE.getRoute(policyID, policyCategory.name), ); @@ -221,7 +225,7 @@ function CategorySettingsPage({ return; } Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_PAYROLL_CODE.getRoute(policyID, policyCategory.name, backTo) : ROUTES.WORKSPACE_CATEGORY_PAYROLL_CODE.getRoute(policyID, policyCategory.name), ); diff --git a/src/pages/workspace/categories/CreateCategoryPage.tsx b/src/pages/workspace/categories/CreateCategoryPage.tsx index 9035242a9dec..28b4ecf015ef 100644 --- a/src/pages/workspace/categories/CreateCategoryPage.tsx +++ b/src/pages/workspace/categories/CreateCategoryPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import type {FormOnyxValues} from '@components/Form/types'; @@ -23,13 +24,14 @@ function CreateCategoryPage({route}: CreateCategoryPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const backTo = route.params?.backTo; + const isQuickSettingsFlow = !isEmpty(backTo); const createCategory = useCallback( (values: FormOnyxValues) => { Category.createPolicyCategory(route.params.policyID, values.categoryName.trim()); - Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined); + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, - [backTo, route.params.policyID], + [isQuickSettingsFlow, route.params.policyID], ); return ( @@ -46,7 +48,7 @@ function CreateCategoryPage({route}: CreateCategoryPageProps) { > Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined)} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined)} /> ) => { @@ -49,12 +51,12 @@ function EditCategoryPage({route}: EditCategoryPageProps) { Category.renamePolicyCategory(route.params.policyID, {oldName: currentCategoryName, newName: values.categoryName}); } Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ); }, - [backTo, currentCategoryName, route.params.categoryName, route.params.policyID], + [isQuickSettingsFlow, currentCategoryName, route.params.categoryName, route.params.policyID], ); return ( @@ -73,7 +75,7 @@ function EditCategoryPage({route}: EditCategoryPageProps) { title={translate('workspace.categories.editCategory')} onBackButtonPress={() => Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ) diff --git a/src/pages/workspace/categories/ImportCategoriesPage.tsx b/src/pages/workspace/categories/ImportCategoriesPage.tsx index 5e5975135005..1c1d6306f065 100644 --- a/src/pages/workspace/categories/ImportCategoriesPage.tsx +++ b/src/pages/workspace/categories/ImportCategoriesPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React from 'react'; import ImportSpreedsheet from '@components/ImportSpreadsheet'; import usePolicy from '@hooks/usePolicy'; @@ -15,6 +16,7 @@ function ImportCategoriesPage({route}: ImportCategoriesPageProps) { const backTo = route.params.backTo; const policy = usePolicy(policyID); const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); + const isQuickSettingsFlow = !isEmpty(backTo); if (hasAccountingConnections) { return ; @@ -22,8 +24,8 @@ function ImportCategoriesPage({route}: ImportCategoriesPageProps) { return ( ); } diff --git a/src/pages/workspace/categories/ImportedCategoriesPage.tsx b/src/pages/workspace/categories/ImportedCategoriesPage.tsx index 869542b729ac..e65080bf73df 100644 --- a/src/pages/workspace/categories/ImportedCategoriesPage.tsx +++ b/src/pages/workspace/categories/ImportedCategoriesPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import ConfirmModal from '@components/ConfirmModal'; @@ -34,6 +35,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); const policy = usePolicy(policyID); const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0); + const isQuickSettingsFlow = !isEmpty(backTo); const getColumnRoles = (): ColumnRole[] => { const roles = []; @@ -121,7 +123,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { const closeImportPageAndModal = () => { setIsImportingCategories(false); closeImportPage(); - Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES.getRoute(policyID)); }; return ( @@ -131,7 +133,9 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { > Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyID))} + onBackButtonPress={() => + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyID)) + } /> 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); + const isQuickSettingsFlow = !isEmpty(backTo); const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; @@ -141,16 +143,18 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { const navigateToCategorySettings = (category: PolicyOption) => { Navigation.navigate( - backTo ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList, backTo) : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList), + isQuickSettingsFlow + ? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList, backTo) + : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList), ); }; const navigateToCategoriesSettings = () => { - Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_SETTINGS.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_SETTINGS.getRoute(policyId)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_SETTINGS.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_SETTINGS.getRoute(policyId)); }; const navigateToCreateCategoryPage = () => { - Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORY_CREATE.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORY_CREATE.getRoute(policyId)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORY_CREATE.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORY_CREATE.getRoute(policyId)); }; const dismissError = (item: PolicyOption) => { @@ -302,7 +306,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { Modal.close(() => setIsOfflineModalVisible(true)); return; } - Navigation.navigate(backTo ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyId)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_IMPORT.getRoute(policyId, backTo) : ROUTES.WORKSPACE_CATEGORIES_IMPORT.getRoute(policyId)); }, }); } @@ -325,7 +329,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { } return menuItems; - }, [policyId, translate, isOffline, hasVisibleCategories, policy, backTo]); + }, [policyId, translate, isOffline, hasVisibleCategories, policy, isQuickSettingsFlow]); const selectionModeHeader = selectionMode?.isEnabled && shouldUseNarrowLayout; diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index e41090260d31..19168cc85822 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -1,3 +1,4 @@ +import isEmpty from 'lodash/isEmpty'; import React, {useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -22,7 +23,6 @@ import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import {Routes} from '@src/types/onyx/Transaction'; import SpendCategorySelectorListItem from './SpendCategorySelectorListItem'; type WorkspaceCategoriesSettingsRouteProps = { @@ -48,6 +48,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet const [isSelectorModalVisible, setIsSelectorModalVisible] = useState(false); const [categoryID, setCategoryID] = useState(); const [groupID, setGroupID] = useState(); + const isQuickSettingsFlow = !isEmpty(backTo); const toggleSubtitle = isConnectedToAccounting && currentConnectionName ? `${translate('workspace.categories.needCategoryForExportToIntegration')} ${currentConnectionName}.` : undefined; @@ -104,7 +105,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet > Navigation.goBack(backTo ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined)} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined)} /> ) => { @@ -61,12 +63,12 @@ function EditTagPage({route}: EditTagPageProps) { } Keyboard.dismiss(); Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName), ); }, - [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight, backTo], + [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight, isQuickSettingsFlow], ); return ( @@ -85,7 +87,7 @@ function EditTagPage({route}: EditTagPageProps) { title={translate('workspace.tags.editTag')} onBackButtonPress={() => Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName), ) diff --git a/src/pages/workspace/tags/ImportTagsPage.tsx b/src/pages/workspace/tags/ImportTagsPage.tsx index 97df6801a658..83d822888f18 100644 --- a/src/pages/workspace/tags/ImportTagsPage.tsx +++ b/src/pages/workspace/tags/ImportTagsPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React from 'react'; import ImportSpreedsheet from '@components/ImportSpreadsheet'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -10,11 +11,12 @@ type ImportTagsPageProps = StackScreenProps ); } diff --git a/src/pages/workspace/tags/ImportedTagsPage.tsx b/src/pages/workspace/tags/ImportedTagsPage.tsx index be98972be01c..153be9fce0c8 100644 --- a/src/pages/workspace/tags/ImportedTagsPage.tsx +++ b/src/pages/workspace/tags/ImportedTagsPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useMemo, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import ConfirmModal from '@components/ConfirmModal'; @@ -35,6 +36,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) { const policyTagLists = useMemo(() => PolicyUtils.getTagLists(policyTags), [policyTags]); const policy = usePolicy(policyID); const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0); + const isQuickSettingsFlow = !isEmpty(backTo); const getColumnRoles = (): ColumnRole[] => { const roles = []; @@ -117,7 +119,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) { const closeImportPageAndModal = () => { setIsImportingTags(false); closeImportPage(); - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS.getRoute(policyID)); }; return ( diff --git a/src/pages/workspace/tags/TagApproverPage.tsx b/src/pages/workspace/tags/TagApproverPage.tsx index 0d66660ae88b..c46dc126f546 100644 --- a/src/pages/workspace/tags/TagApproverPage.tsx +++ b/src/pages/workspace/tags/TagApproverPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React from 'react'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; @@ -23,9 +24,12 @@ function TagApproverPage({route}: TagApproverPageProps) { const {translate} = useLocalize(); const tagApprover = PolicyUtils.getTagApproverRule(policyID, tagName)?.approver; + const isQuickSettingsFlow = !isEmpty(backTo); const goBack = () => { - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName)); + Navigation.goBack( + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, orderWeight, tagName), + ); }; return ( diff --git a/src/pages/workspace/tags/TagGLCodePage.tsx b/src/pages/workspace/tags/TagGLCodePage.tsx index 6fd089d62c7b..c7df9f51a0f7 100644 --- a/src/pages/workspace/tags/TagGLCodePage.tsx +++ b/src/pages/workspace/tags/TagGLCodePage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -36,14 +37,15 @@ function TagGLCodePage({route}: EditTagGLCodePageProps) { const orderWeight = route.params.orderWeight; const {tags} = PolicyUtils.getTagList(policyTags, orderWeight); const glCode = tags?.[route.params.tagName]?.['GL Code']; + const isQuickSettingsFlow = !isEmpty(backTo); const goBack = useCallback(() => { Navigation.goBack( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName), ); - }, [orderWeight, route.params.policyID, tagName, backTo]); + }, [orderWeight, route.params.policyID, tagName, isQuickSettingsFlow]); const editGLCode = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index 31c86d52878c..64d644a640ff 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useEffect, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -41,6 +42,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); const {canUseCategoryAndTagApprovers} = usePermissions(); const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false); + const isQuickSettingsFlow = !isEmpty(backTo); const currentPolicyTag = policyTag.tags[tagName] ?? Object.values(policyTag.tags ?? {}).find((tag) => tag.previousTagName === tagName); @@ -58,7 +60,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const deleteTagAndHideModal = () => { Tag.deletePolicyTags(policyID, [currentPolicyTag.name]); setIsDeleteTagModalOpen(false); - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined); + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined); }; const updateWorkspaceTagEnabled = (value: boolean) => { @@ -67,7 +69,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const navigateToEditTag = () => { Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) : ROUTES.WORKSPACE_TAG_EDIT.getRoute(policyID, orderWeight, currentPolicyTag.name), ); @@ -79,7 +81,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { ROUTES.WORKSPACE_UPGRADE.getRoute( policyID, CONST.UPGRADE_FEATURE_INTRO_MAPPING.glCodes.alias, - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policy?.id ?? '', orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policy?.id ?? '', orderWeight, tagName), ), @@ -87,7 +89,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { return; } Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) : ROUTES.WORKSPACE_TAG_GL_CODE.getRoute(policyID, orderWeight, currentPolicyTag.name), ); @@ -95,7 +97,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const navigateToEditTagApprover = () => { Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name, backTo) : ROUTES.WORKSPACE_TAG_APPROVER.getRoute(policyID, orderWeight, currentPolicyTag.name), ); @@ -123,7 +125,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} /> ) => { @@ -59,9 +61,9 @@ function CreateTagPage({route}: CreateTagPageProps) { (values: FormOnyxValues) => { Tag.createPolicyTag(route.params.policyID, values.tagName.trim()); Keyboard.dismiss(); - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined); + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, - [route.params.policyID, backTo], + [route.params.policyID, isQuickSettingsFlow], ); return ( @@ -78,7 +80,7 @@ function CreateTagPage({route}: CreateTagPageProps) { > Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined)} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined)} /> PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]); const {inputCallbackRef} = useAutoFocusInput(); const backTo = route.params.backTo; + const isQuickSettingsFlow = !isEmpty(backTo); const validateTagName = useCallback( (values: FormOnyxValues) => { @@ -54,9 +56,11 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { if (values[INPUT_IDS.POLICY_TAGS_NAME] !== taglistName) { Tag.renamePolicyTaglist(route.params.policyID, {oldName: taglistName, newName: values[INPUT_IDS.POLICY_TAGS_NAME]}, policyTags, route.params.orderWeight); } - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID)); + Navigation.goBack( + isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID), + ); }, - [policyTags, route.params.orderWeight, route.params.policyID, taglistName, backTo], + [policyTags, route.params.orderWeight, route.params.policyID, taglistName, isQuickSettingsFlow], ); return ( @@ -73,7 +77,9 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID)) + Navigation.goBack( + isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID), + ) } /> { Tag.openPolicyTagsPage(policyID); }, [policyID]); + const isQuickSettingsFlow = !isEmpty(backTo); const {isOffline} = useNetwork({onReconnect: fetchTags}); @@ -172,19 +174,21 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { }; const navigateToTagsSettings = () => { - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(policyID)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(policyID)); }; const navigateToCreateTagPage = () => { - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_CREATE.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAG_CREATE.getRoute(policyID)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_CREATE.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAG_CREATE.getRoute(policyID)); }; const navigateToTagSettings = (tag: TagListItem) => { if (tag.orderWeight !== undefined) { - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo) : ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight)); + Navigation.navigate( + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo) : ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight), + ); } - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, 0, tag.value, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, 0, tag.value)); }; const selectedTagsArray = Object.keys(selectedTags).filter((key) => selectedTags[key]); @@ -304,7 +308,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { Modal.close(() => setIsOfflineModalVisible(true)); return; } - Navigation.navigate(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); + Navigation.navigate(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID)); }, }, ]; @@ -328,7 +332,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { } return menuItems; - }, [translate, hasVisibleTags, isOffline, policyID, backTo]); + }, [translate, hasVisibleTags, isOffline, policyID, isQuickSettingsFlow]); const getHeaderText = () => ( diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index 4fa92afb3269..2a54c77890af 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -1,4 +1,5 @@ import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; @@ -66,6 +67,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { }, [policyID], ); + const isQuickSettingsFlow = !isEmpty(backTo); const getTagsSettings = (policy: OnyxEntry) => ( @@ -81,7 +83,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { description={translate(`workspace.tags.customTagName`)} onPress={() => { Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_EDIT.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0, backTo) : ROUTES.WORKSPACE_EDIT_TAGS.getRoute(policyID, policyTagLists.at(0)?.orderWeight ?? 0), ); @@ -133,7 +135,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { > Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID, backTo) : undefined)} /> {isOffline && isLoading ? {getTagsSettings(policy)} : getTagsSettings(policy)} diff --git a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx index 889d7f2c3015..7a25d44ab875 100644 --- a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx @@ -1,5 +1,6 @@ import {useIsFocused} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; +import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -59,6 +60,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { const {selectionMode} = useMobileSelectionMode(); const currentTagListName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]); const currentPolicyTag = policyTags?.[currentTagListName]; + const isQuickSettingsFlow = !isEmpty(backTo); const fetchTags = useCallback(() => { Tag.openPolicyTagsPage(policyID); @@ -143,7 +145,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { const navigateToTagSettings = (tag: TagListItem) => { Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(policyID, route.params.orderWeight, tag.value), ); @@ -243,7 +245,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { const navigateToEditTag = () => { Navigation.navigate( - backTo + isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_EDIT.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0, backTo) : ROUTES.WORKSPACE_EDIT_TAGS.getRoute(route.params.policyID, currentPolicyTag?.orderWeight ?? 0), ); @@ -270,7 +272,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { turnOffMobileSelectionMode(); return; } - Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : ROUTES.WORKSPACE_TAGS.getRoute(policyID)); + Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(policyID) : ROUTES.WORKSPACE_TAGS.getRoute(policyID)); }} > {!shouldUseNarrowLayout && getHeaderButtons()} From 39130e3eaf704bdb602762cf0199b58959a5f75e Mon Sep 17 00:00:00 2001 From: twilight294 Date: Mon, 14 Oct 2024 11:13:18 +0000 Subject: [PATCH 16/18] add backTo as dependency Signed-off-by: GitHub --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 2 +- src/pages/workspace/categories/CategoryPayrollCodePage.tsx | 2 +- src/pages/workspace/categories/CreateCategoryPage.tsx | 2 +- src/pages/workspace/categories/EditCategoryPage.tsx | 2 +- src/pages/workspace/categories/WorkspaceCategoriesPage.tsx | 2 +- src/pages/workspace/tags/EditTagPage.tsx | 2 +- src/pages/workspace/tags/TagGLCodePage.tsx | 2 +- src/pages/workspace/tags/WorkspaceCreateTagPage.tsx | 2 +- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 2 +- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 6a15dc5143bb..3fa6dadc3d64 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -47,7 +47,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, glCode, route.params.policyID, isQuickSettingsFlow], + [categoryName, glCode, route.params.policyID, isQuickSettingsFlow, backTo], ); return ( diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx index 9dd7120f05bb..41211e3eb278 100644 --- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx +++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx @@ -47,7 +47,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, categoryName), ); }, - [categoryName, payrollCode, route.params.policyID, isQuickSettingsFlow], + [categoryName, payrollCode, route.params.policyID, isQuickSettingsFlow, backTo], ); return ( diff --git a/src/pages/workspace/categories/CreateCategoryPage.tsx b/src/pages/workspace/categories/CreateCategoryPage.tsx index 28b4ecf015ef..60f85f66f604 100644 --- a/src/pages/workspace/categories/CreateCategoryPage.tsx +++ b/src/pages/workspace/categories/CreateCategoryPage.tsx @@ -31,7 +31,7 @@ function CreateCategoryPage({route}: CreateCategoryPageProps) { Category.createPolicyCategory(route.params.policyID, values.categoryName.trim()); Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, - [isQuickSettingsFlow, route.params.policyID], + [isQuickSettingsFlow, route.params.policyID, backTo], ); return ( diff --git a/src/pages/workspace/categories/EditCategoryPage.tsx b/src/pages/workspace/categories/EditCategoryPage.tsx index d8712a4abf90..92491b4911a5 100644 --- a/src/pages/workspace/categories/EditCategoryPage.tsx +++ b/src/pages/workspace/categories/EditCategoryPage.tsx @@ -56,7 +56,7 @@ function EditCategoryPage({route}: EditCategoryPageProps) { : ROUTES.WORKSPACE_CATEGORY_SETTINGS.getRoute(route.params.policyID, route.params.categoryName), ); }, - [isQuickSettingsFlow, currentCategoryName, route.params.categoryName, route.params.policyID], + [isQuickSettingsFlow, currentCategoryName, route.params.categoryName, route.params.policyID, backTo], ); return ( diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index a2ac25a8f179..56ec6651ee25 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -329,7 +329,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { } return menuItems; - }, [policyId, translate, isOffline, hasVisibleCategories, policy, isQuickSettingsFlow]); + }, [policyId, translate, isOffline, hasVisibleCategories, policy, isQuickSettingsFlow, backTo]); const selectionModeHeader = selectionMode?.isEnabled && shouldUseNarrowLayout; diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index c2d39a352af7..371835844072 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -51,7 +51,7 @@ function EditTagPage({route}: EditTagPageProps) { return errors; }, - [policyTags, route.params.orderWeight, currentTagName, translate], + [policyTags, route.params.orderWeight, currentTagName, translate, backTo], ); const editTag = useCallback( diff --git a/src/pages/workspace/tags/TagGLCodePage.tsx b/src/pages/workspace/tags/TagGLCodePage.tsx index c7df9f51a0f7..4c8cd1a8672f 100644 --- a/src/pages/workspace/tags/TagGLCodePage.tsx +++ b/src/pages/workspace/tags/TagGLCodePage.tsx @@ -45,7 +45,7 @@ function TagGLCodePage({route}: EditTagGLCodePageProps) { ? ROUTES.SETTINGS_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName, backTo) : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route.params.policyID, orderWeight, tagName), ); - }, [orderWeight, route.params.policyID, tagName, isQuickSettingsFlow]); + }, [orderWeight, route.params.policyID, tagName, isQuickSettingsFlow, backTo]); const editGLCode = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx index 8e76028eab85..a7deb126fc43 100644 --- a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx +++ b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx @@ -63,7 +63,7 @@ function CreateTagPage({route}: CreateTagPageProps) { Keyboard.dismiss(); Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_ROOT.getRoute(route.params.policyID, backTo) : undefined); }, - [route.params.policyID, isQuickSettingsFlow], + [route.params.policyID, isQuickSettingsFlow, backTo], ); return ( diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index f30ac99fe362..2365e34451aa 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -60,7 +60,7 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_SETTINGS.getRoute(route?.params?.policyID, backTo) : ROUTES.WORKSPACE_TAGS_SETTINGS.getRoute(route?.params?.policyID), ); }, - [policyTags, route.params.orderWeight, route.params.policyID, taglistName, isQuickSettingsFlow], + [policyTags, route.params.orderWeight, route.params.policyID, taglistName, isQuickSettingsFlow, backTo], ); return ( diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index a17e53be0a96..eb25d7407d7a 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -332,7 +332,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { } return menuItems; - }, [translate, hasVisibleTags, isOffline, policyID, isQuickSettingsFlow]); + }, [translate, hasVisibleTags, isOffline, policyID, isQuickSettingsFlow, backTo]); const getHeaderText = () => ( From 82f5ba0dcf9fba2a404f55c19a52817387e609cc Mon Sep 17 00:00:00 2001 From: twilight294 Date: Mon, 14 Oct 2024 11:15:51 +0000 Subject: [PATCH 17/18] fix wrong dependency import Signed-off-by: GitHub --- src/pages/workspace/tags/EditTagPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index 371835844072..7bf3202769a7 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -51,7 +51,7 @@ function EditTagPage({route}: EditTagPageProps) { return errors; }, - [policyTags, route.params.orderWeight, currentTagName, translate, backTo], + [policyTags, route.params.orderWeight, currentTagName, translate], ); const editTag = useCallback( @@ -68,7 +68,7 @@ function EditTagPage({route}: EditTagPageProps) { : ROUTES.WORKSPACE_TAG_SETTINGS.getRoute(route?.params?.policyID, route.params.orderWeight, route.params.tagName), ); }, - [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight, isQuickSettingsFlow], + [currentTagName, route.params.policyID, route.params.tagName, route.params.orderWeight, isQuickSettingsFlow, backTo], ); return ( From 1dd6f993f1e479d4eac6dd3de355510ed8257093 Mon Sep 17 00:00:00 2001 From: twilight294 Date: Mon, 14 Oct 2024 14:46:21 +0000 Subject: [PATCH 18/18] get ride of lodash Signed-off-by: GitHub --- src/pages/workspace/categories/CategoryGLCodePage.tsx | 3 +-- src/pages/workspace/categories/CategoryPayrollCodePage.tsx | 3 +-- src/pages/workspace/categories/CategorySettingsPage.tsx | 3 +-- src/pages/workspace/categories/CreateCategoryPage.tsx | 3 +-- src/pages/workspace/categories/EditCategoryPage.tsx | 3 +-- src/pages/workspace/categories/ImportCategoriesPage.tsx | 3 +-- src/pages/workspace/categories/ImportedCategoriesPage.tsx | 3 +-- src/pages/workspace/categories/WorkspaceCategoriesPage.tsx | 3 +-- .../workspace/categories/WorkspaceCategoriesSettingsPage.tsx | 3 +-- src/pages/workspace/tags/EditTagPage.tsx | 3 +-- src/pages/workspace/tags/ImportTagsPage.tsx | 3 +-- src/pages/workspace/tags/ImportedTagsPage.tsx | 5 ++--- src/pages/workspace/tags/TagApproverPage.tsx | 3 +-- src/pages/workspace/tags/TagGLCodePage.tsx | 3 +-- src/pages/workspace/tags/TagSettingsPage.tsx | 3 +-- src/pages/workspace/tags/WorkspaceCreateTagPage.tsx | 3 +-- src/pages/workspace/tags/WorkspaceEditTagsPage.tsx | 3 +-- src/pages/workspace/tags/WorkspaceTagsPage.tsx | 3 +-- src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx | 3 +-- src/pages/workspace/tags/WorkspaceViewTagsPage.tsx | 3 +-- 20 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/pages/workspace/categories/CategoryGLCodePage.tsx b/src/pages/workspace/categories/CategoryGLCodePage.tsx index 3fa6dadc3d64..01cb73182151 100644 --- a/src/pages/workspace/categories/CategoryGLCodePage.tsx +++ b/src/pages/workspace/categories/CategoryGLCodePage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -33,7 +32,7 @@ function CategoryGLCodePage({route}: EditCategoryPageProps) { const categoryName = route.params.categoryName; const glCode = policyCategories?.[categoryName]?.['GL Code']; const {inputCallbackRef} = useAutoFocusInput(); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const editGLCode = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx index 41211e3eb278..a489d9db656c 100644 --- a/src/pages/workspace/categories/CategoryPayrollCodePage.tsx +++ b/src/pages/workspace/categories/CategoryPayrollCodePage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -33,7 +32,7 @@ function CategoryPayrollCodePage({route}: EditCategoryPageProps) { const categoryName = route.params.categoryName; const payrollCode = policyCategories?.[categoryName]?.['Payroll Code']; const {inputCallbackRef} = useAutoFocusInput(); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const editPayrollCode = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/categories/CategorySettingsPage.tsx b/src/pages/workspace/categories/CategorySettingsPage.tsx index c8195ed83307..b371f9b799ab 100644 --- a/src/pages/workspace/categories/CategorySettingsPage.tsx +++ b/src/pages/workspace/categories/CategorySettingsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -54,7 +53,7 @@ function CategorySettingsPage({ const policyCategoryExpenseLimitType = policyCategory?.expenseLimitType ?? CONST.POLICY.EXPENSE_LIMIT_TYPES.EXPENSE; const areCommentsRequired = policyCategory?.areCommentsRequired ?? false; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const navigateBack = () => { Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_CATEGORIES_ROOT.getRoute(policyID, backTo) : undefined); diff --git a/src/pages/workspace/categories/CreateCategoryPage.tsx b/src/pages/workspace/categories/CreateCategoryPage.tsx index 60f85f66f604..c862be9fc60a 100644 --- a/src/pages/workspace/categories/CreateCategoryPage.tsx +++ b/src/pages/workspace/categories/CreateCategoryPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import type {FormOnyxValues} from '@components/Form/types'; @@ -24,7 +23,7 @@ function CreateCategoryPage({route}: CreateCategoryPageProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const backTo = route.params?.backTo; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const createCategory = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/categories/EditCategoryPage.tsx b/src/pages/workspace/categories/EditCategoryPage.tsx index 92491b4911a5..330c47f0197f 100644 --- a/src/pages/workspace/categories/EditCategoryPage.tsx +++ b/src/pages/workspace/categories/EditCategoryPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import type {FormInputErrors, FormOnyxValues} from '@components/Form/types'; @@ -25,7 +24,7 @@ function EditCategoryPage({route}: EditCategoryPageProps) { const {translate} = useLocalize(); const currentCategoryName = route.params.categoryName; const backTo = route.params?.backTo; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const validate = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/categories/ImportCategoriesPage.tsx b/src/pages/workspace/categories/ImportCategoriesPage.tsx index 1c1d6306f065..82afe6dfc812 100644 --- a/src/pages/workspace/categories/ImportCategoriesPage.tsx +++ b/src/pages/workspace/categories/ImportCategoriesPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React from 'react'; import ImportSpreedsheet from '@components/ImportSpreadsheet'; import usePolicy from '@hooks/usePolicy'; @@ -16,7 +15,7 @@ function ImportCategoriesPage({route}: ImportCategoriesPageProps) { const backTo = route.params.backTo; const policy = usePolicy(policyID); const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; if (hasAccountingConnections) { return ; diff --git a/src/pages/workspace/categories/ImportedCategoriesPage.tsx b/src/pages/workspace/categories/ImportedCategoriesPage.tsx index e65080bf73df..138c7ea681df 100644 --- a/src/pages/workspace/categories/ImportedCategoriesPage.tsx +++ b/src/pages/workspace/categories/ImportedCategoriesPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useState} from 'react'; import {useOnyx} from 'react-native-onyx'; import ConfirmModal from '@components/ConfirmModal'; @@ -35,7 +34,7 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) { const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`); const policy = usePolicy(policyID); const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const getColumnRoles = (): ColumnRole[] => { const roles = []; diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index 56ec6651ee25..02822c8b66d5 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -1,6 +1,5 @@ import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import lodashSortBy from 'lodash/sortBy'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; @@ -76,7 +75,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const canSelectMultiple = shouldUseNarrowLayout ? selectionMode?.isEnabled : true; diff --git a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx index 19168cc85822..2b3fae8e972c 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesSettingsPage.tsx @@ -1,4 +1,3 @@ -import isEmpty from 'lodash/isEmpty'; import React, {useMemo, useState} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -48,7 +47,7 @@ function WorkspaceCategoriesSettingsPage({policy, route}: WorkspaceCategoriesSet const [isSelectorModalVisible, setIsSelectorModalVisible] = useState(false); const [categoryID, setCategoryID] = useState(); const [groupID, setGroupID] = useState(); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = backTo; const toggleSubtitle = isConnectedToAccounting && currentConnectionName ? `${translate('workspace.categories.needCategoryForExportToIntegration')} ${currentConnectionName}.` : undefined; diff --git a/src/pages/workspace/tags/EditTagPage.tsx b/src/pages/workspace/tags/EditTagPage.tsx index 7bf3202769a7..d20fce3b3dd4 100644 --- a/src/pages/workspace/tags/EditTagPage.tsx +++ b/src/pages/workspace/tags/EditTagPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {Keyboard} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -33,7 +32,7 @@ function EditTagPage({route}: EditTagPageProps) { const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); const currentTagName = PolicyUtils.getCleanedTagName(route.params.tagName); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const validate = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/ImportTagsPage.tsx b/src/pages/workspace/tags/ImportTagsPage.tsx index 83d822888f18..1bbe22750210 100644 --- a/src/pages/workspace/tags/ImportTagsPage.tsx +++ b/src/pages/workspace/tags/ImportTagsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React from 'react'; import ImportSpreedsheet from '@components/ImportSpreadsheet'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -11,7 +10,7 @@ type ImportTagsPageProps = StackScreenProps PolicyUtils.getTagLists(policyTags), [policyTags]); const policy = usePolicy(policyID); const columnNames = generateColumnNames(spreadsheet?.data?.length ?? 0); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const getColumnRoles = (): ColumnRole[] => { const roles = []; @@ -129,7 +128,7 @@ function ImportedTagsPage({route}: ImportedTagsPageProps) { > Navigation.goBack(backTo ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))} + onBackButtonPress={() => Navigation.goBack(isQuickSettingsFlow ? ROUTES.SETTINGS_TAGS_IMPORT.getRoute(policyID, backTo) : ROUTES.WORKSPACE_TAGS_IMPORT.getRoute(policyID))} /> { Navigation.goBack( diff --git a/src/pages/workspace/tags/TagGLCodePage.tsx b/src/pages/workspace/tags/TagGLCodePage.tsx index 4c8cd1a8672f..df93b7b61b97 100644 --- a/src/pages/workspace/tags/TagGLCodePage.tsx +++ b/src/pages/workspace/tags/TagGLCodePage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {useOnyx} from 'react-native-onyx'; import FormProvider from '@components/Form/FormProvider'; @@ -37,7 +36,7 @@ function TagGLCodePage({route}: EditTagGLCodePageProps) { const orderWeight = route.params.orderWeight; const {tags} = PolicyUtils.getTagList(policyTags, orderWeight); const glCode = tags?.[route.params.tagName]?.['GL Code']; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const goBack = useCallback(() => { Navigation.goBack( diff --git a/src/pages/workspace/tags/TagSettingsPage.tsx b/src/pages/workspace/tags/TagSettingsPage.tsx index 64d644a640ff..e57571ca0a5f 100644 --- a/src/pages/workspace/tags/TagSettingsPage.tsx +++ b/src/pages/workspace/tags/TagSettingsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useEffect, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -42,7 +41,7 @@ function TagSettingsPage({route, navigation}: TagSettingsPageProps) { const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); const {canUseCategoryAndTagApprovers} = usePermissions(); const [isDeleteTagModalOpen, setIsDeleteTagModalOpen] = React.useState(false); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const currentPolicyTag = policyTag.tags[tagName] ?? Object.values(policyTag.tags ?? {}).find((tag) => tag.previousTagName === tagName); diff --git a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx index a7deb126fc43..a7900fe957a2 100644 --- a/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx +++ b/src/pages/workspace/tags/WorkspaceCreateTagPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback} from 'react'; import {Keyboard} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -33,7 +32,7 @@ function CreateTagPage({route}: CreateTagPageProps) { const {translate} = useLocalize(); const {inputCallbackRef} = useAutoFocusInput(); const backTo = route.params.backTo; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const validate = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx index 2365e34451aa..f243c695e84a 100644 --- a/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceEditTagsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -32,7 +31,7 @@ function WorkspaceEditTagsPage({route}: WorkspaceEditTagsPageProps) { const taglistName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]); const {inputCallbackRef} = useAutoFocusInput(); const backTo = route.params.backTo; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const validateTagName = useCallback( (values: FormOnyxValues) => { diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index eb25d7407d7a..5574b5c78421 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -1,6 +1,5 @@ import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import lodashSortBy from 'lodash/sortBy'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; @@ -75,7 +74,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const fetchTags = useCallback(() => { Tag.openPolicyTagsPage(policyID); }, [policyID]); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const {isOffline} = useNetwork({onReconnect: fetchTags}); diff --git a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx index 2a54c77890af..3fadba088648 100644 --- a/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsSettingsPage.tsx @@ -1,5 +1,4 @@ import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; @@ -67,7 +66,7 @@ function WorkspaceTagsSettingsPage({route}: WorkspaceTagsSettingsPageProps) { }, [policyID], ); - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const getTagsSettings = (policy: OnyxEntry) => ( diff --git a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx index 7a25d44ab875..c7bd1cfbacda 100644 --- a/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceViewTagsPage.tsx @@ -1,6 +1,5 @@ import {useIsFocused} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; -import isEmpty from 'lodash/isEmpty'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {ActivityIndicator, View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; @@ -60,7 +59,7 @@ function WorkspaceViewTagsPage({route}: WorkspaceViewTagsProps) { const {selectionMode} = useMobileSelectionMode(); const currentTagListName = useMemo(() => PolicyUtils.getTagListName(policyTags, route.params.orderWeight), [policyTags, route.params.orderWeight]); const currentPolicyTag = policyTags?.[currentTagListName]; - const isQuickSettingsFlow = !isEmpty(backTo); + const isQuickSettingsFlow = !!backTo; const fetchTags = useCallback(() => { Tag.openPolicyTagsPage(policyID);