From 240f0475bdba2abe53e98e6d9b25547fe292bf53 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 8 Oct 2018 14:59:13 -0700 Subject: [PATCH 01/31] add ProfileImage component to context --- src/lib/theme/components.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/theme/components.js b/src/lib/theme/components.js index 9d8ce6eea6..218877a886 100644 --- a/src/lib/theme/components.js +++ b/src/lib/theme/components.js @@ -34,6 +34,7 @@ import Link from "components/Link"; import MiniCartSummary from "@reactioncommerce/components/MiniCartSummary/v1"; import PhoneNumberInput from "@reactioncommerce/components/PhoneNumberInput/v1"; import Price from "@reactioncommerce/components/Price/v1"; +import ProfileImage from "@reactioncommerce/components/ProfileImage/v1"; import ProgressiveImage from "@reactioncommerce/components/ProgressiveImage/v1"; import QuantityInput from "@reactioncommerce/components/QuantityInput/v1"; import Select from "@reactioncommerce/components/Select/v1"; @@ -74,6 +75,7 @@ export default { MiniCartSummary, PhoneNumberInput, Price, + ProfileImage, ProgressiveImage, QuantityInput, Select, From d55a5dcaba7a92032493efe4d4565c7e1e32fe4a Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 8 Oct 2018 14:59:25 -0700 Subject: [PATCH 02/31] Create new Profile Address Book page --- src/pages/profileAddressBook.js | 129 ++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/pages/profileAddressBook.js diff --git a/src/pages/profileAddressBook.js b/src/pages/profileAddressBook.js new file mode 100644 index 0000000000..1b462e0348 --- /dev/null +++ b/src/pages/profileAddressBook.js @@ -0,0 +1,129 @@ +import React, { Component, Fragment } from "react"; +import PropTypes from "prop-types"; +import { inject, observer } from "mobx-react"; +import Grid from "@material-ui/core/Grid"; +import Typography from "@material-ui/core/Typography"; +import { withStyles } from "@material-ui/core/styles"; +import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; +import CartEmptyMessage from "@reactioncommerce/components/CartEmptyMessage/v1"; +import CartSummary from "@reactioncommerce/components/CartSummary/v1"; +import withCart from "containers/cart/withCart"; +import CartItems from "components/CartItems"; +import Profile from "components/Profile"; +import CheckoutButtons from "components/CheckoutButtons"; +import Link from "components/Link"; +import { Router } from "routes"; + +const styles = (theme) => ({ + cartEmptyMessageContainer: { + margin: "80px 0" + }, + checkoutButtonsContainer: { + backgroundColor: theme.palette.reaction.black02, + padding: theme.spacing.unit * 2 + }, + customerSupportCopy: { + paddingLeft: `${theme.spacing.unit * 4}px !important` + }, + phoneNumber: { + fontWeight: theme.typography.fontWeightBold + }, + title: { + fontWeight: theme.typography.fontWeightRegular, + marginTop: "1.6rem", + marginBottom: "3.1rem" + }, + itemWrapper: { + borderTop: theme.palette.borders.default, + borderBottom: theme.palette.borders.default + } +}); + +@withStyles(styles) +@inject("authStore") +@inject("uiStore") +@observer +class ProfileAddressBook extends Component { + static propTypes = { + cart: PropTypes.shape({ + totalItems: PropTypes.number, + items: PropTypes.arrayOf(PropTypes.object), + checkout: PropTypes.shape({ + fulfillmentTotal: PropTypes.shape({ + displayAmount: PropTypes.string + }), + itemTotal: PropTypes.shape({ + displayAmount: PropTypes.string + }), + taxTotal: PropTypes.shape({ + displayAmount: PropTypes.string + }) + }) + }), + classes: PropTypes.object, + hasMoreCartItems: PropTypes.bool, + loadMoreCartItems: PropTypes.func, + onChangeCartItemsQuantity: PropTypes.func, + onRemoveCartItems: PropTypes.func, + shop: PropTypes.shape({ + name: PropTypes.string.isRequired, + description: PropTypes.string + }) + }; + + renderMainArea() { + const { authStore: { account} } = this.props; + + // if (isLoadingProduct) return ; + + if (!account) return ; + + const viewer = { + firstName: "John", + lastName: "Doe", + name: "John Doe", + primaryEmailAddress: "john@doe.com", + profileImage: "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon&f=y" + }; + + return ( +
+ + + +

This is the menu placeholder

+

This is the menu placeholder

+

This is the menu placeholder

+

This is the menu placeholder

+

This is the menu placeholder

+
+ +

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+

This is the address book placeholder

+
+
+
+ ); + } + + + render() { + const { classes, shop } = this.props; + + return ( + + {this.renderMainArea()} + + ); + } +} + +export default ProfileAddressBook; From d78378b829a62e10a2c12e0bfb504dd1405c659f Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 8 Oct 2018 14:59:35 -0700 Subject: [PATCH 03/31] add new profileAddressBook page to routes --- src/routes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes.js b/src/routes.js index 3f259404ef..77c75aaa0e 100644 --- a/src/routes.js +++ b/src/routes.js @@ -9,6 +9,7 @@ routes .add("login", "/login", "login") .add("shopProduct", "/shop/:shopSlug/product/:slugOrId", "product") .add("product", "/product/:slugOrId/:variantId?", "product") + .add("addressBook", "/profile/address", "profileAddressBook") .add("shop", "/shop/:shopId/:tag", "productGrid") .add("tag", "/tag/:slug", "tag"); From 868a8ac5606551bcfc59bd815f07520144765249 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 8 Oct 2018 14:59:48 -0700 Subject: [PATCH 04/31] update components version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f4fd010287..248640e80c 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ }, "dependencies": { "@material-ui/core": "^3.1.0", - "@reactioncommerce/components": "0.41.1", + "@reactioncommerce/components": "0.43.0", "@reactioncommerce/components-context": "^1.0.0", "@segment/snippet": "^4.3.1", "apollo-cache-inmemory": "^1.1.11", From ca5f4874099b27fe56b6161d14b12cb46cdc2494 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 11:31:30 -0700 Subject: [PATCH 05/31] update appComponent to include new components from library --- src/lib/theme/components.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/theme/components.js b/src/lib/theme/components.js index 218877a886..f0db53b359 100644 --- a/src/lib/theme/components.js +++ b/src/lib/theme/components.js @@ -15,7 +15,10 @@ import iconDiscover from "@reactioncommerce/components/svg/iconDiscover"; import iconMastercard from "@reactioncommerce/components/svg/iconMastercard"; import iconVisa from "@reactioncommerce/components/svg/iconVisa"; import spinner from "@reactioncommerce/components/svg/spinner"; +import Accordion from "@reactioncommerce/components/Accordion/v1"; +import AddressBook from "@reactioncommerce/components/AddressBook/v1"; import AddressForm from "@reactioncommerce/components/AddressForm/v1"; +import AddressReview from "@reactioncommerce/components/AddressReview/v1"; import BadgeOverlay from "@reactioncommerce/components/BadgeOverlay/v1"; import Button from "@reactioncommerce/components/Button/v1"; import CartItem from "@reactioncommerce/components/CartItem/v1"; @@ -30,6 +33,7 @@ import CheckoutActionComplete from "@reactioncommerce/components/CheckoutActionC import CheckoutActionIncomplete from "@reactioncommerce/components/CheckoutActionIncomplete/v1"; import ErrorsBlock from "@reactioncommerce/components/ErrorsBlock/v1"; import Field from "@reactioncommerce/components/Field/v1"; +import InPageMenuItem from "@reactioncommerce/components/InPageMenuItem/v1"; import Link from "components/Link"; import MiniCartSummary from "@reactioncommerce/components/MiniCartSummary/v1"; import PhoneNumberInput from "@reactioncommerce/components/PhoneNumberInput/v1"; @@ -49,7 +53,10 @@ import withLocales from "../utils/withLocales"; const AddressFormWithLocales = withLocales(AddressForm); export default { + Accordion, + AddressBook, AddressForm: AddressFormWithLocales, + AddressReview, BadgeOverlay, Button, CartItem, @@ -72,6 +79,7 @@ export default { iconMastercard, iconValid, iconVisa, + InPageMenuItem, MiniCartSummary, PhoneNumberInput, Price, From 9d3c6e7b5d814334285d323765f30dc64319d9c4 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 11:33:25 -0700 Subject: [PATCH 06/31] add addressBook data to gql query --- src/containers/account/viewer.gql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/containers/account/viewer.gql b/src/containers/account/viewer.gql index 857ba0cdc1..39def0e0bb 100644 --- a/src/containers/account/viewer.gql +++ b/src/containers/account/viewer.gql @@ -1,6 +1,24 @@ query viewer { viewer { _id + addressBook { + edges { + node { + address1 + address2 + city + company + country + fullName + isBillingDefault + isCommercial + isShippingDefault + phone + postal + region + } + } + } emailRecords { address } From ff018a47a95120b9d0068001d501d814e4c63d00 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 11:43:12 -0700 Subject: [PATCH 07/31] remove placeholder info --- src/pages/profileAddressBook.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/pages/profileAddressBook.js b/src/pages/profileAddressBook.js index 1b462e0348..9f7f44c067 100644 --- a/src/pages/profileAddressBook.js +++ b/src/pages/profileAddressBook.js @@ -90,24 +90,11 @@ class ProfileAddressBook extends Component {
- -

This is the menu placeholder

-

This is the menu placeholder

-

This is the menu placeholder

-

This is the menu placeholder

-

This is the menu placeholder

+ +
-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

-

This is the address book placeholder

+
From 4f9b4196773939fbb99ae80e969b66ac7bdba613 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 21:32:32 -0700 Subject: [PATCH 08/31] add icon contextual components --- src/lib/theme/components.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/theme/components.js b/src/lib/theme/components.js index f0db53b359..cf4a885712 100644 --- a/src/lib/theme/components.js +++ b/src/lib/theme/components.js @@ -9,6 +9,8 @@ import iconClear from "@reactioncommerce/components/svg/iconClear"; import iconError from "@reactioncommerce/components/svg/iconError"; +import iconExpand from "@reactioncommerce/components/svg/iconExpand"; +import iconPlus from "@reactioncommerce/components/svg/iconPlus"; import iconValid from "@reactioncommerce/components/svg/iconValid"; import iconAmericanExpress from "@reactioncommerce/components/svg/iconAmericanExpress"; import iconDiscover from "@reactioncommerce/components/svg/iconDiscover"; @@ -76,7 +78,9 @@ export default { iconClear, iconDiscover, iconError, + iconExpand, iconMastercard, + iconPlus, iconValid, iconVisa, InPageMenuItem, From 494c55be3ec281d7f0ef030934efd0e8b81b0a05 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 21:32:59 -0700 Subject: [PATCH 09/31] rename profileAddressBook page to profile --- src/pages/profile.js | 141 ++++++++++++++++++++++++++++++++ src/pages/profileAddressBook.js | 116 -------------------------- 2 files changed, 141 insertions(+), 116 deletions(-) create mode 100644 src/pages/profile.js delete mode 100644 src/pages/profileAddressBook.js diff --git a/src/pages/profile.js b/src/pages/profile.js new file mode 100644 index 0000000000..d6fca676ad --- /dev/null +++ b/src/pages/profile.js @@ -0,0 +1,141 @@ +import React, { Component, Fragment } from "react"; +import PropTypes from "prop-types"; +import { inject, observer } from "mobx-react"; +import Grid from "@material-ui/core/Grid"; +import { withStyles } from "@material-ui/core/styles"; +import AddressBook from "@reactioncommerce/components/AddressBook/v1"; +import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; +import InPageMenu from "@reactioncommerce/components/InPageMenuItem/v1"; +import relayConnectionToArray from "lib/utils/relayConnectionToArray"; +import ErrorPage from "./_error"; + +// const styles = (theme) => ({ +// cartEmptyMessageContainer: { +// margin: "80px 0" +// }, +// checkoutButtonsContainer: { +// backgroundColor: theme.palette.reaction.black02, +// padding: theme.spacing.unit * 2 +// }, +// customerSupportCopy: { +// paddingLeft: `${theme.spacing.unit * 4}px !important` +// }, +// phoneNumber: { +// fontWeight: theme.typography.fontWeightBold +// }, +// shop: PropTypes.shape({ +// name: PropTypes.string.isRequired, +// currency: PropTypes.shape({ +// code: PropTypes.string.isRequired +// }) +// }), +// title: { +// fontWeight: theme.typography.fontWeightRegular, +// marginTop: "1.6rem", +// marginBottom: "3.1rem" +// }, +// itemWrapper: { +// borderTop: theme.palette.borders.default, +// borderBottom: theme.palette.borders.default +// } +// }); + +// @withStyles(styles) +@inject("authStore") +@inject("uiStore") +@observer +class ProfileAddressBook extends Component { + static propTypes = { + authStore: PropTypes.shape({ + account: PropTypes.object.isRequired + }), + classes: PropTypes.object, + shop: PropTypes.shape({ + name: PropTypes.string.isRequired, + description: PropTypes.string + }) + }; + + renderAddressBook() { + const { authStore: { account } } = this.props; + + // Use relayConnectionToArray to remove edges / nodes levels from addressBook object + const addresses = account.addressBook && account.addressBook.length ? relayConnectionToArray(account.addressBook) : []; + console.log("addresses after relayConnectionToArray()", addresses); + + // Create data object to pass to AddressBook component + const accountAddressBook = { + addressBook: addresses + }; + console.log("accountAddressBook", accountAddressBook); + + return ( + + ); + } + + renderOrders() { + return "This is where the orders screen will go"; + } + + + + + renderMainContent() { + const { router: { asPath } } = this.props; + + if (asPath === "/profile/address") { + return this.renderAddressBook(); + } + + if (asPath === "/profile/orders") { + return "Orders placeholder"; + } + + return "Hello"; + } + + renderNavigation() { + const { router: { asPath } } = this.props; + + const menuItems = [ + { + href: "/profile/address", + label: "Address Book", + isSelected: asPath === "/profile/address" + }, + { + href: "/profile/orders", + label: "Orders", + isSelected: asPath === "/profile/orders" + } + ]; + + return ( + + ); + } + + render() { + const { authStore: { account }, shop } = this.props; + + // If there is no logged in user, return Not Found page + if (account && !account._id) return ; + + return ( +
+ + + + {this.renderNavigation()} + + + {this.renderMainContent()} + + +
+ ); + } +} + +export default ProfileAddressBook; diff --git a/src/pages/profileAddressBook.js b/src/pages/profileAddressBook.js deleted file mode 100644 index 9f7f44c067..0000000000 --- a/src/pages/profileAddressBook.js +++ /dev/null @@ -1,116 +0,0 @@ -import React, { Component, Fragment } from "react"; -import PropTypes from "prop-types"; -import { inject, observer } from "mobx-react"; -import Grid from "@material-ui/core/Grid"; -import Typography from "@material-ui/core/Typography"; -import { withStyles } from "@material-ui/core/styles"; -import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; -import CartEmptyMessage from "@reactioncommerce/components/CartEmptyMessage/v1"; -import CartSummary from "@reactioncommerce/components/CartSummary/v1"; -import withCart from "containers/cart/withCart"; -import CartItems from "components/CartItems"; -import Profile from "components/Profile"; -import CheckoutButtons from "components/CheckoutButtons"; -import Link from "components/Link"; -import { Router } from "routes"; - -const styles = (theme) => ({ - cartEmptyMessageContainer: { - margin: "80px 0" - }, - checkoutButtonsContainer: { - backgroundColor: theme.palette.reaction.black02, - padding: theme.spacing.unit * 2 - }, - customerSupportCopy: { - paddingLeft: `${theme.spacing.unit * 4}px !important` - }, - phoneNumber: { - fontWeight: theme.typography.fontWeightBold - }, - title: { - fontWeight: theme.typography.fontWeightRegular, - marginTop: "1.6rem", - marginBottom: "3.1rem" - }, - itemWrapper: { - borderTop: theme.palette.borders.default, - borderBottom: theme.palette.borders.default - } -}); - -@withStyles(styles) -@inject("authStore") -@inject("uiStore") -@observer -class ProfileAddressBook extends Component { - static propTypes = { - cart: PropTypes.shape({ - totalItems: PropTypes.number, - items: PropTypes.arrayOf(PropTypes.object), - checkout: PropTypes.shape({ - fulfillmentTotal: PropTypes.shape({ - displayAmount: PropTypes.string - }), - itemTotal: PropTypes.shape({ - displayAmount: PropTypes.string - }), - taxTotal: PropTypes.shape({ - displayAmount: PropTypes.string - }) - }) - }), - classes: PropTypes.object, - hasMoreCartItems: PropTypes.bool, - loadMoreCartItems: PropTypes.func, - onChangeCartItemsQuantity: PropTypes.func, - onRemoveCartItems: PropTypes.func, - shop: PropTypes.shape({ - name: PropTypes.string.isRequired, - description: PropTypes.string - }) - }; - - renderMainArea() { - const { authStore: { account} } = this.props; - - // if (isLoadingProduct) return ; - - if (!account) return ; - - const viewer = { - firstName: "John", - lastName: "Doe", - name: "John Doe", - primaryEmailAddress: "john@doe.com", - profileImage: "https://www.gravatar.com/avatar/00000000000000000000000000000000?d=identicon&f=y" - }; - - return ( -
- - - - - - - - - -
- ); - } - - - render() { - const { classes, shop } = this.props; - - return ( - - {this.renderMainArea()} - - ); - } -} - -export default ProfileAddressBook; From 706c8f41a5c23a03f6714a7d13db760fb4b2d5a9 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 15 Oct 2018 21:33:09 -0700 Subject: [PATCH 10/31] add routes for addressBook and orders on profile --- src/routes.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 77c75aaa0e..8623f7391d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -9,7 +9,8 @@ routes .add("login", "/login", "login") .add("shopProduct", "/shop/:shopSlug/product/:slugOrId", "product") .add("product", "/product/:slugOrId/:variantId?", "product") - .add("addressBook", "/profile/address", "profileAddressBook") + .add("profileAddressBook", "/profile/address", "profile") + .add("profileOrders", "/profile/orders", "profile") .add("shop", "/shop/:shopId/:tag", "productGrid") .add("tag", "/tag/:slug", "tag"); From d2cec12d7a1214f0b54ef61552810f53c6b02669 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:44:05 -0700 Subject: [PATCH 11/31] add placeholder route for payment options --- src/routes.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes.js b/src/routes.js index 8623f7391d..c83491b100 100644 --- a/src/routes.js +++ b/src/routes.js @@ -11,6 +11,7 @@ routes .add("product", "/product/:slugOrId/:variantId?", "product") .add("profileAddressBook", "/profile/address", "profile") .add("profileOrders", "/profile/orders", "profile") + .add("profilePaymentMethods", "/profile/payments", "profile") .add("shop", "/shop/:shopId/:tag", "productGrid") .add("tag", "/tag/:slug", "tag"); From 09d39bb613aeafbccfbf25abb1551b9066a83036 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:44:42 -0700 Subject: [PATCH 12/31] add styles to component --- src/pages/profile.js | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index d6fca676ad..6f4710d5a1 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -9,38 +9,13 @@ import InPageMenu from "@reactioncommerce/components/InPageMenuItem/v1"; import relayConnectionToArray from "lib/utils/relayConnectionToArray"; import ErrorPage from "./_error"; -// const styles = (theme) => ({ -// cartEmptyMessageContainer: { -// margin: "80px 0" -// }, -// checkoutButtonsContainer: { -// backgroundColor: theme.palette.reaction.black02, -// padding: theme.spacing.unit * 2 -// }, -// customerSupportCopy: { -// paddingLeft: `${theme.spacing.unit * 4}px !important` -// }, -// phoneNumber: { -// fontWeight: theme.typography.fontWeightBold -// }, -// shop: PropTypes.shape({ -// name: PropTypes.string.isRequired, -// currency: PropTypes.shape({ -// code: PropTypes.string.isRequired -// }) -// }), -// title: { -// fontWeight: theme.typography.fontWeightRegular, -// marginTop: "1.6rem", -// marginBottom: "3.1rem" -// }, -// itemWrapper: { -// borderTop: theme.palette.borders.default, -// borderBottom: theme.palette.borders.default -// } -// }); - -// @withStyles(styles) +const styles = (theme) => ({ + accountProfileInfoContainer: { + marginBottom: theme.spacing.unit * 4 + } +}); + +@withStyles(styles) @inject("authStore") @inject("uiStore") @observer From 92a87628f8e503916a38c7c9138c897281aafb5a Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:45:02 -0700 Subject: [PATCH 13/31] add helmet for meta data --- src/pages/profile.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/profile.js b/src/pages/profile.js index 6f4710d5a1..8c75aff6a5 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -1,6 +1,7 @@ import React, { Component, Fragment } from "react"; import PropTypes from "prop-types"; import { inject, observer } from "mobx-react"; +import Helmet from "react-helmet"; import Grid from "@material-ui/core/Grid"; import { withStyles } from "@material-ui/core/styles"; import AddressBook from "@reactioncommerce/components/AddressBook/v1"; @@ -106,6 +107,10 @@ class ProfileAddressBook extends Component { {this.renderMainContent()} + From de3f11afa53f47dc662693b11d998ee7ad748181 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:45:10 -0700 Subject: [PATCH 14/31] fix import directory --- src/pages/profile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index 8c75aff6a5..e8e52d1013 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -6,7 +6,7 @@ import Grid from "@material-ui/core/Grid"; import { withStyles } from "@material-ui/core/styles"; import AddressBook from "@reactioncommerce/components/AddressBook/v1"; import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; -import InPageMenu from "@reactioncommerce/components/InPageMenuItem/v1"; +import InPageMenu from "@reactioncommerce/components/InPageMenu/v1"; import relayConnectionToArray from "lib/utils/relayConnectionToArray"; import ErrorPage from "./_error"; From 3e2805223f34926d1d55746a44159a72e9d11841 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:45:30 -0700 Subject: [PATCH 15/31] remove errant logs --- src/pages/profile.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index e8e52d1013..db1c67d87e 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -36,14 +36,12 @@ class ProfileAddressBook extends Component { const { authStore: { account } } = this.props; // Use relayConnectionToArray to remove edges / nodes levels from addressBook object - const addresses = account.addressBook && account.addressBook.length ? relayConnectionToArray(account.addressBook) : []; - console.log("addresses after relayConnectionToArray()", addresses); + const addresses = account.addressBook && account.addressBook.edges && account.addressBook.edges.length ? relayConnectionToArray(account.addressBook) : []; // Create data object to pass to AddressBook component const accountAddressBook = { addressBook: addresses }; - console.log("accountAddressBook", accountAddressBook); return ( @@ -68,7 +66,6 @@ class ProfileAddressBook extends Component { return "Orders placeholder"; } - return "Hello"; } renderNavigation() { From e9121928854db161ec3b9a2f74b5f2896e8092a2 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 16 Oct 2018 15:45:49 -0700 Subject: [PATCH 16/31] rearrange code for better readability --- src/pages/profile.js | 60 ++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index db1c67d87e..c35ebf4b2a 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -52,11 +52,12 @@ class ProfileAddressBook extends Component { return "This is where the orders screen will go"; } - - + renderPaymentMethods() { + return "This is where the orders screen will go"; + } renderMainContent() { - const { router: { asPath } } = this.props; + const { router: { asPath }, shop } = this.props; if (asPath === "/profile/address") { return this.renderAddressBook(); @@ -66,51 +67,78 @@ class ProfileAddressBook extends Component { return "Orders placeholder"; } + if (asPath === "/profile/payments") { + return "Payment Methods placeholder"; + } + + return ; + } + + renderAccountProfileInfo() { + const { authStore: { account }, classes } = this.props; + + return ( +
+ +
+ ); } renderNavigation() { - const { router: { asPath } } = this.props; + const { classes, router: { asPath } } = this.props; const menuItems = [ { href: "/profile/address", + route: "/profile/address", label: "Address Book", isSelected: asPath === "/profile/address" }, { href: "/profile/orders", + route: "/profile/orders", label: "Orders", isSelected: asPath === "/profile/orders" + }, + { + href: "/profile/payments", + route: "/profile/payments", + label: "Payment Methods", + isSelected: asPath === "/profile/payments" } ]; return ( - +
+ +
); } render() { - const { authStore: { account }, shop } = this.props; + const { authStore: { account }, classes, shop } = this.props; // If there is no logged in user, return Not Found page if (account && !account._id) return ; return ( -
- - - - {this.renderNavigation()} - - - {this.renderMainContent()} + +
+ + + {this.renderAccountProfileInfo()} + {this.renderNavigation()} + + + {this.renderMainContent()} + - -
+
+ ); } } From 1ccee08cdeec902efeb0f3388c51c6ab5775c23f Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 26 Nov 2018 11:14:09 -0800 Subject: [PATCH 17/31] temporary fix for AddressBook component error --- src/pages/profile.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index c35ebf4b2a..7eeeeae6f5 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -44,8 +44,11 @@ class ProfileAddressBook extends Component { }; return ( - + This is a placeholder, remove this and return AddressBook component below when ready. ); + // return ( + // + // ); } renderOrders() { From 68db5cf3cdf35ae5077175c42fcd14eff1458fdd Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Fri, 7 Dec 2018 08:42:00 -0600 Subject: [PATCH 18/31] chore: added AccordionFormList to components context --- src/lib/theme/components.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/theme/components.js b/src/lib/theme/components.js index fd7f4f0273..45dd5f8810 100644 --- a/src/lib/theme/components.js +++ b/src/lib/theme/components.js @@ -18,6 +18,7 @@ import iconMastercard from "@reactioncommerce/components/svg/iconMastercard"; import iconVisa from "@reactioncommerce/components/svg/iconVisa"; import spinner from "@reactioncommerce/components/svg/spinner"; import Accordion from "@reactioncommerce/components/Accordion/v1"; +import AccordionFormList from "@reactioncommerce/components/AccordionFormList/v1"; import AddressBook from "@reactioncommerce/components/AddressBook/v1"; import Address from "@reactioncommerce/components/Address/v1"; import AddressCapture from "@reactioncommerce/components/AddressCapture/v1"; @@ -60,6 +61,7 @@ const AddressFormWithLocales = withLocales(AddressForm); export default { Accordion, + AccordionFormList, AddressBook, Address, AddressCapture, @@ -79,7 +81,6 @@ export default { CheckoutActionIncomplete, ErrorsBlock, Field, - InlineAlert, Link, iconAmericanExpress, iconClear, @@ -90,6 +91,7 @@ export default { iconPlus, iconValid, iconVisa, + InlineAlert, InPageMenuItem, MiniCartSummary, PhoneNumberInput, From 1c1509cf40474f1010943a85ec19f28ff2def6b5 Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Fri, 7 Dec 2018 08:42:36 -0600 Subject: [PATCH 19/31] chore: ask for address _id in viewer query --- src/containers/account/viewer.gql | 1 + 1 file changed, 1 insertion(+) diff --git a/src/containers/account/viewer.gql b/src/containers/account/viewer.gql index 39def0e0bb..a3773fce0c 100644 --- a/src/containers/account/viewer.gql +++ b/src/containers/account/viewer.gql @@ -4,6 +4,7 @@ query viewer { addressBook { edges { node { + _id address1 address2 city From bd9fc7ecf4c3441ee349209bbb2d2edeb5561003 Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Fri, 7 Dec 2018 08:43:36 -0600 Subject: [PATCH 20/31] feat: started creating address gql fragment and mutation --- src/containers/address/fragments.gql | 20 ++++++++++++++ src/containers/address/mutations.gql | 39 ++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/containers/address/fragments.gql create mode 100644 src/containers/address/mutations.gql diff --git a/src/containers/address/fragments.gql b/src/containers/address/fragments.gql new file mode 100644 index 0000000000..3bb4fcd978 --- /dev/null +++ b/src/containers/address/fragments.gql @@ -0,0 +1,20 @@ +fragment AddressCommon on Address { + address1 + address2 + city + postal + country + region +} + +fragment FullAddressCommon on Address { + ...AddressCommon + _id + fullName + company + isBillingDefault + isCommercial + isShippingDefault + metafields + phone +} diff --git a/src/containers/address/mutations.gql b/src/containers/address/mutations.gql new file mode 100644 index 0000000000..38c7f50011 --- /dev/null +++ b/src/containers/address/mutations.gql @@ -0,0 +1,39 @@ +mutation addAccountAddressBookEntry($input: AddAccountAddressBookEntryInput!) { + addAccountAddressBookEntry(input: $input) { + address { + _id + address1 + address2 + city + company + country + fullName + isBillingDefault + isCommercial + isShippingDefault + phone + postal + region + } + } +} + +mutation removeAccountAddressBookEntry($input: RemoveAccountAddressBookEntryInput!) { + removeAccountAddressBookEntry(input: $input) { + address { + _id + address1 + address2 + city + company + country + fullName + isBillingDefault + isCommercial + isShippingDefault + phone + postal + region + } + } +} From 302976113c147dd6e9eac9d8b0dd71a1a6342168 Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Fri, 7 Dec 2018 08:44:13 -0600 Subject: [PATCH 21/31] feat: started a withAddressBook apollo container --- src/containers/address/withAddressBook.js | 142 ++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/containers/address/withAddressBook.js diff --git a/src/containers/address/withAddressBook.js b/src/containers/address/withAddressBook.js new file mode 100644 index 0000000000..c0a822ea74 --- /dev/null +++ b/src/containers/address/withAddressBook.js @@ -0,0 +1,142 @@ +import React, { Component, Fragment } from "react"; +import PropTypes from "prop-types"; +import hoistNonReactStatic from "hoist-non-react-statics"; +import { withApollo } from "react-apollo"; +import { inject, observer } from "mobx-react"; +import relayConnectionToArray from "lib/utils/relayConnectionToArray"; +import { addAccountAddressBookEntry, removeAccountAddressBookEntry } from "./mutations.gql"; +import viewerQuery from "../account/viewer.gql"; + +export default function withAddressBook(Comp) { + @withApollo + @inject("authStore") + @observer + class WithAddressBook extends Component { + static propTypes = { + authStore: PropTypes.shape({ + account: PropTypes.object.isRequired + }), + client: PropTypes.shape({ + query: PropTypes.func.isRequired + }) + }; + + state = {}; + + /** + * + * @method + * @summary + * @param + * @since + * @return + */ + get accountId() { + const { authStore } = this.props; + return authStore && authStore.account && authStore.account._id; + } + + get accountAddressBook() { + const { authStore } = this.props; + return ( + authStore && + authStore.account && + authStore.account.addressBook && + relayConnectionToArray(authStore.account.addressBook) + ); + } + + /** + * + * @method + * @summary + * @param + * @since + * @return + */ + handleAddAccountAddressBookEntry = (address) => { + const { client: apolloClient } = this.props; + + // TEMP delete `addressName` prop until API supports it. + delete address.addressName; + console.log("adding a new addres?", address); + + apolloClient.mutate({ + mutation: addAccountAddressBookEntry, + variables: { + input: { + address, + accountId: this.accountId + } + }, + update: (cache, { data: mutationData }) => { + if (mutationData && mutationData.addAccountAddressBookEntry) { + const { address: newAddressEntry } = mutationData.addAccountAddressBookEntry; + const stuff = cache.readQuery(viewerQuery); + console.log("whats in the mutation cache?", stuff); + if (newAddressEntry) { + // Update Apollo cache + cache.writeQuery({ + query: viewerQuery, + data: { account: { addressBook: [newAddressEntry] } } + }); + } + } + } + }); + }; + + /** + * + * @method + * @summary + * @param + * @since + * @return + */ + handleRemoveAccountAddressBookEntry = (addressId) => { + const { client: apolloClient } = this.props; + + console.log("delete address", addressId); + + apolloClient.mutate({ + mutation: removeAccountAddressBookEntry, + variables: { + input: { + addressId, + accountId: this.accountId + } + }, + update: (cache, { data: mutationData }) => { + if (mutationData && mutationData.removeAccountAddressBookEntry) { + const { address: removedAddressEntry } = mutationData.removeAccountAddressBookEntry; + console.log("whats in the mutation cache?", removedAddressEntry, this.accountAddressBook); + if (removedAddressEntry) { + // Update Apollo cache + cache.writeQuery({ + query: viewerQuery, + data: { account: { addressBook: [removedAddressEntry] } } + }); + } + } + } + }); + }; + + render() { + return ( + + + + ); + } + } + + hoistNonReactStatic(WithAddressBook, Comp); + + return WithAddressBook; +} From a6134dc8106f0bc8b9b938828af40e7c67b0c9b9 Mon Sep 17 00:00:00 2001 From: Nat Hamilton Date: Fri, 7 Dec 2018 08:45:05 -0600 Subject: [PATCH 22/31] feat: connecting the profile AddressBook with gql data --- src/pages/profile.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/pages/profile.js b/src/pages/profile.js index 7eeeeae6f5..5c38c9bbb6 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -7,6 +7,7 @@ import { withStyles } from "@material-ui/core/styles"; import AddressBook from "@reactioncommerce/components/AddressBook/v1"; import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; import InPageMenu from "@reactioncommerce/components/InPageMenu/v1"; +import withAddressBook from "containers/address/withAddressBook"; import relayConnectionToArray from "lib/utils/relayConnectionToArray"; import ErrorPage from "./_error"; @@ -17,6 +18,7 @@ const styles = (theme) => ({ }); @withStyles(styles) +@withAddressBook @inject("authStore") @inject("uiStore") @observer @@ -26,6 +28,8 @@ class ProfileAddressBook extends Component { account: PropTypes.object.isRequired }), classes: PropTypes.object, + onAddressAdded: PropTypes.func.isRequired, + onAddressDeleted: PropTypes.func.isRequired, shop: PropTypes.shape({ name: PropTypes.string.isRequired, description: PropTypes.string @@ -33,22 +37,25 @@ class ProfileAddressBook extends Component { }; renderAddressBook() { - const { authStore: { account } } = this.props; + const { authStore: { account }, onAddressAdded, onAddressDeleted } = this.props; // Use relayConnectionToArray to remove edges / nodes levels from addressBook object - const addresses = account.addressBook && account.addressBook.edges && account.addressBook.edges.length ? relayConnectionToArray(account.addressBook) : []; + const addresses = + account.addressBook && account.addressBook.edges && account.addressBook.edges.length + ? relayConnectionToArray(account.addressBook) + : []; // Create data object to pass to AddressBook component const accountAddressBook = { addressBook: addresses }; + console.log("address book data", accountAddressBook, account); + + //return This is a placeholder, remove this and return AddressBook component below when ready.; return ( - This is a placeholder, remove this and return AddressBook component below when ready. + ); - // return ( - // - // ); } renderOrders() { From 62e09de3e669b409b2c5cd5bd418c9ae8cb4e9e3 Mon Sep 17 00:00:00 2001 From: Daniel Castellon Date: Mon, 4 Feb 2019 12:23:36 -0500 Subject: [PATCH 23/31] fix: profile - edit address, update cache on add/delete, add profile button to menu --- .../AccountDropdown/AccountDropdown.js | 9 +- src/containers/address/mutations.gql | 20 +++++ src/containers/address/withAddressBook.js | 88 +++++++++++-------- src/pages/profile.js | 32 ++++--- 4 files changed, 98 insertions(+), 51 deletions(-) diff --git a/src/components/AccountDropdown/AccountDropdown.js b/src/components/AccountDropdown/AccountDropdown.js index 30c8da399b..c4ba2d88b3 100644 --- a/src/components/AccountDropdown/AccountDropdown.js +++ b/src/components/AccountDropdown/AccountDropdown.js @@ -14,7 +14,7 @@ const styles = (theme) => ({ width: 320, padding: theme.spacing.unit * 2 }, - authContent: { + marginBottom: { marginBottom: theme.spacing.unit * 2 } }); @@ -73,13 +73,18 @@ class AccountDropdown extends Component {
{authStore.isAuthenticated ? +
+ +
: -
+
diff --git a/src/containers/address/mutations.gql b/src/containers/address/mutations.gql index 38c7f50011..38aaf7f5bd 100644 --- a/src/containers/address/mutations.gql +++ b/src/containers/address/mutations.gql @@ -18,6 +18,26 @@ mutation addAccountAddressBookEntry($input: AddAccountAddressBookEntryInput!) { } } +mutation updateAccountAddressBookEntry($input: UpdateAccountAddressBookEntryInput!) { + updateAccountAddressBookEntry(input: $input) { + address { + _id + address1 + address2 + city + company + country + fullName + isBillingDefault + isCommercial + isShippingDefault + phone + postal + region + } + } +} + mutation removeAccountAddressBookEntry($input: RemoveAccountAddressBookEntryInput!) { removeAccountAddressBookEntry(input: $input) { address { diff --git a/src/containers/address/withAddressBook.js b/src/containers/address/withAddressBook.js index c0a822ea74..7928c33fe9 100644 --- a/src/containers/address/withAddressBook.js +++ b/src/containers/address/withAddressBook.js @@ -4,8 +4,12 @@ import hoistNonReactStatic from "hoist-non-react-statics"; import { withApollo } from "react-apollo"; import { inject, observer } from "mobx-react"; import relayConnectionToArray from "lib/utils/relayConnectionToArray"; -import { addAccountAddressBookEntry, removeAccountAddressBookEntry } from "./mutations.gql"; import viewerQuery from "../account/viewer.gql"; +import { + addAccountAddressBookEntry, + updateAccountAddressBookEntry, + removeAccountAddressBookEntry +} from "./mutations.gql"; export default function withAddressBook(Comp) { @withApollo @@ -23,43 +27,27 @@ export default function withAddressBook(Comp) { state = {}; - /** - * - * @method - * @summary - * @param - * @since - * @return - */ get accountId() { const { authStore } = this.props; return authStore && authStore.account && authStore.account._id; } get accountAddressBook() { - const { authStore } = this.props; - return ( - authStore && - authStore.account && - authStore.account.addressBook && - relayConnectionToArray(authStore.account.addressBook) - ); + const { authStore: { account: { addressBook } } } = this.props; + return (addressBook && relayConnectionToArray(addressBook)) || []; } /** - * - * @method - * @summary - * @param - * @since - * @return + * @name handleAddAccountAddressBookEntry + * @summary Adds an address to current user's address book + * @param {Object} address Address to add + * @return {Undefined} undefined */ handleAddAccountAddressBookEntry = (address) => { const { client: apolloClient } = this.props; // TEMP delete `addressName` prop until API supports it. delete address.addressName; - console.log("adding a new addres?", address); apolloClient.mutate({ mutation: addAccountAddressBookEntry, @@ -72,13 +60,19 @@ export default function withAddressBook(Comp) { update: (cache, { data: mutationData }) => { if (mutationData && mutationData.addAccountAddressBookEntry) { const { address: newAddressEntry } = mutationData.addAccountAddressBookEntry; - const stuff = cache.readQuery(viewerQuery); - console.log("whats in the mutation cache?", stuff); if (newAddressEntry) { + const cacheData = cache.readQuery({ query: viewerQuery }); + if (!cacheData.viewer.addressBook) { + cacheData.viewer.addressBook = { edges: [] }; + } + cacheData.viewer.addressBook.edges.push({ + __typename: "AddressEdge", + node: newAddressEntry + }); // Update Apollo cache cache.writeQuery({ query: viewerQuery, - data: { account: { addressBook: [newAddressEntry] } } + data: cacheData }); } } @@ -87,17 +81,38 @@ export default function withAddressBook(Comp) { }; /** - * - * @method - * @summary - * @param - * @since - * @return + * @name handleEditAccountAddressBookEntry + * @summary Updates an address in current user's address book + * @param {String} addressId _id of address to update + * @param {Object} updates Field updates + * @return {Undefined} undefined + */ + handleEditAccountAddressBookEntry = (addressId, updates) => { + const { client: apolloClient } = this.props; + apolloClient.mutate({ + mutation: updateAccountAddressBookEntry, + variables: { + input: { + addressId, + accountId: this.accountId, + updates + } + } + }); + }; + + /** + * @name handleRemoveAccountAddressBookEntry + * @summary Asks user to confirm, then deletes address from current user's address book + * @param {String} addressId _id of address to delete + * @return {Undefined} undefined */ handleRemoveAccountAddressBookEntry = (addressId) => { const { client: apolloClient } = this.props; - console.log("delete address", addressId); + if (!confirm("Delete this address?")) { + return; + } apolloClient.mutate({ mutation: removeAccountAddressBookEntry, @@ -110,12 +125,14 @@ export default function withAddressBook(Comp) { update: (cache, { data: mutationData }) => { if (mutationData && mutationData.removeAccountAddressBookEntry) { const { address: removedAddressEntry } = mutationData.removeAccountAddressBookEntry; - console.log("whats in the mutation cache?", removedAddressEntry, this.accountAddressBook); if (removedAddressEntry) { + const cacheData = cache.readQuery({ query: viewerQuery }); + const removedIndex = cacheData.viewer.addressBook.edges.findIndex((edge) => edge.node._id === addressId); + cacheData.viewer.addressBook.edges.splice(removedIndex, 1); // Update Apollo cache cache.writeQuery({ query: viewerQuery, - data: { account: { addressBook: [removedAddressEntry] } } + data: cacheData }); } } @@ -129,6 +146,7 @@ export default function withAddressBook(Comp) { diff --git a/src/pages/profile.js b/src/pages/profile.js index 5c38c9bbb6..e94bc05156 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -30,6 +30,7 @@ class ProfileAddressBook extends Component { classes: PropTypes.object, onAddressAdded: PropTypes.func.isRequired, onAddressDeleted: PropTypes.func.isRequired, + onAddressEdited: PropTypes.func.isRequired, shop: PropTypes.shape({ name: PropTypes.string.isRequired, description: PropTypes.string @@ -37,24 +38,27 @@ class ProfileAddressBook extends Component { }; renderAddressBook() { - const { authStore: { account }, onAddressAdded, onAddressDeleted } = this.props; - + const { + authStore: { account: { addressBook } }, + onAddressAdded, + onAddressEdited, + onAddressDeleted + } = this.props; // Use relayConnectionToArray to remove edges / nodes levels from addressBook object - const addresses = - account.addressBook && account.addressBook.edges && account.addressBook.edges.length - ? relayConnectionToArray(account.addressBook) - : []; + const addresses = (addressBook && relayConnectionToArray(addressBook)) || []; // Create data object to pass to AddressBook component const accountAddressBook = { addressBook: addresses }; - console.log("address book data", accountAddressBook, account); - - //return This is a placeholder, remove this and return AddressBook component below when ready.; return ( - + ); } @@ -103,8 +107,8 @@ class ProfileAddressBook extends Component { route: "/profile/address", label: "Address Book", isSelected: asPath === "/profile/address" - }, - { + } + /* { href: "/profile/orders", route: "/profile/orders", label: "Orders", @@ -115,7 +119,7 @@ class ProfileAddressBook extends Component { route: "/profile/payments", label: "Payment Methods", isSelected: asPath === "/profile/payments" - } + } */ ]; return ( @@ -126,7 +130,7 @@ class ProfileAddressBook extends Component { } render() { - const { authStore: { account }, classes, shop } = this.props; + const { authStore: { account }, shop } = this.props; // If there is no logged in user, return Not Found page if (account && !account._id) return ; From 7eec3c329689c016804fe9ff05fff5bf0df9546e Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Mon, 4 Feb 2019 10:37:20 -0800 Subject: [PATCH 24/31] fix: lint fix: remove duplicate key Signed-off-by: Erik Kieckhafer --- src/custom/componentsContext.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/custom/componentsContext.js b/src/custom/componentsContext.js index 34ea91c097..c5d89af94c 100644 --- a/src/custom/componentsContext.js +++ b/src/custom/componentsContext.js @@ -103,7 +103,6 @@ export default { iconPlus, iconValid, iconVisa, - InlineAlert, InPageMenuItem, MiniCartSummary, PhoneNumberInput, From c93d705bc39c1c30cc6515c1834c8cd0df106e87 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Fri, 8 Feb 2019 15:24:44 -0800 Subject: [PATCH 25/31] refactor: move ProfileAddressBook into its' own component Signed-off-by: Erik Kieckhafer --- .../ProfileAddressBook/ProfileAddressBook.js | 75 +++++++++++++++++++ .../ProfileAddressBook.test.js | 60 +++++++++++++++ .../__snapshots__/Profile.test.js.snap | 3 + src/components/ProfileAddressBook/index.js | 1 + src/pages/profile.js | 70 +++++------------ 5 files changed, 158 insertions(+), 51 deletions(-) create mode 100644 src/components/ProfileAddressBook/ProfileAddressBook.js create mode 100644 src/components/ProfileAddressBook/ProfileAddressBook.test.js create mode 100644 src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap create mode 100644 src/components/ProfileAddressBook/index.js diff --git a/src/components/ProfileAddressBook/ProfileAddressBook.js b/src/components/ProfileAddressBook/ProfileAddressBook.js new file mode 100644 index 0000000000..f8db7ed025 --- /dev/null +++ b/src/components/ProfileAddressBook/ProfileAddressBook.js @@ -0,0 +1,75 @@ +import React, { Component } from "react"; +import PropTypes from "prop-types"; +import { inject, observer } from "mobx-react"; +import Grid from "@material-ui/core/Grid"; +import { withStyles } from "@material-ui/core/styles"; +import AddressBook from "@reactioncommerce/components/AddressBook/v1"; +import withAddressBook from "containers/address/withAddressBook"; +import relayConnectionToArray from "lib/utils/relayConnectionToArray"; +import ErrorPage from "../../pages/_error"; + +const styles = (theme) => ({ + accountProfileInfoContainer: { + marginBottom: theme.spacing.unit * 4 + } +}); + +@withStyles(styles) +@withAddressBook +@inject("authStore") +@inject("uiStore") +@observer +class ProfileAddressBook extends Component { + static propTypes = { + authStore: PropTypes.shape({ + account: PropTypes.object.isRequired + }), + classes: PropTypes.object, + onAddressAdded: PropTypes.func.isRequired, + onAddressDeleted: PropTypes.func.isRequired, + onAddressEdited: PropTypes.func.isRequired, + shop: PropTypes.shape({ + name: PropTypes.string.isRequired, + description: PropTypes.string + }) + }; + + renderAddressBook() { + const { + authStore: { account: { addressBook } }, + onAddressAdded, + onAddressEdited, + onAddressDeleted + } = this.props; + // Use relayConnectionToArray to remove edges / nodes levels from addressBook object + const addresses = (addressBook && relayConnectionToArray(addressBook)) || []; + + // Create data object to pass to AddressBook component + const accountAddressBook = { + addressBook: addresses + }; + + return ( + + ); + } + + render() { + const { authStore: { account }, shop } = this.props; + + if (account && !account._id) return ; + + return ( + + {this.renderAddressBook()} + + ); + } +} + +export default ProfileAddressBook; diff --git a/src/components/ProfileAddressBook/ProfileAddressBook.test.js b/src/components/ProfileAddressBook/ProfileAddressBook.test.js new file mode 100644 index 0000000000..269704956d --- /dev/null +++ b/src/components/ProfileAddressBook/ProfileAddressBook.test.js @@ -0,0 +1,60 @@ +import React from "react"; +import renderer from "react-test-renderer"; +import { shallow } from "enzyme"; +import { ComponentsProvider } from "@reactioncommerce/components-context"; +import { MuiThemeProvider } from "@material-ui/core/styles"; +import mockComponents from "../../../tests/mockComponents"; +import realComponents from "../../../tests/realComponents"; +import theme from "custom/reactionTheme"; +import ProfileAddressBook from "./ProfileAddressBook"; + + +const authStore = { + account: { + addressBook: [ + { + address1: "123 Main Street", + address2: null, + city: "Santa Monica", + company: null, + country: "US", + fullName: "Jane Doe", + isBillingDefault: null, + isCommercial: false, + isShippingDefault: null, + phone: "3105556789", + postal: "90405", + region: "CA" + }, + { + address1: "123 Broadway", + address2: null, + city: "New York", + company: null, + country: "US", + fullName: "Jane Doe", + isBillingDefault: null, + isCommercial: false, + isShippingDefault: null, + phone: "2125556789", + postal: "10001", + region: "NY" + } + ] + } +}; + +test("basic snapshot", () => { + const component = renderer.create(( + + + + + + )); + + const tree = component.toJSON(); + expect(tree).toMatchSnapshot(); +}); diff --git a/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap b/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap new file mode 100644 index 0000000000..86bd41929f --- /dev/null +++ b/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`basic snapshot 1`] = `null`; diff --git a/src/components/ProfileAddressBook/index.js b/src/components/ProfileAddressBook/index.js new file mode 100644 index 0000000000..db6aa58a66 --- /dev/null +++ b/src/components/ProfileAddressBook/index.js @@ -0,0 +1 @@ +export { default } from "./ProfileAddressBook"; diff --git a/src/pages/profile.js b/src/pages/profile.js index e94bc05156..5b05cf30b3 100644 --- a/src/pages/profile.js +++ b/src/pages/profile.js @@ -4,11 +4,10 @@ import { inject, observer } from "mobx-react"; import Helmet from "react-helmet"; import Grid from "@material-ui/core/Grid"; import { withStyles } from "@material-ui/core/styles"; -import AddressBook from "@reactioncommerce/components/AddressBook/v1"; import AccountProfileInfo from "@reactioncommerce/components/AccountProfileInfo/v1"; import InPageMenu from "@reactioncommerce/components/InPageMenu/v1"; +import ProfileAddressBook from "components/ProfileAddressBook"; import withAddressBook from "containers/address/withAddressBook"; -import relayConnectionToArray from "lib/utils/relayConnectionToArray"; import ErrorPage from "./_error"; const styles = (theme) => ({ @@ -22,7 +21,7 @@ const styles = (theme) => ({ @inject("authStore") @inject("uiStore") @observer -class ProfileAddressBook extends Component { +class Profile extends Component { static propTypes = { authStore: PropTypes.shape({ account: PropTypes.object.isRequired @@ -37,44 +36,11 @@ class ProfileAddressBook extends Component { }) }; - renderAddressBook() { - const { - authStore: { account: { addressBook } }, - onAddressAdded, - onAddressEdited, - onAddressDeleted - } = this.props; - // Use relayConnectionToArray to remove edges / nodes levels from addressBook object - const addresses = (addressBook && relayConnectionToArray(addressBook)) || []; - - // Create data object to pass to AddressBook component - const accountAddressBook = { - addressBook: addresses - }; - - return ( - - ); - } - - renderOrders() { - return "This is where the orders screen will go"; - } - - renderPaymentMethods() { - return "This is where the orders screen will go"; - } - renderMainContent() { const { router: { asPath }, shop } = this.props; if (asPath === "/profile/address") { - return this.renderAddressBook(); + return ; } if (asPath === "/profile/orders") { @@ -108,18 +74,18 @@ class ProfileAddressBook extends Component { label: "Address Book", isSelected: asPath === "/profile/address" } - /* { - href: "/profile/orders", - route: "/profile/orders", - label: "Orders", - isSelected: asPath === "/profile/orders" - }, - { - href: "/profile/payments", - route: "/profile/payments", - label: "Payment Methods", - isSelected: asPath === "/profile/payments" - } */ + // { + // href: "/profile/orders", + // route: "/profile/orders", + // label: "Orders", + // isSelected: asPath === "/profile/orders" + // }, + // { + // href: "/profile/payments", + // route: "/profile/payments", + // label: "Payment Methods", + // isSelected: asPath === "/profile/payments" + // } ]; return ( @@ -143,13 +109,15 @@ class ProfileAddressBook extends Component { />
+ {/* MUI grid doesn't have an offset. Use blank grid item instead. */} {this.renderAccountProfileInfo()} {this.renderNavigation()} - + {this.renderMainContent()} + {/* MUI grid doesn't have an offset. Use blank grid item instead. */}
@@ -157,4 +125,4 @@ class ProfileAddressBook extends Component { } } -export default ProfileAddressBook; +export default Profile; From 8546264b93474b05f503dbf3e65d3111047c23e6 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 12 Feb 2019 22:56:04 -0800 Subject: [PATCH 26/31] lint fixes --- .../ProfileAddressBook/ProfileAddressBook.test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ProfileAddressBook/ProfileAddressBook.test.js b/src/components/ProfileAddressBook/ProfileAddressBook.test.js index 269704956d..b0b2be106b 100644 --- a/src/components/ProfileAddressBook/ProfileAddressBook.test.js +++ b/src/components/ProfileAddressBook/ProfileAddressBook.test.js @@ -1,11 +1,11 @@ import React from "react"; import renderer from "react-test-renderer"; -import { shallow } from "enzyme"; +// import { shallow } from "enzyme"; import { ComponentsProvider } from "@reactioncommerce/components-context"; import { MuiThemeProvider } from "@material-ui/core/styles"; import mockComponents from "../../../tests/mockComponents"; -import realComponents from "../../../tests/realComponents"; -import theme from "custom/reactionTheme"; +// import realComponents from "../../../tests/realComponents"; +// import theme from "custom/reactionTheme"; import ProfileAddressBook from "./ProfileAddressBook"; From d2739de89b5a026476f0f8070e26295448532d38 Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 12 Feb 2019 22:56:32 -0800 Subject: [PATCH 27/31] test snapshot Signed-off-by: Erik Kieckhafer --- .../ProfileAddressBook/__snapshots__/Profile.test.js.snap | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap diff --git a/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap b/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap deleted file mode 100644 index 86bd41929f..0000000000 --- a/src/components/ProfileAddressBook/__snapshots__/Profile.test.js.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`basic snapshot 1`] = `null`; From b32e487695c9777adcaf8cce27518b65bc2d162c Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Tue, 12 Feb 2019 22:59:17 -0800 Subject: [PATCH 28/31] lint fixes Signed-off-by: Erik Kieckhafer --- src/components/ProfileAddressBook/ProfileAddressBook.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ProfileAddressBook/ProfileAddressBook.test.js b/src/components/ProfileAddressBook/ProfileAddressBook.test.js index b0b2be106b..f86a9e8e87 100644 --- a/src/components/ProfileAddressBook/ProfileAddressBook.test.js +++ b/src/components/ProfileAddressBook/ProfileAddressBook.test.js @@ -3,9 +3,9 @@ import renderer from "react-test-renderer"; // import { shallow } from "enzyme"; import { ComponentsProvider } from "@reactioncommerce/components-context"; import { MuiThemeProvider } from "@material-ui/core/styles"; +import theme from "custom/reactionTheme"; import mockComponents from "../../../tests/mockComponents"; // import realComponents from "../../../tests/realComponents"; -// import theme from "custom/reactionTheme"; import ProfileAddressBook from "./ProfileAddressBook"; From df198dcdc591e2cb301e9b46302e7d3cd96150ef Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Wed, 13 Feb 2019 15:44:35 -0800 Subject: [PATCH 29/31] add jest test default reporter Signed-off-by: Erik Kieckhafer --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b00f9a4881..eb74fcc0b9 100644 --- a/package.json +++ b/package.json @@ -128,6 +128,7 @@ ], "coverageDirectory": "reports/coverage", "reporters": [ + "default", "jest-junit" ], "roots": [ From d2be9b829343e8da5947f8b067d7ae261613758f Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Wed, 13 Feb 2019 15:45:25 -0800 Subject: [PATCH 30/31] remove failing test (fixed in #393) Signed-off-by: Erik Kieckhafer --- .../ProfileAddressBook.test.js | 60 ------------------- 1 file changed, 60 deletions(-) delete mode 100644 src/components/ProfileAddressBook/ProfileAddressBook.test.js diff --git a/src/components/ProfileAddressBook/ProfileAddressBook.test.js b/src/components/ProfileAddressBook/ProfileAddressBook.test.js deleted file mode 100644 index f86a9e8e87..0000000000 --- a/src/components/ProfileAddressBook/ProfileAddressBook.test.js +++ /dev/null @@ -1,60 +0,0 @@ -import React from "react"; -import renderer from "react-test-renderer"; -// import { shallow } from "enzyme"; -import { ComponentsProvider } from "@reactioncommerce/components-context"; -import { MuiThemeProvider } from "@material-ui/core/styles"; -import theme from "custom/reactionTheme"; -import mockComponents from "../../../tests/mockComponents"; -// import realComponents from "../../../tests/realComponents"; -import ProfileAddressBook from "./ProfileAddressBook"; - - -const authStore = { - account: { - addressBook: [ - { - address1: "123 Main Street", - address2: null, - city: "Santa Monica", - company: null, - country: "US", - fullName: "Jane Doe", - isBillingDefault: null, - isCommercial: false, - isShippingDefault: null, - phone: "3105556789", - postal: "90405", - region: "CA" - }, - { - address1: "123 Broadway", - address2: null, - city: "New York", - company: null, - country: "US", - fullName: "Jane Doe", - isBillingDefault: null, - isCommercial: false, - isShippingDefault: null, - phone: "2125556789", - postal: "10001", - region: "NY" - } - ] - } -}; - -test("basic snapshot", () => { - const component = renderer.create(( - - - - - - )); - - const tree = component.toJSON(); - expect(tree).toMatchSnapshot(); -}); From 539b1632b2590b966c8cc25b80d8e7e58e2f5a9c Mon Sep 17 00:00:00 2001 From: Erik Kieckhafer Date: Wed, 13 Feb 2019 15:45:38 -0800 Subject: [PATCH 31/31] add primaryShopId to withOrder Signed-off-by: Erik Kieckhafer --- src/containers/order/withOrder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/order/withOrder.js b/src/containers/order/withOrder.js index 47ecd97090..9d3f0c7cbe 100644 --- a/src/containers/order/withOrder.js +++ b/src/containers/order/withOrder.js @@ -13,7 +13,7 @@ import { orderByReferenceId } from "./queries.gql"; */ export default function withOrder(Component) { @withApollo - @inject("cartStore", "routingStore") + @inject("cartStore", "primaryShopId", "routingStore") @observer class WithOrder extends React.Component { static propTypes = {