Skip to content

armgit / ente

Public Imported from GitHub
0

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

Use

Manav Rathi488c239cf2c9
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
index 3879d3667a..c016bbe0dd 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx
@@ -39,7 +39,6 @@ import {
cancelSubscription,
getLocalUserSubscription,
hasAddOnBonus,
- hasMobileSubscription,
hasPaidSubscription,
hasStripeSubscription,
isOnFreePlan,
@@ -49,6 +48,7 @@ import {
isUserSubscribedPlan,
manageFamilyMethod,
planForSubscription,
+ planSelectionOutcome,
updatePaymentMethod,
updateSubscription,
} from "utils/billing";
@@ -177,58 +177,63 @@ function PlanSelectorCard(props: PlanSelectorCardProps) {
}, []);
async function onPlanSelect(plan: Plan) {
- if (
- !hasPaidSubscription(subscription) &&
- !isSubscriptionCancelled(subscription)
- ) {
- try {
- props.setLoading(true);
- await billingService.buySubscription(plan.stripeID);
- } catch (e) {
- props.setLoading(false);
+ switch (planSelectionOutcome(subscription)) {
+ case "buyPlan":
+ try {
+ props.setLoading(true);
+ await billingService.buySubscription(plan.stripeID);
+ } catch (e) {
+ props.setLoading(false);
+ appContext.setDialogMessage({
+ title: t("ERROR"),
+ content: t("SUBSCRIPTION_PURCHASE_FAILED"),
+ close: { variant: "critical" },
+ });
+ }
+ break;
+
+ case "updateSubscriptionToPlan":
appContext.setDialogMessage({
- title: t("ERROR"),
- content: t("SUBSCRIPTION_PURCHASE_FAILED"),
- close: { variant: "critical" },
+ title: t("update_subscription_title"),
+ content: t("UPDATE_SUBSCRIPTION_MESSAGE"),
+ proceed: {
+ text: t("UPDATE_SUBSCRIPTION"),
+ action: updateSubscription.bind(
+ null,
+ plan,
+ appContext.setDialogMessage,
+ props.setLoading,
+ props.closeModal,
+ ),
+ variant: "accent",
+ },
+ close: { text: t("cancel") },
});
- }
- } else if (hasStripeSubscription(subscription)) {
- appContext.setDialogMessage({
- title: t("update_subscription_title"),
- content: t("UPDATE_SUBSCRIPTION_MESSAGE"),
- proceed: {
- text: t("UPDATE_SUBSCRIPTION"),
- action: updateSubscription.bind(
- null,
- plan,
- appContext.setDialogMessage,
- props.setLoading,
- props.closeModal,
+ break;
+
+ case "cancelOnMobile":
+ appContext.setDialogMessage({
+ title: t("CANCEL_SUBSCRIPTION_ON_MOBILE"),
+ content: t("CANCEL_SUBSCRIPTION_ON_MOBILE_MESSAGE"),
+ close: { variant: "secondary" },
+ });
+ break;
+
+ case "contactSupport":
+ appContext.setDialogMessage({
+ title: t("MANAGE_PLAN"),
+ content: (
+ <Trans
+ i18nKey={"MAIL_TO_MANAGE_SUBSCRIPTION"}
+ components={{
+ a: <Link href="mailto:[email protected]" />,
+ }}
+ values={{ emailID: "[email protected]" }}
+ />
),
- variant: "accent",
- },
- close: { text: t("cancel") },
- });
- } else if (hasMobileSubscription(subscription)) {
- appContext.setDialogMessage({
- title: t("CANCEL_SUBSCRIPTION_ON_MOBILE"),
- content: t("CANCEL_SUBSCRIPTION_ON_MOBILE_MESSAGE"),
- close: { variant: "secondary" },
- });
- } else {
- appContext.setDialogMessage({
- title: t("MANAGE_PLAN"),
- content: (
- <Trans
- i18nKey={"MAIL_TO_MANAGE_SUBSCRIPTION"}
- components={{
- a: <Link href="mailto:[email protected]" />,
- }}
- values={{ emailID: "[email protected]" }}
- />
- ),
- close: { variant: "secondary" },
- });
+ close: { variant: "secondary" },
+ });
+ break;
}
}