mirror of
https://github.com/vercel/commerce.git
synced 2025-07-05 12:41:21 +00:00
Run prettier autofix on all files.
This commit is contained in:
parent
a94f049f0a
commit
14fcbaa5b3
@ -24,11 +24,8 @@ export const getLoggedInCustomerQuery = /* GraphQL */ `
|
|||||||
|
|
||||||
export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>
|
export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>
|
||||||
|
|
||||||
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] = async ({
|
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
|
||||||
req,
|
async ({ req, res, config }) => {
|
||||||
res,
|
|
||||||
config,
|
|
||||||
}) => {
|
|
||||||
const token = req.cookies[config.customerCookie]
|
const token = req.cookies[config.customerCookie]
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
@ -54,6 +51,6 @@ const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({ data: null })
|
res.status(200).json({ data: null })
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getLoggedInCustomer
|
export default getLoggedInCustomer
|
||||||
|
@ -34,7 +34,7 @@ export interface BigcommerceConfig extends CommerceAPIConfig {
|
|||||||
storeChannelId?: string
|
storeChannelId?: string
|
||||||
storeUrl?: string
|
storeUrl?: string
|
||||||
storeApiClientSecret?: string
|
storeApiClientSecret?: string
|
||||||
storeHash?:string
|
storeHash?: string
|
||||||
storeApiFetch<T>(endpoint: string, options?: RequestInit): Promise<T>
|
storeApiFetch<T>(endpoint: string, options?: RequestInit): Promise<T>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,8 +81,8 @@ const config: BigcommerceConfig = {
|
|||||||
storeApiToken: STORE_API_TOKEN,
|
storeApiToken: STORE_API_TOKEN,
|
||||||
storeApiClientId: STORE_API_CLIENT_ID,
|
storeApiClientId: STORE_API_CLIENT_ID,
|
||||||
storeChannelId: STORE_CHANNEL_ID,
|
storeChannelId: STORE_CHANNEL_ID,
|
||||||
storeUrl:STORE_URL,
|
storeUrl: STORE_URL,
|
||||||
storeApiClientSecret:CLIENT_SECRET,
|
storeApiClientSecret: CLIENT_SECRET,
|
||||||
storeHash: STOREFRONT_HASH,
|
storeHash: STOREFRONT_HASH,
|
||||||
storeApiFetch: createFetchStoreApi(() => getCommerceApi().getConfig()),
|
storeApiFetch: createFetchStoreApi(() => getCommerceApi().getConfig()),
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,7 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
async fetcher({ input: { email, password }, options, fetch }) {
|
async fetcher({ input: { email, password }, options, fetch }) {
|
||||||
if (!(email && password)) {
|
if (!(email && password)) {
|
||||||
throw new CommerceError({
|
throw new CommerceError({
|
||||||
message:
|
message: 'An email and password are required to login',
|
||||||
'An email and password are required to login',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +24,9 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
body: { email, password },
|
body: { email, password },
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -11,7 +11,9 @@ export const handler: MutationHook<LogoutHook> = {
|
|||||||
url: '/api/logout',
|
url: '/api/logout',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCustomer()
|
const { mutate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -29,7 +29,9 @@ export const handler: MutationHook<SignupHook> = {
|
|||||||
body: { firstName, lastName, email, password },
|
body: { firstName, lastName, email, password },
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -29,7 +29,9 @@ export const handler: MutationHook<AddItemHook> = {
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -10,7 +10,9 @@ export const handler: SWRHook<GetCartHook> = {
|
|||||||
url: '/api/cart',
|
url: '/api/cart',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
const response = useData({
|
const response = useData({
|
||||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||||
})
|
})
|
||||||
|
@ -30,11 +30,9 @@ export const handler = {
|
|||||||
}: HookFetcherContext<RemoveItemHook>) {
|
}: HookFetcherContext<RemoveItemHook>) {
|
||||||
return await fetch({ ...options, body: { itemId } })
|
return await fetch({ ...options, body: { itemId } })
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<RemoveItemHook>) =>
|
||||||
>(
|
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
|
||||||
ctx: { item?: T } = {}
|
|
||||||
) => {
|
|
||||||
const { item } = ctx
|
const { item } = ctx
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
||||||
|
@ -46,9 +46,9 @@ export const handler = {
|
|||||||
body: { itemId, item },
|
body: { itemId, item },
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
||||||
>(
|
<T extends LineItem | undefined = undefined>(
|
||||||
ctx: {
|
ctx: {
|
||||||
item?: T
|
item?: T
|
||||||
wait?: number
|
wait?: number
|
||||||
|
@ -13,7 +13,9 @@ export const handler: SWRHook<CustomerHook> = {
|
|||||||
const data = await fetch(options)
|
const data = await fetch(options)
|
||||||
return data?.customer ?? null
|
return data?.customer ?? null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
return useData({
|
return useData({
|
||||||
swrOptions: {
|
swrOptions: {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
|
@ -8,11 +8,7 @@ import getSlug from './get-slug'
|
|||||||
|
|
||||||
function normalizeProductOption(productOption: any) {
|
function normalizeProductOption(productOption: any) {
|
||||||
const {
|
const {
|
||||||
node: {
|
node: { entityId, values: { edges = [] } = {}, ...rest },
|
||||||
entityId,
|
|
||||||
values: { edges = [] } = {},
|
|
||||||
...rest
|
|
||||||
},
|
|
||||||
} = productOption
|
} = productOption
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -33,7 +33,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
method: options.method,
|
method: options.method,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input = {}) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input = {}) => {
|
||||||
return useData({
|
return useData({
|
||||||
input: [
|
input: [
|
||||||
['search', input.search],
|
['search', input.search],
|
||||||
|
@ -20,4 +20,5 @@ export type WishlistTypes = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type WishlistSchema = Core.WishlistSchema<WishlistTypes>
|
export type WishlistSchema = Core.WishlistSchema<WishlistTypes>
|
||||||
export type GetCustomerWishlistOperation = Core.GetCustomerWishlistOperation<WishlistTypes>
|
export type GetCustomerWishlistOperation =
|
||||||
|
Core.GetCustomerWishlistOperation<WishlistTypes>
|
||||||
|
@ -13,7 +13,9 @@ export const handler: MutationHook<AddItemHook> = {
|
|||||||
url: '/api/wishlist',
|
url: '/api/wishlist',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { data: customer } = useCustomer()
|
const { data: customer } = useCustomer()
|
||||||
const { revalidate } = useWishlist()
|
const { revalidate } = useWishlist()
|
||||||
|
|
||||||
|
@ -15,7 +15,9 @@ export const handler: MutationHook<RemoveItemHook> = {
|
|||||||
url: '/api/wishlist',
|
url: '/api/wishlist',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => ({ wishlist } = {}) => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
({ wishlist } = {}) => {
|
||||||
const { data: customer } = useCustomer()
|
const { data: customer } = useCustomer()
|
||||||
const { revalidate } = useWishlist(wishlist)
|
const { revalidate } = useWishlist(wishlist)
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ export const handler: SWRHook<GetWishlistHook> = {
|
|||||||
method: options.method,
|
method: options.method,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
const { data: customer } = useCustomer()
|
const { data: customer } = useCustomer()
|
||||||
const response = useData({
|
const response = useData({
|
||||||
input: [
|
input: [
|
||||||
|
@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
|
|||||||
import isAllowedOperation from '../utils/is-allowed-operation'
|
import isAllowedOperation from '../utils/is-allowed-operation'
|
||||||
import type { GetAPISchema } from '..'
|
import type { GetAPISchema } from '..'
|
||||||
|
|
||||||
const cartEndpoint: GetAPISchema<
|
const cartEndpoint: GetAPISchema<any, CartSchema<any>>['endpoint']['handler'] =
|
||||||
any,
|
async (ctx) => {
|
||||||
CartSchema<any>
|
|
||||||
>['endpoint']['handler'] = async (ctx) => {
|
|
||||||
const { req, res, handlers, config } = ctx
|
const { req, res, handlers, config } = ctx
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -57,6 +55,6 @@ const cartEndpoint: GetAPISchema<
|
|||||||
|
|
||||||
res.status(500).json({ data: null, errors: [{ message }] })
|
res.status(500).json({ data: null, errors: [{ message }] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default cartEndpoint
|
export default cartEndpoint
|
||||||
|
@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
|
|||||||
import isAllowedOperation from '../utils/is-allowed-operation'
|
import isAllowedOperation from '../utils/is-allowed-operation'
|
||||||
import type { GetAPISchema } from '..'
|
import type { GetAPISchema } from '..'
|
||||||
|
|
||||||
const logoutEndpoint: GetAPISchema<
|
const logoutEndpoint: GetAPISchema<any, LogoutSchema>['endpoint']['handler'] =
|
||||||
any,
|
async (ctx) => {
|
||||||
LogoutSchema
|
|
||||||
>['endpoint']['handler'] = async (ctx) => {
|
|
||||||
const { req, res, handlers } = ctx
|
const { req, res, handlers } = ctx
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -32,6 +30,6 @@ const logoutEndpoint: GetAPISchema<
|
|||||||
|
|
||||||
res.status(500).json({ data: null, errors: [{ message }] })
|
res.status(500).json({ data: null, errors: [{ message }] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default logoutEndpoint
|
export default logoutEndpoint
|
||||||
|
@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
|
|||||||
import isAllowedOperation from '../utils/is-allowed-operation'
|
import isAllowedOperation from '../utils/is-allowed-operation'
|
||||||
import type { GetAPISchema } from '..'
|
import type { GetAPISchema } from '..'
|
||||||
|
|
||||||
const signupEndpoint: GetAPISchema<
|
const signupEndpoint: GetAPISchema<any, SignupSchema>['endpoint']['handler'] =
|
||||||
any,
|
async (ctx) => {
|
||||||
SignupSchema
|
|
||||||
>['endpoint']['handler'] = async (ctx) => {
|
|
||||||
const { req, res, handlers, config } = ctx
|
const { req, res, handlers, config } = ctx
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -33,6 +31,6 @@ const signupEndpoint: GetAPISchema<
|
|||||||
|
|
||||||
res.status(500).json({ data: null, errors: [{ message }] })
|
res.status(500).json({ data: null, errors: [{ message }] })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default signupEndpoint
|
export default signupEndpoint
|
||||||
|
@ -77,12 +77,11 @@ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetAllProductPathsOperation<
|
export type GetAllProductPathsOperation<T extends ProductTypes = ProductTypes> =
|
||||||
T extends ProductTypes = ProductTypes
|
{
|
||||||
> = {
|
|
||||||
data: { products: Pick<T['product'], 'path'>[] }
|
data: { products: Pick<T['product'], 'path'>[] }
|
||||||
variables: { first?: number }
|
variables: { first?: number }
|
||||||
}
|
}
|
||||||
|
|
||||||
export type GetAllProductsOperation<T extends ProductTypes = ProductTypes> = {
|
export type GetAllProductsOperation<T extends ProductTypes = ProductTypes> = {
|
||||||
data: { products: T['product'][] }
|
data: { products: T['product'][] }
|
||||||
|
@ -11,8 +11,10 @@ type InferValue<Prop extends PropertyKey, Desc> = Desc extends {
|
|||||||
? Record<Prop, T>
|
? Record<Prop, T>
|
||||||
: never
|
: never
|
||||||
|
|
||||||
type DefineProperty<Prop extends PropertyKey, Desc extends PropertyDescriptor> =
|
type DefineProperty<
|
||||||
Desc extends { writable: any; set(val: any): any }
|
Prop extends PropertyKey,
|
||||||
|
Desc extends PropertyDescriptor
|
||||||
|
> = Desc extends { writable: any; set(val: any): any }
|
||||||
? never
|
? never
|
||||||
: Desc extends { writable: any; get(): any }
|
: Desc extends { writable: any; get(): any }
|
||||||
? never
|
? never
|
||||||
|
@ -6,11 +6,7 @@ export type CheckoutAPI = GetAPISchema<CommerceAPI, CheckoutSchema>
|
|||||||
|
|
||||||
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
export type CheckoutEndpoint = CheckoutAPI['endpoint']
|
||||||
|
|
||||||
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({
|
const checkout: CheckoutEndpoint['handlers']['checkout'] = async ({ req, res, config }) => {
|
||||||
req,
|
|
||||||
res,
|
|
||||||
config,
|
|
||||||
}) => {
|
|
||||||
try {
|
try {
|
||||||
const html = `
|
const html = `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -6,14 +6,9 @@ import * as Query from '../../utils/queries'
|
|||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
|
|
||||||
export type GetAllPagesResult<
|
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> = T
|
||||||
T extends { pages: any[] } = { pages: Page[] }
|
|
||||||
> = T
|
|
||||||
|
|
||||||
export default function getAllPagesOperation({
|
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
|
|
||||||
|
export default function getAllPagesOperation({ commerce }: OperationContext<Provider>) {
|
||||||
async function getAllPages({
|
async function getAllPages({
|
||||||
query = Query.PageMany,
|
query = Query.PageMany,
|
||||||
config,
|
config,
|
||||||
@ -27,7 +22,9 @@ export default function getAllPagesOperation({
|
|||||||
} = {}): Promise<GetAllPagesResult> {
|
} = {}): Promise<GetAllPagesResult> {
|
||||||
const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config)
|
const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config)
|
||||||
|
|
||||||
const { data } = await fetch(query, { variables },
|
const { data } = await fetch(
|
||||||
|
query,
|
||||||
|
{ variables },
|
||||||
{
|
{
|
||||||
...(locale && {
|
...(locale && {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -12,9 +12,7 @@ type ReturnType = {
|
|||||||
products: Product[]
|
products: Product[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getAllProductsOperation({
|
export default function getAllProductsOperation({ commerce }: OperationContext<Provider>) {
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getAllProducts({
|
async function getAllProducts({
|
||||||
query = Query.ProductMany,
|
query = Query.ProductMany,
|
||||||
variables,
|
variables,
|
||||||
@ -30,11 +28,10 @@ export default function getAllProductsOperation({
|
|||||||
const { fetch, locale } = commerce.getConfig(config)
|
const { fetch, locale } = commerce.getConfig(config)
|
||||||
|
|
||||||
if (featured) {
|
if (featured) {
|
||||||
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' };
|
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' }
|
||||||
query = Query.CollectionOne
|
query = Query.CollectionOne
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const { data }: GraphQLFetcherResult = await fetch(
|
const { data }: GraphQLFetcherResult = await fetch(
|
||||||
query,
|
query,
|
||||||
{ variables },
|
{ variables },
|
||||||
@ -48,7 +45,8 @@ export default function getAllProductsOperation({
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (featured) {
|
if (featured) {
|
||||||
const products = data.collection.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
|
const products =
|
||||||
|
data.collection.products?.edges?.map(({ node: p }: ProductCountableEdge) => normalizeProduct(p)) ?? []
|
||||||
|
|
||||||
return {
|
return {
|
||||||
products,
|
products,
|
||||||
@ -60,7 +58,6 @@ export default function getAllProductsOperation({
|
|||||||
products,
|
products,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAllProducts
|
return getAllProducts
|
||||||
|
@ -6,19 +6,16 @@ import * as Query from '../../utils/queries'
|
|||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
|
|
||||||
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T
|
||||||
|
|
||||||
export default function getPageOperation({
|
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
|
|
||||||
|
export default function getPageOperation({ commerce }: OperationContext<Provider>) {
|
||||||
async function getPage({
|
async function getPage({
|
||||||
query = Query.PageOne,
|
query = Query.PageOne,
|
||||||
variables,
|
variables,
|
||||||
config,
|
config,
|
||||||
}: {
|
}: {
|
||||||
query?: string
|
query?: string
|
||||||
variables: QueryPageArgs,
|
variables: QueryPageArgs
|
||||||
config?: Partial<SaleorConfig>
|
config?: Partial<SaleorConfig>
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
}): Promise<GetPageResult> {
|
}): Promise<GetPageResult> {
|
||||||
@ -26,7 +23,9 @@ export default function getPageOperation({
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
data: { page },
|
data: { page },
|
||||||
} = await fetch(query, { variables },
|
} = await fetch(
|
||||||
|
query,
|
||||||
|
{ variables },
|
||||||
{
|
{
|
||||||
...(locale && {
|
...(locale && {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type { OperationContext } from '@commerce/api/operations'
|
import type { OperationContext } from '@commerce/api/operations'
|
||||||
import { normalizeProduct, } from '../../utils'
|
import { normalizeProduct } from '../../utils'
|
||||||
import type { Provider, SaleorConfig } from '..'
|
import type { Provider, SaleorConfig } from '..'
|
||||||
|
|
||||||
import * as Query from '../../utils/queries'
|
import * as Query from '../../utils/queries'
|
||||||
@ -12,9 +12,7 @@ type ReturnType = {
|
|||||||
product: any
|
product: any
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function getProductOperation({
|
export default function getProductOperation({ commerce }: OperationContext<Provider>) {
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function getProduct({
|
async function getProduct({
|
||||||
query = Query.ProductOneBySlug,
|
query = Query.ProductOneBySlug,
|
||||||
variables,
|
variables,
|
||||||
@ -27,7 +25,9 @@ export default function getProductOperation({
|
|||||||
}): Promise<ReturnType> {
|
}): Promise<ReturnType> {
|
||||||
const { fetch, locale } = commerce.getConfig(cfg)
|
const { fetch, locale } = commerce.getConfig(cfg)
|
||||||
|
|
||||||
const { data } = await fetch(query, { variables },
|
const { data } = await fetch(
|
||||||
|
query,
|
||||||
|
{ variables },
|
||||||
{
|
{
|
||||||
...(locale && {
|
...(locale && {
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import type { ServerResponse } from 'http'
|
import type { ServerResponse } from 'http'
|
||||||
import type { OperationContext } from '@commerce/api/operations'
|
import type { OperationContext } from '@commerce/api/operations'
|
||||||
import type { Provider, SaleorConfig } from '..'
|
import type { Provider, SaleorConfig } from '..'
|
||||||
import {
|
import { throwUserErrors } from '../../utils'
|
||||||
throwUserErrors,
|
|
||||||
} from '../../utils'
|
|
||||||
|
|
||||||
import * as Mutation from '../../utils/mutations'
|
import * as Mutation from '../../utils/mutations'
|
||||||
|
|
||||||
export default function loginOperation({
|
export default function loginOperation({ commerce }: OperationContext<Provider>) {
|
||||||
commerce,
|
|
||||||
}: OperationContext<Provider>) {
|
|
||||||
async function login({
|
async function login({
|
||||||
query = Mutation.SessionCreate,
|
query = Mutation.SessionCreate,
|
||||||
variables,
|
variables,
|
||||||
@ -22,7 +18,9 @@ export default function loginOperation({
|
|||||||
}): Promise<any> {
|
}): Promise<any> {
|
||||||
config = commerce.getConfig(config)
|
config = commerce.getConfig(config)
|
||||||
|
|
||||||
const { data: { customerAccessTokenCreate } } = await config.fetch(query, { variables })
|
const {
|
||||||
|
data: { customerAccessTokenCreate },
|
||||||
|
} = await config.fetch(query, { variables })
|
||||||
|
|
||||||
throwUserErrors(customerAccessTokenCreate?.customerUserErrors)
|
throwUserErrors(customerAccessTokenCreate?.customerUserErrors)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ export const handler: MutationHook<SignupHook> = {
|
|||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
redirectUrl: 'https://localhost.com',
|
redirectUrl: 'https://localhost.com',
|
||||||
channel: 'default-channel'
|
channel: 'default-channel',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -21,9 +21,9 @@ export const handler = {
|
|||||||
})
|
})
|
||||||
return checkoutToCart(data.checkoutLineDelete)
|
return checkoutToCart(data.checkoutLineDelete)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<RemoveItemHook>) =>
|
||||||
> () => {
|
<T extends LineItem | undefined = undefined>() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
@ -34,6 +34,6 @@ export const handler = {
|
|||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
[fetch, mutate]
|
[fetch, mutate]
|
||||||
);
|
)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,7 @@ export default useUpdateItem as UseUpdateItem<typeof handler>
|
|||||||
|
|
||||||
export const handler = {
|
export const handler = {
|
||||||
fetchOptions: { query: mutation.CheckoutLineUpdate },
|
fetchOptions: { query: mutation.CheckoutLineUpdate },
|
||||||
async fetcher({
|
async fetcher({ input: { itemId, item }, options, fetch }: HookFetcherContext<UpdateItemHook>) {
|
||||||
input: { itemId, item },
|
|
||||||
options,
|
|
||||||
fetch
|
|
||||||
}: HookFetcherContext<UpdateItemHook>) {
|
|
||||||
if (Number.isInteger(item.quantity)) {
|
if (Number.isInteger(item.quantity)) {
|
||||||
// Also allow the update hook to remove an item if the quantity is lower than 1
|
// Also allow the update hook to remove an item if the quantity is lower than 1
|
||||||
if (item.quantity! < 1) {
|
if (item.quantity! < 1) {
|
||||||
@ -59,7 +55,8 @@ export const handler = {
|
|||||||
|
|
||||||
return checkoutToCart(checkoutLinesUpdate)
|
return checkoutToCart(checkoutLinesUpdate)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
useHook:
|
||||||
|
({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
||||||
<T extends LineItem | undefined = undefined>(
|
<T extends LineItem | undefined = undefined>(
|
||||||
ctx: {
|
ctx: {
|
||||||
item?: T
|
item?: T
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
import { Cart } from '../types'
|
import { Cart } from '../types'
|
||||||
import { CommerceError } from '@commerce/utils/errors'
|
import { CommerceError } from '@commerce/utils/errors'
|
||||||
|
|
||||||
import { CheckoutLinesAdd, CheckoutLinesUpdate, CheckoutCreate, CheckoutError, Checkout, Maybe, CheckoutLineDelete } from '../schema'
|
import {
|
||||||
|
CheckoutLinesAdd,
|
||||||
|
CheckoutLinesUpdate,
|
||||||
|
CheckoutCreate,
|
||||||
|
CheckoutError,
|
||||||
|
Checkout,
|
||||||
|
Maybe,
|
||||||
|
CheckoutLineDelete,
|
||||||
|
} from '../schema'
|
||||||
|
|
||||||
import { normalizeCart } from './normalize'
|
import { normalizeCart } from './normalize'
|
||||||
import throwUserErrors from './throw-user-errors'
|
import throwUserErrors from './throw-user-errors'
|
||||||
@ -11,7 +19,12 @@ export type CheckoutQuery = {
|
|||||||
errors?: Array<CheckoutError>
|
errors?: Array<CheckoutError>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CheckoutPayload = CheckoutLinesAdd | CheckoutLinesUpdate | CheckoutCreate | CheckoutQuery | CheckoutLineDelete
|
export type CheckoutPayload =
|
||||||
|
| CheckoutLinesAdd
|
||||||
|
| CheckoutLinesUpdate
|
||||||
|
| CheckoutCreate
|
||||||
|
| CheckoutQuery
|
||||||
|
| CheckoutLineDelete
|
||||||
|
|
||||||
const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
|
const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
|
||||||
if (!checkoutPayload) {
|
if (!checkoutPayload) {
|
||||||
|
@ -38,9 +38,11 @@ export default function getAllPagesOperation({
|
|||||||
preview?: boolean
|
preview?: boolean
|
||||||
query?: string
|
query?: string
|
||||||
} = {}): Promise<T['data']> {
|
} = {}): Promise<T['data']> {
|
||||||
const { fetch, locale, locales = ['en-US', 'es'] } = commerce.getConfig(
|
const {
|
||||||
config
|
fetch,
|
||||||
)
|
locale,
|
||||||
|
locales = ['en-US', 'es'],
|
||||||
|
} = commerce.getConfig(config)
|
||||||
|
|
||||||
const { data } = await fetch<GetAllPagesQuery, GetAllPagesQueryVariables>(
|
const { data } = await fetch<GetAllPagesQuery, GetAllPagesQueryVariables>(
|
||||||
query,
|
query,
|
||||||
|
@ -21,8 +21,7 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
async fetcher({ input: { email, password }, options, fetch }) {
|
async fetcher({ input: { email, password }, options, fetch }) {
|
||||||
if (!(email && password)) {
|
if (!(email && password)) {
|
||||||
throw new CommerceError({
|
throw new CommerceError({
|
||||||
message:
|
message: 'An email and password are required to login',
|
||||||
'An email and password are required to login',
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +46,9 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -22,7 +22,9 @@ export const handler: MutationHook<LogoutHook> = {
|
|||||||
setCustomerToken(null)
|
setCustomerToken(null)
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCustomer()
|
const { mutate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -50,7 +50,9 @@ export const handler: MutationHook<SignupHook> = {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -46,7 +46,9 @@ export const handler: MutationHook<AddItemHook> = {
|
|||||||
|
|
||||||
return checkoutToCart(checkoutLineItemsAdd)
|
return checkoutToCart(checkoutLineItemsAdd)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -37,7 +37,9 @@ export const handler: SWRHook<GetCartHook> = {
|
|||||||
|
|
||||||
return checkoutToCart({ checkout })
|
return checkoutToCart({ checkout })
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
const response = useData({
|
const response = useData({
|
||||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||||
})
|
})
|
||||||
|
@ -41,11 +41,9 @@ export const handler = {
|
|||||||
})
|
})
|
||||||
return checkoutToCart(data.checkoutLineItemsRemove)
|
return checkoutToCart(data.checkoutLineItemsRemove)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<RemoveItemHook>) =>
|
||||||
>(
|
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
|
||||||
ctx: { item?: T } = {}
|
|
||||||
) => {
|
|
||||||
const { item } = ctx
|
const { item } = ctx
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
const removeItem: RemoveItemFn<LineItem> = async (input) => {
|
||||||
|
@ -64,9 +64,9 @@ export const handler = {
|
|||||||
|
|
||||||
return checkoutToCart(checkoutLineItemsUpdate)
|
return checkoutToCart(checkoutLineItemsUpdate)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
||||||
>(
|
<T extends LineItem | undefined = undefined>(
|
||||||
ctx: {
|
ctx: {
|
||||||
item?: T
|
item?: T
|
||||||
wait?: number
|
wait?: number
|
||||||
|
@ -21,7 +21,9 @@ export const handler: SWRHook<CustomerHook> = {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
return useData({
|
return useData({
|
||||||
swrOptions: {
|
swrOptions: {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
|
@ -71,7 +71,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
found: !!products?.length,
|
found: !!products?.length,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input = {}) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input = {}) => {
|
||||||
return useData({
|
return useData({
|
||||||
input: [
|
input: [
|
||||||
['search', input.search],
|
['search', input.search],
|
||||||
|
@ -2,9 +2,8 @@ import { Provider, SwellConfig } from '..'
|
|||||||
import type { OperationContext } from '@commerce/api/operations'
|
import type { OperationContext } from '@commerce/api/operations'
|
||||||
import type { Page } from '../../types/page'
|
import type { Page } from '../../types/page'
|
||||||
|
|
||||||
export type GetAllPagesResult<
|
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
|
||||||
T extends { pages: any[] } = { pages: Page[] }
|
T
|
||||||
> = T
|
|
||||||
|
|
||||||
export default function getAllPagesOperation({
|
export default function getAllPagesOperation({
|
||||||
commerce,
|
commerce,
|
||||||
|
@ -59,7 +59,9 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -22,7 +22,9 @@ export const handler: MutationHook<LogoutHook> = {
|
|||||||
setCustomerToken(null)
|
setCustomerToken(null)
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCustomer()
|
const { mutate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -44,7 +44,9 @@ export const handler: MutationHook<SignupHook> = {
|
|||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -44,7 +44,9 @@ export const handler: MutationHook<AddItemHook> = {
|
|||||||
|
|
||||||
return checkoutToCart(response) as any
|
return checkoutToCart(response) as any
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -17,7 +17,9 @@ export const handler: SWRHook<GetCartHook> = {
|
|||||||
|
|
||||||
return cart ? normalizeCart(cart) : null
|
return cart ? normalizeCart(cart) : null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
const response = useData({
|
const response = useData({
|
||||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||||
})
|
})
|
||||||
|
@ -33,7 +33,9 @@ export const handler = {
|
|||||||
|
|
||||||
return checkoutToCart(response)
|
return checkoutToCart(response)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => () => {
|
useHook:
|
||||||
|
({ fetch }: MutationHookContext<RemoveItemHook>) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -57,9 +57,9 @@ export const handler = {
|
|||||||
|
|
||||||
return checkoutToCart(response)
|
return checkoutToCart(response)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
|
useHook:
|
||||||
T extends LineItem | undefined = undefined
|
({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
||||||
>(
|
<T extends LineItem | undefined = undefined>(
|
||||||
ctx: {
|
ctx: {
|
||||||
item?: T
|
item?: T
|
||||||
wait?: number
|
wait?: number
|
||||||
|
@ -16,7 +16,9 @@ export const handler: SWRHook<CustomerHook> = {
|
|||||||
})
|
})
|
||||||
return data ? normalizeCustomer(data) : null
|
return data ? normalizeCustomer(data) : null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
return useData({
|
return useData({
|
||||||
swrOptions: {
|
swrOptions: {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
|
@ -42,7 +42,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
found,
|
found,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input = {}) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input = {}) => {
|
||||||
return useData({
|
return useData({
|
||||||
input: [
|
input: [
|
||||||
['search', input.search],
|
['search', input.search],
|
||||||
|
@ -4,9 +4,8 @@ import { Provider } from '../../../bigcommerce/api'
|
|||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
|
|
||||||
export type GetAllPagesResult<
|
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
|
||||||
T extends { pages: any[] } = { pages: Page[] }
|
T
|
||||||
> = T
|
|
||||||
|
|
||||||
export default function getAllPagesOperation({
|
export default function getAllPagesOperation({
|
||||||
commerce,
|
commerce,
|
||||||
|
@ -36,7 +36,9 @@ export const handler: MutationHook<LoginHook> = {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -54,7 +54,9 @@ export const handler: MutationHook<SignupHook> = {
|
|||||||
|
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { revalidate } = useCustomer()
|
const { revalidate } = useCustomer()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -37,7 +37,9 @@ export const handler: MutationHook<AddItemHook> = {
|
|||||||
}
|
}
|
||||||
throw new CommerceError(addItemToOrder)
|
throw new CommerceError(addItemToOrder)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -23,7 +23,9 @@ export const handler: SWRHook<GetCartHook> = {
|
|||||||
const { activeOrder } = await fetch<ActiveOrderQuery>(options)
|
const { activeOrder } = await fetch<ActiveOrderQuery>(options)
|
||||||
return activeOrder ? normalizeCart(activeOrder) : null
|
return activeOrder ? normalizeCart(activeOrder) : null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
const response = useData({
|
const response = useData({
|
||||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||||
})
|
})
|
||||||
|
@ -37,7 +37,9 @@ export const handler: MutationHook<RemoveItemHook> = {
|
|||||||
}
|
}
|
||||||
throw new CommerceError(removeOrderLine)
|
throw new CommerceError(removeOrderLine)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }) => () => {
|
useHook:
|
||||||
|
({ fetch }) =>
|
||||||
|
() => {
|
||||||
const { mutate } = useCart()
|
const { mutate } = useCart()
|
||||||
|
|
||||||
return useCallback(
|
return useCallback(
|
||||||
|
@ -42,7 +42,9 @@ export const handler = {
|
|||||||
}
|
}
|
||||||
throw new CommerceError(adjustOrderLine)
|
throw new CommerceError(adjustOrderLine)
|
||||||
},
|
},
|
||||||
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => (
|
useHook:
|
||||||
|
({ fetch }: MutationHookContext<UpdateItemHook>) =>
|
||||||
|
(
|
||||||
ctx: {
|
ctx: {
|
||||||
item?: LineItem
|
item?: LineItem
|
||||||
wait?: number
|
wait?: number
|
||||||
|
@ -22,7 +22,9 @@ export const handler: SWRHook<CustomerHook> = {
|
|||||||
} as any)
|
} as any)
|
||||||
: null
|
: null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input) => {
|
||||||
return useData({
|
return useData({
|
||||||
swrOptions: {
|
swrOptions: {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
|
@ -45,7 +45,9 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
products: search.items.map((item) => normalizeSearchResult(item)) ?? [],
|
products: search.items.map((item) => normalizeSearchResult(item)) ?? [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input = {}) => {
|
useHook:
|
||||||
|
({ useData }) =>
|
||||||
|
(input = {}) => {
|
||||||
return useData({
|
return useData({
|
||||||
input: [
|
input: [
|
||||||
['search', input.search],
|
['search', input.search],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user