Skip to content

armgit / ente

Public Imported from GitHub
0

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

Inline

Manav Rathiad0b8ae0179c
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
index c722534cfe..4fac1e131e 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/card.tsx
@@ -1,8 +1,19 @@
import log from "@/base/log";
import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units";
-import { SpaceBetweenFlex } from "@ente/shared/components/Container";
+import {
+ FluidContainer,
+ SpaceBetweenFlex,
+} from "@ente/shared/components/Container";
+import ChevronRight from "@mui/icons-material/ChevronRight";
import Close from "@mui/icons-material/Close";
-import { IconButton, Link, Stack, styled } from "@mui/material";
+import {
+ Button,
+ ButtonProps,
+ IconButton,
+ Link,
+ Stack,
+ styled,
+} from "@mui/material";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { PLAN_PERIOD } from "constants/gallery";
@@ -12,9 +23,12 @@ import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useMemo, useState } from "react";
import { Trans } from "react-i18next";
import billingService, { type PlansResponse } from "services/billingService";
-import { Plan } from "types/billing";
+import { Plan, Subscription } from "types/billing";
import { SetLoading } from "types/gallery";
+import { BonusData } from "types/user";
import {
+ activateSubscription,
+ cancelSubscription,
getLocalUserSubscription,
hasAddOnBonus,
hasMobileSubscription,
@@ -24,12 +38,13 @@ import {
isSubscriptionActive,
isSubscriptionCancelled,
isUserSubscribedPlan,
+ manageFamilyMethod,
planForSubscription,
+ updatePaymentMethod,
updateSubscription,
} from "utils/billing";
import { getLocalUserDetails } from "utils/user";
import { getTotalFamilyUsage, isPartOfFamily } from "utils/user/family";
-import { ManageSubscription } from "./manageSubscription";
import { PeriodToggler } from "./periodToggler";
import Plans from "./plans";
@@ -390,3 +405,128 @@ const AddOnRowContainer = styled(SpaceBetweenFlex)(({ theme }) => ({
backgroundColor: "rgba(255,255,255,0.08)",
},
}));
+
+interface ManageSubscriptionProps {
+ subscription: Subscription;
+ bonusData?: BonusData;
+ closeModal: () => void;
+ setLoading: SetLoading;
+}
+
+function ManageSubscription({
+ subscription,
+ bonusData,
+ closeModal,
+ setLoading,
+}: ManageSubscriptionProps) {
+ const appContext = useContext(AppContext);
+ const openFamilyPortal = () =>
+ manageFamilyMethod(appContext.setDialogMessage, setLoading);
+
+ return (
+ <Stack spacing={1}>
+ {hasStripeSubscription(subscription) && (
+ <StripeSubscriptionOptions
+ subscription={subscription}
+ bonusData={bonusData}
+ closeModal={closeModal}
+ setLoading={setLoading}
+ />
+ )}
+ <ManageSubscriptionButton
+ color="secondary"
+ onClick={openFamilyPortal}
+ >
+ {t("MANAGE_FAMILY_PORTAL")}
+ </ManageSubscriptionButton>
+ </Stack>
+ );
+}
+
+function StripeSubscriptionOptions({
+ subscription,
+ bonusData,
+ setLoading,
+ closeModal,
+}: ManageSubscriptionProps) {
+ const appContext = useContext(AppContext);
+
+ const confirmReactivation = () =>
+ appContext.setDialogMessage({
+ title: t("REACTIVATE_SUBSCRIPTION"),
+ content: t("REACTIVATE_SUBSCRIPTION_MESSAGE", {
+ date: subscription.expiryTime,
+ }),
+ proceed: {
+ text: t("REACTIVATE_SUBSCRIPTION"),
+ action: activateSubscription.bind(
+ null,
+ appContext.setDialogMessage,
+ closeModal,
+ setLoading,
+ ),
+ variant: "accent",
+ },
+ close: {
+ text: t("cancel"),
+ },
+ });
+ const confirmCancel = () =>
+ appContext.setDialogMessage({
+ title: t("CANCEL_SUBSCRIPTION"),
+ content: hasAddOnBonus(bonusData) ? (
+ <Trans i18nKey={"CANCEL_SUBSCRIPTION_WITH_ADDON_MESSAGE"} />
+ ) : (
+ <Trans i18nKey={"CANCEL_SUBSCRIPTION_MESSAGE"} />
+ ),
+ proceed: {
+ text: t("CANCEL_SUBSCRIPTION"),
+ action: cancelSubscription.bind(
+ null,
+ appContext.setDialogMessage,
+ closeModal,
+ setLoading,
+ ),
+ variant: "critical",
+ },
+ close: {
+ text: t("NEVERMIND"),
+ },
+ });
+ const openManagementPortal = updatePaymentMethod.bind(
+ null,
+ appContext.setDialogMessage,
+ setLoading,
+ );
+ return (
+ <>
+ {isSubscriptionCancelled(subscription) ? (
+ <ManageSubscriptionButton
+ color="secondary"
+ onClick={confirmReactivation}
+ >
+ {t("REACTIVATE_SUBSCRIPTION")}
+ </ManageSubscriptionButton>
+ ) : (
+ <ManageSubscriptionButton
+ color="secondary"
+ onClick={confirmCancel}
+ >
+ {t("CANCEL_SUBSCRIPTION")}
+ </ManageSubscriptionButton>
+ )}
+ <ManageSubscriptionButton
+ color="secondary"
+ onClick={openManagementPortal}
+ >
+ {t("MANAGEMENT_PORTAL")}
+ </ManageSubscriptionButton>
+ </>
+ );
+}
+
+const ManageSubscriptionButton = ({ children, ...props }: ButtonProps) => (
+ <Button size="large" endIcon={<ChevronRight />} {...props}>
+ <FluidContainer>{children}</FluidContainer>
+ </Button>
+);
diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector/manageSubscription/index.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector/manageSubscription/index.tsx
index ef3dcfd521..e69de29bb2 100644
--- a/web/apps/photos/src/components/pages/gallery/PlanSelector/manageSubscription/index.tsx
+++ b/web/apps/photos/src/components/pages/gallery/PlanSelector/manageSubscription/index.tsx
@@ -1,144 +0,0 @@
-import { FluidContainer } from "@ente/shared/components/Container";
-import ChevronRight from "@mui/icons-material/ChevronRight";
-import { Button, ButtonProps, Stack } from "@mui/material";
-import { t } from "i18next";
-import { AppContext } from "pages/_app";
-import { useContext } from "react";
-import { Trans } from "react-i18next";
-import { Subscription } from "types/billing";
-import { SetLoading } from "types/gallery";
-import { BonusData } from "types/user";
-import {
- activateSubscription,
- cancelSubscription,
- hasAddOnBonus,
- hasStripeSubscription,
- isSubscriptionCancelled,
- manageFamilyMethod,
- updatePaymentMethod,
-} from "utils/billing";
-
-interface Iprops {
- subscription: Subscription;
- bonusData?: BonusData;
- closeModal: () => void;
- setLoading: SetLoading;
-}
-
-export function ManageSubscription({
- subscription,
- bonusData,
- closeModal,
- setLoading,
-}: Iprops) {
- const appContext = useContext(AppContext);
- const openFamilyPortal = () =>
- manageFamilyMethod(appContext.setDialogMessage, setLoading);
-
- return (
- <Stack spacing={1}>
- {hasStripeSubscription(subscription) && (
- <StripeSubscriptionOptions
- subscription={subscription}
- bonusData={bonusData}
- closeModal={closeModal}
- setLoading={setLoading}
- />
- )}
- <ManageSubscriptionButton
- color="secondary"
- onClick={openFamilyPortal}
- >
- {t("MANAGE_FAMILY_PORTAL")}
- </ManageSubscriptionButton>
- </Stack>
- );
-}
-
-function StripeSubscriptionOptions({
- subscription,
- bonusData,
- setLoading,
- closeModal,
-}: Iprops) {
- const appContext = useContext(AppContext);
-
- const confirmReactivation = () =>
- appContext.setDialogMessage({
- title: t("REACTIVATE_SUBSCRIPTION"),
- content: t("REACTIVATE_SUBSCRIPTION_MESSAGE", {
- date: subscription.expiryTime,
- }),
- proceed: {
- text: t("REACTIVATE_SUBSCRIPTION"),
- action: activateSubscription.bind(
- null,
- appContext.setDialogMessage,
- closeModal,
- setLoading,
- ),
- variant: "accent",
- },
- close: {
- text: t("cancel"),
- },
- });
- const confirmCancel = () =>
- appContext.setDialogMessage({
- title: t("CANCEL_SUBSCRIPTION"),
- content: hasAddOnBonus(bonusData) ? (
- <Trans i18nKey={"CANCEL_SUBSCRIPTION_WITH_ADDON_MESSAGE"} />
- ) : (
- <Trans i18nKey={"CANCEL_SUBSCRIPTION_MESSAGE"} />
- ),
- proceed: {
- text: t("CANCEL_SUBSCRIPTION"),
- action: cancelSubscription.bind(
- null,
- appContext.setDialogMessage,
- closeModal,
- setLoading,
- ),
- variant: "critical",
- },
- close: {
- text: t("NEVERMIND"),
- },
- });
- const openManagementPortal = updatePaymentMethod.bind(
- null,
- appContext.setDialogMessage,
- setLoading,
- );
- return (
- <>
- {isSubscriptionCancelled(subscription) ? (
- <ManageSubscriptionButton
- color="secondary"
- onClick={confirmReactivation}
- >
- {t("REACTIVATE_SUBSCRIPTION")}
- </ManageSubscriptionButton>
- ) : (
- <ManageSubscriptionButton
- color="secondary"
- onClick={confirmCancel}
- >
- {t("CANCEL_SUBSCRIPTION")}
- </ManageSubscriptionButton>
- )}
- <ManageSubscriptionButton
- color="secondary"
- onClick={openManagementPortal}
- >
- {t("MANAGEMENT_PORTAL")}
- </ManageSubscriptionButton>
- </>
- );
-}
-
-const ManageSubscriptionButton = ({ children, ...props }: ButtonProps) => (
- <Button size="large" endIcon={<ChevronRight />} {...props}>
- <FluidContainer>{children}</FluidContainer>
- </Button>
-);