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

Account creation (issue #250) #293

Merged
merged 68 commits into from
Oct 3, 2018
Merged

Account creation (issue #250) #293

merged 68 commits into from
Oct 3, 2018

Conversation

JStein92
Copy link
Contributor

@JStein92 JStein92 commented Sep 20, 2018

This PR is a:

[x] New feature
[ ] Enhancement/Optimization
[ ] Refactor
[ ] Bugfix
[ ] Test for existing code
[ ] Documentation

Summary

This pull request is an extension to PR #281 - login feature.

Addresses issue #250

When this pull request is merged, in addition to the changes of #281, it will enable users to create accounts through Magento's REST api.

New components

  • CreateAccount
  • Checkbox
  • Form

create_account_gif

Additional information

  • User is automatically logged in after creating an account through getUserDetails() in the root index.js

  • signin_token expires after some time but stays in local storage, so it's possible to receive a 401 Unauthorized when the root index.js tries to get user details with an expired token. Automatic token refresh should be addressed in the future.

  • Guest cart is merged into newly created account, but the carts will not show up because getCartDetails still only looks for guest cart ids. Changing this seemed out of scope for this issue so we left it as is.

  • Style changes for Input component to better match Invision designs.

  • Automatic email availability check with debounce using Magento isEmailAvailable endpoint.

JStein92 and others added 30 commits September 7, 2018 07:28
- Style form to match mockup
- Fix misimport of user reducer
- Rename log in to sign in to match mockups
- Style error messages in sign in form
- Transferring cart to a newly created customer account created an
issue where a guest cart could not be made. getCartDetails now checks if
a user is signed in.
Copy link
Contributor

@zetlen zetlen left a comment

Choose a reason for hiding this comment

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

This is an excellent addition and I'm excited to see it merged. I have a few comments, a couple suggestions, and a couple necessary changes. Please let me know what you think.

It also may require a significant back-merge, but that's just where we are at right now. I'll try to conduct the merge for you--since you have lots of tests, it should be easy to detect regressions.

@@ -7,7 +7,7 @@
"main": "src/index.js",
"repository": "github:magento-research/pwa-studio",
"bugs": {
"url": "https://github.com/magento-research/pwa-studio/issues"
"url": "https://github.com/magento-research/pwa-studio/issues"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are your editors doing four-space indentation on package.json files? If so, our prettier should be catching this. Whoopsie!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Our editors are set to follow the editor config - not sure why it wasn't caught in the prettier. Thanks!

const [dispatch, getState] = args;
const { user } = getState();
if (user.isSignedIn) {
///////////////////////////////////////////
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good default behavior for now, but could you please add a "TODO: handle logged-in cart retrieval" to this comment? The comment is already helpful, but the string TODO is searchable and helps us find tech debt in the future.

@@ -0,0 +1,121 @@
import { RestApi } from '@magento/peregrine';
import BrowserPersistence from 'src/util/simplePersistence.js';
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're using localStorage in Peregrine and the BrowserPersistence abstraction here (that later might use Cache or IndexedDB or ServiceWorker or whatever), maybe it's time to move BrowserPersistence to Peregrine and pull it from there!

Feel like you could do that quickly with this PR, or should we save that for an upcoming PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! We're exporting it the same way as RestAPI is exported from Peregrine. 👍

};

function setToken(token) {
localStorage.setItem('signin_token', token);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're using a BrowserPersistence instance above, maybe use it here.

return this.state.password !== this.state.passwordConfirm;
}

get disableAccountCreation() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I did a double take on these method names. hasEmailError is great, because the wording of the method name says it's a pure method that checks state and returns a boolean. But passwordConfirmError doesn't follow that convention; seems like it should be called hasPasswordConfirmError.

Same with disableAccountCreation. It might be better called isIncompleteOrInvalid.

<Input
onChange={this.updateUsername}
helpText={'example help text'}
label={'Username or Email'}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: If the user has filled out this field and then clicks "Create Account" instead, it should copy this value into the CreateAccount counterpart field.

});

const authLink = setContext((_, { headers }) => {
// get the authentication token from local storage if it exists
Copy link
Contributor

Choose a reason for hiding this comment

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

Here's another place where you would want to use a BrowserPersistence instance.


const apolloClient = new ApolloClient();
const apolloClient = new ApolloClient({
link: authLink.concat(httpLink),
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent job using Apollo Client exactly as intended.

@@ -0,0 +1,73 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this and all other mocks/fixtures into a tests subfolder like fixtures. Add to the Jest exclude pattern if you have to.

"created_at": "2018-09-13T18:26:34.662Z",
"updated_at": "2018-09-13T18:26:34.662Z",
"created_in": "string",
"dob": "1/1/2010",
Copy link
Contributor

Choose a reason for hiding this comment

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

Your customer created their account when they were eight years old. Adorable!

@zetlen zetlen changed the base branch from release/1.0 to release/2.0 September 26, 2018 21:05
@zetlen zetlen added the enhancement New feature or request label Sep 27, 2018
@JStein92
Copy link
Contributor Author

JStein92 commented Oct 3, 2018

@zetlen Ok, this pull request has been updated to meet the release/2.0 standards. : ) Also now includes tests (just basic coverage) for user actions/asyncActions.

That was quite a merge!

@zetlen
Copy link
Contributor

zetlen commented Oct 3, 2018

It sure was, @JStein92 . It sure was. Thank you so, so much. I guess this closes #250 now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants