mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Simplified cart types for the provider
This commit is contained in:
parent
543054225f
commit
731486e07b
@ -43,36 +43,21 @@ export type CartItemBody = Core.CartItemBody & {
|
||||
optionSelections?: OptionSelections
|
||||
}
|
||||
|
||||
export type CartHooks = Core.CartHooks & {
|
||||
getCart: { data: Cart | null }
|
||||
addItem: {
|
||||
data: Cart
|
||||
body: { item: CartItemBody }
|
||||
input: CartItemBody
|
||||
fetchInput: CartItemBody
|
||||
actionInput: CartItemBody
|
||||
}
|
||||
updateItem: { data: Cart; body: { item: CartItemBody } }
|
||||
removeItem: { data: Cart | null }
|
||||
export type CartTypes = {
|
||||
cart: Cart
|
||||
item: CartItemBody
|
||||
}
|
||||
|
||||
export type CartHooks = Core.CartHooks<CartTypes>
|
||||
|
||||
export type GetCartHook = CartHooks['getCart']
|
||||
export type AddItemHook = CartHooks['addItem']
|
||||
export type UpdateItemHook = CartHooks['updateItem']
|
||||
export type RemoveItemHook = CartHooks['removeItem']
|
||||
|
||||
export type CartSchema = Core.CartSchema & {
|
||||
endpoint: {
|
||||
operations: CartOperations
|
||||
}
|
||||
}
|
||||
export type CartSchema = Core.CartSchema<CartTypes>
|
||||
|
||||
export type CartOperations = {
|
||||
getCart: GetCartHook
|
||||
addItem: AddItemHook
|
||||
updateItem: UpdateItemHook
|
||||
removeItem: RemoveItemHook
|
||||
}
|
||||
export type CartOperations = Core.CartOperations<CartTypes>
|
||||
|
||||
export type GetCartOperation = CartOperations['getCart']
|
||||
export type AddItemOperation = CartOperations['addItem']
|
||||
|
@ -4,9 +4,9 @@ import type { SWRHook, HookFetcherFn } from '../utils/types'
|
||||
import type { GetCartHook } from '../types/cart'
|
||||
import { Provider, useCommerce } from '..'
|
||||
|
||||
export type UseCart<
|
||||
H extends SWRHook<GetCartHook> = SWRHook<GetCartHook>
|
||||
> = ReturnType<H['useHook']>
|
||||
export type UseCart<H extends SWRHook<any> = SWRHook<GetCartHook>> = ReturnType<
|
||||
H['useHook']
|
||||
>
|
||||
|
||||
export const fetcher: HookFetcherFn<GetCartHook> = async ({
|
||||
options,
|
||||
|
@ -85,35 +85,40 @@ export type CartItemBody = {
|
||||
* Hooks schema
|
||||
*/
|
||||
|
||||
export type CartHooks = {
|
||||
getCart: GetCartHook
|
||||
addItem: AddItemHook
|
||||
updateItem: UpdateItemHook
|
||||
remoteItem: RemoveItemHook
|
||||
export type CartTypes = {
|
||||
cart: Cart
|
||||
item: CartItemBody
|
||||
}
|
||||
|
||||
export type GetCartHook = {
|
||||
data: Cart | null
|
||||
export type CartHooks<T extends CartTypes = CartTypes> = {
|
||||
getCart: GetCartHook<T>
|
||||
addItem: AddItemHook<T>
|
||||
updateItem: UpdateItemHook<T>
|
||||
removeItem: RemoveItemHook<T>
|
||||
}
|
||||
|
||||
export type GetCartHook<T extends CartTypes = CartTypes> = {
|
||||
data: T['cart'] | null
|
||||
input: {}
|
||||
fetchInput: { cartId?: string }
|
||||
swrState: { isEmpty: boolean }
|
||||
}
|
||||
|
||||
export type AddItemHook = {
|
||||
data: Cart
|
||||
body: { item: CartItemBody }
|
||||
input: CartItemBody
|
||||
fetchInput: CartItemBody
|
||||
actionInput: CartItemBody
|
||||
export type AddItemHook<T extends CartTypes = CartTypes> = {
|
||||
data: T['cart']
|
||||
body: { item: T['item'] }
|
||||
input: T['item']
|
||||
fetchInput: T['item']
|
||||
actionInput: T['item']
|
||||
}
|
||||
|
||||
export type UpdateItemHook = {
|
||||
data: Cart
|
||||
body: { itemId: string; item: CartItemBody }
|
||||
export type UpdateItemHook<T extends CartTypes = CartTypes> = {
|
||||
data: T['cart']
|
||||
body: { itemId: string; item: T['item'] }
|
||||
}
|
||||
|
||||
export type RemoveItemHook = {
|
||||
data: Cart | null
|
||||
export type RemoveItemHook<T extends CartTypes = CartTypes> = {
|
||||
data: T['cart'] | null
|
||||
body: { itemId: string }
|
||||
}
|
||||
|
||||
@ -121,32 +126,40 @@ export type RemoveItemHook = {
|
||||
* API Schema
|
||||
*/
|
||||
|
||||
export type CartSchema = {
|
||||
export type CartSchema<T extends CartTypes = CartTypes> = {
|
||||
endpoint: {
|
||||
options: {}
|
||||
operations: CartOperations
|
||||
operations: CartOperations<T>
|
||||
}
|
||||
}
|
||||
|
||||
export type CartOperations = {
|
||||
getCart: GetCartOperation
|
||||
addItem: AddItemOperation
|
||||
updateItem: UpdateItemOperation
|
||||
removeItem: RemoveItemOperation
|
||||
export type CartOperations<T extends CartTypes = CartTypes> = {
|
||||
getCart: GetCartOperation<T>
|
||||
addItem: AddItemOperation<T>
|
||||
updateItem: UpdateItemOperation<T>
|
||||
removeItem: RemoveItemOperation<T>
|
||||
}
|
||||
|
||||
export type GetCartOperation = GetCartHook & {
|
||||
export type GetCartOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = GetCartHook<T> & {
|
||||
body: { cartId?: string }
|
||||
}
|
||||
|
||||
export type AddItemOperation = AddItemHook & {
|
||||
export type AddItemOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = AddItemHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
|
||||
export type UpdateItemOperation = UpdateItemHook & {
|
||||
export type UpdateItemOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = UpdateItemHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
|
||||
export type RemoveItemOperation = RemoveItemHook & {
|
||||
export type RemoveItemOperation<
|
||||
T extends CartTypes = CartTypes
|
||||
> = RemoveItemHook<T> & {
|
||||
body: { cartId: string }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user