From 73c5e9df1003420a13b9ebebd6430e0e6263fc3d Mon Sep 17 00:00:00 2001 From: tniezg Date: Fri, 24 Sep 2021 14:25:02 +0200 Subject: [PATCH] Upgrade checkout behavior in line with core NextJS Commerce changes --- .../checkout/{checkout.ts => get-checkout.ts} | 8 ++++---- framework/spree/api/endpoints/checkout/index.ts | 7 +++++-- .../spree/api/endpoints/customer/address.ts | 1 + framework/spree/api/endpoints/customer/card.ts | 1 + framework/spree/checkout/use-checkout.tsx | 14 ++++++++++++++ framework/spree/commerce.config.json | 3 ++- .../spree/customer/address/use-add-item.tsx | 16 ++++++++++++++++ framework/spree/customer/card/use-add-item.tsx | 16 ++++++++++++++++ framework/spree/provider.ts | 2 ++ 9 files changed, 61 insertions(+), 7 deletions(-) rename framework/spree/api/endpoints/checkout/{checkout.ts => get-checkout.ts} (90%) create mode 100644 framework/spree/api/endpoints/customer/address.ts create mode 100644 framework/spree/api/endpoints/customer/card.ts create mode 100644 framework/spree/checkout/use-checkout.tsx create mode 100644 framework/spree/customer/address/use-add-item.tsx create mode 100644 framework/spree/customer/card/use-add-item.tsx diff --git a/framework/spree/api/endpoints/checkout/checkout.ts b/framework/spree/api/endpoints/checkout/get-checkout.ts similarity index 90% rename from framework/spree/api/endpoints/checkout/checkout.ts rename to framework/spree/api/endpoints/checkout/get-checkout.ts index 3622e1630..985239678 100644 --- a/framework/spree/api/endpoints/checkout/checkout.ts +++ b/framework/spree/api/endpoints/checkout/get-checkout.ts @@ -1,9 +1,9 @@ import type { CheckoutEndpoint } from '.' -const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ - req: request, +const getCheckout: CheckoutEndpoint['handlers']['getCheckout'] = async ({ + req: _request, res: response, - config, + config: _config, }) => { try { const html = ` @@ -41,4 +41,4 @@ const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ } } -export default checkout +export default getCheckout diff --git a/framework/spree/api/endpoints/checkout/index.ts b/framework/spree/api/endpoints/checkout/index.ts index ffa1bb04f..cd4ffea5d 100644 --- a/framework/spree/api/endpoints/checkout/index.ts +++ b/framework/spree/api/endpoints/checkout/index.ts @@ -2,7 +2,7 @@ import { createEndpoint } from '@commerce/api' import type { GetAPISchema, CommerceAPI } from '@commerce/api' import checkoutEndpoint from '@commerce/api/endpoints/checkout' import type { CheckoutSchema } from '@commerce/types/checkout' -import checkout from './checkout' +import getCheckout from './get-checkout' import type { SpreeApiProvider } from '../..' export type CheckoutAPI = GetAPISchema< @@ -12,7 +12,10 @@ export type CheckoutAPI = GetAPISchema< export type CheckoutEndpoint = CheckoutAPI['endpoint'] -export const handlers: CheckoutEndpoint['handlers'] = { checkout } +export const handlers: CheckoutEndpoint['handlers'] = { + getCheckout, + submitCheckout: () => {}, +} const checkoutApi = createEndpoint({ handler: checkoutEndpoint, diff --git a/framework/spree/api/endpoints/customer/address.ts b/framework/spree/api/endpoints/customer/address.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/spree/api/endpoints/customer/address.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/spree/api/endpoints/customer/card.ts b/framework/spree/api/endpoints/customer/card.ts new file mode 100644 index 000000000..491bf0ac9 --- /dev/null +++ b/framework/spree/api/endpoints/customer/card.ts @@ -0,0 +1 @@ +export default function noopApi(...args: any[]): void {} diff --git a/framework/spree/checkout/use-checkout.tsx b/framework/spree/checkout/use-checkout.tsx new file mode 100644 index 000000000..942f85b83 --- /dev/null +++ b/framework/spree/checkout/use-checkout.tsx @@ -0,0 +1,14 @@ +import { SWRHook } from '@commerce/utils/types' +import useCheckout, { UseCheckout } from '@commerce/checkout/use-checkout' + +export default useCheckout as UseCheckout + +export const handler: SWRHook = { + fetchOptions: { + query: '', + }, + async fetcher({ input, options, fetch }) {}, + useHook: + ({ useData }) => + async (input) => ({}), +} diff --git a/framework/spree/commerce.config.json b/framework/spree/commerce.config.json index e1e53245c..a27eb30c8 100644 --- a/framework/spree/commerce.config.json +++ b/framework/spree/commerce.config.json @@ -4,6 +4,7 @@ "wishlist": false, "cart": true, "search": true, - "customerAuth": false + "customerAuth": false, + "customCheckout": false } } diff --git a/framework/spree/customer/address/use-add-item.tsx b/framework/spree/customer/address/use-add-item.tsx new file mode 100644 index 000000000..2394bbd3c --- /dev/null +++ b/framework/spree/customer/address/use-add-item.tsx @@ -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 + +export const handler: MutationHook = { + fetchOptions: { + query: '', + }, + async fetcher({ input, options, fetch }) {}, + useHook: + ({ fetch }) => + () => + async () => ({}), +} diff --git a/framework/spree/customer/card/use-add-item.tsx b/framework/spree/customer/card/use-add-item.tsx new file mode 100644 index 000000000..2394bbd3c --- /dev/null +++ b/framework/spree/customer/card/use-add-item.tsx @@ -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 + +export const handler: MutationHook = { + fetchOptions: { + query: '', + }, + async fetcher({ input, options, fetch }) {}, + useHook: + ({ fetch }) => + () => + async () => ({}), +} diff --git a/framework/spree/provider.ts b/framework/spree/provider.ts index a39f1201d..4adda3bbd 100644 --- a/framework/spree/provider.ts +++ b/framework/spree/provider.ts @@ -8,6 +8,7 @@ import { handler as useSearch } from './product/use-search' import { handler as useLogin } from './auth/use-login' import { handler as useLogout } from './auth/use-logout' import { handler as useSignup } from './auth/use-signup' +import { handler as useCheckout } from './checkout/use-checkout' import { requireConfigValue } from './isomorphic-config' const spreeProvider = { @@ -18,6 +19,7 @@ const spreeProvider = { customer: { useCustomer }, products: { useSearch }, auth: { useLogin, useLogout, useSignup }, + checkout: { useCheckout }, } export { spreeProvider }