Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

People: Accept invite by email subscription only #1190

Merged
merged 2 commits into from
Dec 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that if we moved to using GET parameters, the heavy lifting would be done here. In this method we would get the GET parameters above (See what I did there 😛 👓 ) and then we would do the page.replace() or similar.

The only other change I think we would need is updating the route in my-sites/invites/index.js to be '/accept-invite/:site_id/:invitation_key.

),
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice change :)

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

footerLink() {
subscribeUserByEmailOnly() {
this.setState( { submitting: true } );
acceptInvite(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change what acceptInvite receives to a single object with multiple keys, what do you think?

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to send the user to subscribe.wordpress.com if we're using the API to accept the invite? I think we should be sending follows to the front-end of the site.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea! I was just mimicking the current flow.

}
}
);
},

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.' ) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both links should be in the same translation string in order to give Translators some context. "Or" could be tricky to place/translate.

</a>
{ this.renderEmailOnlySubscriptionLink() }
</div>
);
},

renderEmailOnlySubscriptionLink() {
if ( this.props.invite.meta.role !== 'follower' || ! this.props.invite.activationKey ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance, I thought this could prevent a potential issue with viewers on private WPCOM sites since viewers are also labeled as followers in the code.

But, since we control the invitation email, and since we don't need an activation key for viewers, I don't anticipate this being an issue.

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