mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 00:16:59 +00:00
normalize data output in use-customer
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
parent
ea9cfe9c02
commit
254659e7c0
@ -97,8 +97,8 @@ const addItem: CartHandlers['addItem'] = async ({
|
||||
console.log('reconciliating carts')(
|
||||
({ _id: cartId } = await reconcileCarts({
|
||||
config,
|
||||
anonymousCartId: cartId,
|
||||
cartToken: anonymousCartToken,
|
||||
cartId,
|
||||
anonymousCartToken,
|
||||
reactionCustomerToken,
|
||||
}))
|
||||
)
|
||||
|
@ -27,8 +27,8 @@ const getCart: CartHandlers['getCart'] = async ({ req, res, config }) => {
|
||||
if (cartId && anonymousCartToken && reactionCustomerToken) {
|
||||
const rawReconciledCart = await reconcileCarts({
|
||||
config,
|
||||
anonymousCartId,
|
||||
cartToken,
|
||||
cartId,
|
||||
anonymousCartToken,
|
||||
reactionCustomerToken,
|
||||
})
|
||||
|
||||
|
@ -2,8 +2,8 @@ import reconcileCartsMutation from '@framework/utils/mutations/reconcile-carts'
|
||||
|
||||
async function reconcileCarts({
|
||||
config,
|
||||
anonymousCartId,
|
||||
cartToken,
|
||||
cartId,
|
||||
anonymousCartToken,
|
||||
reactionCustomerToken,
|
||||
}) {
|
||||
const {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"provider": "reactioncommerce",
|
||||
"features": {
|
||||
"wishlist": false
|
||||
"wishlist": false,
|
||||
"customCheckout": true
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||
import { Customer } from '@commerce/types'
|
||||
import { SWRHook } from '@commerce/utils/types'
|
||||
import { viewerQuery } from '../utils'
|
||||
import { viewerQuery, normalizeCustomer } from '../utils'
|
||||
|
||||
export default useCustomer as UseCustomer<typeof handler>
|
||||
|
||||
@ -13,7 +13,7 @@ export const handler: SWRHook<Customer | null> = {
|
||||
const data = await fetch<any | null>({
|
||||
...options,
|
||||
})
|
||||
return data.viewer ?? null
|
||||
return normalizeCustomer(data.viewer) ?? null
|
||||
},
|
||||
useHook: ({ useData }) => (input) => {
|
||||
return useData({
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Product } from '@commerce/types'
|
||||
import { Customer } from '@commerce/types'
|
||||
|
||||
import {
|
||||
Account,
|
||||
CatalogItem,
|
||||
Cart as ReactionCart,
|
||||
ProductPricingInfo,
|
||||
@ -222,3 +223,11 @@ function normalizeLineItem({
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeCustomer(viewer: Account): Customer {
|
||||
return {
|
||||
firstName: viewer.firstName ?? '',
|
||||
lastName: viewer.lastName ?? '',
|
||||
email: viewer.primaryEmailAddress,
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ module.exports = withCommerceConfig({
|
||||
},
|
||||
rewrites() {
|
||||
return [
|
||||
(isBC || isShopify || isRC) && {
|
||||
(isBC || isShopify) && {
|
||||
source: '/checkout',
|
||||
destination: '/api/bigcommerce/checkout',
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user