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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/components/ImportSpreadsheetConfirmModal.tsx
Comment thread
shubham1206agra marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import type {TranslationParameters} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import ConfirmModal from './ConfirmModal';

type ImportSpreadsheetConfirmModalProps = {
/** Modal visibility */
isVisible: boolean;

/** A function to close both the import page and the modal. */
closeImportPageAndModal: () => void;

/** Callback method fired when the modal is hidden */
onModalHide?: () => void;
};

function ImportSpreadsheetConfirmModal({isVisible, closeImportPageAndModal, onModalHide}: ImportSpreadsheetConfirmModalProps) {
const {translate} = useLocalize();
const [spreadsheet] = useOnyx(ONYXKEYS.IMPORTED_SPREADSHEET, {canBeMissing: true});

const titleText = spreadsheet?.importFinalModal?.titleKey ? translate(spreadsheet.importFinalModal.titleKey) : '';
const promptText = spreadsheet?.importFinalModal?.promptKey
? translate(spreadsheet.importFinalModal.promptKey, spreadsheet.importFinalModal.promptKeyParams as TranslationParameters<typeof spreadsheet.importFinalModal.promptKey>[0])
: '';

return (
<ConfirmModal
isVisible={isVisible}
title={titleText}
prompt={promptText}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
shouldHandleNavigationBack
onModalHide={onModalHide}
/>
);
}

ImportSpreadsheetConfirmModal.displayName = 'ImportSpreadsheetConfirmModal';

