Run prettier fix on all files (#581)

This commit is contained in:
Gonzalo Pozzo 2021-11-25 09:17:13 -03:00 committed by GitHub
parent 96e990268d
commit 73470c9232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 904 additions and 845 deletions

View File

@ -28,9 +28,16 @@ const UserNav: FC<Props> = ({ className }) => {
<ul className={s.list}>
{process.env.COMMERCE_CART_ENABLED && (
<li className={s.item}>
<Button className={s.item} variant="naked" onClick={toggleSidebar} aria-label={`Cart items: ${itemsCount}`}>
<Button
className={s.item}
variant="naked"
onClick={toggleSidebar}
aria-label={`Cart items: ${itemsCount}`}
>
<Bag />
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>}
{itemsCount > 0 && (
<span className={s.bagCount}>{itemsCount}</span>
)}
</Button>
</li>
)}

View File

@ -44,7 +44,7 @@ const Swatch: React.FC<Omit<ButtonProps, 'variant'> & SwatchProps> = React.memo(
<Button
role="option"
aria-selected={active}
aria-label={(variant && label) ? `${variant} ${label}` : "Variant Swatch"}
aria-label={variant && label ? `${variant} ${label}` : 'Variant Swatch'}
className={swatchClassName}
{...(label && color && { title: label })}
style={color ? { backgroundColor: color } : {}}

View File

@ -14,7 +14,6 @@
@apply pt-1 pb-2 text-2xl font-bold tracking-wide cursor-pointer mb-2;
}
/* Apply base font sizes and styles for typography markup (h2, h2, ul, p, etc.).
A helpful addition for whenn page content is consumed from a source managed through a wysiwyg editor. */

View File

@ -24,11 +24,8 @@ export const getLoggedInCustomerQuery = /* GraphQL */ `
export type Customer = NonNullable<GetLoggedInCustomerQuery['customer']>
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] = async ({
req,
res,
config,
}) => {
const getLoggedInCustomer: CustomerEndpoint['handlers']['getLoggedInCustomer'] =
async ({ req, res, config }) => {
const token = req.cookies[config.customerCookie]
if (token) {

View File

@ -15,8 +15,7 @@ export const handler: MutationHook<LoginHook> = {
async fetcher({ input: { email, password }, options, fetch }) {
if (!(email && password)) {
throw new CommerceError({
message:
'An email and password are required to login',
message: 'An email and password are required to login',
})
}
@ -25,7 +24,9 @@ export const handler: MutationHook<LoginHook> = {
body: { email, password },
})
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -11,7 +11,9 @@ export const handler: MutationHook<LogoutHook> = {
url: '/api/logout',
method: 'GET',
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCustomer()
return useCallback(

View File

@ -29,7 +29,9 @@ export const handler: MutationHook<SignupHook> = {
body: { firstName, lastName, email, password },
})
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -29,7 +29,9 @@ export const handler: MutationHook<AddItemHook> = {
return data
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()
return useCallback(

View File

@ -10,7 +10,9 @@ export const handler: SWRHook<GetCartHook> = {
url: '/api/cart',
method: 'GET',
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

View File

@ -30,11 +30,9 @@ export const handler = {
}: HookFetcherContext<RemoveItemHook>) {
return await fetch({ ...options, body: { itemId } })
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
T extends LineItem | undefined = undefined
>(
ctx: { item?: T } = {}
) => {
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {

View File

@ -46,9 +46,9 @@ export const handler = {
body: { itemId, item },
})
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
T extends LineItem | undefined = undefined
>(
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
<T extends LineItem | undefined = undefined>(
ctx: {
item?: T
wait?: number

View File

@ -13,7 +13,9 @@ export const handler: SWRHook<CustomerHook> = {
const data = await fetch(options)
return data?.customer ?? null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,

View File

@ -8,11 +8,7 @@ import getSlug from './get-slug'
function normalizeProductOption(productOption: any) {
const {
node: {
entityId,
values: { edges = [] } = {},
...rest
},
node: { entityId, values: { edges = [] } = {}, ...rest },
} = productOption
return {

View File

@ -33,7 +33,9 @@ export const handler: SWRHook<SearchProductsHook> = {
method: options.method,
})
},
useHook: ({ useData }) => (input = {}) => {
useHook:
({ useData }) =>
(input = {}) => {
return useData({
input: [
['search', input.search],

View File

@ -20,4 +20,5 @@ export type WishlistTypes = {
}
export type WishlistSchema = Core.WishlistSchema<WishlistTypes>
export type GetCustomerWishlistOperation = Core.GetCustomerWishlistOperation<WishlistTypes>
export type GetCustomerWishlistOperation =
Core.GetCustomerWishlistOperation<WishlistTypes>

View File

@ -13,7 +13,9 @@ export const handler: MutationHook<AddItemHook> = {
url: '/api/wishlist',
method: 'POST',
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { data: customer } = useCustomer()
const { revalidate } = useWishlist()

View File

@ -15,7 +15,9 @@ export const handler: MutationHook<RemoveItemHook> = {
url: '/api/wishlist',
method: 'DELETE',
},
useHook: ({ fetch }) => ({ wishlist } = {}) => {
useHook:
({ fetch }) =>
({ wishlist } = {}) => {
const { data: customer } = useCustomer()
const { revalidate } = useWishlist(wishlist)

View File

@ -24,7 +24,9 @@ export const handler: SWRHook<GetWishlistHook> = {
method: options.method,
})
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
const { data: customer } = useCustomer()
const response = useData({
input: [

View File

@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
import isAllowedOperation from '../utils/is-allowed-operation'
import type { GetAPISchema } from '..'
const cartEndpoint: GetAPISchema<
any,
CartSchema<any>
>['endpoint']['handler'] = async (ctx) => {
const cartEndpoint: GetAPISchema<any, CartSchema<any>>['endpoint']['handler'] =
async (ctx) => {
const { req, res, handlers, config } = ctx
if (

View File

@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
import isAllowedOperation from '../utils/is-allowed-operation'
import type { GetAPISchema } from '..'
const logoutEndpoint: GetAPISchema<
any,
LogoutSchema
>['endpoint']['handler'] = async (ctx) => {
const logoutEndpoint: GetAPISchema<any, LogoutSchema>['endpoint']['handler'] =
async (ctx) => {
const { req, res, handlers } = ctx
if (

View File

@ -3,10 +3,8 @@ import { CommerceAPIError } from '../utils/errors'
import isAllowedOperation from '../utils/is-allowed-operation'
import type { GetAPISchema } from '..'
const signupEndpoint: GetAPISchema<
any,
SignupSchema
>['endpoint']['handler'] = async (ctx) => {
const signupEndpoint: GetAPISchema<any, SignupSchema>['endpoint']['handler'] =
async (ctx) => {
const { req, res, handlers, config } = ctx
if (

View File

@ -1,5 +1,5 @@
export * as Card from "./card"
export * as Address from "./address"
export * as Card from './card'
export * as Address from './address'
// TODO: define this type
export type Customer = any

View File

@ -77,9 +77,8 @@ export type ProductsSchema<T extends ProductTypes = ProductTypes> = {
}
}
export type GetAllProductPathsOperation<
T extends ProductTypes = ProductTypes
> = {
export type GetAllProductPathsOperation<T extends ProductTypes = ProductTypes> =
{
data: { products: Pick<T['product'], 'path'>[] }
variables: { first?: number }
}

View File

@ -11,8 +11,10 @@ type InferValue<Prop extends PropertyKey, Desc> = Desc extends {
? Record<Prop, T>
: never
type DefineProperty<Prop extends PropertyKey, Desc extends PropertyDescriptor> =
Desc extends { writable: any; set(val: any): any }
type DefineProperty<
Prop extends PropertyKey,
Desc extends PropertyDescriptor
> = Desc extends { writable: any; set(val: any): any }
? never
: Desc extends { writable: any; get(): any }
? never

View File

@ -9,7 +9,10 @@ import addItem from './add-item'
import updateItem from './update-item'
import removeItem from './remove-item'
export type CustomerAddressAPI = GetAPISchema<OrdercloudAPI, CustomerAddressSchema>
export type CustomerAddressAPI = GetAPISchema<
OrdercloudAPI,
CustomerAddressSchema
>
export type CustomerAddressEndpoint = CustomerAddressAPI['endpoint']
export const handlers: CustomerAddressEndpoint['handlers'] = {

View File

@ -1,4 +1,4 @@
import { GetPageOperation } from "@commerce/types/page"
import { GetPageOperation } from '@commerce/types/page'
export type Page = any
export type GetPageResult = { page?: Page }

View File

@ -14,7 +14,7 @@ export const handler: SWRHook<GetCheckoutHook> = {
},
useHook: ({ useData }) =>
function useHook(input) {
const submit = useSubmitCheckout();
const submit = useSubmitCheckout()
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

View File

@ -2,7 +2,9 @@ import type { SubmitCheckoutHook } from '@commerce/types/checkout'
import type { MutationHook } from '@commerce/utils/types'
import { useCallback } from 'react'
import useSubmitCheckout, { UseSubmitCheckout } from '@commerce/checkout/use-submit-checkout'
import useSubmitCheckout, {
UseSubmitCheckout,
} from '@commerce/checkout/use-submit-checkout'
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>

View File

@ -12,7 +12,6 @@ export const handler: SWRHook<SearchProductsHook> = {
// Use a dummy base as we only care about the relative path
const url = new URL(options.url!, 'http://a')
if (search) url.searchParams.set('search', String(search))
if (categoryId) url.searchParams.set('categoryId', String(categoryId))
if (brandId) url.searchParams.set('brandId', String(brandId))
@ -23,13 +22,15 @@ export const handler: SWRHook<SearchProductsHook> = {
method: options.method,
})
},
useHook: ({ useData }) => (input = {}) => {
useHook:
({ useData }) =>
(input = {}) => {
return useData({
input: [
['search', input.search],
['categoryId', input.categoryId],
['brandId', input.brandId],
['sort', input.sort]
['sort', input.sort],
],
swrOptions: {
revalidateOnFocus: false,

View File

@ -34,7 +34,7 @@ export const ordercloudProvider = {
useCart,
useAddItem: useAddCartItem,
useUpdateItem: useUpdateCartItem,
useRemoveItem: useRemoveCartItem
useRemoveItem: useRemoveCartItem,
},
checkout: {
useCheckout,
@ -46,14 +46,14 @@ export const ordercloudProvider = {
useCards,
useAddItem: useAddCardItem,
useUpdateItem: useUpdateCardItem,
useRemoveItem: useRemoveCardItem
useRemoveItem: useRemoveCardItem,
},
address: {
useAddresses,
useAddItem: useAddAddressItem,
useUpdateItem: useUpdateAddressItem,
useRemoveItem: useRemoveAddressItem
}
useRemoveItem: useRemoveAddressItem,
},
},
products: { useSearch },
auth: { useLogin, useLogout, useSignup },

View File

@ -1,31 +1,32 @@
import * as Core from '@commerce/types/customer/address'
export type CustomerAddressTypes = Core.CustomerAddressTypes
export type CustomerAddressSchema = Core.CustomerAddressSchema<CustomerAddressTypes>
export type CustomerAddressSchema =
Core.CustomerAddressSchema<CustomerAddressTypes>
export interface OrdercloudAddress {
ID: string;
"FromCompanyID": string;
"ToCompanyID": string;
"FromUserID": string;
"BillingAddressID": null,
"BillingAddress": null,
"ShippingAddressID": null,
"Comments": null,
"LineItemCount": number;
"Status": string;
"DateCreated": string;
"DateSubmitted": null,
"DateApproved": null,
"DateDeclined": null,
"DateCanceled": null,
"DateCompleted": null,
"LastUpdated": string;
"Subtotal": number
"ShippingCost": number
"TaxCost": number
"PromotionDiscount": number
"Total": number
"IsSubmitted": false,
"xp": null
ID: string
FromCompanyID: string
ToCompanyID: string
FromUserID: string
BillingAddressID: null
BillingAddress: null
ShippingAddressID: null
Comments: null
LineItemCount: number
Status: string
DateCreated: string
DateSubmitted: null
DateApproved: null
DateDeclined: null
DateCanceled: null
DateCompleted: null
LastUpdated: string
Subtotal: number
ShippingCost: number
TaxCost: number
PromotionDiscount: number
Total: number
IsSubmitted: false
xp: null
}

View File

@ -4,13 +4,13 @@ export type CustomerCardTypes = Core.CustomerCardTypes
export type CustomerCardSchema = Core.CustomerCardSchema<CustomerCardTypes>
export interface OredercloudCreditCard {
"ID": string;
"Editable": boolean;
"Token": string;
"DateCreated": string;
"CardType": string;
"PartialAccountNumber": string;
"CardholderName": string;
"ExpirationDate": string;
"xp": null
ID: string
Editable: boolean
Token: string
DateCreated: string
CardType: string
PartialAccountNumber: string
CardholderName: string
ExpirationDate: string
xp: null
}

View File

@ -6,14 +6,9 @@ import * as Query from '../../utils/queries'
export type Page = any
export type GetAllPagesResult<
T extends { pages: any[] } = { pages: Page[] }
> = T
export default function getAllPagesOperation({
commerce,
}: OperationContext<Provider>) {
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> = T
export default function getAllPagesOperation({ commerce }: OperationContext<Provider>) {
async function getAllPages({
query = Query.PageMany,
config,
@ -27,7 +22,9 @@ export default function getAllPagesOperation({
} = {}): Promise<GetAllPagesResult> {
const { fetch, locale, locales = ['en-US'] } = commerce.getConfig(config)
const { data } = await fetch(query, { variables },
const { data } = await fetch(
query,
{ variables },
{
...(locale && {
headers: {

View File

@ -12,9 +12,7 @@ type ReturnType = {
products: Product[]
}
export default function getAllProductsOperation({
commerce,
}: OperationContext<Provider>) {
export default function getAllProductsOperation({ commerce }: OperationContext<Provider>) {
async function getAllProducts({
query = Query.ProductMany,
variables,
@ -30,11 +28,10 @@ export default function getAllProductsOperation({
const { fetch, locale } = commerce.getConfig(config)
if (featured) {
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' };
variables = { ...variables, categoryId: 'Q29sbGVjdGlvbjo0' }
query = Query.CollectionOne
}
const { data }: GraphQLFetcherResult = await fetch(
query,
{ variables },
@ -48,7 +45,8 @@ export default function getAllProductsOperation({
)
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 {
products,
@ -60,7 +58,6 @@ export default function getAllProductsOperation({
products,
}
}
}
return getAllProducts

View File

@ -8,17 +8,14 @@ export type Page = any
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({
query = Query.PageOne,
variables,
config,
}: {
query?: string
variables: QueryPageArgs,
variables: QueryPageArgs
config?: Partial<SaleorConfig>
preview?: boolean
}): Promise<GetPageResult> {
@ -26,7 +23,9 @@ export default function getPageOperation({
const {
data: { page },
} = await fetch(query, { variables },
} = await fetch(
query,
{ variables },
{
...(locale && {
headers: {

View File

@ -1,5 +1,5 @@
import type { OperationContext } from '@commerce/api/operations'
import { normalizeProduct, } from '../../utils'
import { normalizeProduct } from '../../utils'
import type { Provider, SaleorConfig } from '..'
import * as Query from '../../utils/queries'
@ -12,9 +12,7 @@ type ReturnType = {
product: any
}
export default function getProductOperation({
commerce,
}: OperationContext<Provider>) {
export default function getProductOperation({ commerce }: OperationContext<Provider>) {
async function getProduct({
query = Query.ProductOneBySlug,
variables,
@ -27,7 +25,9 @@ export default function getProductOperation({
}): Promise<ReturnType> {
const { fetch, locale } = commerce.getConfig(cfg)
const { data } = await fetch(query, { variables },
const { data } = await fetch(
query,
{ variables },
{
...(locale && {
headers: {

View File

@ -1,15 +1,11 @@
import type { ServerResponse } from 'http'
import type { OperationContext } from '@commerce/api/operations'
import type { Provider, SaleorConfig } from '..'
import {
throwUserErrors,
} from '../../utils'
import { throwUserErrors } from '../../utils'
import * as Mutation from '../../utils/mutations'
export default function loginOperation({
commerce,
}: OperationContext<Provider>) {
export default function loginOperation({ commerce }: OperationContext<Provider>) {
async function login({
query = Mutation.SessionCreate,
variables,
@ -22,7 +18,9 @@ export default function loginOperation({
}): Promise<any> {
config = commerce.getConfig(config)
const { data: { customerAccessTokenCreate } } = await config.fetch(query, { variables })
const {
data: { customerAccessTokenCreate },
} = await config.fetch(query, { variables })
throwUserErrors(customerAccessTokenCreate?.customerUserErrors)

View File

@ -29,7 +29,7 @@ export const handler: MutationHook<SignupHook> = {
email,
password,
redirectUrl: 'https://localhost.com',
channel: 'default-channel'
channel: 'default-channel',
},
},
})

View File

@ -21,9 +21,9 @@ export const handler = {
})
return checkoutToCart(data.checkoutLineDelete)
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
T extends LineItem | undefined = undefined
> () => {
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
<T extends LineItem | undefined = undefined>() => {
const { mutate } = useCart()
return useCallback(
@ -34,6 +34,6 @@ export const handler = {
return data
},
[fetch, mutate]
);
)
},
}

View File

@ -23,11 +23,7 @@ export default useUpdateItem as UseUpdateItem<typeof handler>
export const handler = {
fetchOptions: { query: mutation.CheckoutLineUpdate },
async fetcher({
input: { itemId, item },
options,
fetch
}: HookFetcherContext<UpdateItemHook>) {
async fetcher({ input: { itemId, item }, options, fetch }: HookFetcherContext<UpdateItemHook>) {
if (Number.isInteger(item.quantity)) {
// Also allow the update hook to remove an item if the quantity is lower than 1
if (item.quantity! < 1) {
@ -59,7 +55,8 @@ export const handler = {
return checkoutToCart(checkoutLinesUpdate)
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) =>
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
<T extends LineItem | undefined = undefined>(
ctx: {
item?: T

View File

@ -1,7 +1,15 @@
import { Cart } from '../types'
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 throwUserErrors from './throw-user-errors'
@ -11,7 +19,12 @@ export type CheckoutQuery = {
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 => {
if (!checkoutPayload) {

View File

@ -38,9 +38,11 @@ export default function getAllPagesOperation({
preview?: boolean
query?: string
} = {}): Promise<T['data']> {
const { fetch, locale, locales = ['en-US', 'es'] } = commerce.getConfig(
config
)
const {
fetch,
locale,
locales = ['en-US', 'es'],
} = commerce.getConfig(config)
const { data } = await fetch<GetAllPagesQuery, GetAllPagesQueryVariables>(
query,

View File

@ -21,8 +21,7 @@ export const handler: MutationHook<LoginHook> = {
async fetcher({ input: { email, password }, options, fetch }) {
if (!(email && password)) {
throw new CommerceError({
message:
'An email and password are required to login',
message: 'An email and password are required to login',
})
}
@ -47,7 +46,9 @@ export const handler: MutationHook<LoginHook> = {
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -22,7 +22,9 @@ export const handler: MutationHook<LogoutHook> = {
setCustomerToken(null)
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCustomer()
return useCallback(

View File

@ -50,7 +50,9 @@ export const handler: MutationHook<SignupHook> = {
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -41,11 +41,9 @@ export const handler = {
})
return checkoutToCart(data.checkoutLineItemsRemove)
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
T extends LineItem | undefined = undefined
>(
ctx: { item?: T } = {}
) => {
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {

View File

@ -64,9 +64,9 @@ export const handler = {
return checkoutToCart(checkoutLineItemsUpdate)
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
T extends LineItem | undefined = undefined
>(
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
<T extends LineItem | undefined = undefined>(
ctx: {
item?: T
wait?: number

View File

@ -21,7 +21,9 @@ export const handler: SWRHook<CustomerHook> = {
}
return null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,

View File

@ -71,7 +71,9 @@ export const handler: SWRHook<SearchProductsHook> = {
found: !!products?.length,
}
},
useHook: ({ useData }) => (input = {}) => {
useHook:
({ useData }) =>
(input = {}) => {
return useData({
input: [
['search', input.search],

View File

@ -2,9 +2,8 @@ import { Provider, SwellConfig } from '..'
import type { OperationContext } from '@commerce/api/operations'
import type { Page } from '../../types/page'
export type GetAllPagesResult<
T extends { pages: any[] } = { pages: Page[] }
> = T
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
T
export default function getAllPagesOperation({
commerce,

View File

@ -59,7 +59,9 @@ export const handler: MutationHook<LoginHook> = {
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -22,7 +22,9 @@ export const handler: MutationHook<LogoutHook> = {
setCustomerToken(null)
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCustomer()
return useCallback(

View File

@ -44,7 +44,9 @@ export const handler: MutationHook<SignupHook> = {
} catch (error) {}
return data
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -44,7 +44,9 @@ export const handler: MutationHook<AddItemHook> = {
return checkoutToCart(response) as any
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()
return useCallback(

View File

@ -17,7 +17,9 @@ export const handler: SWRHook<GetCartHook> = {
return cart ? normalizeCart(cart) : null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

View File

@ -33,7 +33,9 @@ export const handler = {
return checkoutToCart(response)
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => () => {
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
() => {
const { mutate } = useCart()
return useCallback(

View File

@ -57,9 +57,9 @@ export const handler = {
return checkoutToCart(response)
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
T extends LineItem | undefined = undefined
>(
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
<T extends LineItem | undefined = undefined>(
ctx: {
item?: T
wait?: number

View File

@ -16,7 +16,9 @@ export const handler: SWRHook<CustomerHook> = {
})
return data ? normalizeCustomer(data) : null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,

View File

@ -42,7 +42,9 @@ export const handler: SWRHook<SearchProductsHook> = {
found,
}
},
useHook: ({ useData }) => (input = {}) => {
useHook:
({ useData }) =>
(input = {}) => {
return useData({
input: [
['search', input.search],

View File

@ -4,9 +4,8 @@ import { Provider } from '../../../bigcommerce/api'
export type Page = any
export type GetAllPagesResult<
T extends { pages: any[] } = { pages: Page[] }
> = T
export type GetAllPagesResult<T extends { pages: any[] } = { pages: Page[] }> =
T
export default function getAllPagesOperation({
commerce,

View File

@ -36,7 +36,9 @@ export const handler: MutationHook<LoginHook> = {
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -54,7 +54,9 @@ export const handler: MutationHook<SignupHook> = {
return null
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { revalidate } = useCustomer()
return useCallback(

View File

@ -37,7 +37,9 @@ export const handler: MutationHook<AddItemHook> = {
}
throw new CommerceError(addItemToOrder)
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()
return useCallback(

View File

@ -23,7 +23,9 @@ export const handler: SWRHook<GetCartHook> = {
const { activeOrder } = await fetch<ActiveOrderQuery>(options)
return activeOrder ? normalizeCart(activeOrder) : null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

View File

@ -37,7 +37,9 @@ export const handler: MutationHook<RemoveItemHook> = {
}
throw new CommerceError(removeOrderLine)
},
useHook: ({ fetch }) => () => {
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()
return useCallback(

View File

@ -42,7 +42,9 @@ export const handler = {
}
throw new CommerceError(adjustOrderLine)
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => (
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
(
ctx: {
item?: LineItem
wait?: number

View File

@ -22,7 +22,9 @@ export const handler: SWRHook<CustomerHook> = {
} as any)
: null
},
useHook: ({ useData }) => (input) => {
useHook:
({ useData }) =>
(input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,

View File

@ -45,7 +45,9 @@ export const handler: SWRHook<SearchProductsHook> = {
products: search.items.map((item) => normalizeSearchResult(item)) ?? [],
}
},
useHook: ({ useData }) => (input = {}) => {
useHook:
({ useData }) =>
(input = {}) => {
return useData({
input: [
['search', input.search],