Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OWA-84: Stripe external link to billing portal #596

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/hooks-react/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type UseFormReturnValue<T> = {
handleBlur: UseFormBlurHandler;
handleSubmit: UseFormSubmitHandler;
setValue: (key: keyof T, value: T[keyof T]) => void;
setValues: (values: T | ((currValues: T) => T)) => void;
setErrors: (errors: FormErrors<T>) => void;
setSubmitting: (submitting: boolean) => void;
setValidationSchemaError: (error: boolean) => void;
Expand Down Expand Up @@ -188,6 +189,7 @@ export default function useForm<T extends GenericFormValues>({
handleSubmit,
submitting,
setValue,
setValues,
setErrors,
setSubmitting,
setValidationSchemaError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ const ChoosePlanForm: React.FC<Props> = ({ values, errors, submitting, offers, o
const [offerFilter, setOfferFilter] = useState<OfferPeriod>(() => Object.keys(groupedOffers)[0] as OfferPeriod);

useLayoutEffect(() => {
setValue('selectedOfferId', groupedOffers[offerFilter as OfferPeriod]?.[0].offerId || '');
const offerGroup = groupedOffers[offerFilter as OfferPeriod];

if (offerGroup) {
setValue('selectedOfferId', offerGroup[0].offerId);
}

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [offerFilter]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ChooseOffer = () => {
const upgradeSuccessUrl = modalURLFromLocation(location, 'upgrade-subscription-success');
const upgradeErrorUrl = modalURLFromLocation(location, 'upgrade-subscription-error');

const { values, errors, submitting, setValue, handleSubmit, handleChange } = useForm<ChooseOfferFormData>({
const { values, errors, submitting, setValue, setValues, handleSubmit, handleChange } = useForm<ChooseOfferFormData>({
initialValues: { selectedOfferType: defaultOfferType, selectedOfferId: undefined },
validationSchema: object().shape({
selectedOfferId: mixed<string>().required(t('choose_offer.field_required')),
Expand Down Expand Up @@ -91,8 +91,12 @@ const ChooseOffer = () => {

const offerId = visibleOffers[visibleOffers.length - 1]?.offerId;

setValue('selectedOfferId', offerId);
}, [visibleOffers, values.selectedOfferType, setValue, isLoading]);
setValues((currValues) => {
if (currValues.selectedOfferId) return currValues;

return { ...currValues, selectedOfferId: offerId };
});
}, [visibleOffers, values.selectedOfferType, setValues, isLoading]);

useEffect(() => {
if (isLoading || !defaultOfferType) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const StartWatchingButton: React.VFC<Props> = ({ item, playUrl, disabled = false
const breakpoint = useBreakpoint();

// account
const accessModel = useConfigStore((state) => state.accessModel);
const { accessModel, isAccessBridgeEnabled } = useConfigStore(({ accessModel, settings }) => ({
accessModel,
isAccessBridgeEnabled: !!settings?.apiAccessBridgeUrl,
}));

const user = useAccountStore((state) => state.user);
const isLoggedIn = !!user;

Expand Down Expand Up @@ -66,8 +70,12 @@ const StartWatchingButton: React.VFC<Props> = ({ item, playUrl, disabled = false
if (!isLoggedIn) return navigate(modalURLFromLocation(location, 'create-account'));
if (hasMediaOffers) return navigate(modalURLFromLocation(location, 'choose-offer'));

if (isAccessBridgeEnabled) {
return navigate('/u/subscription');
}

return navigate('/u/payments');
}, [isEntitled, playUrl, navigate, isLoggedIn, location, hasMediaOffers, onClick]);
}, [isEntitled, playUrl, navigate, isLoggedIn, location, hasMediaOffers, isAccessBridgeEnabled, onClick]);

useEffect(() => {
// set the TVOD mediaOffers in the checkout store
Expand Down
Loading