2022-07-15 15:44:26 +03:00
|
|
|
import ConfirmEmailModal from './modals/settings/confirm-email';
|
2020-06-19 19:06:49 +03:00
|
|
|
import ModalComponent from 'ghost-admin/components/modal-base';
|
2020-07-07 07:22:42 +03:00
|
|
|
import copyTextToClipboard from 'ghost-admin/utils/copy-text-to-clipboard';
|
2021-05-19 17:36:46 +03:00
|
|
|
import {action, computed} from '@ember/object';
|
2021-05-12 14:33:36 +03:00
|
|
|
import {htmlSafe} from '@ember/template';
|
2022-11-03 14:14:36 +03:00
|
|
|
import {inject} from 'ghost-admin/decorators/inject';
|
2020-06-19 19:06:49 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2020-07-07 07:22:42 +03:00
|
|
|
import {task, timeout} from 'ember-concurrency';
|
2020-07-21 20:12:55 +03:00
|
|
|
const ICON_EXTENSIONS = ['gif', 'jpg', 'jpeg', 'png', 'svg'];
|
|
|
|
|
2020-06-19 19:06:49 +03:00
|
|
|
export default ModalComponent.extend({
|
2022-07-15 15:44:26 +03:00
|
|
|
modals: service(),
|
2021-01-28 20:28:19 +03:00
|
|
|
membersUtils: service(),
|
|
|
|
settings: service(),
|
2021-05-04 18:43:31 +03:00
|
|
|
store: service(),
|
2021-08-17 13:03:29 +03:00
|
|
|
session: service(),
|
2021-08-23 13:54:33 +03:00
|
|
|
feature: service(),
|
2022-01-27 14:40:11 +03:00
|
|
|
ghostPaths: service(),
|
|
|
|
ajax: service(),
|
2021-01-28 20:28:19 +03:00
|
|
|
|
2020-06-25 23:45:47 +03:00
|
|
|
page: 'signup',
|
2020-07-07 07:22:42 +03:00
|
|
|
iconExtensions: null,
|
|
|
|
isShowModalLink: true,
|
|
|
|
customIcon: null,
|
2020-07-30 16:12:44 +03:00
|
|
|
showLinksPage: false,
|
2020-07-30 13:56:07 +03:00
|
|
|
showLeaveSettingsModal: false,
|
2021-05-19 17:36:46 +03:00
|
|
|
isPreloading: true,
|
2022-05-11 20:11:54 +03:00
|
|
|
changedTiers: null,
|
2022-04-28 11:24:12 +03:00
|
|
|
openSection: null,
|
2021-05-19 22:24:13 +03:00
|
|
|
portalPreviewGuid: 'modal-portal-settings',
|
2021-01-28 20:28:19 +03:00
|
|
|
|
2020-06-25 23:45:47 +03:00
|
|
|
confirm() {},
|
2020-06-29 20:37:11 +03:00
|
|
|
|
2022-11-03 14:14:36 +03:00
|
|
|
config: inject(),
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
backgroundStyle: computed('settings.accentColor', function () {
|
2022-10-07 16:23:21 +03:00
|
|
|
let color = this.settings.accentColor || '#ffffff';
|
2020-07-07 07:22:42 +03:00
|
|
|
return htmlSafe(`background-color: ${color}`);
|
|
|
|
}),
|
|
|
|
|
|
|
|
showModalLinkOrAttribute: computed('isShowModalLink', function () {
|
|
|
|
if (this.isShowModalLink) {
|
2020-10-12 14:56:37 +03:00
|
|
|
return `#/portal`;
|
2020-07-07 07:22:42 +03:00
|
|
|
}
|
|
|
|
return `data-portal`;
|
|
|
|
}),
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
portalPreviewUrl: computed('page', 'model.tiers.[]', 'changedTiers.[]', 'membersUtils.{isFreeChecked,isMonthlyChecked,isYearlyChecked}', 'settings.{portalName,portalButton,portalButtonIcon,portalButtonSignupText,portalButtonStyle,accentColor,portalPlans.[]}', function () {
|
2021-05-18 15:59:47 +03:00
|
|
|
const options = this.getProperties(['page']);
|
2022-05-11 20:11:54 +03:00
|
|
|
options.portalTiers = this.model.tiers?.filter((tier) => {
|
|
|
|
return tier.get('visibility') === 'public'
|
|
|
|
&& tier.get('active') === true
|
|
|
|
&& tier.get('type') === 'paid';
|
|
|
|
}).map((tier) => {
|
|
|
|
return tier.id;
|
2022-03-08 10:30:31 +03:00
|
|
|
});
|
2022-05-11 20:11:54 +03:00
|
|
|
const freeTier = this.model.tiers?.find((tier) => {
|
|
|
|
return tier.type === 'free';
|
2022-03-08 10:30:31 +03:00
|
|
|
});
|
2022-05-11 20:11:54 +03:00
|
|
|
options.isFreeChecked = freeTier?.visibility === 'public';
|
2021-01-28 21:41:03 +03:00
|
|
|
return this.membersUtils.getPortalPreviewUrl(options);
|
2020-06-25 23:45:47 +03:00
|
|
|
}),
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
showIconSetting: computed('selectedButtonStyle', function () {
|
|
|
|
const selectedButtonStyle = this.get('selectedButtonStyle.name') || '';
|
|
|
|
return selectedButtonStyle.includes('icon');
|
|
|
|
}),
|
|
|
|
|
2020-07-16 16:21:14 +03:00
|
|
|
showButtonTextSetting: computed('selectedButtonStyle', function () {
|
|
|
|
const selectedButtonStyle = this.get('selectedButtonStyle.name') || '';
|
|
|
|
return selectedButtonStyle.includes('text');
|
|
|
|
}),
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
selectedButtonStyle: computed('settings.portalButtonStyle', function () {
|
|
|
|
return this.buttonStyleOptions.find((buttonStyle) => {
|
2022-10-07 16:23:21 +03:00
|
|
|
return (buttonStyle.name === this.settings.portalButtonStyle);
|
2020-07-07 07:22:42 +03:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
|
2021-06-04 10:45:49 +03:00
|
|
|
isFreeChecked: computed('settings.{portalPlans.[],membersSignupAccess}', function () {
|
2022-10-07 16:23:21 +03:00
|
|
|
const allowedPlans = this.settings.portalPlans || [];
|
|
|
|
return (this.settings.membersSignupAccess === 'all' && allowedPlans.includes('free'));
|
2021-06-04 10:45:49 +03:00
|
|
|
}),
|
2022-05-24 17:53:03 +03:00
|
|
|
isMonthlyChecked: computed('settings.portalPlans.[]', 'membersUtils.paidMembersEnabled', function () {
|
2022-10-07 16:23:21 +03:00
|
|
|
const allowedPlans = this.settings.portalPlans || [];
|
2022-05-24 17:53:03 +03:00
|
|
|
return (this.membersUtils.paidMembersEnabled && allowedPlans.includes('monthly'));
|
2021-06-04 10:45:49 +03:00
|
|
|
}),
|
2022-05-24 17:53:03 +03:00
|
|
|
isYearlyChecked: computed('settings.portalPlans.[]', 'membersUtils.paidMembersEnabled', function () {
|
2022-10-07 16:23:21 +03:00
|
|
|
const allowedPlans = this.settings.portalPlans || [];
|
2022-05-24 17:53:03 +03:00
|
|
|
return (this.membersUtils.paidMembersEnabled && allowedPlans.includes('yearly'));
|
2021-06-04 10:45:49 +03:00
|
|
|
}),
|
2022-05-11 20:11:54 +03:00
|
|
|
tiers: computed('model.tiers.[]', 'changedTiers.[]', 'isPreloading', function () {
|
|
|
|
const paidTiers = this.model.tiers?.filter(tier => tier.type === 'paid' && tier.active === true);
|
|
|
|
if (this.isPreloading || !paidTiers?.length) {
|
2021-06-21 11:51:48 +03:00
|
|
|
return [];
|
|
|
|
}
|
2022-03-08 10:30:31 +03:00
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
const tiers = paidTiers.map((tier) => {
|
2021-06-21 11:51:48 +03:00
|
|
|
return {
|
2022-05-11 20:11:54 +03:00
|
|
|
id: tier.id,
|
|
|
|
name: tier.name,
|
|
|
|
checked: tier.visibility === 'public'
|
2021-06-21 11:51:48 +03:00
|
|
|
};
|
|
|
|
});
|
2022-05-11 20:11:54 +03:00
|
|
|
return tiers;
|
2021-06-21 11:51:48 +03:00
|
|
|
}),
|
2021-06-04 10:45:49 +03:00
|
|
|
|
2022-05-16 18:25:03 +03:00
|
|
|
showPortalPrices: computed('tiers', function () {
|
2022-05-11 20:11:54 +03:00
|
|
|
const visibleTiers = this.model.tiers?.filter((tier) => {
|
|
|
|
return tier.visibility === 'public' && tier.type === 'paid';
|
2022-03-08 10:30:31 +03:00
|
|
|
});
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
return !!visibleTiers?.length;
|
2021-08-23 09:56:12 +03:00
|
|
|
}),
|
|
|
|
|
2020-06-19 19:06:49 +03:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
2020-07-07 07:22:42 +03:00
|
|
|
this.buttonStyleOptions = [
|
|
|
|
{name: 'icon-and-text', label: 'Icon and text'},
|
|
|
|
{name: 'icon-only', label: 'Icon only'},
|
|
|
|
{name: 'text-only', label: 'Text only'}
|
|
|
|
];
|
2022-04-28 11:24:12 +03:00
|
|
|
this.availablePages = [{
|
|
|
|
name: 'signup',
|
|
|
|
label: 'Signup'
|
|
|
|
}, {
|
|
|
|
name: 'accountHome',
|
|
|
|
label: 'Account'
|
|
|
|
}, {
|
|
|
|
name: 'links',
|
|
|
|
label: 'Links'
|
|
|
|
}];
|
2020-07-07 07:22:42 +03:00
|
|
|
this.iconExtensions = ICON_EXTENSIONS;
|
2022-05-11 20:11:54 +03:00
|
|
|
this.changedTiers = [];
|
2022-10-07 16:23:21 +03:00
|
|
|
this.set('supportAddress', this.parseEmailAddress(this.settings.membersSupportAddress));
|
2022-08-17 12:06:53 +03:00
|
|
|
this.set('openSection', 'signup-options');
|
2020-06-19 19:06:49 +03:00
|
|
|
},
|
|
|
|
|
2020-08-11 09:34:42 +03:00
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.errors.clear();
|
2020-08-11 09:34:42 +03:00
|
|
|
},
|
|
|
|
|
2020-06-19 19:06:49 +03:00
|
|
|
actions: {
|
|
|
|
toggleFreePlan(isChecked) {
|
|
|
|
this.updateAllowedPlan('free', isChecked);
|
|
|
|
},
|
2021-06-04 10:45:49 +03:00
|
|
|
togglePlan(plan, event) {
|
|
|
|
this.updateAllowedPlan(plan, event.target.checked);
|
2021-05-04 18:43:31 +03:00
|
|
|
},
|
2022-05-11 20:11:54 +03:00
|
|
|
toggleTier(tierId, event) {
|
|
|
|
this.updateAllowedTier(tierId, event.target.checked);
|
2021-06-21 11:51:48 +03:00
|
|
|
},
|
2020-07-07 07:22:42 +03:00
|
|
|
togglePortalButton(showButton) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButton = showButton;
|
2020-06-19 19:06:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
togglePortalName(showSignupName) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalName = showSignupName;
|
2020-06-19 19:06:49 +03:00
|
|
|
},
|
2022-04-28 11:24:12 +03:00
|
|
|
toggleSection(section) {
|
|
|
|
if (this.get('openSection') === section) {
|
|
|
|
this.set('openSection', null);
|
|
|
|
} else {
|
|
|
|
this.set('openSection', section);
|
|
|
|
}
|
|
|
|
},
|
2020-06-19 19:06:49 +03:00
|
|
|
|
|
|
|
confirm() {
|
|
|
|
return this.saveTask.perform();
|
|
|
|
},
|
|
|
|
|
|
|
|
isPlanSelected(plan) {
|
2022-10-07 16:23:21 +03:00
|
|
|
const allowedPlans = this.settings.portalPlans;
|
2020-06-19 19:06:49 +03:00
|
|
|
return allowedPlans.includes(plan);
|
2020-06-25 23:45:47 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
switchPreviewPage(page) {
|
2022-04-28 11:24:12 +03:00
|
|
|
if (page.name === 'links') {
|
2020-07-30 16:12:44 +03:00
|
|
|
this.set('showLinksPage', true);
|
|
|
|
this.set('page', '');
|
|
|
|
} else {
|
|
|
|
this.set('showLinksPage', false);
|
2022-04-28 11:24:12 +03:00
|
|
|
this.set('page', page.name);
|
2020-07-30 16:12:44 +03:00
|
|
|
}
|
2020-07-07 07:22:42 +03:00
|
|
|
},
|
|
|
|
|
2020-10-16 16:34:22 +03:00
|
|
|
switchToSignupPage() {
|
|
|
|
if (this.showLinksPage) {
|
|
|
|
this.set('showLinksPage', false);
|
|
|
|
this.set('page', 'signup');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
setButtonStyle(buttonStyle) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButtonStyle = buttonStyle.name;
|
2020-07-07 07:22:42 +03:00
|
|
|
},
|
2022-01-27 14:40:11 +03:00
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
setSignupButtonText(event) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButtonSignupText = event.target.value;
|
2020-07-07 07:22:42 +03:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Fired after an image upload completes
|
|
|
|
* @param {string} property - Property name to be set on `this.settings`
|
|
|
|
* @param {UploadResult[]} results - Array of UploadResult objects
|
|
|
|
* @return {string} The URL that was set on `this.settings.property`
|
|
|
|
*/
|
|
|
|
imageUploaded(property, results) {
|
|
|
|
if (results[0]) {
|
|
|
|
this.set('customIcon', results[0].url);
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButtonIcon = results[0].url;
|
2020-07-07 07:22:42 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Opens a file selection dialog - Triggered by "Upload Image" buttons,
|
|
|
|
* searches for the hidden file input within the .gh-setting element
|
|
|
|
* containing the clicked button then simulates a click
|
|
|
|
* @param {MouseEvent} event - MouseEvent fired by the button click
|
|
|
|
*/
|
|
|
|
triggerFileDialog(event) {
|
2022-05-29 13:18:49 +03:00
|
|
|
event?.target.closest('.gh-setting-action')?.querySelector('input[type="file"]')?.click();
|
2020-07-07 07:22:42 +03:00
|
|
|
},
|
|
|
|
|
2020-08-19 18:00:06 +03:00
|
|
|
deleteCustomIcon() {
|
|
|
|
this.set('customIcon', null);
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButtonIcon = this.membersUtils.defaultIconKeys[0];
|
2020-08-19 18:00:06 +03:00
|
|
|
},
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
selectDefaultIcon(icon) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalButtonIcon = icon;
|
2020-07-30 13:56:07 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
closeLeaveSettingsModal() {
|
|
|
|
this.set('showLeaveSettingsModal', false);
|
|
|
|
},
|
|
|
|
|
2022-05-24 17:53:03 +03:00
|
|
|
openStripeConnect() {
|
2021-05-19 22:24:13 +03:00
|
|
|
this.isWaitingForStripeConnection = true;
|
2022-05-24 17:53:03 +03:00
|
|
|
this.model.openStripeConnect();
|
2020-10-22 13:39:00 +03:00
|
|
|
},
|
|
|
|
|
2020-07-30 13:56:07 +03:00
|
|
|
leaveSettings() {
|
|
|
|
this.closeModal();
|
2020-11-23 12:38:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
validateFreeSignupRedirect() {
|
2022-01-21 22:25:47 +03:00
|
|
|
return this._validateSignupRedirect(this.freeSignupRedirect, 'membersFreeSignupRedirect');
|
2020-11-23 12:38:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
validatePaidSignupRedirect() {
|
2022-01-21 22:25:47 +03:00
|
|
|
return this._validateSignupRedirect(this.paidSignupRedirect, 'membersPaidSignupRedirect');
|
2022-01-27 14:40:11 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
setSupportAddress(supportAddress) {
|
|
|
|
this.set('supportAddress', supportAddress);
|
2022-07-15 15:44:26 +03:00
|
|
|
|
|
|
|
if (this.config.emailDomain && supportAddress === `noreply@${this.config.emailDomain}`) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.membersSupportAddress = 'noreply';
|
2022-07-15 15:44:26 +03:00
|
|
|
} else {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.membersSupportAddress = supportAddress;
|
2022-07-15 15:44:26 +03:00
|
|
|
}
|
2022-01-27 14:40:11 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
parseEmailAddress(address) {
|
|
|
|
const emailAddress = address || 'noreply';
|
|
|
|
// Adds default domain as site domain
|
|
|
|
if (emailAddress.indexOf('@') < 0 && this.config.emailDomain) {
|
|
|
|
return `${emailAddress}@${this.config.emailDomain}`;
|
2020-06-19 19:06:49 +03:00
|
|
|
}
|
2022-01-27 14:40:11 +03:00
|
|
|
return emailAddress;
|
2020-06-19 19:06:49 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
updateAllowedPlan(plan, isChecked) {
|
2022-10-07 16:23:21 +03:00
|
|
|
const portalPlans = this.settings.portalPlans || [];
|
2021-04-27 20:03:13 +03:00
|
|
|
const allowedPlans = [...portalPlans];
|
2022-05-11 20:11:54 +03:00
|
|
|
const freeTier = this.model.tiers.find(p => p.type === 'free');
|
2020-06-19 19:06:49 +03:00
|
|
|
|
|
|
|
if (!isChecked) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalPlans = allowedPlans.filter(p => p !== plan);
|
2022-03-08 10:30:31 +03:00
|
|
|
if (plan === 'free') {
|
2022-05-11 20:11:54 +03:00
|
|
|
freeTier.set('visibility', 'none');
|
2022-03-08 10:30:31 +03:00
|
|
|
}
|
2020-06-19 19:06:49 +03:00
|
|
|
} else {
|
|
|
|
allowedPlans.push(plan);
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.portalPlans = allowedPlans;
|
2022-03-08 10:30:31 +03:00
|
|
|
if (plan === 'free') {
|
2022-05-11 20:11:54 +03:00
|
|
|
freeTier.set('visibility', 'public');
|
2022-03-08 10:30:31 +03:00
|
|
|
}
|
2020-06-19 19:06:49 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-05-11 20:11:54 +03:00
|
|
|
updateAllowedTier(tierId, isChecked) {
|
|
|
|
const tier = this.model.tiers.find(p => p.id === tierId);
|
2021-06-21 11:51:48 +03:00
|
|
|
if (!isChecked) {
|
2022-05-11 20:11:54 +03:00
|
|
|
tier.set('visibility', 'none');
|
2021-06-21 11:51:48 +03:00
|
|
|
} else {
|
2022-05-11 20:11:54 +03:00
|
|
|
tier.set('visibility', 'public');
|
2021-06-21 11:51:48 +03:00
|
|
|
}
|
2022-05-11 20:11:54 +03:00
|
|
|
let portalTiers = this.model.tiers.filter((p) => {
|
2022-03-08 10:30:31 +03:00
|
|
|
return p.visibility === 'public';
|
|
|
|
}).map(p => p.id);
|
2022-05-11 20:11:54 +03:00
|
|
|
this.set('changedTiers', portalTiers);
|
2021-06-21 11:51:48 +03:00
|
|
|
},
|
|
|
|
|
2020-11-20 12:53:08 +03:00
|
|
|
_validateSignupRedirect(url, type) {
|
2020-11-23 12:38:29 +03:00
|
|
|
let errMessage = `Please enter a valid URL`;
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.errors.remove(type);
|
|
|
|
this.settings.hasValidated.removeObject(type);
|
2020-11-20 12:53:08 +03:00
|
|
|
|
2020-11-23 12:38:29 +03:00
|
|
|
if (url === null) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.errors.add(type, errMessage);
|
|
|
|
this.settings.hasValidated.pushObject(type);
|
2020-11-23 12:38:29 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url === undefined) {
|
|
|
|
// Not initialised
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-20 12:53:08 +03:00
|
|
|
if (url.href.startsWith(this.siteUrl)) {
|
|
|
|
const path = url.href.replace(this.siteUrl, '');
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings[type] = path;
|
2020-11-23 12:38:29 +03:00
|
|
|
} else {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings[type] = url.href;
|
2020-11-20 12:53:08 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-05-19 17:36:46 +03:00
|
|
|
finishPreloading: action(async function () {
|
|
|
|
if (this.model.preloadTask?.isRunning) {
|
|
|
|
await this.model.preloadTask;
|
|
|
|
}
|
|
|
|
|
2022-10-07 16:23:21 +03:00
|
|
|
const portalButtonIcon = this.settings.portalButtonIcon || '';
|
2021-05-19 17:36:46 +03:00
|
|
|
if (portalButtonIcon && !this.membersUtils.defaultIconKeys.includes(portalButtonIcon)) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.set('customIcon', this.settings.portalButtonIcon);
|
2021-05-19 17:36:46 +03:00
|
|
|
}
|
|
|
|
|
2022-10-07 17:24:03 +03:00
|
|
|
this.siteUrl = this.config.blogUrl;
|
2021-05-19 17:36:46 +03:00
|
|
|
this.set('isPreloading', false);
|
|
|
|
}),
|
|
|
|
|
2021-05-19 22:24:13 +03:00
|
|
|
refreshAfterStripeConnected: action(async function () {
|
|
|
|
if (this.isWaitingForStripeConnection) {
|
|
|
|
await this.finishPreloading();
|
|
|
|
this.notifyPropertyChange('page'); // force preview url to recompute
|
|
|
|
this.set('portalPreviewGuid', Date.now().valueOf()); // force preview re-render
|
|
|
|
this.isWaitingForStripeConnection = false;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
2020-07-07 07:22:42 +03:00
|
|
|
copyLinkOrAttribute: task(function* () {
|
|
|
|
copyTextToClipboard(this.showModalLinkOrAttribute);
|
|
|
|
yield timeout(this.isTesting ? 50 : 3000);
|
|
|
|
}),
|
|
|
|
|
2020-06-19 19:06:49 +03:00
|
|
|
saveTask: task(function* () {
|
2020-11-23 12:38:29 +03:00
|
|
|
this.send('validateFreeSignupRedirect');
|
|
|
|
this.send('validatePaidSignupRedirect');
|
2022-07-15 15:44:26 +03:00
|
|
|
|
|
|
|
this.settings.errors.remove('members_support_address');
|
|
|
|
this.settings.hasValidated.removeObject('members_support_address');
|
|
|
|
|
2022-10-07 16:23:21 +03:00
|
|
|
if (this.settings.errors.length !== 0) {
|
2020-11-23 12:38:29 +03:00
|
|
|
return;
|
|
|
|
}
|
2022-03-08 10:30:31 +03:00
|
|
|
|
|
|
|
// Save tier visibility if changed
|
|
|
|
yield Promise.all(
|
2022-05-11 20:11:54 +03:00
|
|
|
this.model.tiers.filter((tier) => {
|
|
|
|
const changedAttrs = tier.changedAttributes();
|
2022-03-08 10:30:31 +03:00
|
|
|
return !!changedAttrs.visibility;
|
2022-05-11 20:11:54 +03:00
|
|
|
}).map((tier) => {
|
|
|
|
return tier.save();
|
2022-03-08 10:30:31 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2022-10-07 16:23:21 +03:00
|
|
|
const newEmail = this.settings.membersSupportAddress;
|
2022-03-08 10:30:31 +03:00
|
|
|
|
2022-01-27 14:40:11 +03:00
|
|
|
try {
|
2022-07-15 15:44:26 +03:00
|
|
|
const result = yield this.settings.save();
|
|
|
|
if (result._meta?.sent_email_verification) {
|
|
|
|
yield this.modals.open(ConfirmEmailModal, {
|
|
|
|
newEmail,
|
2022-10-07 16:23:21 +03:00
|
|
|
currentEmail: this.settings.membersSupportAddress
|
2022-07-15 15:44:26 +03:00
|
|
|
});
|
|
|
|
}
|
2022-05-24 19:56:12 +03:00
|
|
|
|
2022-07-15 15:44:26 +03:00
|
|
|
this.closeModal();
|
|
|
|
} catch (error) {
|
|
|
|
// Do we have an error that we can show inline?
|
|
|
|
if (error.payload && error.payload.errors) {
|
|
|
|
for (const payloadError of error.payload.errors) {
|
|
|
|
if (payloadError.type === 'ValidationError' && payloadError.property && (payloadError.context || payloadError.message)) {
|
|
|
|
// Context has a better error message for validation errors
|
|
|
|
this.settings.errors.add(payloadError.property, payloadError.context || payloadError.message);
|
|
|
|
this.settings.hasValidated.pushObject(payloadError.property);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw error;
|
2022-01-27 14:40:11 +03:00
|
|
|
}
|
2020-06-19 19:06:49 +03:00
|
|
|
}).drop()
|
|
|
|
});
|