0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Wired welcome page UI to settings API

refs https://github.com/TryGhost/Team/issues/611

The UI for welcome page for paid signups is moved from Portal settings to Product page, this change wires up the new UI to the settings API as in Portal settings to function correctly
This commit is contained in:
Rishabh 2021-05-06 22:27:52 +05:30
parent f4a4ef52fd
commit 6bdc1c85e0
2 changed files with 57 additions and 2 deletions

View file

@ -6,11 +6,18 @@ import {tracked} from '@glimmer/tracking';
export default class ProductController extends Controller {
@service settings;
@service config;
@tracked showLeaveSettingsModal = false;
@tracked showPriceModal = false;
@tracked priceModel = null;
@tracked showUnsavedChangesModal = false;
@tracked paidSignupRedirect;
constructor() {
super(...arguments);
this.siteUrl = this.config.get('blogUrl');
}
get product() {
return this.model;
@ -111,8 +118,47 @@ export default class ProductController extends Controller {
this.showPriceModal = false;
}
@action
setPaidSignupRedirect(url) {
this.paidSignupRedirect = url;
}
@action
validatePaidSignupRedirect() {
return this._validateSignupRedirect(this.paidSignupRedirect, 'membersPaidSignupRedirect');
}
@task({drop: true})
*saveTask() {
this.send('validatePaidSignupRedirect');
if (this.settings.get('errors').length !== 0) {
return;
}
yield this.settings.save();
return yield this.product.save();
}
_validateSignupRedirect(url, type) {
let errMessage = `Please enter a valid URL`;
this.settings.get('errors').remove(type);
this.settings.get('hasValidated').removeObject(type);
if (url === null) {
this.settings.get('errors').add(type, errMessage);
this.settings.get('hasValidated').pushObject(type);
return false;
}
if (url === undefined) {
// Not initialised
return;
}
if (url.href.startsWith(this.siteUrl)) {
const path = url.href.replace(this.siteUrl, '');
this.settings.set(type, path);
} else {
this.settings.set(type, url.href);
}
}
}

View file

@ -43,9 +43,18 @@
<GhFormGroup @property="_welcome-page" @classNames="max-width">
<label for="_welcome-page">Welcome page</label>
<GhTextInput data-test-input="_welcome-page" @value="" />
<GhUrlInput
@value={{readonly this.settings.membersPaidSignupRedirect}}
@baseUrl={{readonly this.siteUrl}}
@setResult={{action "setPaidSignupRedirect"}}
@validateUrl={{action "validatePaidSignupRedirect"}}
@placeholder={{readonly this.siteUrl}}
/>
<p>Redirect to this URL after signup for this product</p>
<GhErrorMessage @property="_welcome-page" />
<GhErrorMessage
@errors={{settings.errors}}
@property="membersPaidSignupRedirect"
/>
</GhFormGroup>
</div>
</div>