Show placeholder message for /chechout and adjust api fetcher type

This commit is contained in:
tniezg 2021-08-18 17:53:53 +02:00
parent 3b3a181dac
commit 17f8d497b8
7 changed files with 96 additions and 10 deletions

View File

@ -0,0 +1,44 @@
import type { CheckoutEndpoint } from '.'
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
req: request,
res: response,
config,
}) => {
try {
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Checkout</title>
</head>
<body>
<div style='margin: 10rem auto; text-align: center; font-family: SansSerif, "Segoe UI", Helvetica; color: #888;'>
<svg xmlns="http://www.w3.org/2000/svg" style='height: 60px; width: 60px;' fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
</svg>
<h1>Checkout not yet implemented :(</h1>
<p>
See <a href='https://github.com/vercel/commerce/issues/64' target='_blank'>#64</a>
</p>
</div>
</body>
</html>
`
response.status(200)
response.setHeader('Content-Type', 'text/html')
response.write(html)
response.end()
} catch (error) {
console.error(error)
const message = 'An unexpected error ocurred'
response.status(500).json({ data: null, errors: [{ message }] })
}
}
export default checkout

View File

@ -1 +1,23 @@
export default function noopApi(...args: any[]): void {}
import { createEndpoint } from '@commerce/api'
import type { CommerceAPI } from '@commerce/api'
import type { GetAPISchema } from '@commerce/api'
import checkoutEndpoint from '@commerce/api/endpoints/checkout'
import type { CheckoutSchema } from '@commerce/types/checkout'
import type { SpreeApiProvider } from '@framework/api'
import checkout from './checkout'
export type CheckoutAPI = GetAPISchema<
CommerceAPI<SpreeApiProvider>,
CheckoutSchema
>
export type CheckoutEndpoint = CheckoutAPI['endpoint']
export const handlers: CheckoutEndpoint['handlers'] = { checkout }
const checkoutApi = createEndpoint<CheckoutAPI>({
handler: checkoutEndpoint,
handlers,
})
export default checkoutApi

View File

@ -10,7 +10,9 @@ import getAllProductPaths from './operations/get-all-product-paths'
import getAllProducts from './operations/get-all-products'
import getProduct from './operations/get-product'
export interface SpreeApiConfig extends CommerceAPIConfig {}
export interface SpreeApiConfig extends CommerceAPIConfig {
fetch: any // Using any type, because CommerceAPIConfig['fetch'] cannot be extended from Variables = any to SpreeSdkVariables
}
const config: SpreeApiConfig = {
commerceUrl: '',

View File

@ -57,7 +57,9 @@ export default function getAllProductsOperation({
const {
data: { data: spreeSuccessResponse },
} = await apiFetch<{ data: IProducts }>('__UNUSED__', { variables })
} = await apiFetch<{ data: IProducts }, SpreeSdkVariables>('__UNUSED__', {
variables,
})
const normalizedProducts: Product[] = spreeSuccessResponse.data.map(
(spreeProduct) => normalizeProduct(spreeSuccessResponse, spreeProduct)

View File

@ -63,7 +63,9 @@ export default function getProductOperation({
const {
data: { data: spreeSuccessResponse },
} = await apiFetch<{ data: IProduct }>('__UNUSED__', { variables })
} = await apiFetch<{ data: IProduct }, SpreeSdkVariables>('__UNUSED__', {
variables,
})
return {
product: normalizeProduct(

View File

@ -86,9 +86,12 @@ export default function getSiteInfoOperation({
const {
data: { data: spreeCategoriesSuccessResponse },
} = await apiFetch<{
data: ITaxons
}>('__UNUSED__', {
} = await apiFetch<
{
data: ITaxons
},
SpreeSdkVariables
>('__UNUSED__', {
variables: createVariables(
requireConfigValue('spreeCategoriesTaxonomyId') as string
),
@ -96,9 +99,12 @@ export default function getSiteInfoOperation({
const {
data: { data: spreeBrandsSuccessResponse },
} = await apiFetch<{
data: ITaxons
}>('__UNUSED__', {
} = await apiFetch<
{
data: ITaxons
},
SpreeSdkVariables
>('__UNUSED__', {
variables: createVariables(
requireConfigValue('spreeBrandsTaxonomyId') as string
),

View File

@ -5,4 +5,12 @@ module.exports = {
images: {
domains: [process.env.NEXT_PUBLIC_SPREE_ALLOWED_IMAGE_DOMAIN],
},
rewrites() {
return [
{
source: '/checkout',
destination: '/api/checkout',
},
]
},
}