2021-05-04 18:50:05 +03:00
|
|
|
import ModalBase from 'ghost-admin/components/modal-base';
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
import {action} from '@ember/object';
|
2021-05-07 20:16:35 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2022-02-09 13:49:38 +03:00
|
|
|
import {task} from 'ember-concurrency';
|
2021-05-07 20:16:35 +03:00
|
|
|
import {tracked} from '@glimmer/tracking';
|
2021-05-04 18:50:05 +03:00
|
|
|
|
|
|
|
// TODO: update modals to work fully with Glimmer components
|
|
|
|
@classic
|
|
|
|
export default class ModalFreeMembershipSettings extends ModalBase {
|
2021-05-07 20:16:35 +03:00
|
|
|
@service settings;
|
|
|
|
@service config;
|
|
|
|
|
|
|
|
@tracked freeSignupRedirect;
|
|
|
|
@tracked siteUrl;
|
2021-05-04 18:50:05 +03:00
|
|
|
init() {
|
|
|
|
super.init(...arguments);
|
2022-10-07 17:24:03 +03:00
|
|
|
this.siteUrl = this.config.blogUrl;
|
2021-05-04 18:50:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
close(event) {
|
|
|
|
event?.preventDefault?.();
|
|
|
|
this.closeModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
// needed because ModalBase uses .send() for keyboard events
|
|
|
|
closeModal() {
|
|
|
|
this.close();
|
2021-05-07 20:16:35 +03:00
|
|
|
},
|
|
|
|
updateName(value) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.membersFreePriceName = value;
|
2021-05-07 20:16:35 +03:00
|
|
|
},
|
|
|
|
updateDescription(value) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.membersFreePriceDescription = value;
|
2021-05-07 20:16:35 +03:00
|
|
|
},
|
|
|
|
setFreeSignupRedirect(url) {
|
|
|
|
this.freeSignupRedirect = url;
|
|
|
|
},
|
|
|
|
validateFreeSignupRedirect() {
|
|
|
|
return this._validateSignupRedirect(this.freeSignupRedirect, 'membersFreeSignupRedirect');
|
|
|
|
}
|
2022-02-10 13:41:36 +03:00
|
|
|
};
|
2021-05-07 20:16:35 +03:00
|
|
|
|
|
|
|
@task({drop: true})
|
|
|
|
*save() {
|
|
|
|
try {
|
|
|
|
this.send('validateFreeSignupRedirect');
|
2022-10-07 16:23:21 +03:00
|
|
|
if (this.settings.errors.length !== 0) {
|
2021-05-07 20:16:35 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
yield this.settings.save();
|
|
|
|
this.send('closeModal');
|
|
|
|
} catch (error) {
|
|
|
|
this.notifications.showAPIError(error, {key: 'settings.save'});
|
|
|
|
} finally {
|
|
|
|
this.send('closeModal');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_validateSignupRedirect(url, type) {
|
|
|
|
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);
|
2021-05-07 20:16:35 +03:00
|
|
|
|
|
|
|
if (url === null) {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.errors.add(type, errMessage);
|
|
|
|
this.settings.hasValidated.pushObject(type);
|
2021-05-07 20:16:35 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (url === undefined) {
|
|
|
|
// Not initialised
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-05-07 20:16:35 +03:00
|
|
|
} else {
|
2022-10-07 16:23:21 +03:00
|
|
|
this.settings.type = url.href;
|
2021-05-04 18:50:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|