mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 08:26: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')(
|
console.log('reconciliating carts')(
|
||||||
({ _id: cartId } = await reconcileCarts({
|
({ _id: cartId } = await reconcileCarts({
|
||||||
config,
|
config,
|
||||||
anonymousCartId: cartId,
|
cartId,
|
||||||
cartToken: anonymousCartToken,
|
anonymousCartToken,
|
||||||
reactionCustomerToken,
|
reactionCustomerToken,
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
@ -27,8 +27,8 @@ const getCart: CartHandlers['getCart'] = async ({ req, res, config }) => {
|
|||||||
if (cartId && anonymousCartToken && reactionCustomerToken) {
|
if (cartId && anonymousCartToken && reactionCustomerToken) {
|
||||||
const rawReconciledCart = await reconcileCarts({
|
const rawReconciledCart = await reconcileCarts({
|
||||||
config,
|
config,
|
||||||
anonymousCartId,
|
cartId,
|
||||||
cartToken,
|
anonymousCartToken,
|
||||||
reactionCustomerToken,
|
reactionCustomerToken,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ import reconcileCartsMutation from '@framework/utils/mutations/reconcile-carts'
|
|||||||
|
|
||||||
async function reconcileCarts({
|
async function reconcileCarts({
|
||||||
config,
|
config,
|
||||||
anonymousCartId,
|
cartId,
|
||||||
cartToken,
|
anonymousCartToken,
|
||||||
reactionCustomerToken,
|
reactionCustomerToken,
|
||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"provider": "reactioncommerce",
|
"provider": "reactioncommerce",
|
||||||
"features": {
|
"features": {
|
||||||
"wishlist": false
|
"wishlist": false,
|
||||||
|
"customCheckout": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
|
||||||
import { Customer } from '@commerce/types'
|
import { Customer } from '@commerce/types'
|
||||||
import { SWRHook } from '@commerce/utils/types'
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
import { viewerQuery } from '../utils'
|
import { viewerQuery, normalizeCustomer } from '../utils'
|
||||||
|
|
||||||
export default useCustomer as UseCustomer<typeof handler>
|
export default useCustomer as UseCustomer<typeof handler>
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ export const handler: SWRHook<Customer | null> = {
|
|||||||
const data = await fetch<any | null>({
|
const data = await fetch<any | null>({
|
||||||
...options,
|
...options,
|
||||||
})
|
})
|
||||||
return data.viewer ?? null
|
return normalizeCustomer(data.viewer) ?? null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook: ({ useData }) => (input) => {
|
||||||
return useData({
|
return useData({
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Product } from '@commerce/types'
|
import { Customer } from '@commerce/types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
Account,
|
||||||
CatalogItem,
|
CatalogItem,
|
||||||
Cart as ReactionCart,
|
Cart as ReactionCart,
|
||||||
ProductPricingInfo,
|
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() {
|
rewrites() {
|
||||||
return [
|
return [
|
||||||
(isBC || isShopify || isRC) && {
|
(isBC || isShopify) && {
|
||||||
source: '/checkout',
|
source: '/checkout',
|
||||||
destination: '/api/bigcommerce/checkout',
|
destination: '/api/bigcommerce/checkout',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user