Skip to content

Commit

Permalink
Merge pull request #47882 from Expensify/arosiclair-revert-47341
Browse files Browse the repository at this point in the history
Revert "Merge pull request #47341 from software-mansion-labs/@zfurtak
  • Loading branch information
arosiclair authored Aug 23, 2024
2 parents 2026c78 + f3312e1 commit 804bd26
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 62 deletions.
1 change: 0 additions & 1 deletion src/components/AttachmentModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,6 @@ function AttachmentModal({
onSelected: () => {
setIsDeleteReceiptConfirmModalVisible(true);
},
shouldCallAfterModalHide: true,
});
}
return menuItems;
Expand Down
38 changes: 19 additions & 19 deletions src/components/AvatarWithImagePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as FileUtils from '@libs/fileDownload/FileUtils';
import getImageResolution from '@libs/fileDownload/getImageResolution';
import type {AvatarSource} from '@libs/UserUtils';
import variables from '@styles/variables';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -43,7 +44,6 @@ type MenuItem = {
icon: IconAsset;
text: string;
onSelected: () => void;
shouldCallAfterModalHide?: boolean;
};

type AvatarWithImagePickerProps = {
Expand Down Expand Up @@ -260,19 +260,19 @@ function AvatarWithImagePicker({
* Create menu items list for avatar menu
*/
const createMenuItems = (openPicker: OpenPicker): MenuItem[] => {
const menuItems: MenuItem[] = [
const menuItems = [
{
icon: Expensicons.Upload,
text: translate('avatarWithImagePicker.uploadPhoto'),
onSelected: () => {
if (Browser.isSafari()) {
return;
}
openPicker({
onPicked: showAvatarCropModal,
});
},
shouldCallAfterModalHide: true,
onSelected: () =>
Modal.close(() => {
if (Browser.isSafari()) {
return;
}
openPicker({
onPicked: showAvatarCropModal,
});
}),
},
];

Expand Down Expand Up @@ -344,14 +344,14 @@ function AvatarWithImagePicker({
menuItems.push({
icon: Expensicons.Eye,
text: translate('avatarWithImagePicker.viewPhoto'),
onSelected: () => {
if (typeof onViewPhotoPress !== 'function') {
show();
return;
}
onViewPhotoPress();
},
shouldCallAfterModalHide: true,
onSelected: () =>
Modal.close(() => {
if (typeof onViewPhotoPress !== 'function') {
show();
return;
}
onViewPhotoPress();
}),
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/ButtonWithDropdownMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import mergeRefs from '@libs/mergeRefs';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';
import type {ButtonWithDropdownMenuProps} from './types';
Expand Down Expand Up @@ -177,12 +178,11 @@ function ButtonWithDropdownMenu<IValueType>({
menuItems={options.map((item, index) => ({
...item,
onSelected: item.onSelected
? () => item.onSelected?.()
? () => Modal.close(() => item.onSelected?.())
: () => {
onOptionSelected?.(item);
setSelectedItemIndex(index);
},
shouldCallAfterModalHide: true,
}))}
/>
)}
Expand Down
11 changes: 0 additions & 11 deletions src/components/PopoverMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import useKeyboardShortcut from '@hooks/useKeyboardShortcut';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import type {AnchorPosition} from '@src/styles';
import type AnchorAlignment from '@src/types/utils/AnchorAlignment';
Expand Down Expand Up @@ -36,11 +35,6 @@ type PopoverMenuItem = MenuItemProps & {

/** Determines whether the menu item is disabled or not */
disabled?: boolean;

/** Determines whether the menu item's onSelected() function is called after the modal is hidden
* It is meant to be used in situations where, after clicking on the modal, another one is opened.
*/
shouldCallAfterModalHide?: boolean;
};

type PopoverModalProps = Pick<ModalProps, 'animationIn' | 'animationOut' | 'animationInTiming'>;
Expand Down Expand Up @@ -134,11 +128,6 @@ function PopoverMenu({
setEnteredSubMenuIndexes([...enteredSubMenuIndexes, index]);
const selectedSubMenuItemIndex = selectedItem?.subMenuItems.findIndex((option) => option.isSelected);
setFocusedIndex(selectedSubMenuItemIndex);
} else if (selectedItem.shouldCallAfterModalHide) {
Modal.close(() => {
onItemSelected(selectedItem, index);
selectedItem.onSelected?.();
});
} else {
onItemSelected(selectedItem, index);
selectedItem.onSelected?.();
Expand Down
6 changes: 1 addition & 5 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie
const unsubscribeSearchShortcut = KeyboardShortcut.subscribe(
searchShortcutConfig.shortcutKey,
() => {
Modal.close(
Session.checkIfActionIsAllowed(() => Navigation.navigate(ROUTES.CHAT_FINDER)),
true,
true,
);
Modal.close(Session.checkIfActionIsAllowed(() => Navigation.navigate(ROUTES.CHAT_FINDER)));
},
shortcutsOverviewShortcutConfig.descriptionKey,
shortcutsOverviewShortcutConfig.modifiers,
Expand Down
6 changes: 2 additions & 4 deletions src/libs/actions/Modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const closeModals: Array<(isNavigating?: boolean) => void> = [];

let onModalClose: null | (() => void);
let isNavigate: undefined | boolean;
let shouldCloseAll: boolean | undefined;

/**
* Allows other parts of the app to call modal close function
Expand Down Expand Up @@ -40,13 +39,12 @@ function closeTop() {
/**
* Close modal in other parts of the app
*/
function close(onModalCloseCallback: () => void, isNavigating = true, shouldCloseAllModals = false) {
function close(onModalCloseCallback: () => void, isNavigating = true) {
if (closeModals.length === 0) {
onModalCloseCallback();
return;
}
onModalClose = onModalCloseCallback;
shouldCloseAll = shouldCloseAllModals;
isNavigate = isNavigating;
closeTop();
}
Expand All @@ -55,7 +53,7 @@ function onModalDidClose() {
if (!onModalClose) {
return;
}
if (closeModals.length && shouldCloseAll) {
if (closeModals.length) {
closeTop();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as SubscriptionUtils from '@libs/SubscriptionUtils';
import * as IOU from '@userActions/IOU';
import * as Modal from '@userActions/Modal';
import * as Report from '@userActions/Report';
import * as Task from '@userActions/Task';
import type {IOUType} from '@src/CONST';
Expand Down Expand Up @@ -224,13 +225,13 @@ function AttachmentPickerWithMenuItems({
{
icon: Expensicons.Paperclip,
text: translate('reportActionCompose.addAttachment'),
onSelected: () => {
if (Browser.isSafari()) {
return;
}
triggerAttachmentPicker();
},
shouldCallAfterModalHide: true,
onSelected: () =>
Modal.close(() => {
if (Browser.isSafari()) {
return;
}
triggerAttachmentPicker();
}),
},
];
return (
Expand Down
8 changes: 5 additions & 3 deletions src/pages/iou/request/step/IOURequestStepWaypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as ValidationUtils from '@libs/ValidationUtils';
import * as Modal from '@userActions/Modal';
import * as Transaction from '@userActions/Transaction';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -178,10 +179,11 @@ function IOURequestStepWaypoint({
icon: Expensicons.Trashcan,
text: translate('distance.deleteWaypoint'),
onSelected: () => {
setRestoreFocusType(undefined);
setIsDeleteStopModalOpen(true);
Modal.close(() => {
setRestoreFocusType(undefined);
setIsDeleteStopModalOpen(true);
});
},
shouldCallAfterModalHide: true,
},
]}
/>
Expand Down
13 changes: 7 additions & 6 deletions src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import type {AvatarSource} from '@libs/UserUtils';
import * as App from '@userActions/App';
import * as Modal from '@userActions/Modal';
import * as Policy from '@userActions/Policy/Policy';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -161,12 +162,12 @@ function WorkspacesListPage({policies, reimbursementAccount, reports, session}:
threeDotsMenuItems.push({
icon: Expensicons.Trashcan,
text: translate('workspace.common.delete'),
onSelected: () => {
setPolicyIDToDelete(item.policyID ?? '-1');
setPolicyNameToDelete(item.title);
setIsDeleteModalOpen(true);
},
shouldCallAfterModalHide: true,
onSelected: () =>
Modal.close(() => {
setPolicyIDToDelete(item.policyID ?? '-1');
setPolicyNameToDelete(item.title);
setIsDeleteModalOpen(true);
}),
});
}

Expand Down
7 changes: 3 additions & 4 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import Navigation from '@navigation/Navigation';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
import type {AnchorPosition} from '@styles/index';
import * as Modal from '@userActions/Modal';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -97,8 +98,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
{
icon: Expensicons.Key,
text: translate('workspace.accounting.enterCredentials'),
onSelected: () => startIntegrationFlow({name: connectedIntegration}),
shouldCallAfterModalHide: true,
onSelected: () => Modal.close(() => startIntegrationFlow({name: connectedIntegration})),
disabled: isOffline,
iconRight: Expensicons.NewWindow,
shouldShowRightIcon: true,
Expand All @@ -115,8 +115,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
{
icon: Expensicons.Trashcan,
text: translate('workspace.accounting.disconnect'),
onSelected: () => setIsDisconnectModalOpen(true),
shouldCallAfterModalHide: true,
onSelected: () => Modal.close(() => setIsDisconnectModalOpen(true)),
},
],
[shouldShowEnterCredentials, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow],
Expand Down

0 comments on commit 804bd26

Please sign in to comment.