From 0fe9f4db4b772edcb00b882b282fd7d0b0ca3848 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Sat, 9 Nov 2024 15:35:13 +0530 Subject: [PATCH] Tweak --- .../components/pages/gallery/PlanSelector.tsx | 347 +++++++++--------- 1 file changed, 181 insertions(+), 166 deletions(-) diff --git a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx index 760b909f21..4e44ccbb8a 100644 --- a/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx +++ b/web/apps/photos/src/components/pages/gallery/PlanSelector.tsx @@ -59,7 +59,6 @@ import Typography from "@mui/material/Typography"; import { t } from "i18next"; import React, { useCallback, useContext, useEffect, useState } from "react"; import { Trans } from "react-i18next"; -import { SetLoading } from "types/gallery"; type PlanSelectorProps = ModalVisibilityProps & { setLoading: (loading: boolean) => void; @@ -209,22 +208,22 @@ const PlanSelectorCard: React.FC = ({ }; const commonCardData = { + onClose, + setLoading, subscription, addOnBonuses, - closeModal: onClose, planPeriod, togglePeriod, - setLoading, }; const plansList = ( 0} - closeModal={onClose} /> ); @@ -283,136 +282,156 @@ const planSelectionOutcome = (subscription: Subscription | undefined) => { return "contactSupport"; }; -function FreeSubscriptionPlanSelectorCard({ - children, +type FreeSubscriptionPlanSelectorCardProps = Pick< + PlanSelectorProps, + "onClose" | "setLoading" +> & { + subscription: Subscription; + addOnBonuses: Bonus[]; + planPeriod: PlanPeriod; + togglePeriod: () => void; +}; + +const FreeSubscriptionPlanSelectorCard: React.FC< + React.PropsWithChildren +> = ({ + onClose, + setLoading, subscription, addOnBonuses, - closeModal, - setLoading, planPeriod, togglePeriod, -}) { - return ( - <> - - {t("choose_plan")} - - - - - - - - {t("two_months_free")} - - - {children} - {subscription && addOnBonuses.length > 0 && ( - <> - - - - )} - - - - ); -} - -function PaidSubscriptionPlanSelectorCard({ children, - subscription, - addOnBonuses, - closeModal, - usage, - planPeriod, - togglePeriod, - setLoading, -}) { - return ( - <> - - - - - {t("subscription")} - - - {bytesInGB(subscription.storage, 2)}{" "} - {t("storage_unit.gb")} - - - - - - - - - - - ( + <> + + {t("choose_plan")} + + + + + - - - - - `1px solid ${theme.palette.divider}`} - p={1.5} - borderRadius={(theme) => `${theme.shape.borderRadius}px`} - > - - - - {t("two_months_free")} - - - {children} - - - - - {!isSubscriptionCancelled(subscription) - ? t("subscription_status_renewal_active", { - date: subscription.expiryTime, - }) - : t("subscription_status_renewal_cancelled", { - date: subscription.expiryTime, - })} + + {t("two_months_free")} - {addOnBonuses.length > 0 && ( - - )} - + {children} + {subscription && addOnBonuses.length > 0 && ( + <> + + + + )} + + + +); - 0} - closeModal={closeModal} - setLoading={setLoading} - /> - - ); +type PaidSubscriptionPlanSelectorCardProps = + FreeSubscriptionPlanSelectorCardProps & { + usage: number; + }; + +const PaidSubscriptionPlanSelectorCard: React.FC< + React.PropsWithChildren +> = ({ + onClose, + setLoading, + subscription, + addOnBonuses, + planPeriod, + togglePeriod, + usage, + children, +}) => ( + <> + + + + + {t("subscription")} + + + {bytesInGB(subscription.storage, 2)}{" "} + {t("storage_unit.gb")} + + + + + + + + + + + + + + + + `1px solid ${theme.palette.divider}`} + p={1.5} + borderRadius={(theme) => `${theme.shape.borderRadius}px`} + > + + + + {t("two_months_free")} + + + {children} + + + + + {!isSubscriptionCancelled(subscription) + ? t("subscription_status_renewal_active", { + date: subscription.expiryTime, + }) + : t("subscription_status_renewal_cancelled", { + date: subscription.expiryTime, + })} + + {addOnBonuses.length > 0 && ( + + )} + + + + 0} + /> + +); + +interface PeriodTogglerProps { + planPeriod: PlanPeriod; + togglePeriod: () => void; } -function PeriodToggler({ planPeriod, togglePeriod }) { +const PeriodToggler: React.FC = ({ + planPeriod, + togglePeriod, +}) => { const handleChange = (_, newPlanPeriod: PlanPeriod) => { if (newPlanPeriod !== planPeriod) togglePeriod(); }; @@ -432,7 +451,7 @@ function PeriodToggler({ planPeriod, togglePeriod }) { ); -} +}; const CustomToggleButton = styled(ToggleButton)(({ theme }) => ({ textTransform: "none", @@ -453,22 +472,22 @@ const CustomToggleButton = styled(ToggleButton)(({ theme }) => ({ })); interface PlansProps { + onClose: () => void; plansData: PlansData | undefined; planPeriod: PlanPeriod; subscription: Subscription; hasAddOnBonus: boolean; onPlanSelect: (plan: Plan) => void; - closeModal: () => void; } -const Plans = ({ +const Plans: React.FC = ({ + onClose, plansData, planPeriod, subscription, hasAddOnBonus, onPlanSelect, - closeModal, -}: PlansProps) => { +}) => { const { freePlan, plans } = plansData ?? {}; return ( @@ -490,10 +509,7 @@ const Plans = ({ {!(subscription && isSubscriptionActivePaid(subscription)) && !hasAddOnBonus && freePlan && ( - + )} ); @@ -510,13 +526,13 @@ interface PlanRowProps { popular: boolean; } -function PlanRow({ +const PlanRow: React.FC = ({ plan, subscription, onPlanSelect, disabled, popular, -}: PlanRowProps) { +}) => { const handleClick = () => !disabled && onPlanSelect(plan); const PlanButton = disabled ? DisabledPlanButton : ActivePlanButton; @@ -564,7 +580,7 @@ function PlanRow({ ); -} +}; const PlanRowContainer = styled(FlexWrapper)(() => ({ background: @@ -606,27 +622,25 @@ const Badge = styled(Box)(({ theme }) => ({ })); interface FreePlanRowProps { + onClose: () => void; storage: number; - closeModal: () => void; } -const FreePlanRow: React.FC = ({ closeModal, storage }) => { - return ( - - - {t("free_plan_option")} - - {t("free_plan_description", { - storage: formattedStorageByteSize(storage), - })} - - - - - - - ); -}; +const FreePlanRow: React.FC = ({ onClose, storage }) => ( + + + {t("free_plan_option")} + + {t("free_plan_description", { + storage: formattedStorageByteSize(storage), + })} + + + + + + +); const FreePlanRow_ = styled(SpaceBetweenFlex)(({ theme }) => ({ gap: theme.spacing(1.5), @@ -657,18 +671,19 @@ const AddOnBonusRows: React.FC = ({ addOnBonuses }) => ( ); -interface ManageSubscriptionProps { +type ManageSubscriptionProps = Pick< + PlanSelectorProps, + "onClose" | "setLoading" +> & { subscription: Subscription; hasAddOnBonus: boolean; - closeModal: () => void; - setLoading: SetLoading; -} +}; function ManageSubscription({ + onClose, + setLoading, subscription, hasAddOnBonus, - closeModal, - setLoading, }: ManageSubscriptionProps) { const { onGenericError } = useAppContext(); @@ -686,9 +701,7 @@ function ManageSubscription({ {isSubscriptionStripe(subscription) && ( )} void; +type StripeSubscriptionOptionsProps = Pick & { subscription: Subscription; hasAddOnBonus: boolean; -} +}; const StripeSubscriptionOptions: React.FC = ({ onClose, @@ -797,7 +809,10 @@ const StripeSubscriptionOptions: React.FC = ({ ); }; -const ManageSubscriptionButton = ({ children, ...props }: ButtonProps) => ( +const ManageSubscriptionButton: React.FC = ({ + children, + ...props +}) => (