Skip to content

Commit

Permalink
fix(payment): tvod checkout fixes for authvod platform
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed May 31, 2022
1 parent c7478e1 commit 31325e4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/CheckoutForm/CheckoutForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const CheckoutForm: React.FC<Props> = ({
<td className={styles.couponCell}>
{t('checkout.coupon_discount')}
<br />
{!!offer.period && (
{!!offer.period && offerType === 'svod' && (
<small>
{t('checkout.discount_period', {
count: order.discount.periods,
Expand Down
4 changes: 3 additions & 1 deletion src/containers/AccountModal/forms/ChooseOffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useOffers from '../../../hooks/useOffers';

import { addQueryParam, removeQueryParam } from '#src/utils/history';
import { useCheckoutStore } from '#src/stores/CheckoutStore';
import { useConfigStore } from '#src/stores/ConfigStore';
import LoadingOverlay from '#src/components/LoadingOverlay/LoadingOverlay';
import ChooseOfferForm from '#src/components/ChooseOfferForm/ChooseOfferForm';
import useForm, { UseFormOnSubmitHandler } from '#src/hooks/useForm';
Expand All @@ -17,6 +18,7 @@ const ChooseOffer = () => {
const history = useHistory();
const { t } = useTranslation('account');
const { setOffer } = useCheckoutStore(({ setOffer }) => ({ setOffer }), shallow);
const { accessModel } = useConfigStore(({ accessModel }) => ({ accessModel }), shallow);
const { isLoading, offerType, setOfferType, offers, offersDict, defaultOfferId, hasTVODOffers, hasPremierOffer } = useOffers();

const validationSchema: SchemaOf<ChooseOfferFormData> = object().shape({
Expand Down Expand Up @@ -67,7 +69,7 @@ const ChooseOffer = () => {
submitting={submitting}
offers={offers}
offerType={offerType}
setOfferType={hasTVODOffers && !hasPremierOffer ? setOfferType : undefined}
setOfferType={accessModel === 'SVOD' && hasTVODOffers && !hasPremierOffer ? setOfferType : undefined}
/>
);
};
Expand Down
11 changes: 9 additions & 2 deletions src/hooks/useOffers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@ import type { OfferType } from '#types/account';
import { isSVODOffer } from '#src/utils/subscription';

const useOffers = () => {
const { cleengSandbox, json } = useConfigStore(({ config }) => config, shallow);
const { config, accessModel } = useConfigStore(
({ config, accessModel }) => ({
config,
accessModel,
}),
shallow,
);
const { cleengSandbox, json } = config;
const { requestedMediaOffers } = useCheckoutStore(({ requestedMediaOffers }) => ({ requestedMediaOffers }), shallow);
const hasPremierOffer = (requestedMediaOffers || []).some((offer) => offer.premier);
const tvodOfferIds = (requestedMediaOffers || []).map(({ offerId }) => offerId);
const [offerType, setOfferType] = useState<OfferType>('svod');
const [offerType, setOfferType] = useState<OfferType>(accessModel === 'SVOD' ? 'svod' : 'tvod');

const monthlyOfferId = json?.cleengMonthlyOffer ? (json.cleengMonthlyOffer as string) : '';
const yearlyOfferId = json?.cleengYearlyOffer ? (json.cleengYearlyOffer as string) : '';
Expand Down

0 comments on commit 31325e4

Please sign in to comment.