Skip to content

Commit

Permalink
fix(user): show payments menu in authvod access model
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Jun 1, 2022
1 parent 833c364 commit 6e2671a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 34 deletions.
65 changes: 35 additions & 30 deletions src/components/Payment/Payment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import { addQueryParam } from '../../utils/history';
import styles from './Payment.module.scss';

import type { PaymentDetail, Subscription, Transaction } from '#types/subscription';
import type { AccessModel } from '#types/Config';

const VISIBLE_TRANSACTIONS = 4;

type Props = {
accessModel: AccessModel;
activeSubscription: Subscription | null;
activePaymentDetail: PaymentDetail | null;
transactions: Transaction[] | null;
Expand All @@ -28,6 +30,7 @@ type Props = {
};

const Payment = ({
accessModel,
activePaymentDetail,
activeSubscription,
transactions,
Expand Down Expand Up @@ -72,37 +75,39 @@ const Payment = ({

return (
<>
<div className={panelClassName}>
<div className={panelHeaderClassName}>
<h3>{t('user:payment.subscription_details')}</h3>
{accessModel === 'SVOD' && (
<div className={panelClassName}>
<div className={panelHeaderClassName}>
<h3>{t('user:payment.subscription_details')}</h3>
</div>
{activeSubscription ? (
<React.Fragment>
<div className={styles.infoBox} key={activeSubscription.subscriptionId}>
<p>
<strong>{getTitle(activeSubscription.period)}</strong> <br />
{activeSubscription.status === 'active'
? t('user:payment.next_billing_date_on', { date: formatDate(activeSubscription.expiresAt) })
: t('user:payment.subscription_expires_on', { date: formatDate(activeSubscription.expiresAt) })}
</p>
<p className={styles.price}>
<strong>{formatPrice(activeSubscription.nextPaymentPrice, activeSubscription.nextPaymentCurrency, customer.country)}</strong>
<small>/{t(`account:periods.${activeSubscription.period}`)}</small>
</p>
</div>
{activeSubscription.status === 'active' ? (
<Button label={t('user:payment.cancel_subscription')} onClick={onCancelSubscriptionClick} />
) : (
<Button label={t('user:payment.renew_subscription')} onClick={onRenewSubscriptionClick} />
)}
</React.Fragment>
) : isLoading ? null : (
<React.Fragment>
<p>{t('user:payment.no_subscription')}</p>
<Button variant="contained" color="primary" label={t('user:payment.complete_subscription')} onClick={onCompleteSubscriptionClick} />
</React.Fragment>
)}
</div>
{activeSubscription ? (
<React.Fragment>
<div className={styles.infoBox} key={activeSubscription.subscriptionId}>
<p>
<strong>{getTitle(activeSubscription.period)}</strong> <br />
{activeSubscription.status === 'active'
? t('user:payment.next_billing_date_on', { date: formatDate(activeSubscription.expiresAt) })
: t('user:payment.subscription_expires_on', { date: formatDate(activeSubscription.expiresAt) })}
</p>
<p className={styles.price}>
<strong>{formatPrice(activeSubscription.nextPaymentPrice, activeSubscription.nextPaymentCurrency, customer.country)}</strong>
<small>/{t(`account:periods.${activeSubscription.period}`)}</small>
</p>
</div>
{activeSubscription.status === 'active' ? (
<Button label={t('user:payment.cancel_subscription')} onClick={onCancelSubscriptionClick} />
) : (
<Button label={t('user:payment.renew_subscription')} onClick={onRenewSubscriptionClick} />
)}
</React.Fragment>
) : isLoading ? null : (
<React.Fragment>
<p>{t('user:payment.no_subscription')}</p>
<Button variant="contained" color="primary" label={t('user:payment.complete_subscription')} onClick={onCompleteSubscriptionClick} />
</React.Fragment>
)}
</div>
)}
<div className={panelClassName}>
<div className={panelHeaderClassName}>
<h3>{t('user:payment.payment_method')}</h3>
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const Layout: FC<LayoutProps> = ({ children }) => {
if (!cleengId) return null;

return isLoggedIn ? (
<UserMenu showPaymentsItem={accessModel === 'SVOD'} />
<UserMenu showPaymentsItem={accessModel !== 'AVOD'} />
) : (
<div className={styles.buttonContainer}>
<Button fullWidth onClick={loginButtonClickHandler} label={t('sign_in')} />
Expand Down Expand Up @@ -124,7 +124,7 @@ const Layout: FC<LayoutProps> = ({ children }) => {
userMenuOpen={userMenuOpen}
toggleUserMenu={toggleUserMenu}
canLogin={!!cleengId}
showPaymentsMenuItem={accessModel === 'SVOD'}
showPaymentsMenuItem={accessModel !== 'AVOD'}
>
<Button label={t('home')} to="/" variant="text" />
{menu.map((item) => (
Expand Down
5 changes: 3 additions & 2 deletions src/screens/User/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const User = (): JSX.Element => {
<li>
<Button to="/u/favorites" label={t('nav.favorites')} variant="text" startIcon={<Favorite />} className={styles.button} />
</li>
{accessModel === 'SVOD' && (
{accessModel !== 'AVOD' && (
<li>
<Button to="/u/payments" label={t('nav.payments')} variant="text" startIcon={<BalanceWallet />} className={styles.button} />
</li>
Expand Down Expand Up @@ -117,8 +117,9 @@ const User = (): JSX.Element => {
/>
</Route>
<Route path="/u/payments">
{accessModel === 'SVOD' ? (
{accessModel !== 'AVOD' ? (
<Payment
accessModel={accessModel}
activeSubscription={subscription}
activePaymentDetail={activePayment}
transactions={transactions}
Expand Down

0 comments on commit 6e2671a

Please sign in to comment.