diff --git a/ghost/portal/src/components/pages/OfferPage.js b/ghost/portal/src/components/pages/OfferPage.js index e84ee0808a..50f13a8ffa 100644 --- a/ghost/portal/src/components/pages/OfferPage.js +++ b/ghost/portal/src/components/pages/OfferPage.js @@ -146,7 +146,18 @@ export default class OfferPage extends React.Component { name: context?.member?.name || '', email: context?.member?.email || '', plan: 'free', - showNewsletterSelection: false + showNewsletterSelection: false, + termsCheckboxChecked: false + }; + } + + getFormErrors(state) { + const checkboxRequired = this.context.site.portal_signup_checkbox_required; + const checkboxError = checkboxRequired && !state.termsCheckboxChecked; + + return { + ...ValidateInputForm({fields: this.getInputFields({state})}), + checkbox: checkboxError }; } @@ -198,6 +209,55 @@ export default class OfferPage extends React.Component { return fields; } + renderSignupTerms() { + const {site} = this.context; + if (site.portal_signup_terms_html === null || site.portal_signup_terms_html === '') { + return null; + } + + const handleCheckboxChange = (e) => { + this.setState({ + termsCheckboxChecked: e.target.checked + }); + }; + + const termsText = ( +
+ ); + + const signupTerms = site.portal_signup_checkbox_required ? ( + + ) : termsText; + + const errorClassName = this.state.errors?.checkbox ? 'gh-portal-error' : ''; + + const className = `gh-portal-signup-terms ${errorClassName}`; + + const interceptAnchorClicks = (e) => { + if (e.target.tagName === 'A') { + e.preventDefault(); + window.open(e.target.href, '_blank'); + } + }; + + return ( +
+ {signupTerms} +
+ ); + } + onKeyDown(e) { // Handles submit on Enter press if (e.keyCode === 13){ @@ -215,7 +275,7 @@ export default class OfferPage extends React.Component { const price = offer.cadence === 'month' ? product.monthlyPrice : product.yearlyPrice; this.setState((state) => { return { - errors: ValidateInputForm({fields: this.getInputFields({state})}) + errors: this.getFormErrors(state) }; }, () => { const {onAction} = this.context; @@ -301,6 +361,9 @@ export default class OfferPage extends React.Component { onChange={(e, field) => this.handleInputChange(e, field)} onKeyDown={e => this.onKeyDown(e)} /> +
+ {this.renderSignupTerms()} +
);