ソースを参照

Forward storage

Manav Rathi 1 年間 前
コミット
98d38a3e44

+ 2 - 2
web/apps/photos/src/components/pages/gallery/PlanSelector/card/free.tsx

@@ -9,7 +9,7 @@ import Plans from "../plans";
 import { BFAddOnRow } from "../plans/BfAddOnRow";
 import { BFAddOnRow } from "../plans/BfAddOnRow";
 
 
 export default function FreeSubscriptionPlanSelectorCard({
 export default function FreeSubscriptionPlanSelectorCard({
-    plans,
+    plansResponse,
     subscription,
     subscription,
     bonusData,
     bonusData,
     closeModal,
     closeModal,
@@ -36,7 +36,7 @@ export default function FreeSubscriptionPlanSelectorCard({
                         </Typography>
                         </Typography>
                     </Box>
                     </Box>
                     <Plans
                     <Plans
-                        plans={plans}
+                        plansResponse={plansResponse}
                         planPeriod={planPeriod}
                         planPeriod={planPeriod}
                         onPlanSelect={onPlanSelect}
                         onPlanSelect={onPlanSelect}
                         subscription={subscription}
                         subscription={subscription}

+ 9 - 8
web/apps/photos/src/components/pages/gallery/PlanSelector/card/index.tsx

@@ -1,7 +1,5 @@
 import log from "@/next/log";
 import log from "@/next/log";
 import { SUPPORT_EMAIL } from "@ente/shared/constants/urls";
 import { SUPPORT_EMAIL } from "@ente/shared/constants/urls";
-import { useLocalState } from "@ente/shared/hooks/useLocalState";
-import { LS_KEYS } from "@ente/shared/storage/localStorage";
 import { Link, Stack } from "@mui/material";
 import { Link, Stack } from "@mui/material";
 import { PLAN_PERIOD } from "constants/gallery";
 import { PLAN_PERIOD } from "constants/gallery";
 import { t } from "i18next";
 import { t } from "i18next";
@@ -9,7 +7,7 @@ import { AppContext } from "pages/_app";
 import { GalleryContext } from "pages/gallery";
 import { GalleryContext } from "pages/gallery";
 import { useContext, useEffect, useMemo, useState } from "react";
 import { useContext, useEffect, useMemo, useState } from "react";
 import { Trans } from "react-i18next";
 import { Trans } from "react-i18next";
-import billingService from "services/billingService";
+import billingService, { type PlansResponse } from "services/billingService";
 import { Plan } from "types/billing";
 import { Plan } from "types/billing";
 import { SetLoading } from "types/gallery";
 import { SetLoading } from "types/gallery";
 import {
 import {
@@ -36,7 +34,9 @@ interface Props {
 
 
 function PlanSelectorCard(props: Props) {
 function PlanSelectorCard(props: Props) {
     const subscription = useMemo(() => getLocalUserSubscription(), []);
     const subscription = useMemo(() => getLocalUserSubscription(), []);
-    const [plans, setPlans] = useLocalState<Plan[]>(LS_KEYS.PLANS);
+    const [plansResponse, setPlansResponse] = useState<
+        PlansResponse | undefined
+    >();
 
 
     const [planPeriod, setPlanPeriod] = useState<PLAN_PERIOD>(
     const [planPeriod, setPlanPeriod] = useState<PLAN_PERIOD>(
         subscription?.period || PLAN_PERIOD.MONTH,
         subscription?.period || PLAN_PERIOD.MONTH,
@@ -76,7 +76,8 @@ function PlanSelectorCard(props: Props) {
         const main = async () => {
         const main = async () => {
             try {
             try {
                 props.setLoading(true);
                 props.setLoading(true);
-                const plans = await billingService.getPlans();
+                const response = await billingService.getPlans();
+                const { plans } = response;
                 if (isSubscriptionActive(subscription)) {
                 if (isSubscriptionActive(subscription)) {
                     const planNotListed =
                     const planNotListed =
                         plans.filter((plan) =>
                         plans.filter((plan) =>
@@ -90,7 +91,7 @@ function PlanSelectorCard(props: Props) {
                         plans.push(planForSubscription(subscription));
                         plans.push(planForSubscription(subscription));
                     }
                     }
                 }
                 }
-                setPlans(plans);
+                setPlansResponse(response);
             } catch (e) {
             } catch (e) {
                 log.error("plan selector modal open failed", e);
                 log.error("plan selector modal open failed", e);
                 props.closeModal();
                 props.closeModal();
@@ -172,7 +173,7 @@ function PlanSelectorCard(props: Props) {
             <Stack spacing={3} p={1.5}>
             <Stack spacing={3} p={1.5}>
                 {hasPaidSubscription(subscription) ? (
                 {hasPaidSubscription(subscription) ? (
                     <PaidSubscriptionPlanSelectorCard
                     <PaidSubscriptionPlanSelectorCard
-                        plans={plans}
+                        plansResponse={plansResponse}
                         subscription={subscription}
                         subscription={subscription}
                         bonusData={bonusData}
                         bonusData={bonusData}
                         closeModal={props.closeModal}
                         closeModal={props.closeModal}
@@ -184,7 +185,7 @@ function PlanSelectorCard(props: Props) {
                     />
                     />
                 ) : (
                 ) : (
                     <FreeSubscriptionPlanSelectorCard
                     <FreeSubscriptionPlanSelectorCard
-                        plans={plans}
+                        plansResponse={plansResponse}
                         subscription={subscription}
                         subscription={subscription}
                         bonusData={bonusData}
                         bonusData={bonusData}
                         closeModal={props.closeModal}
                         closeModal={props.closeModal}

+ 2 - 2
web/apps/photos/src/components/pages/gallery/PlanSelector/card/paid.tsx

@@ -13,7 +13,7 @@ import Plans from "../plans";
 import { BFAddOnRow } from "../plans/BfAddOnRow";
 import { BFAddOnRow } from "../plans/BfAddOnRow";
 
 
 export default function PaidSubscriptionPlanSelectorCard({
 export default function PaidSubscriptionPlanSelectorCard({
-    plans,
+    plansResponse,
     subscription,
     subscription,
     bonusData,
     bonusData,
     closeModal,
     closeModal,
@@ -70,7 +70,7 @@ export default function PaidSubscriptionPlanSelectorCard({
                         </Typography>
                         </Typography>
                     </Box>
                     </Box>
                     <Plans
                     <Plans
-                        plans={plans}
+                        plansResponse={plansResponse}
                         planPeriod={planPeriod}
                         planPeriod={planPeriod}
                         onPlanSelect={onPlanSelect}
                         onPlanSelect={onPlanSelect}
                         subscription={subscription}
                         subscription={subscription}

+ 30 - 21
web/apps/photos/src/components/pages/gallery/PlanSelector/plans/index.tsx

@@ -3,6 +3,7 @@ import ArrowForward from "@mui/icons-material/ArrowForward";
 import { Box, IconButton, Stack, Typography, styled } from "@mui/material";
 import { Box, IconButton, Stack, Typography, styled } from "@mui/material";
 import { PLAN_PERIOD } from "constants/gallery";
 import { PLAN_PERIOD } from "constants/gallery";
 import { t } from "i18next";
 import { t } from "i18next";
+import type { PlansResponse } from "services/billingService";
 import { Plan, Subscription } from "types/billing";
 import { Plan, Subscription } from "types/billing";
 import { BonusData } from "types/user";
 import { BonusData } from "types/user";
 import {
 import {
@@ -14,7 +15,7 @@ import {
 import { PlanRow } from "./planRow";
 import { PlanRow } from "./planRow";
 
 
 interface Iprops {
 interface Iprops {
-    plans: Plan[];
+    plansResponse: PlansResponse;
     planPeriod: PLAN_PERIOD;
     planPeriod: PLAN_PERIOD;
     subscription: Subscription;
     subscription: Subscription;
     bonusData?: BonusData;
     bonusData?: BonusData;
@@ -23,35 +24,43 @@ interface Iprops {
 }
 }
 
 
 const Plans = ({
 const Plans = ({
-    plans,
+    plansResponse,
     planPeriod,
     planPeriod,
     subscription,
     subscription,
     bonusData,
     bonusData,
     onPlanSelect,
     onPlanSelect,
     closeModal,
     closeModal,
-}: Iprops) => (
-    <Stack spacing={2}>
-        {plans
-            ?.filter((plan) => plan.period === planPeriod)
-            ?.map((plan) => (
-                <PlanRow
-                    disabled={isUserSubscribedPlan(plan, subscription)}
-                    popular={isPopularPlan(plan)}
-                    key={plan.stripeID}
-                    plan={plan}
-                    subscription={subscription}
-                    onPlanSelect={onPlanSelect}
-                />
-            ))}
-        {!hasPaidSubscription(subscription) && !hasAddOnBonus(bonusData) && (
-            <FreePlanRow closeModal={closeModal} />
-        )}
-    </Stack>
-);
+}: Iprops) => {
+    const { freePlan, plans } = plansResponse;
+    return (
+        <Stack spacing={2}>
+            {plans
+                ?.filter((plan) => plan.period === planPeriod)
+                ?.map((plan) => (
+                    <PlanRow
+                        disabled={isUserSubscribedPlan(plan, subscription)}
+                        popular={isPopularPlan(plan)}
+                        key={plan.stripeID}
+                        plan={plan}
+                        subscription={subscription}
+                        onPlanSelect={onPlanSelect}
+                    />
+                ))}
+            {!hasPaidSubscription(subscription) &&
+                !hasAddOnBonus(bonusData) && (
+                    <FreePlanRow
+                        storage={freePlan.storage}
+                        closeModal={closeModal}
+                    />
+                )}
+        </Stack>
+    );
+};
 
 
 export default Plans;
 export default Plans;
 
 
 interface FreePlanRowProps {
 interface FreePlanRowProps {
+    storage: number;
     closeModal: () => void;
     closeModal: () => void;
 }
 }
 
 

+ 12 - 3
web/apps/photos/src/services/billingService.ts

@@ -19,8 +19,18 @@ enum PaymentActionType {
     Update = "update",
     Update = "update",
 }
 }
 
 
+export interface FreePlan {
+    /* Number of bytes available in the free plan */
+    storage: number;
+}
+
+export interface PlansResponse {
+    freePlan: FreePlan;
+    plans: Plan[];
+}
+
 class billingService {
 class billingService {
-    public async getPlans(): Promise<Plan[]> {
+    public async getPlans(): Promise<PlansResponse> {
         const token = getToken();
         const token = getToken();
         try {
         try {
             let response;
             let response;
@@ -37,8 +47,7 @@ class billingService {
                     },
                     },
                 );
                 );
             }
             }
-            const { plans } = response.data;
-            return plans;
+            return response.data;
         } catch (e) {
         } catch (e) {
             log.error("failed to get plans", e);
             log.error("failed to get plans", e);
         }
         }

+ 1 - 0
web/apps/photos/src/types/billing/index.ts

@@ -14,6 +14,7 @@ export interface Subscription {
     price: string;
     price: string;
     period: PLAN_PERIOD;
     period: PLAN_PERIOD;
 }
 }
+
 export interface Plan {
 export interface Plan {
     id: string;
     id: string;
     androidID: string;
     androidID: string;

+ 0 - 1
web/packages/shared/storage/localStorage/index.ts

@@ -7,7 +7,6 @@ export enum LS_KEYS {
     ORIGINAL_KEY_ATTRIBUTES = "originalKeyAttributes",
     ORIGINAL_KEY_ATTRIBUTES = "originalKeyAttributes",
     SUBSCRIPTION = "subscription",
     SUBSCRIPTION = "subscription",
     FAMILY_DATA = "familyData",
     FAMILY_DATA = "familyData",
-    PLANS = "plans",
     IS_FIRST_LOGIN = "isFirstLogin",
     IS_FIRST_LOGIN = "isFirstLogin",
     JUST_SIGNED_UP = "justSignedUp",
     JUST_SIGNED_UP = "justSignedUp",
     SHOW_BACK_BUTTON = "showBackButton",
     SHOW_BACK_BUTTON = "showBackButton",