diff --git a/web/packages/new/photos/components/PlanSelector.tsx b/web/packages/new/photos/components/PlanSelector.tsx index 4e44ccbb8a..e8b9a7e715 100644 --- a/web/packages/new/photos/components/PlanSelector.tsx +++ b/web/packages/new/photos/components/PlanSelector.tsx @@ -29,9 +29,10 @@ import { redirectToPaymentsApp, userDetailsAddOnBonuses, } from "@/new/photos/services/user-details"; -import { AppContext, useAppContext } from "@/new/photos/types/context"; +import { useAppContext } from "@/new/photos/types/context"; import { bytesInGB, formattedStorageByteSize } from "@/new/photos/utils/units"; import { openURL } from "@/new/photos/utils/web"; +import { ensure } from "@/utils/ensure"; import { FlexWrapper, FluidContainer, @@ -43,7 +44,7 @@ import Close from "@mui/icons-material/Close"; import Done from "@mui/icons-material/Done"; import { Button, - ButtonProps, + type ButtonProps, Dialog, IconButton, Link, @@ -57,7 +58,7 @@ import { import Box from "@mui/material/Box"; import Typography from "@mui/material/Typography"; import { t } from "i18next"; -import React, { useCallback, useContext, useEffect, useState } from "react"; +import React, { useCallback, useEffect, useState } from "react"; import { Trans } from "react-i18next"; type PlanSelectorProps = ModalVisibilityProps & { @@ -97,13 +98,13 @@ const PlanSelectorCard: React.FC = ({ onClose, setLoading, }) => { - const { showMiniDialog } = useContext(AppContext); + const { showMiniDialog } = useAppContext(); const userDetails = useUserDetailsSnapshot(); const [plansData, setPlansData] = useState(); - const [planPeriod, setPlanPeriod] = useState( - userDetails?.subscription?.period ?? "month", + const [planPeriod, setPlanPeriod] = useState( + userDetails?.subscription.period ?? "month", ); const usage = userDetails ? planUsage(userDetails) : 0; @@ -118,7 +119,7 @@ const PlanSelectorCard: React.FC = ({ ); useEffect(() => { - const main = async () => { + void (async () => { try { setLoading(true); const plansData = await getPlansData(); @@ -147,8 +148,9 @@ const PlanSelectorCard: React.FC = ({ } finally { setLoading(false); } - }; - main(); + })(); + // TODO + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handlePlanSelect = async (plan: Plan) => { @@ -156,7 +158,7 @@ const PlanSelectorCard: React.FC = ({ case "buyPlan": try { setLoading(true); - await redirectToPaymentsApp(plan.stripeID, "buy"); + await redirectToPaymentsApp(ensure(plan.stripeID), "buy"); } catch (e) { setLoading(false); showMiniDialog( @@ -174,7 +176,10 @@ const PlanSelectorCard: React.FC = ({ continue: { text: t("update_subscription"), action: () => - redirectToPaymentsApp(plan.stripeID, "update"), + redirectToPaymentsApp( + ensure(plan.stripeID), + "update", + ), }, }); break; @@ -431,27 +436,17 @@ interface PeriodTogglerProps { const PeriodToggler: React.FC = ({ planPeriod, togglePeriod, -}) => { - const handleChange = (_, newPlanPeriod: PlanPeriod) => { - if (newPlanPeriod !== planPeriod) togglePeriod(); - }; - - return ( - - - {t("monthly")} - - - {t("yearly")} - - - ); -}; +}) => ( + newPeriod == planPeriod || togglePeriod()} + color="primary" + > + {t("monthly")} + {t("yearly")} + +); const CustomToggleButton = styled(ToggleButton)(({ theme }) => ({ textTransform: "none",