mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
488d9bb135
no issue - Ghost users that make >= $100 MRR will see a dismissible notification that invites them to the Ghost Referral program - Only applies to Admin and Owner users and when Stripe is setup and connected in live mode - By saving a `referralInviteDismissed` property to the users' `accessibility` JSON object we can determine if the notification has been dismissed and won't show it again - Added new `gh-referral-invite` component
69 lines
2.1 KiB
JavaScript
69 lines
2.1 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import envConfig from 'ghost-admin/config/environment';
|
|
import moment from 'moment-timezone';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default class GhReferralInvite extends Component {
|
|
@service session;
|
|
@service dashboardStats;
|
|
@service feature;
|
|
@service membersUtils;
|
|
@service settings;
|
|
|
|
constructor() {
|
|
super(...arguments);
|
|
this.loadCurrentMRR.perform();
|
|
}
|
|
|
|
get isAdminOrOwner() {
|
|
return this.session.user.isAdmin;
|
|
}
|
|
|
|
get isReferralNotificationNotDismissed() {
|
|
return !this.feature.accessibility.referralInviteDismissed;
|
|
}
|
|
|
|
get stripeLiveModeEnabled() {
|
|
// allow testing mode when not in a production environment
|
|
const isDevModeStripeEnabled = envConfig.environment !== 'production' && this.membersUtils.isStripeEnabled;
|
|
const isLiveEnabled = this.settings.stripeConnectLivemode;
|
|
return isDevModeStripeEnabled || isLiveEnabled;
|
|
}
|
|
|
|
get hasReachedMRR() {
|
|
return this.dashboardStats.currentMRR / 100 >= 100;
|
|
}
|
|
|
|
get showReferralInvite() {
|
|
// Conditions to see the referral invite
|
|
// 1. Needs to be Owner or Admin
|
|
// 2. Stripe is setup and enabled in live mode
|
|
// 3. MRR is > $100
|
|
// 4. Notification has not yet been dismissed by the user
|
|
return !this.args.hasThemeErrors && this.isAdminOrOwner && this.isReferralNotificationNotDismissed && this.stripeLiveModeEnabled && this.hasReachedMRR;
|
|
}
|
|
|
|
@task
|
|
*loadCurrentMRR() {
|
|
if (this.isAdminOrOwnern) {
|
|
try {
|
|
yield this.dashboardStats.loadMrrStats();
|
|
} catch (error) {
|
|
// noop
|
|
}
|
|
}
|
|
}
|
|
|
|
@action
|
|
dismissReferralInvite(event) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
|
|
if (!this.feature.referralInviteDismissed) {
|
|
this.feature.referralInviteDismissed = moment().tz(this.settings.timezone);
|
|
}
|
|
}
|
|
}
|