From 22799fe56e0a4b26235ca8714eddfb1496b19972 Mon Sep 17 00:00:00 2001 From: Benjamin Goering <171782+gobengo@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:58:30 -0800 Subject: [PATCH] feat: /account/payment disables changing plans after scheduled sunset date (#2321) Motivation: * https://github.com/web3-storage/secrets/issues/23 Notes * it takes effect when rendering after the date configured by `NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START`, which is also the date that is used inside the announcement banner. We can easily change the exact logic in the `shouldPreventPlanSwitching` in w3up-launch.js later too * I got sick of looking at a React warning in browser console about invalid nesting of div inside p, and it was because payment page Tooltip (div) was in a p, so I made the Tooltip element name configurable to get rid of the warning. seems to work ok --- .env.tpl | 4 ++ .github/workflows/website.yml | 2 + .../account/paymentTable.js/paymentTable.js | 43 +++++++++++++++---- packages/website/components/w3up-launch.js | 11 ++++- .../zero/components/tooltip/tooltip.js | 9 ++-- packages/website/pages/account/payment.js | 7 ++- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/.env.tpl b/.env.tpl index 52463255c1..98c39973a8 100644 --- a/.env.tpl +++ b/.env.tpl @@ -73,6 +73,10 @@ NEXT_PUBLIC_ENV=dev # NEXT_PUBLIC_COUNTLY_KEY= # NEXT_PUBLIC_COUNTLY_URL= +# set to schedule when announcement banners should show about the w3up launch and related product sunsets +# NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START='2023-11-21T00:00:00Z' +# set to schedule when certain features hide bcause the product has been sunset and w3up is launched +# NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START='2024-01-10T00:00:00Z' ## ---- cron ------------------------------------------------------------------ diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index ef3900a8dc..19a1e47dcf 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -200,6 +200,7 @@ jobs: NEXT_PUBLIC_COUNTLY_KEY: ${{ secrets.COUNTLY_KEY }} NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${{ secrets.TESTING_STRIPE_PUBLISHABLE_KEY }} NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START }} + NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START }} DID_DOCUMENT_ID: ${{ secrets.STAGING_DID_DOCUMENT_ID }} DID_DOCUMENT_PRIMARY_DID_KEY: ${{ secrets.STAGING_DID_DOCUMENT_PRIMARY_DID_KEY }} - name: Add to web3.storage @@ -296,6 +297,7 @@ jobs: NEXT_PUBLIC_COUNTLY_KEY: ${{ secrets.COUNTLY_KEY }} NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${{ secrets.STRIPE_PUBLISHABLE_KEY }} NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_ANNOUNCEMENT_START }} + NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START: ${{ vars.NEXT_PUBLIC_W3UP_LAUNCH_SUNSET_START }} DID_DOCUMENT_ID: ${{ secrets.PRODUCTION_DID_DOCUMENT_ID }} DID_DOCUMENT_PRIMARY_DID_KEY: ${{ secrets.PRODUCTION_DID_DOCUMENT_PRIMARY_DID_KEY }} - name: Add to web3.storage diff --git a/packages/website/components/account/paymentTable.js/paymentTable.js b/packages/website/components/account/paymentTable.js/paymentTable.js index e5994f8fe6..7b5489c487 100644 --- a/packages/website/components/account/paymentTable.js/paymentTable.js +++ b/packages/website/components/account/paymentTable.js/paymentTable.js @@ -7,17 +7,37 @@ import { formatAsStorageAmount, formatCurrency } from '../../../lib/utils.js'; const getAdditionalStoragePrice = price => (typeof price === 'number' ? `${formatCurrency(price / 100)} / GiB` : 'N/A'); -const PaymentTable = ({ plans: plansProp, currentPlan, setPlanSelection, setIsPaymentPlanModalOpen }) => { +/** + * @typedef {import('../../../components/contexts/plansContext.js').Plan} Plan + * @typedef {import('../../../components/contexts/plansContext.js').StorageSubscription} StorageSubscription + * @typedef {import('../../../components/contexts/plansContext.js').StoragePrice} StoragePrice + */ + +/** + * @param {object} props + * @param {Plan} [props.currentPlan] + * @param {boolean} [props.disablePlanSwitching] - whether to disable plan switching e.g. hide 'select plan' buttons + * @param {Plan[]} props.plans + * @param {(isOpen: boolean) => void} props.setIsPaymentPlanModalOpen + * @param {(plan?: Plan) => void} props.setPlanSelection + */ +const PaymentTable = ({ + plans: plansProp, + currentPlan, + setPlanSelection, + setIsPaymentPlanModalOpen, + disablePlanSwitching, +}) => { const plans = useMemo(() => { - const isCurrentPlanStandard = ['free', 'lite', 'pro'].includes(currentPlan?.id); + const isCurrentPlanStandard = currentPlan ? ['free', 'lite', 'pro'].includes(currentPlan?.id) : false; if (!isCurrentPlanStandard) { - return [currentPlan, ...plansProp.slice(1)]; + return [...(currentPlan ? [currentPlan] : []), ...plansProp.slice(1)]; } return plansProp; }, [plansProp, currentPlan]); - + const shouldShowSelectPlanButtons = !disablePlanSwitching; return ( <> {currentPlan && ( @@ -42,7 +62,10 @@ const PaymentTable = ({ plans: plansProp, currentPlan, setPlanSelection, setIsPa
Base Storage Capacity
Additional Storage{' '}
-
{currentPlan.description}
{formatAsStorageAmount(plan.tiers?.[0]?.upTo)}
+{formatAsStorageAmount(plan.tiers?.[0]?.upTo ?? 0)}
{getAdditionalStoragePrice(plan.tiers?.[1]?.unitAmount)}
-{plan.bandwidth ? `${formatAsStorageAmount(plan.bandwidth)} / month` : 'N/A'}
++ {plan.bandwidth ? `${formatAsStorageAmount(parseInt(plan.bandwidth, 10) ?? 0)} / month` : 'N/A'} +