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

feat: initial inplayer subscription change implementation #320

Merged
merged 25 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b335b69
feat: initial inplayer subscription change implementation
naumovski-filip Jun 19, 2023
00eab09
chore: fix tests
naumovski-filip Jun 19, 2023
87297ce
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jun 20, 2023
2faf833
chore: add translations
naumovski-filip Jun 20, 2023
7722e79
chore: add disabled check to save button
naumovski-filip Jun 20, 2023
53ee10d
feat: temporary FE handling for downgrade subscription
naumovski-filip Jun 27, 2023
0d43981
chore: linter
naumovski-filip Jun 27, 2023
265b16c
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jun 27, 2023
c52b13e
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 5, 2023
8f71448
fix: hide cancel button for inplayer configs
naumovski-filip Jul 6, 2023
da4dd40
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 6, 2023
7d824dd
chore: fix tests
naumovski-filip Jul 6, 2023
be09ba2
fix: disable change subscription button when subscription is cancelle…
naumovski-filip Jul 6, 2023
4a8a5ff
fix: remove unnecessary redirect
naumovski-filip Jul 11, 2023
c9d5bbb
fix: pr comments
naumovski-filip Jul 17, 2023
d79f779
fix: offerswitch props
naumovski-filip Jul 17, 2023
1cfcf45
fix: move useoffers call to payments
naumovski-filip Jul 17, 2023
d6b369d
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 18, 2023
6b7a72a
fix: move logic from user and payment to paymentcontainer
naumovski-filip Jul 18, 2023
7a350fa
fix: move additional logic to container
naumovski-filip Jul 18, 2023
f9c8ad1
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 18, 2023
fd96e9b
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 21, 2023
59c23cb
Merge branch 'develop' into feat/change-subscription
naumovski-filip Jul 21, 2023
1435d0d
chore: add translation
naumovski-filip Jul 21, 2023
19cd475
fix: add per-provider flag for subscription change tests
naumovski-filip Jul 24, 2023
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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"@adyen/adyen-web": "^5.42.1",
"@codeceptjs/allure-legacy": "^1.0.2",
"@inplayer-org/inplayer.js": "^3.13.12",
"@inplayer-org/inplayer.js": "^3.13.13",
"classnames": "^2.3.1",
"date-fns": "^2.28.0",
"dompurify": "^2.3.8",
Expand Down
7 changes: 7 additions & 0 deletions public/locales/en/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@
"annual_subscription": "Annual subscription",
"cancel_subscription": "Cancel subscription",
"card_number": "Card number",
"change_plan": "Change Plan",
"change_plan_error": "There was a problem saving your subscription plan change.",
"change_subscription": "Change subscription",
"complete_subscription": "Complete subscription",
"current_plan": "CURRENT PLAN",
"daily_subscription": "Daily subscription",
"downgrade_on": "Pending downgrade on {{date}}",
"downgrade_plan_success": "You've successfully changed the subscription plan. Your new plan will start after the end of the current cycle ({{date}}).",
"expiry_date": "Expiry date",
"granted_subscription": "Granted subscription",
"hidden_transactions_one": "One more transaction",
Expand All @@ -84,6 +89,7 @@
"no_transactions": "No transactions",
"other": "other",
"payment_method": "Payment method",
"pending_downgrade": "Pending downgrade",
"pending_offer_switch": "Will update to a \"{{title}}\" after the next billing date",
"price_payed_with": "{{price}} payed with {{method}}",
"price_payed_with_card": "Price payed with card",
Expand All @@ -95,6 +101,7 @@
"subscription_expires_on": "This plan will expire on {{date}}",
"transactions": "Transactions",
"update_payment_details": "Update payment details",
"upgrade_plan_success": "You've successfully changed the subscription plan. You can enjoy your additional benefits immediately.",
"weekly_subscription": "Weekly subscription"
}
}
7 changes: 7 additions & 0 deletions public/locales/es/user.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@
"annual_subscription": "Suscripción anual",
"cancel_subscription": "Cancelar suscripción",
"card_number": "Número de tarjeta",
"change_plan": "",
"change_plan_error": "",
"change_subscription": "Cambiar suscripción",
"complete_subscription": "Completar suscripción",
"current_plan": "",
"daily_subscription": "Suscripción diaria",
"downgrade_on": "",
"downgrade_plan_success": "",
"expiry_date": "Fecha de vencimiento",
"granted_subscription": "Suscripción otorgada",
"hidden_transactions_one": "Una transacción más",
Expand All @@ -85,6 +90,7 @@
"no_transactions": "No hay transacciones",
"other": "otro",
"payment_method": "Método de pago",
"pending_downgrade": "",
"pending_offer_switch": "Se actualizará a \"{{title}}\" después de la próxima fecha de facturación",
"price_payed_with": "{{price}} pagado con {{method}}",
"price_payed_with_card": "Precio pagado con tarjeta",
Expand All @@ -96,6 +102,7 @@
"subscription_expires_on": "Este plan expirará el {{date}}",
"transactions": "Transacciones",
"update_payment_details": "Actualizar detalles de pago",
"upgrade_plan_success": "",
"weekly_subscription": "Suscripción semanal"
}
}
62 changes: 62 additions & 0 deletions src/components/OfferSwitch/OfferSwitch.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
@use 'src/styles/variables';
@use 'src/styles/theme';

