diff --git a/src/pages/gallery/index.tsx b/src/pages/gallery/index.tsx index ed6c32ac1..ebdce7d71 100644 --- a/src/pages/gallery/index.tsx +++ b/src/pages/gallery/index.tsx @@ -29,6 +29,7 @@ import { buySubscription, cancelSubscription, isSubscribed, + updatePaymentMethod, } from 'utils/billingUtil'; import Delete from 'components/Delete'; @@ -36,13 +37,14 @@ import ConfirmDialog, { CONFIRM_ACTION } from 'components/ConfirmDialog'; import FullScreenDropZone from 'components/FullScreenDropZone'; import Sidebar from 'components/Sidebar'; import UploadButton from './components/UploadButton'; -import { checkConnectivity } from 'utils/common'; +import { checkConnectivity, downloadApp } from 'utils/common'; import { isFirstLogin, setIsFirstLogin } from 'utils/storage'; import { logoutUser } from 'services/userService'; import AlertBanner from './components/AlertBanner'; import MessageDialog, { MessageAttributes } from 'components/MessageDialog'; import { LoadingOverlay } from './components/CollectionSelector'; import EnteSpinner from 'components/EnteSpinner'; +import { fileDelete } from 'utils/file'; const DATE_CONTAINER_HEIGHT = 45; const IMAGE_CONTAINER_HEIGHT = 200; const NO_OF_PAGES = 2; @@ -399,31 +401,24 @@ export default function Gallery(props: Props) { const closePlanSelectorModal = function () { setPlanModalView(false); }; + const clearSelection = function () { + setSelected({ count: 0 }); + }; const confirmCallbacks = new Map([ [ CONFIRM_ACTION.DELETE, - async function () { - await deleteFiles(selected); - syncWithRemote(); - setSelected({ count: 0 }); - }, + fileDelete.bind(null, selected, clearSelection, syncWithRemote), ], [CONFIRM_ACTION.SESSION_EXPIRED, logoutUser], [CONFIRM_ACTION.LOGOUT, logoutUser], - [ - CONFIRM_ACTION.DOWNLOAD_APP, - function () { - var win = window.open(constants.APP_DOWNLOAD_URL, '_blank'); - win.focus(); - }, - ], + [CONFIRM_ACTION.DOWNLOAD_APP, downloadApp], [ CONFIRM_ACTION.CANCEL_SUBSCRIPTION, cancelSubscription.bind( null, setDialogMessage, closePlanSelectorModal, - setConfirmAction + setLoading ), ], [ @@ -439,18 +434,13 @@ export default function Gallery(props: Props) { ], [ CONFIRM_ACTION.UPDATE_PAYMENT_METHOD, - async function (event) { - try { - event.preventDefault(); - await billingService.redirectToCustomerPortal(); - } catch (error) { - setDialogMessage({ - title: constants.UNKNOWN_ERROR, - close: { variant: 'danger' }, - }); - } - setConfirmAction(null); - }, + (event) => + updatePaymentMethod.bind( + null, + event, + setDialogMessage, + setLoading + ), ], ]); diff --git a/src/utils/billingUtil.ts b/src/utils/billingUtil.ts index 1603c9cc0..3642de85b 100644 --- a/src/utils/billingUtil.ts +++ b/src/utils/billingUtil.ts @@ -111,9 +111,10 @@ export async function buySubscription( export async function cancelSubscription( setDialogMessage, closePlanSelectorModal, - setConfirmAction + setLoading ) { try { + setLoading(true); await billingService.cancelSubscription(); setDialogMessage({ title: constants.SUBSCRIPTION_CANCEL_SUCCESS, @@ -124,7 +125,22 @@ export async function cancelSubscription( title: constants.SUBSCRIPTION_CANCEL_FAILED, close: { variant: 'danger' }, }); + } finally { + closePlanSelectorModal(); + setLoading(false); + } +} +export async function updatePaymentMethod(event, setDialogMessage, setLoading) { + try { + setLoading(true); + event.preventDefault(); + await billingService.redirectToCustomerPortal(); + } catch (error) { + setDialogMessage({ + title: constants.UNKNOWN_ERROR, + close: { variant: 'danger' }, + }); + } finally { + setLoading(true); } - closePlanSelectorModal(); - setConfirmAction(null); } diff --git a/src/utils/common/index.ts b/src/utils/common/index.ts index ad3c36f11..5cb5520d4 100644 --- a/src/utils/common/index.ts +++ b/src/utils/common/index.ts @@ -1,3 +1,4 @@ +import constants from 'utils/strings/constants'; import { errorCodes } from './errorUtil'; const TwoSecondInMillSeconds = 2000; @@ -19,3 +20,7 @@ export async function WaitFor2Seconds() { setTimeout(() => resolve(null), TwoSecondInMillSeconds); }); } +export function downloadApp() { + var win = window.open(constants.APP_DOWNLOAD_URL, '_blank'); + win.focus(); +} diff --git a/src/utils/file/index.ts b/src/utils/file/index.ts index a0c903a90..9f37e45e5 100644 --- a/src/utils/file/index.ts +++ b/src/utils/file/index.ts @@ -1,4 +1,4 @@ -import { file } from 'services/fileService'; +import { deleteFiles, file } from 'services/fileService'; import { runningInBrowser } from 'utils/common'; const TYPE_HEIC = 'heic'; @@ -42,3 +42,9 @@ export function sortFilesIntoCollections(files: file[]) { } return collectionWiseFiles; } + +export async function fileDelete(selected, clearSelection, syncWithRemote) { + await deleteFiles(selected); + syncWithRemote(); + clearSelection; +}