export default ImportSpreadsheetConfirmModal;
17 changes: 9 additions & 8 deletions src/libs/actions/Policy/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from '@libs/Localize';
import Log from '@libs/Log';
import enhanceParameters from '@libs/Network/enhanceParameters';
import {hasEnabledOptions} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -260,10 +258,11 @@ function updateImportSpreadsheetData(categoriesLength: number) {
value: {
shouldFinalModalBeOpened: true,
importFinalModal: {
// eslint-disable-next-line @typescript-eslint/no-deprecated
title: translateLocal('spreadsheet.importSuccessfulTitle'),
// eslint-disable-next-line @typescript-eslint/no-deprecated
prompt: translateLocal('spreadsheet.importCategoriesSuccessfulDescription', {categories: categoriesLength}),
titleKey: 'spreadsheet.importSuccessfulTitle',
promptKey: 'spreadsheet.importCategoriesSuccessfulDescription',
promptKeyParams: {
categories: categoriesLength,
},
},
},
},
Expand All @@ -275,8 +274,10 @@ function updateImportSpreadsheetData(categoriesLength: number) {
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importFailedTitle',
promptKey: 'spreadsheet.importFailedDescription',
},
},
},
],
Expand Down
18 changes: 10 additions & 8 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import * as ApiUtils from '@libs/ApiUtils';
import DateUtils from '@libs/DateUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from '@libs/Localize';
import Log from '@libs/Log';
import enhanceParameters from '@libs/Network/enhanceParameters';
import Parser from '@libs/Parser';
Expand Down Expand Up @@ -208,10 +206,12 @@ function updateImportSpreadsheetData(addedMembersLength: number, updatedMembersL
value: {
shouldFinalModalBeOpened: true,
importFinalModal: {
// eslint-disable-next-line @typescript-eslint/no-deprecated
title: translateLocal('spreadsheet.importSuccessfulTitle'),
// eslint-disable-next-line @typescript-eslint/no-deprecated
prompt: translateLocal('spreadsheet.importMembersSuccessfulDescription', {added: addedMembersLength, updated: updatedMembersLength}),
titleKey: 'spreadsheet.importSuccessfulTitle',
promptKey: 'spreadsheet.importMembersSuccessfulDescription',
promptKeyParams: {
added: addedMembersLength,
updated: updatedMembersLength,
},
},
},
},
Expand All @@ -223,8 +223,10 @@ function updateImportSpreadsheetData(addedMembersLength: number, updatedMembersL
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importFailedTitle',
promptKey: 'spreadsheet.importFailedDescription',
},
},
},
],
Expand Down
17 changes: 9 additions & 8 deletions src/libs/actions/Policy/PerDiem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import {getCommandURL} from '@libs/ApiUtils';
import fileDownload from '@libs/fileDownload';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from '@libs/Localize';
import enhanceParameters from '@libs/Network/enhanceParameters';
import {generateHexadecimalValue} from '@libs/NumberUtils';
import {goBackWhenEnableFeature} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -112,10 +110,11 @@ function updateImportSpreadsheetData(ratesLength: number) {
value: {
shouldFinalModalBeOpened: true,
importFinalModal: {
// eslint-disable-next-line @typescript-eslint/no-deprecated
title: translateLocal('spreadsheet.importSuccessfulTitle'),
// eslint-disable-next-line @typescript-eslint/no-deprecated
prompt: translateLocal('spreadsheet.importPerDiemRatesSuccessfulDescription', {rates: ratesLength}),
titleKey: 'spreadsheet.importSuccessfulTitle',
promptKey: 'spreadsheet.importPerDiemRatesSuccessfulDescription',
promptKeyParams: {
rates: ratesLength,
},
},
},
},
Expand All @@ -127,8 +126,10 @@ function updateImportSpreadsheetData(ratesLength: number) {
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importFailedTitle',
promptKey: 'spreadsheet.importFailedDescription',
},
},
},
],
Expand Down
29 changes: 17 additions & 12 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import * as ErrorUtils from '@libs/ErrorUtils';
import fileDownload from '@libs/fileDownload';
import {readFileAsync} from '@libs/fileDownload/FileUtils';
import getIsNarrowLayout from '@libs/getIsNarrowLayout';
// eslint-disable-next-line @typescript-eslint/no-deprecated
import {translateLocal} from '@libs/Localize';
import Log from '@libs/Log';
import enhanceParameters from '@libs/Network/enhanceParameters';
import * as PolicyUtils from '@libs/PolicyUtils';
Expand Down Expand Up @@ -97,10 +95,11 @@ function updateImportSpreadsheetData(tagsLength: number): OnyxData {
value: {
shouldFinalModalBeOpened: true,
importFinalModal: {
// eslint-disable-next-line @typescript-eslint/no-deprecated
title: translateLocal('spreadsheet.importSuccessfulTitle'),
// eslint-disable-next-line @typescript-eslint/no-deprecated
prompt: translateLocal('spreadsheet.importTagsSuccessfulDescription', {tags: tagsLength}),
titleKey: 'spreadsheet.importSuccessfulTitle',
promptKey: 'spreadsheet.importTagsSuccessfulDescription',
promptKeyParams: {
tags: tagsLength,
},
},
},
},
Expand All @@ -112,8 +111,10 @@ function updateImportSpreadsheetData(tagsLength: number): OnyxData {
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importFailedTitle',
promptKey: 'spreadsheet.importFailedDescription',
},
},
},
],
Expand Down Expand Up @@ -809,8 +810,10 @@ function importMultiLevelTags(policyID: string, spreadsheet: ImportedSpreadsheet
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importSuccessfulTitle'), prompt: translateLocal('spreadsheet.importMultiLevelTagsSuccessfulDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importSuccessfulTitle',
promptKey: 'spreadsheet.importMultiLevelTagsSuccessfulDescription',
},
},
},
],
Expand All @@ -827,8 +830,10 @@ function importMultiLevelTags(policyID: string, spreadsheet: ImportedSpreadsheet
key: ONYXKEYS.IMPORTED_SPREADSHEET,
value: {
shouldFinalModalBeOpened: true,
// eslint-disable-next-line @typescript-eslint/no-deprecated
importFinalModal: {title: translateLocal('spreadsheet.importFailedTitle'), prompt: translateLocal('spreadsheet.importFailedDescription')},
importFinalModal: {
titleKey: 'spreadsheet.importFailedTitle',
promptKey: 'spreadsheet.importFailedDescription',
},
},
},
],
Expand Down
12 changes: 3 additions & 9 deletions src/pages/workspace/categories/ImportedCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useCallback, useState} from 'react';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import type {ColumnRole} from '@components/ImportColumn';
import ImportSpreadsheetColumns from '@components/ImportSpreadsheetColumns';
import ImportSpreadsheetConfirmModal from '@components/ImportSpreadsheetConfirmModal';
import ScreenWrapper from '@components/ScreenWrapper';
import useCloseImportPage from '@hooks/useCloseImportPage';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -156,15 +156,9 @@ function ImportedCategoriesPage({route}: ImportedCategoriesPageProps) {
learnMoreLink={CONST.IMPORT_SPREADSHEET.CATEGORIES_ARTICLE_LINK}
/>

<ConfirmModal
<ImportSpreadsheetConfirmModal
isVisible={spreadsheet?.shouldFinalModalBeOpened}
title={spreadsheet?.importFinalModal?.title ?? ''}
prompt={spreadsheet?.importFinalModal?.prompt ?? ''}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
Comment on lines +159 to -164

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Came from this issue
We need to pass shouldHandleNavigationBack={false} to prevent the issue with navigation to the import spreadsheet page after importing categories and pressing go back
More context here

confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
shouldHandleNavigationBack
closeImportPageAndModal={closeImportPageAndModal}
/>
</ScreenWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import {View} from 'react-native';
import type {GestureResponderEvent} from 'react-native/Libraries/Types/CoreEventTypes';
import type {ValueOf} from 'type-fest';
import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
import FixedFooter from '@components/FixedFooter';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ImportSpreadsheetConfirmModal from '@components/ImportSpreadsheetConfirmModal';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
Expand Down Expand Up @@ -194,15 +194,9 @@ function ImportedMembersConfirmationPage({route}: ImportedMembersConfirmationPag
</View>
</PressableWithoutFeedback>
</FixedFooter>
<ConfirmModal
<ImportSpreadsheetConfirmModal
isVisible={spreadsheet?.shouldFinalModalBeOpened}
title={spreadsheet?.importFinalModal?.title ?? ''}
prompt={spreadsheet?.importFinalModal?.prompt ?? ''}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
shouldHandleNavigationBack
closeImportPageAndModal={closeImportPageAndModal}
/>
<WorkspaceMemberDetailsRoleSelectionModal
isVisible={isRoleSelectionModalVisible}
Expand Down
12 changes: 3 additions & 9 deletions src/pages/workspace/members/ImportedMembersPage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {useCallback, useState} from 'react';
import {InteractionManager} from 'react-native';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import type {ColumnRole} from '@components/ImportColumn';
import ImportSpreadsheetColumns from '@components/ImportSpreadsheetColumns';
import ImportSpreadsheetConfirmModal from '@components/ImportSpreadsheetConfirmModal';
import ScreenWrapper from '@components/ScreenWrapper';
import useCloseImportPage from '@hooks/useCloseImportPage';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -188,15 +188,9 @@ function ImportedMembersPage({route}: ImportedMembersPageProps) {
isButtonLoading={isImporting}
learnMoreLink={CONST.IMPORT_SPREADSHEET.MEMBERS_ARTICLE_LINK}
/>
<ConfirmModal
<ImportSpreadsheetConfirmModal
isVisible={spreadsheet?.shouldFinalModalBeOpened && shouldShowConfirmModal}
title={spreadsheet?.importFinalModal?.title ?? ''}
prompt={spreadsheet?.importFinalModal?.prompt ?? ''}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
shouldHandleNavigationBack
closeImportPageAndModal={closeImportPageAndModal}
onModalHide={() => {
// eslint-disable-next-line @typescript-eslint/no-deprecated
InteractionManager.runAfterInteractions(() => Navigation.goBack(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)));
Expand Down
11 changes: 3 additions & 8 deletions src/pages/workspace/perDiem/ImportedPerDiemPage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, {useCallback, useState} from 'react';
import ConfirmModal from '@components/ConfirmModal';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import type {ColumnRole} from '@components/ImportColumn';
import ImportSpreadsheetColumns from '@components/ImportSpreadsheetColumns';
import ImportSpreadsheetConfirmModal from '@components/ImportSpreadsheetConfirmModal';
import ScreenWrapper from '@components/ScreenWrapper';
import useCloseImportPage from '@hooks/useCloseImportPage';
import useLocalize from '@hooks/useLocalize';
Expand Down Expand Up @@ -161,14 +161,9 @@ function ImportedPerDiemPage({route}: ImportedPerDiemPageProps) {
learnMoreLink={CONST.IMPORT_SPREADSHEET.CATEGORIES_ARTICLE_LINK}
/>

<ConfirmModal
<ImportSpreadsheetConfirmModal
isVisible={spreadsheet?.shouldFinalModalBeOpened}
title={spreadsheet?.importFinalModal?.title ?? ''}
prompt={spreadsheet?.importFinalModal?.prompt ?? ''}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
closeImportPageAndModal={closeImportPageAndModal}
/>
</ScreenWrapper>
);
Expand Down
12 changes: 3 additions & 9 deletions src/pages/workspace/tags/ImportMultiLevelTagsSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import Button from '@components/Button';
import ConfirmModal from '@components/ConfirmModal';
import FixedFooter from '@components/FixedFooter';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ImportSpreadsheet from '@components/ImportSpreadsheet';
import ImportSpreadsheetConfirmModal from '@components/ImportSpreadsheetConfirmModal';
import ScreenWrapper from '@components/ScreenWrapper';
import Switch from '@components/Switch';
import Text from '@components/Text';
Expand Down Expand Up @@ -146,15 +146,9 @@ function ImportMultiLevelTagsSettingsPage({route}: ImportMultiLevelTagsSettingsP
large
/>
</FixedFooter>
<ConfirmModal
<ImportSpreadsheetConfirmModal
isVisible={isFocused && (spreadsheet?.shouldFinalModalBeOpened ?? false)}
title={spreadsheet?.importFinalModal?.title ?? ''}
prompt={spreadsheet?.importFinalModal?.prompt ?? ''}
onConfirm={closeImportPageAndModal}
onCancel={closeImportPageAndModal}
confirmText={translate('common.buttonConfirm')}
shouldShowCancelButton={false}
shouldHandleNavigationBack
closeImportPageAndModal={closeImportPageAndModal}
/>
</FullPageOfflineBlockingView>
</ScreenWrapper>
Expand Down
Loading