.offerSwitchContainer {
display: flex;
align-items: center;
width: 100%;
height: auto;
padding: 16px;
gap: 25px;
color: variables.$gray-white;
background-color: theme.$panel-bg;
border-radius: 4px;
}

.activeOfferSwitchContainer {
color: variables.$gray-darker;
background-color: variables.$white;
}

.offerSwitchInfoContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
height: 100%;
gap: 4px;
font-weight: 600;
}

.offerSwitchPlanContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
gap: 2px;
}

.currentPlanHeading {
color: variables.$gray;
font-size: 10px;
}

.activeCurrentPlanHeading {
color: variables.$gray;
}

.nextBillingDate {
color: variables.$gray;
font-weight: 400;
font-size: 12px;
}

.price {
margin-left: auto;
font-size: 20px;
line-height: 28px;
}

.paymentFrequency {
font-size: 12px;
}
61 changes: 61 additions & 0 deletions src/components/OfferSwitch/OfferSwitch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import classNames from 'classnames';
import { useTranslation } from 'react-i18next';

import styles from './OfferSwitch.module.scss';

import type { Offer } from '#types/checkout';
import Checkbox from '#components/Checkbox/Checkbox';
import { formatLocalizedDate, formatPrice } from '#src/utils/formatting';
import { useAccountStore } from '#src/stores/AccountStore';

interface OfferSwitchProps {
naumovski-filip marked this conversation as resolved.
Show resolved Hide resolved
isCurrentOffer: boolean;
pendingDowngradeOfferId: string;
offer: Offer;
selected: {
value: boolean;
set: React.Dispatch<React.SetStateAction<string | null>>;
};
naumovski-filip marked this conversation as resolved.
Show resolved Hide resolved
}

const OfferSwitch = ({ isCurrentOffer, pendingDowngradeOfferId, offer, selected }: OfferSwitchProps) => {
const { t, i18n } = useTranslation('user');
const { customerPriceInclTax, customerCurrency, period } = offer;
const expiresAt = useAccountStore((state) => state.subscription?.expiresAt);
naumovski-filip marked this conversation as resolved.
Show resolved Hide resolved

const isPendingDowngrade = pendingDowngradeOfferId === offer.offerId;

return (
<div className={classNames(styles.offerSwitchContainer, { [styles.activeOfferSwitchContainer]: selected.value })}>
<Checkbox disabled={isPendingDowngrade} name={offer.offerId} checked={selected.value} onChange={() => selected.set(offer.offerId)} />
<div className={styles.offerSwitchInfoContainer}>
{(isCurrentOffer || isPendingDowngrade) && (
<div className={classNames(styles.currentPlanHeading, { [styles.activeCurrentPlanHeading]: selected.value })}>
{isCurrentOffer && t('payment.current_plan').toUpperCase()}
{isPendingDowngrade && t('payment.pending_downgrade').toUpperCase()}
</div>
)}
<div className={styles.offerSwitchPlanContainer}>
<div>{t(`payment.${period === 'month' ? 'monthly' : 'annual'}_subscription`)}</div>
{(isCurrentOffer || isPendingDowngrade) && expiresAt && (
<div className={styles.nextBillingDate}>
{isCurrentOffer &&
!pendingDowngradeOfferId &&
t('payment.next_billing_date_on', { date: formatLocalizedDate(new Date(expiresAt * 1000), i18n.language) })}
{isPendingDowngrade && t('payment.downgrade_on', { date: formatLocalizedDate(new Date(expiresAt * 1000), i18n.language) })}
</div>
)}
</div>
</div>
<div className={styles.price}>
{formatPrice(customerPriceInclTax, customerCurrency, undefined)}
{
//todo: i18n
}
<span className={styles.paymentFrequency}>/{period === 'month' ? 'month' : 'year'}</span>
</div>
</div>
);
};

export default OfferSwitch;
17 changes: 17 additions & 0 deletions src/components/Payment/Payment.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@
margin: 0 0 8px;
}
}

.changePlanContainer {
display: flex;
flex-direction: column;
gap: 24px;
}

.changePlanButtons {
display: flex;
flex-direction: row;
width: 100%;
gap: 12px;
}

.changePlanCancelButton {
margin-left: auto;
}
Loading