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