diff --git a/packages/shared/src/components/plus/PlusCheckoutContainer.tsx b/packages/shared/src/components/plus/PlusCheckoutContainer.tsx index b164b821a5..a4fe7611cc 100644 --- a/packages/shared/src/components/plus/PlusCheckoutContainer.tsx +++ b/packages/shared/src/components/plus/PlusCheckoutContainer.tsx @@ -1,27 +1,51 @@ import type { ReactElement } from 'react'; import React from 'react'; +import classNames from 'classnames'; import { usePaymentContext } from '../../contexts/PaymentContext'; import { usePlusSubscription } from '../../hooks'; import { PlusUnavailable } from './PlusUnavailable'; import { PlusPlus } from './PlusPlus'; -import type { WithClassNameProps } from '../utilities/common'; -export type PlusCheckoutContainerProps = WithClassNameProps; +export type PlusCheckoutContainerProps = { + checkoutRef?: React.LegacyRef; + className?: { + container?: string; + element?: string; + }; +}; export const PlusCheckoutContainer = ({ + checkoutRef, className, }: PlusCheckoutContainerProps): ReactElement => { const { isPlusAvailable } = usePaymentContext(); const { isPlus } = usePlusSubscription(); - if (!isPlusAvailable) { - return ; - } + const getContainerElement = () => { + if (!isPlusAvailable) { + return PlusUnavailable; + } + + if (isPlus) { + return PlusPlus; + } + + return null; + }; - if (isPlus) { - return ; - } + const ContainerElement = getContainerElement(); + const shouldRenderCheckout = !ContainerElement; - return null; + return ( +
+ {ContainerElement && } +
+ ); }; diff --git a/packages/shared/src/components/plus/PlusDesktop.tsx b/packages/shared/src/components/plus/PlusDesktop.tsx index 89adff7ee0..191390fa6e 100644 --- a/packages/shared/src/components/plus/PlusDesktop.tsx +++ b/packages/shared/src/components/plus/PlusDesktop.tsx @@ -50,12 +50,14 @@ export const PlusDesktop = (): ReactElement => { onChange={toggleCheckoutOption} /> -
- -
+ ); }; diff --git a/packages/webapp/pages/plus/payment.tsx b/packages/webapp/pages/plus/payment.tsx index 0cda9dec93..a37ef578e4 100644 --- a/packages/webapp/pages/plus/payment.tsx +++ b/packages/webapp/pages/plus/payment.tsx @@ -29,18 +29,19 @@ const PlusPaymentPage = (): ReactElement => { <>
-
{ + { if (!element) { return; } openCheckout({ priceId: pid as string }); }} - className="checkout-container h-full w-full bg-background-default p-5" - > - -
+ className={{ + container: 'h-full w-full bg-background-default p-5', + element: 'h-full', + }} + />
);