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

Acccount detail page hook integration #995

Conversation

alexvuong
Copy link
Collaborator

@alexvuong alexvuong commented Feb 18, 2023

Description

Account details page hook integration

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • (change1)

How to Test-Drive This PR

  • (step1)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@alexvuong alexvuong requested a review from a team as a code owner February 18, 2023 00:42
@alexvuong alexvuong self-assigned this Feb 18, 2023
Comment on lines 64 to 66
const customerId = useCustomerId()
const {isRegistered} = useCustomerType()
const {data: customer} = useCustomer({customerId}, {enabled: !!customerId && isRegistered})
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general I would have expected that there is a code reduction when using the hooks library or at a minimum no change line count as that was part of our goal, to move some complexities out of the project and into the commerce-sdk-react.

From the looks of it things have gotten a little more complex, one thing that is sticking out at me is that it's not easy to the customer. You have to get the id, then get the customer object, and we are also twisting in the use of this useCustomerType hook.

The funny thing is that I'm sure all the customer data is somewhere already. Have you thought of creating a utility hook in the commerce-sdk-react?

We previously talked about using some kind of app state. I think this would be a good reason to do that now.

Off of the top of me head you might have a usage like this:

const {customer, basket, others} = useAppState()

Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@bendvc To avoid scope creep in this PR, I've created an appStateProvider and hook to handle customer info in there for now. This will help us to achieve DRY for the customer. I'll create a ticket to move basket info in there, and we will discuss whether we want to move this provider inside commerce-react-sdk

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@kevinxh and I had a chat about useAppState for many data and have some concerns about performance issue if we aim to put many data together. Let's keep the scope to a single Provider CustomerProvider, and we are likely to have a discussion around how we want to manage state in another ticket

* @type {React.Context<unknown>}
*/
export const AppStateContext = React.createContext()
export const AppStateProvider = ({children}) => {
Copy link
Collaborator

@kevinxh kevinxh Feb 24, 2023

Choose a reason for hiding this comment

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

would it make more sense if it is called CustomerProvider? I think AppState is a bit misleading

Comment on lines 68 to 69
<CustomerProvider>
<MultiSiteProvider
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there a particular reason why CustomerProvider is the parent of the MultiSiteProvider? I'd imagine customer data is associate with a site on the backend, so i feel like it should be the other way around, MultiSiteProvider being the parent.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, it should be inside MultiSiteProvider

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

Successfully merging this pull request may close these issues.

3 participants