Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Inline

Manav Rathi0a45caa5b2cf
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
index 13b2379506..a7f413e5d0 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
@@ -41,13 +41,14 @@ import type {
PlansData,
Subscription,
} from "services/billingService";
-import { getPlansData, redirectToPaymentsApp } from "services/billingService";
+import billingService, {
+ getPlansData,
+ redirectToPaymentsApp,
+} from "services/billingService";
import { getFamilyPortalRedirectURL } from "services/userService";
import { SetLoading } from "types/gallery";
import { BonusData, UserDetails } from "types/user";
import {
- activateSubscription,
- cancelSubscription,
getLocalUserSubscription,
hasAddOnBonus,
hasPaidSubscription,
@@ -737,6 +738,7 @@ function StripeSubscriptionOptions({
closeModal,
}: ManageSubscriptionProps) {
const appContext = useContext(AppContext);
+ const { setDialogMessage } = appContext;
const confirmReactivation = () =>
appContext.setDialogMessage({
@@ -746,18 +748,35 @@ function StripeSubscriptionOptions({
}),
proceed: {
text: t("REACTIVATE_SUBSCRIPTION"),
- action: activateSubscription.bind(
- null,
- appContext.setDialogMessage,
- closeModal,
- setLoading,
- ),
+ action: reactivate,
variant: "accent",
},
close: {
text: t("cancel"),
},
});
+
+ const reactivate = async () => {
+ try {
+ setLoading(true);
+ await billingService.activateSubscription();
+ setDialogMessage({
+ title: t("success"),
+ content: t("SUBSCRIPTION_ACTIVATE_SUCCESS"),
+ close: { variant: "accent" },
+ });
+ } catch (e) {
+ setDialogMessage({
+ title: t("error"),
+ content: t("SUBSCRIPTION_ACTIVATE_FAILED"),
+ close: { variant: "critical" },
+ });
+ } finally {
+ closeModal();
+ setLoading(false);
+ }
+ };
+
const confirmCancel = () =>
appContext.setDialogMessage({
title: t("CANCEL_SUBSCRIPTION"),
@@ -768,23 +787,41 @@ function StripeSubscriptionOptions({
),
proceed: {
text: t("CANCEL_SUBSCRIPTION"),
- action: cancelSubscription.bind(
- null,
- appContext.setDialogMessage,
- closeModal,
- setLoading,
- ),
+ action: cancel,
variant: "critical",
},
close: {
text: t("NEVERMIND"),
},
});
+
+ const cancel = async () => {
+ try {
+ setLoading(true);
+ await billingService.cancelSubscription();
+ setDialogMessage({
+ title: t("success"),
+ content: t("SUBSCRIPTION_CANCEL_SUCCESS"),
+ close: { variant: "accent" },
+ });
+ } catch (e) {
+ setDialogMessage({
+ title: t("error"),
+ content: t("SUBSCRIPTION_CANCEL_FAILED"),
+ close: { variant: "critical" },
+ });
+ } finally {
+ closeModal();
+ setLoading(false);
+ }
+ };
+
const openManagementPortal = updatePaymentMethod.bind(
null,
appContext.setDialogMessage,
setLoading,
);
+
return (
<>
{isSubscriptionCancelled(subscription) ? (
diff --git a/web/apps/photos/src/utils/billing/index.ts b/web/apps/photos/src/utils/billing/index.ts
index 8738ae7d3f..9c1314b1f4 100644
--- a/web/apps/photos/src/utils/billing/index.ts
+++ b/web/apps/photos/src/utils/billing/index.ts
@@ -144,56 +144,6 @@ export function isSubscriptionPastDue(subscription: Subscription) {
export const isPopularPlan = (plan: Plan) =>
plan.storage === 100 * 1024 * 1024 * 1024; /* 100 GB */
-export async function cancelSubscription(
- setDialogMessage: SetDialogBoxAttributes,
- closePlanSelectorModal: () => void,
- setLoading: SetLoading,
-) {
- try {
- setLoading(true);
- await billingService.cancelSubscription();
- setDialogMessage({
- title: t("success"),
- content: t("SUBSCRIPTION_CANCEL_SUCCESS"),
- close: { variant: "accent" },
- });
- } catch (e) {
- setDialogMessage({
- title: t("error"),
- content: t("SUBSCRIPTION_CANCEL_FAILED"),
- close: { variant: "critical" },
- });
- } finally {
- closePlanSelectorModal();
- setLoading(false);
- }
-}
-
-export async function activateSubscription(
- setDialogMessage: SetDialogBoxAttributes,
- closePlanSelectorModal: () => void,
- setLoading: SetLoading,
-) {
- try {
- setLoading(true);
- await billingService.activateSubscription();
- setDialogMessage({
- title: t("success"),
- content: t("SUBSCRIPTION_ACTIVATE_SUCCESS"),
- close: { variant: "accent" },
- });
- } catch (e) {
- setDialogMessage({
- title: t("error"),
- content: t("SUBSCRIPTION_ACTIVATE_FAILED"),
- close: { variant: "critical" },
- });
- } finally {
- closePlanSelectorModal();
- setLoading(false);
- }
-}
-
export async function updatePaymentMethod(
setDialogMessage: SetDialogBoxAttributes,
setLoading: SetLoading,