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 ( +