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

CIF-1398 - [My Account] Address book management #353

Merged
merged 99 commits into from
Aug 3, 2020
Merged

Conversation

nettree
Copy link
Contributor

@nettree nettree commented Jul 29, 2020

This PR is to add the feature of address book management for the signed in user

Description

  • User can see the saved address by accessing the address book page

  • User can create a new address, edit and delete an existing address

  • User can set an address to their default address(shipping and billing at the moment)

Related Issue

#327

Motivation and Context

This is to enhance the feature set of the user account so that the user can manage their shipping and billing addresses when they've signed in.

How Has This Been Tested?

All the changes made have jest tests covered, features are tested in the browser, including create, edit, delete the address, and set the default address

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

Zhi Wang and others added 30 commits June 24, 2020 17:44
* Add a new component `account` to header, it provides a container div for its react component

* Add new `<Account>` component to main React app `react-components.js`, it renders `<AccountTrigger>` component to toggle the `<AccountDropdown>` component, two components `<SignOutLink>` and `<SignInForm>` are created for reusable purpose

* Add a new reducer to toggle open state of account dropdown
* Refactor `<SignIn>` and `<MyAccount>` components to use `<SignOutLink>` and `<SignInForm>` created for account dropdown, remove the duplicate CSS as they are existing in CSS file of `<SignInForm>`
* Fix a bug found in `<AccountLink>` component, the issue was that the `identity-obj-proxy` module used by `jest` during the test running will mock `classes` imported to `<AccountLink>`, this breaks the rendering of the `<Button>` component because it doesn't expect `classes` to be mocked, instead, it should be an imported CSS modules, so we assign imported CSS modules to an object `classes`, now the mock won't happen so the test can run correctly

* Add or update test files for `<AccountLink>`, `<MyAccount>`, `<SignOutLink>`, `<SignIn>`, and `<SignInForm>`, add generated or updated snapshots files for them as well
* Add a new component `<AccountIconText>` to display the sign in text if the user is not signed in, or display greeting text if the user has signed in, this component will be displayed next to the account icon on header of storefront

