mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Upgrade checkout behavior in line with core NextJS Commerce changes
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import type { CheckoutEndpoint } from '.'
|
import type { CheckoutEndpoint } from '.'
|
||||||
|
|
||||||
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
|
const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({
|
||||||
req: request,
|
req: _request,
|
||||||
res: response,
|
res: response,
|
||||||
config,
|
config: _config,
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const html = `
|
const html = `
|
||||||
@@ -41,4 +41,4 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default checkout
|
export default getCheckout
|
@@ -2,7 +2,7 @@ import { createEndpoint } from '@commerce/api'
|
|||||||
import type { GetAPISchema, CommerceAPI } from '@commerce/api'
|
import type { GetAPISchema, CommerceAPI } from '@commerce/api'
|
||||||
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
|
||||||
import type { CheckoutSchema } from '@commerce/types/checkout'
|
import type { CheckoutSchema } from '@commerce/types/checkout'
|
||||||
import checkout from './checkout'
|
import getCheckout from './get-checkout'
|
||||||
import type { SpreeApiProvider } from '../..'
|
import type { SpreeApiProvider } from '../..'
|
||||||
|
|
||||||
export type CheckoutAPI = GetAPISchema<
|
export type CheckoutAPI = GetAPISchema<
|
||||||
@@ -12,7 +12,10 @@ export type CheckoutAPI = GetAPISchema<
|
|||||||
|
|
||||||
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
||||||
|
|
||||||
export const handlers: CheckoutEndpoint['handlers'] = { checkout }
|
export const handlers: CheckoutEndpoint['handlers'] = {
|
||||||
|
getCheckout,
|
||||||
|
submitCheckout: () => {},
|
||||||
|
}
|
||||||
|
|
||||||
const checkoutApi = createEndpoint<CheckoutAPI>({
|
const checkoutApi = createEndpoint<CheckoutAPI>({
|
||||||
handler: checkoutEndpoint,
|
handler: checkoutEndpoint,
|
||||||
|
1
framework/spree/api/endpoints/customer/address.ts
Normal file
1
framework/spree/api/endpoints/customer/address.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default function noopApi(...args: any[]): void {}
|
1
framework/spree/api/endpoints/customer/card.ts
Normal file
1
framework/spree/api/endpoints/customer/card.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export default function noopApi(...args: any[]): void {}
|
14
framework/spree/checkout/use-checkout.tsx
Normal file
14
framework/spree/checkout/use-checkout.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { SWRHook } from '@commerce/utils/types'
|
||||||
|
import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout'
|
||||||
|
|
||||||
|
export default useCheckout as UseCheckout<typeof handler>
|
||||||
|
|
||||||
|
export const handler: SWRHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
async (input) => ({}),
|
||||||
|
}
|
@@ -4,6 +4,7 @@
|
|||||||
"wishlist": false,
|
"wishlist": false,
|
||||||
"cart": true,
|
"cart": true,
|
||||||
"search": true,
|
"search": true,
|
||||||
"customerAuth": false
|
"customerAuth": false,
|
||||||
|
"customCheckout": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
framework/spree/customer/address/use-add-item.tsx
Normal file
16
framework/spree/customer/address/use-add-item.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import useAddItem from '@commerce/customer/address/use-add-item'
|
||||||
|
import type { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||||
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
|
|
||||||
|
export default useAddItem as UseAddItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
16
framework/spree/customer/card/use-add-item.tsx
Normal file
16
framework/spree/customer/card/use-add-item.tsx
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import useAddItem from '@commerce/customer/address/use-add-item'
|
||||||
|
import type { UseAddItem } from '@commerce/customer/address/use-add-item'
|
||||||
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
|
|
||||||
|
export default useAddItem as UseAddItem<typeof handler>
|
||||||
|
|
||||||
|
export const handler: MutationHook<any> = {
|
||||||
|
fetchOptions: {
|
||||||
|
query: '',
|
||||||
|
},
|
||||||
|
async fetcher({ input, options, fetch }) {},
|
||||||
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() =>
|
||||||
|
async () => ({}),
|
||||||
|
}
|
@@ -8,6 +8,7 @@ import { handler as useSearch } from './product/use-search'
|
|||||||
import { handler as useLogin } from './auth/use-login'
|
import { handler as useLogin } from './auth/use-login'
|
||||||
import { handler as useLogout } from './auth/use-logout'
|
import { handler as useLogout } from './auth/use-logout'
|
||||||
import { handler as useSignup } from './auth/use-signup'
|
import { handler as useSignup } from './auth/use-signup'
|
||||||
|
import { handler as useCheckout } from './checkout/use-checkout'
|
||||||
import { requireConfigValue } from './isomorphic-config'
|
import { requireConfigValue } from './isomorphic-config'
|
||||||
|
|
||||||
const spreeProvider = {
|
const spreeProvider = {
|
||||||
@@ -18,6 +19,7 @@ const spreeProvider = {
|
|||||||
customer: { useCustomer },
|
customer: { useCustomer },
|
||||||
products: { useSearch },
|
products: { useSearch },
|
||||||
auth: { useLogin, useLogout, useSignup },
|
auth: { useLogin, useLogout, useSignup },
|
||||||
|
checkout: { useCheckout },
|
||||||
}
|
}
|
||||||
|
|
||||||
export { spreeProvider }
|
export { spreeProvider }
|
||||||
|
Reference in New Issue
Block a user