({
shouldShowPlusHeader,
}: CommonPlusPageProps)
| 21 | ); |
| 22 | |
| 23 | export const PlusDesktop = ({ |
| 24 | shouldShowPlusHeader, |
| 25 | }: CommonPlusPageProps): ReactElement => { |
| 26 | const { |
| 27 | openCheckout, |
| 28 | isPaddleReady, |
| 29 | productOptions, |
| 30 | giftOneYear, |
| 31 | isPricesPending, |
| 32 | isOrganization, |
| 33 | } = usePaymentContext(); |
| 34 | const { giftToUser } = useGiftUserContext(); |
| 35 | const { |
| 36 | query: { selectedPlan }, |
| 37 | } = useRouter(); |
| 38 | const { isPlus } = usePlusSubscription(); |
| 39 | const initialPaymentOption = selectedPlan ? `${selectedPlan}` : null; |
| 40 | const [selectedOption, setSelectedOption] = useState<string | null>(null); |
| 41 | const ref = useRef<HTMLDivElement>(null); |
| 42 | |
| 43 | const onChangeCheckoutOption: OpenCheckoutFn = useCallback( |
| 44 | ({ priceId, giftToUserId, quantity }) => { |
| 45 | setSelectedOption(priceId); |
| 46 | openCheckout?.({ priceId, giftToUserId, quantity }); |
| 47 | }, |
| 48 | [openCheckout], |
| 49 | ); |
| 50 | |
| 51 | useEffect(() => { |
| 52 | if (!ref?.current || !isPaddleReady || selectedOption) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if (giftToUser) { |
| 57 | if (!giftOneYear) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const { priceId } = giftOneYear; |
| 62 | setSelectedOption(priceId); |
| 63 | openCheckout?.({ priceId, giftToUserId: giftToUser.id }); |
| 64 | |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | const option = initialPaymentOption || productOptions?.[0]?.priceId; |
| 69 | |
| 70 | // Auto-select if user is not plus or it is organization checkout |
| 71 | if (option && (!isPlus || isOrganization)) { |
| 72 | setSelectedOption(option); |
| 73 | openCheckout?.({ priceId: option }); |
| 74 | } |
| 75 | }, [ |
| 76 | giftOneYear, |
| 77 | giftToUser, |
| 78 | initialPaymentOption, |
| 79 | openCheckout, |
| 80 | isPaddleReady, |
nothing calls this directly
no test coverage detected