Skip to content

Commit

Permalink
Merge pull request #1190 from Automattic/accept-invite-email-only
Browse files Browse the repository at this point in the history
People: Accept invite by email subscription only
  • Loading branch information
roccotripaldi committed Dec 3, 2015
2 parents eec5860 + 0b1b8d6 commit a7c39bd
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/components/signup-form/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export default React.createClass( {
<div>
{ this.getNotice() }
{ this.termsOfServiceLink() }
<FormButton className="signup-form__submit">
<FormButton className="signup-form__submit" disabled={ this.state.submitting || this.props.disabled }>
{ this.props.submitButtonText }
</FormButton>
</div>
Expand Down
3 changes: 1 addition & 2 deletions client/lib/invites/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ export function acceptInvite( invite, callback, bearerToken ) {
wpcom.loadToken( bearerToken );
}
return wpcom.undocumented().acceptInvite(
invite.blog_id,
invite.invite_slug,
invite,
callback
);
}
Expand Down
5 changes: 4 additions & 1 deletion client/my-sites/invites/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export function acceptInvite( context ) {
context.layout.setState( { noSidebar: true } );

React.render(
React.createElement( InviteAccept, context.params ),
React.createElement(
InviteAccept,
context.params
),
document.getElementById( 'primary' )
);
}
5 changes: 5 additions & 0 deletions client/my-sites/invites/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ export default () => {
'/accept-invite/:site_id/:invitation_key',
acceptInvite
);

page(
'/accept-invite/:site_id/:invitation_key/:activation_key/:auth_key',
acceptInvite
);
};
41 changes: 35 additions & 6 deletions client/my-sites/invites/invite-accept-logged-out/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default React.createClass( {
);
},

getFormHeader() {
renderFormHeader() {
return (
<InviteFormHeader { ...this.props } />
);
Expand All @@ -60,11 +60,40 @@ export default React.createClass( {
)
},

footerLink() {
subscribeUserByEmailOnly() {
this.setState( { submitting: true } );
acceptInvite(
this.props.invite,
( error ) => {
if ( error ) {
this.setState( { error } );
} else {
window.location = 'https://subscribe.wordpress.com?update=activate&email=' + encodeURIComponent( this.props.invite.meta.sent_to ) + '&key=' + this.props.invite.authKey;
}
}
);
},

renderFooterLink() {
let logInUrl = config( 'login_url' ) + '?redirect_to=' + encodeURIComponent( window.location.href );
return (
<a href={ logInUrl } className="logged-out-form__link">
{ this.translate( 'Already have a WordPress.com account? Log in now.' ) }
<div>
<a href={ logInUrl } className="logged-out-form__link">
{ this.translate( 'Already have a WordPress.com account? Log in now.' ) }
</a>
{ this.renderEmailOnlySubscriptionLink() }
</div>
);
},

renderEmailOnlySubscriptionLink() {
if ( this.props.invite.meta.role !== 'follower' || ! this.props.invite.activationKey ) {
return null;
}

return (
<a onClick={ this.subscribeUserByEmailOnly } className="logged-out-form__link">
{ this.translate( 'Follow by email subscription only.' ) }
</a>
);
},
Expand All @@ -75,12 +104,12 @@ export default React.createClass( {
<SignupForm
getRedirectToAfterLoginUrl={ this.getRedirectToAfterLoginUrl }
disabled={ this.state.submitting }
formHeader={ this.getFormHeader() }
formHeader={ this.renderFormHeader() }
submitting={ this.state.submitting }
save={ this.save }
submitForm={ this.submitForm }
submitButtonText={ this.submitButtonText() }
footerLink={ this.footerLink() }
footerLink={ this.renderFooterLink() }
email={ get( this.props, 'invite.meta.sent_to' ) }
/>
{ this.state.userData && this.loginUser() }
Expand Down
8 changes: 8 additions & 0 deletions client/my-sites/invites/invite-accept/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export default React.createClass( {
refreshInvite() {
const invite = InvitesStore.getInvite( this.props.site_id, this.props.invitation_key );
const error = InvitesStore.getInviteError( this.props.site_id, this.props.invitation_key );

if ( invite ) {
// add subscription-related keys to the invite
Object.assign( invite.invite, {
activationKey: this.props.activation_key,
authKey: this.props.auth_key
} );
}
this.setState( { invite, error } );
},

Expand Down
2 changes: 2 additions & 0 deletions client/signup/logged-out-form/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
display: block;
font-size: 12px;
text-align: center;
margin-bottom: 8px;
cursor: pointer;
}
6 changes: 4 additions & 2 deletions shared/lib/wpcom-undocumented/lib/undocumented.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,11 @@ Undocumented.prototype.getInvite = function( siteId, inviteKey, fn ) {
this.wpcom.req.get( { path: '/sites/' + siteId + '/invites/' + inviteKey }, fn );
};

Undocumented.prototype.acceptInvite = function( siteId, inviteKey, fn ) {
Undocumented.prototype.acceptInvite = function( invite, fn ) {
debug( '/sites/:site_id:/invites/:inviteKey:/accept query' );
this.wpcom.req.get( '/sites/' + siteId + '/invites/' + inviteKey + '/accept', fn );
this.wpcom.req.get( '/sites/' + invite.blog_id + '/invites/' + invite.invite_slug + '/accept', {
activate: invite.activationKey
}, fn );
};

/**
Expand Down

0 comments on commit a7c39bd

Please sign in to comment.