-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clear checkout if plus becomes unavailable
- Loading branch information
Showing
3 changed files
with
48 additions
and
21 deletions.
There are no files selected for viewing
42 changes: 33 additions & 9 deletions
42
packages/shared/src/components/plus/PlusCheckoutContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HTMLDivElement>; | ||
className?: { | ||
container?: string; | ||
element?: string; | ||
}; | ||
}; | ||
|
||
export const PlusCheckoutContainer = ({ | ||
checkoutRef, | ||
className, | ||
}: PlusCheckoutContainerProps): ReactElement => { | ||
const { isPlusAvailable } = usePaymentContext(); | ||
const { isPlus } = usePlusSubscription(); | ||
|
||
if (!isPlusAvailable) { | ||
return <PlusUnavailable className={className} />; | ||
} | ||
const getContainerElement = () => { | ||
if (!isPlusAvailable) { | ||
return PlusUnavailable; | ||
} | ||
|
||
if (isPlus) { | ||
return PlusPlus; | ||
} | ||
|
||
return null; | ||
}; | ||
|
||
if (isPlus) { | ||
return <PlusPlus className={className} />; | ||
} | ||
const ContainerElement = getContainerElement(); | ||
const shouldRenderCheckout = !ContainerElement; | ||
|
||
return null; | ||
return ( | ||
<div | ||
ref={shouldRenderCheckout ? checkoutRef : undefined} | ||
className={classNames( | ||
shouldRenderCheckout && 'checkout-container', | ||
className?.container, | ||
)} | ||
> | ||
{ContainerElement && <ContainerElement className={className?.element} />} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters