forked from crowetic/commerce
Run prettier fix on all files (#581)
This commit is contained in:
parent
96e990268d
commit
73470c9232
@ -28,9 +28,16 @@ const UserNav: FC<Props> = ({ className }) => {
|
|||||||
<ul className={s.list}>
|
<ul className={s.list}>
|
||||||
{process.env.COMMERCE_CART_ENABLED && (
|
{process.env.COMMERCE_CART_ENABLED && (
|
||||||
<li className={s.item}>
|
<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 />
|
<Bag />
|
||||||
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>}
|
{itemsCount > 0 && (
|
||||||
|
<span className={s.bagCount}>{itemsCount}</span>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</li>
|
</li>
|
||||||
)}
|
)}
|
||||||
|
@ -44,7 +44,7 @@ const Swatch: React.FC<Omit<ButtonProps, 'variant'> & SwatchProps> = React.memo(
|
|||||||
<Button
|
<Button
|
||||||
role="option"
|
role="option"
|
||||||
aria-selected={active}
|
aria-selected={active}
|
||||||
aria-label={(variant && label) ? `${variant} ${label}` : "Variant Swatch"}
|
aria-label={variant && label ? `${variant} ${label}` : 'Variant Swatch'}
|
||||||
className={swatchClassName}
|
className={swatchClassName}
|
||||||
{...(label && color && { title: label })}
|
{...(label && color && { title: label })}
|
||||||
style={color ? { backgroundColor: color } : {}}
|
style={color ? { backgroundColor: color } : {}}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
@apply pt-1 pb-2 text-2xl font-bold tracking-wide cursor-pointer mb-2;
|
@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.).
|
/* 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. */
|
A helpful addition for whenn page content is consumed from a source managed through a wysiwyg editor. */
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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 (
|
||||||
|
@ -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 (
|
||||||
|
@ -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 (
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export * as Card from "./card"
|
export * as Card from './card'
|
||||||
export * as Address from "./address"
|
export * as Address from './address'
|
||||||
|
|
||||||
// TODO: define this type
|
// TODO: define this type
|
||||||
export type Customer = any
|
export type Customer = any
|
||||||
|
@ -77,9 +77,8 @@ 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 }
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -9,7 +9,10 @@ import addItem from './add-item'
|
|||||||
import updateItem from './update-item'
|
import updateItem from './update-item'
|
||||||
import removeItem from './remove-item'
|
import removeItem from './remove-item'
|
||||||
|
|
||||||
export type CustomerAddressAPI = GetAPISchema<OrdercloudAPI, CustomerAddressSchema>
|
export type CustomerAddressAPI = GetAPISchema<
|
||||||
|
OrdercloudAPI,
|
||||||
|
CustomerAddressSchema
|
||||||
|
>
|
||||||
export type CustomerAddressEndpoint = CustomerAddressAPI['endpoint']
|
export type CustomerAddressEndpoint = CustomerAddressAPI['endpoint']
|
||||||
|
|
||||||
export const handlers: CustomerAddressEndpoint['handlers'] = {
|
export const handlers: CustomerAddressEndpoint['handlers'] = {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { GetPageOperation } from "@commerce/types/page"
|
import { GetPageOperation } from '@commerce/types/page'
|
||||||
|
|
||||||
export type Page = any
|
export type Page = any
|
||||||
export type GetPageResult = { page?: Page }
|
export type GetPageResult = { page?: Page }
|
||||||
|
@ -14,7 +14,7 @@ export const handler: SWRHook<GetCheckoutHook> = {
|
|||||||
},
|
},
|
||||||
useHook: ({ useData }) =>
|
useHook: ({ useData }) =>
|
||||||
function useHook(input) {
|
function useHook(input) {
|
||||||
const submit = useSubmitCheckout();
|
const submit = useSubmitCheckout()
|
||||||
const response = useData({
|
const response = useData({
|
||||||
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
|
||||||
})
|
})
|
||||||
|
@ -2,7 +2,9 @@ import type { SubmitCheckoutHook } from '@commerce/types/checkout'
|
|||||||
import type { MutationHook } from '@commerce/utils/types'
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
|
|
||||||
import { useCallback } from 'react'
|
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>
|
export default useSubmitCheckout as UseSubmitCheckout<typeof handler>
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ export const handler: SWRHook<SearchProductsHook> = {
|
|||||||
// Use a dummy base as we only care about the relative path
|
// Use a dummy base as we only care about the relative path
|
||||||
const url = new URL(options.url!, 'http://a')
|
const url = new URL(options.url!, 'http://a')
|
||||||
|
|
||||||
|
|
||||||
if (search) url.searchParams.set('search', String(search))
|
if (search) url.searchParams.set('search', String(search))
|
||||||
if (categoryId) url.searchParams.set('categoryId', String(categoryId))
|
if (categoryId) url.searchParams.set('categoryId', String(categoryId))
|
||||||
if (brandId) url.searchParams.set('brandId', String(brandId))
|
if (brandId) url.searchParams.set('brandId', String(brandId))
|
||||||
@ -23,13 +22,15 @@ 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],
|
||||||
['categoryId', input.categoryId],
|
['categoryId', input.categoryId],
|
||||||
['brandId', input.brandId],
|
['brandId', input.brandId],
|
||||||
['sort', input.sort]
|
['sort', input.sort],
|
||||||
],
|
],
|
||||||
swrOptions: {
|
swrOptions: {
|
||||||
revalidateOnFocus: false,
|
revalidateOnFocus: false,
|
||||||
|
@ -34,7 +34,7 @@ export const ordercloudProvider = {
|
|||||||
useCart,
|
useCart,
|
||||||
useAddItem: useAddCartItem,
|
useAddItem: useAddCartItem,
|
||||||
useUpdateItem: useUpdateCartItem,
|
useUpdateItem: useUpdateCartItem,
|
||||||
useRemoveItem: useRemoveCartItem
|
useRemoveItem: useRemoveCartItem,
|
||||||
},
|
},
|
||||||
checkout: {
|
checkout: {
|
||||||
useCheckout,
|
useCheckout,
|
||||||
@ -46,14 +46,14 @@ export const ordercloudProvider = {
|
|||||||
useCards,
|
useCards,
|
||||||
useAddItem: useAddCardItem,
|
useAddItem: useAddCardItem,
|
||||||
useUpdateItem: useUpdateCardItem,
|
useUpdateItem: useUpdateCardItem,
|
||||||
useRemoveItem: useRemoveCardItem
|
useRemoveItem: useRemoveCardItem,
|
||||||
},
|
},
|
||||||
address: {
|
address: {
|
||||||
useAddresses,
|
useAddresses,
|
||||||
useAddItem: useAddAddressItem,
|
useAddItem: useAddAddressItem,
|
||||||
useUpdateItem: useUpdateAddressItem,
|
useUpdateItem: useUpdateAddressItem,
|
||||||
useRemoveItem: useRemoveAddressItem
|
useRemoveItem: useRemoveAddressItem,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
products: { useSearch },
|
products: { useSearch },
|
||||||
auth: { useLogin, useLogout, useSignup },
|
auth: { useLogin, useLogout, useSignup },
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
import * as Core from '@commerce/types/customer/address'
|
import * as Core from '@commerce/types/customer/address'
|
||||||
|
|
||||||
export type CustomerAddressTypes = Core.CustomerAddressTypes
|
export type CustomerAddressTypes = Core.CustomerAddressTypes
|
||||||
export type CustomerAddressSchema = Core.CustomerAddressSchema<CustomerAddressTypes>
|
export type CustomerAddressSchema =
|
||||||
|
Core.CustomerAddressSchema<CustomerAddressTypes>
|
||||||
|
|
||||||
export interface OrdercloudAddress {
|
export interface OrdercloudAddress {
|
||||||
ID: string;
|
ID: string
|
||||||
"FromCompanyID": string;
|
FromCompanyID: string
|
||||||
"ToCompanyID": string;
|
ToCompanyID: string
|
||||||
"FromUserID": string;
|
FromUserID: string
|
||||||
"BillingAddressID": null,
|
BillingAddressID: null
|
||||||
"BillingAddress": null,
|
BillingAddress: null
|
||||||
"ShippingAddressID": null,
|
ShippingAddressID: null
|
||||||
"Comments": null,
|
Comments: null
|
||||||
"LineItemCount": number;
|
LineItemCount: number
|
||||||
"Status": string;
|
Status: string
|
||||||
"DateCreated": string;
|
DateCreated: string
|
||||||
"DateSubmitted": null,
|
DateSubmitted: null
|
||||||
"DateApproved": null,
|
DateApproved: null
|
||||||
"DateDeclined": null,
|
DateDeclined: null
|
||||||
"DateCanceled": null,
|
DateCanceled: null
|
||||||
"DateCompleted": null,
|
DateCompleted: null
|
||||||
"LastUpdated": string;
|
LastUpdated: string
|
||||||
"Subtotal": number
|
Subtotal: number
|
||||||
"ShippingCost": number
|
ShippingCost: number
|
||||||
"TaxCost": number
|
TaxCost: number
|
||||||
"PromotionDiscount": number
|
PromotionDiscount: number
|
||||||
"Total": number
|
Total: number
|
||||||
"IsSubmitted": false,
|
IsSubmitted: false
|
||||||
"xp": null
|
xp: null
|
||||||
}
|
}
|
||||||
|
@ -4,13 +4,13 @@ export type CustomerCardTypes = Core.CustomerCardTypes
|
|||||||
export type CustomerCardSchema = Core.CustomerCardSchema<CustomerCardTypes>
|
export type CustomerCardSchema = Core.CustomerCardSchema<CustomerCardTypes>
|
||||||
|
|
||||||
export interface OredercloudCreditCard {
|
export interface OredercloudCreditCard {
|
||||||
"ID": string;
|
ID: string
|
||||||
"Editable": boolean;
|
Editable: boolean
|
||||||
"Token": string;
|
Token: string
|
||||||
"DateCreated": string;
|
DateCreated: string
|
||||||
"CardType": string;
|
CardType: string
|
||||||
"PartialAccountNumber": string;
|
PartialAccountNumber: string
|
||||||
"CardholderName": string;
|
CardholderName: string
|
||||||
"ExpirationDate": string;
|
ExpirationDate: string
|
||||||
"xp": null
|
xp: null
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -8,17 +8,14 @@ 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({
|
export default function getPageOperation({ commerce }: OperationContext<Provider>) {
|
||||||
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(
|
||||||
|
@ -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