* Add corresponding translations in `account.json` i18n file
* Fix the prettier issue for `accountIconText.css`
* Add 'package-info.java' to change the version to '2.0.0' as suggested by Java baseline plugin during the mvn build
* Now we can use account dropdown to reset password and create a new account
* Add 'Address Book' and 'Address Information' to dropdown, at the moment, they're dummy links, the implementations will be added in other ticket
* Add new behaviour, now after user signs in, the account dropdown will be hidden, same behaviour is applied after user signs out
* Refactor code so that components and hooks can be reused for account dropdown
* Add tests to verify the components are rendered as expected
…e '<AccountIconText>' component (#303)

* Changes the references of account component in other files

* Merge logic of '<AccountIconText>' to '<AccountContainer>', now '<AccountTrigger>' will render icon label based on 'label' property passed in

* Update test and snapshots of '<AccountContainer>' component
* Remove '<MyAccountLinks>' and '<SignOutLink>' components and move their logic back to '<MyAccount>' component because now we will reuse '<MyAccount>' in account dropdown

* Add translation string for cancel button of change password form

* Add links of address book and account information to my account so that side panel now will have them available to
* Add a new form title

* Move forgot password button to underneath the password field

* Change label of email input field

* Delete '<SignInForm>' component and merge its logic back into '<SignIn>' as now we are going to reuse it in account drop down and side panel

* Update test and snapshots
…oing to use miniaccount component to render the mount point for account dropdown
…reate one React portal in '<AccountContainer>' component, rather than create two React portals in '<AccountDropdown>' and '<AccountTrigger>' respectively (#303)
…to the folder of 'AccountContainer', update the import paths in '<AccountContainer>', this change allows us to group the account dropdown related components in same place (#303)
…ere is sign-in error (#302)

* Now we only dispatch 'toggleAccountDropdown' action when the sign-in is successful
* Test if handler function of click event is called when button is clicked
* Remove mock of 'ReactDOM.createPortal' from test suits of account dropdown and account trigger as this method is not used by these two components any more
* Add a new state 'accountContainerQuerySelector' in '<UserContextProvider>' to specify the DOM query selector that should be used to find the account container on header

* Add a new state 'authBarContainerQuerySelector' in '<NavigationContextProvider>' to specify the DOM query selector that should be used to find the auth bar container on navigation side panel
@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #353 into master will increase coverage by 17.85%.
The diff coverage is 93.90%.

Impacted file tree graph

@@              Coverage Diff              @@
##             master     #353       +/-   ##
=============================================
+ Coverage     66.67%   84.52%   +17.85%     
  Complexity      852      852               
=============================================
  Files           192      174       -18     
  Lines          5845     4400     -1445     
  Branches        912      587      -325     
=============================================
- Hits           3897     3719      -178     
+ Misses         1822      555     -1267     
  Partials        126      126               
Flag Coverage Δ Complexity Δ
#integration 66.86% <ø> (ø) 628.00 <ø> (ø)
#jest 77.36% <93.90%> (+31.65%) 0.00 <0.00> (ø)
#karma 93.93% <ø> (ø) 0.00 <ø> (ø)
#unittests 85.81% <ø> (ø) 821.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...src/components/AccountContainer/accountDropdown.js 95.83% <ø> (+3.83%) 0.00 <0.00> (ø)
react-components/src/context/NavigationContext.js 92.00% <66.66%> (-1.62%) 0.00 <0.00> (ø)
react-components/src/context/UserContext.js 90.59% <81.81%> (+9.51%) 0.00 <0.00> (ø)
...nents/src/components/AddressBook/useAddressForm.js 96.77% <96.77%> (ø) 0.00 <0.00> (?)
react-components/src/actions/user/actions.js 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
...nts/src/components/AddressBook/addAddressButton.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...mponents/src/components/AddressBook/addressBook.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...s/src/components/AddressBook/addressDeleteModal.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...src/components/AddressBook/addressFormContainer.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...mponents/src/components/AddressBook/addressItem.js 100.00% <100.00%> (ø) 0.00 <0.00> (?)
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90920d2...a3b2edf. Read the comment docs.

@dplaton dplaton marked this pull request as ready for review July 29, 2020 14:16
@@ -72,6 +75,10 @@ const NavigationContextProvider = props => {

const showAccountCreated = () => NavigationActions.showAccountCreated({ dispatch, t });

const showAddressBook = () => {
window.location.href = navigationState.addressBookPath;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we rather use history.push here? See https://reactrouter.com/web/api/Hooks/usehistory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently, the react-router-dom is only installed in venia repo not in core components repo, are you happy with how the router is used in venia repo? I tested in my local, it seems that browser controls history works as well, but I will have a look for sure, thank you @herzog31 :)

Copy link
Contributor

Choose a reason for hiding this comment

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

We can install react-router-dom in aem-core-cif-components, but we have to put it as peerDependency. But as long as the feature works without it...

Copy link
Member

Choose a reason for hiding this comment

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

Browser history should work with window.location.href, just wondering if it has any side effects in terms of navigating within React. Probably only works for navigating between actual AEM pages.

Copy link
Contributor Author

@nettree nettree Aug 3, 2020

Choose a reason for hiding this comment

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

Hi @herzog31, I tried to use useHistory and then history.push, but since we don't have React router context introduced in core components repo yet, it doesn't seem working at the moment, so are you happy for leaving this logic as is at the moment or do you have other thoughts on this? :)

Copy link
Member

Choose a reason for hiding this comment

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

If React navigation works with it, let's keep it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that @herzog31 :)

@dplaton
Copy link
Contributor

dplaton commented Jul 30, 2020

@nettree I quickly check the feature and run into some bugs:

  1. You can create several "default" addresses. There should be only one default address
  2. When you edit an address the e-mail field is empty.

@nettree
Copy link
Contributor Author

nettree commented Jul 31, 2020

Hi @dplaton, this is something I'd like to discuss with you, it seems like the endpoints don't accept email as one of the address field, in this case, shall we hide the email field from the address form for address book? I've added the logic to hide the email field by default in address form and display it for address form used in checkout now. :)

The issue for the default address has been fixed, it's because the state is not updated properly when there is another address set as default address, but the actual change is applied to BE, when refreshing the page we can only see one default address, I've added the logic to reset corresponding fields when it's necessary to fix that

Zhi Wang added 3 commits July 31, 2020 10:47
… the related tests

* When an address is created or updated, the GraphQL endpoints won't accept email as a valid field thus won't save it, so we will hide email input field from address form used in address book now

* Explicitly show email input field in address form used in checkout to keep the existing feature working as expected

* Update the tests to reflect this changes

* Add one test suite to increase the test coverage rate for addressForm.js
…fault address, the previous default address still has the 'Default' label applied
@dplaton dplaton added enhancement New feature or request To Verify labels Jul 31, 2020
@dplaton dplaton merged commit 51c0f71 into master Aug 3, 2020
@dplaton dplaton deleted the issues/CIF-1398 branch August 3, 2020 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request verified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants