0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Updated handling for complimentary member

no refs

With multiple products, its possible to assign a member complimentary product without active subscription.

- updates complimentary member helper to check for `paid` without subscription
- updates account home page to consider complimentary member without subscription
This commit is contained in:
Rishabh 2021-07-02 15:20:05 +05:30
parent 30491bf27b
commit 6a68039334
4 changed files with 35 additions and 17 deletions

View file

@ -139,7 +139,7 @@ const UserHeader = () => {
const PaidAccountActions = () => {
const {member, site, onAction} = useContext(AppContext);
const onEditBilling = () => {
const subscription = getMemberSubscription({member});
onAction('editBilling', {subscriptionId: subscription.id});
@ -156,10 +156,13 @@ const PaidAccountActions = () => {
};
const PlanLabel = ({price, isComplimentary}) => {
const {amount = 0, currency, interval} = price;
let label = `${Intl.NumberFormat('en', {currency, style: 'currency'}).format(amount / 100)}/${interval}`;
let label = '';
if (price) {
const {amount = 0, currency, interval} = price;
label = `${Intl.NumberFormat('en', {currency, style: 'currency'}).format(amount / 100)}/${interval}`;
}
if (isComplimentary) {
label = `Complimentary (${label})`;
label = label ? `Complimentary (${label})` : `Complimentary`;
}
return (
<p>
@ -210,13 +213,13 @@ const PaidAccountActions = () => {
};
const subscription = getMemberSubscription({member});
if (subscription) {
let isComplimentary = isComplimentaryMember({member});
const isComplimentary = isComplimentaryMember({member});
if (subscription || isComplimentary) {
const {
plan,
price,
default_payment_card_last4: defaultCardLast4
} = subscription;
} = subscription || {};
return (
<>
<section>
@ -313,11 +316,14 @@ const AccountWelcome = () => {
if (!isStripeConfigured) {
return null;
}
if (member.paid) {
const subscription = getMemberSubscription({member});
const currentPeriodEnd = subscription.current_period_end;
if (subscription.cancel_at_period_end) {
const subscription = getMemberSubscription({member});
const isComplimentary = isComplimentaryMember({member});
if (isComplimentary && !subscription) {
return null;
}
if (subscription) {
const currentPeriodEnd = subscription?.current_period_end;
if (subscription?.cancel_at_period_end) {
return null;
}
return (
@ -337,9 +343,6 @@ const AccountWelcome = () => {
const ContinueSubscriptionButton = () => {
const {member, onAction, action, brandColor} = useContext(AppContext);
if (!member.paid) {
return null;
}
const subscription = getMemberSubscription({member});
if (!subscription) {
return null;
@ -426,10 +429,10 @@ export default class AccountHomePage extends React.Component {
return (
<div className='gh-portal-account-wrapper'>
<AccountMain />
<AccountFooter
<AccountFooter
onClose={() => this.context.onAction('closePopup')}
handleSignout={e => this.handleSignout(e)}
supportAddress={supportAddress}
supportAddress={supportAddress}
/>
</div>
);

View file

@ -1,4 +1,7 @@
export const getDateString = (isoDate) => {
if (!isoDate) {
return '';
}
const event = new Date(isoDate);
const options = {year: 'numeric', month: 'short', day: 'numeric'};
return event.toLocaleDateString('en-GB', options);

View file

@ -190,6 +190,16 @@ export const member = {
subscriptions: [],
paid: false
},
alphaComplimentary: {
uuid: '7dcc8939-3be0-4ac8-a363-96d19f909de6',
email: 'jamie@example.com',
name: 'Jamie Larson',
firstname: 'Jamie',
// avatar_image: 'https://gravatar.com/avatar/eb0ef27b5faa9528c900170cba4c11dc?s=250&',
avatar_image: '',
subscriptions: [],
paid: true
},
paid: {
uuid: '7dcc8939-3be0-4ac8-a363-96d19f909de6',
email: 'jamie@example.com',

View file

@ -55,6 +55,8 @@ export function isComplimentaryMember({member = {}}) {
if (subscription) {
const {price} = subscription;
return (price && price.amount === 0);
} else if (!subscription && !!member.paid) {
return true;
}
return false;
}