Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0924904
Add Reaction Commerce provider
loan-laux Mar 30, 2021
5f1c341
Add missing empty wishlist hooks
loan-laux Mar 30, 2021
0709e5e
create codegen file for provider
CristianCucunuba Mar 31, 2021
8d68add
Merge pull request #1 from CristianCucunuba/add-codegen
loan-laux Mar 31, 2021
49bd38f
replace customer query with viewer
loan-laux Mar 31, 2021
d614e81
fix types for normalize products
CristianCucunuba Apr 7, 2021
8f260d6
implement login
loan-laux Apr 23, 2021
12a9610
add logout
loan-laux Apr 23, 2021
652a454
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux Apr 26, 2021
946545b
add fallback value for variant price
loan-laux Apr 26, 2021
25ba1f1
implement account-tied carts and cart reconciliation
loan-laux Apr 27, 2021
3563e93
implement sign-up
loan-laux Apr 27, 2021
f52978e
fix cart update and add API calls to work for logged-in users
loan-laux Apr 27, 2021
3496b2a
rename checkoutCreate to createCart and remove Shopify checkout API
loan-laux Apr 27, 2021
e5d410e
remove last usage of SHOPIFY_CHECKOUT_URL
loan-laux Apr 27, 2021
ea9cfe9
reconcile carts on add-item if needed
loan-laux Apr 27, 2021
254659e
normalize data output in use-customer
loan-laux Apr 28, 2021
805100a
remove unused handleLogin util
loan-laux Apr 28, 2021
ffe33d6
remove/update Shopify wording in vars
loan-laux Apr 28, 2021
4ac8ea2
overall clean up
loan-laux Apr 28, 2021
9d485ba
Merge branch 'outgrow-reaction-commerce-provider' of github.com:outgr…
CristianCucunuba Apr 28, 2021
a0f4ab6
fix: merge conflicts
CristianCucunuba Apr 28, 2021
b125f9f
Merge pull request #2 from CristianCucunuba/fix-types
loan-laux May 5, 2021
d5804d6
update wording for Reaction API URL const/env var
loan-laux May 5, 2021
6f0dfb7
fix some option types and pass REACTION_API_DOMAIN to front-end
loan-laux May 10, 2021
76bb0c7
add searchQuery
loan-laux May 12, 2021
b5559cc
use minPrice for display price
loan-laux May 12, 2021
16e4750
update codegen to include new vendors query and implement vendors query
loan-laux May 14, 2021
3112c7f
WIP pages implementation & fix add to cart variant ID bug
loan-laux May 17, 2021
fb11238
Implement product attributes (variants)
tedraykov May 21, 2021
c6df70c
Graphql codegen change
tedraykov May 23, 2021
7d1a226
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux May 24, 2021
f933d66
Merge remote-tracking branch 'origin/outgrow-reaction-commerce-provid…
tedraykov May 25, 2021
081a9a5
Trailing commas, null checks, formatting
tedraykov May 25, 2021
7de1c37
Merge pull request #3 from tedraykov/outgrow-reaction-commerce-provider
loan-laux May 25, 2021
1332345
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux May 27, 2021
94c04bf
Merge branch 'outgrow-reaction-commerce-provider' of github.com:outgr…
loan-laux May 27, 2021
55c4d7c
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux May 28, 2021
92179b3
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux Jun 1, 2021
8dc6881
Merge branch 'master' of github.com:vercel/commerce into outgrow-reac…
loan-laux Jun 14, 2021
23e0d57
Move API to new Node architecture
loan-laux Jul 6, 2021
ad1547a
Refactor API for getProduct and getAllProductPaths
loan-laux Jul 6, 2021
3001611
Add catalogItems API method
loan-laux Jul 6, 2021
36efe7e
Merge branch 'main' of github.com:vercel/commerce into outgrow-reacti…
loan-laux Jul 6, 2021
aa65a9b
refactor catalog products API method
loan-laux Jul 6, 2021
2160264
enable customerAuth
loan-laux Jul 7, 2021
c2c43b7
refactor category and brand filtering logic
loan-laux Jul 7, 2021
4d48c51
pass pricing to addItem call for verification and update cart API URL
loan-laux Jul 7, 2021
07dfc21
remove console.log statement
loan-laux Jul 8, 2021
f5cdc66
Merge branch 'main' of github.com:vercel/commerce into outgrow-reacti…
loan-laux Jul 30, 2021
b79a3cd
use Stripe.js payment input fields
loan-laux Jul 30, 2021
0ab3a97
add payment method state management
loan-laux Aug 2, 2021
45c5b52
add shipping address state management and country list
loan-laux Aug 4, 2021
fb1fa86
revert to trash icon on payment widget
loan-laux Aug 4, 2021
2943168
add useAddShippingAddress hook + add phone and region fields in address
loan-laux Aug 5, 2021
894f133
add support for displaying taxes
loan-laux Aug 10, 2021
eced304
Merge branch 'main' of github.com:vercel/commerce into outgrow-reacti…
loan-laux Mar 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/commerce/src/api/endpoints/customer/card.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { CustomerCardSchema } from '../../../types/customer/card'
import type { GetAPISchema } from '../..'

import { CommerceAPIError } from '../../utils/errors'
import isAllowedOperation from '../../utils/is-allowed-operation'

Expand Down Expand Up @@ -60,6 +59,5 @@ const customerCardEndpoint: GetAPISchema<

res.status(500).json({ data: null, errors: [{ message }] })
}
}

export default customerCardEndpoint
6 changes: 2 additions & 4 deletions packages/commerce/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,8 @@ export type EndpointSchemaBase = {
}
}

export type Endpoint<
C extends CommerceAPI,
E extends EndpointSchemaBase
> = APIEndpoint<C, EndpointHandlers<C, E>, any, E['options']>
export type Endpoint<C extends CommerceAPI, E extends EndpointSchemaBase> =
APIEndpoint<C, EndpointHandlers<C, E>, any, E['options']>

export type EndpointHandlers<
C extends CommerceAPI,
Expand Down
20 changes: 20 additions & 0 deletions packages/commerce/src/cart/use-add-shipping-address.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useHook, useMutationHook } from '../utils/use-hook'
import { mutationFetcher } from '../utils/default-fetcher'
import type { HookFetcherFn, MutationHook } from '../utils/types'
import type { AddShippingAddressHook } from '../types/cart'
import type { Provider } from '..'

export type UseAddShippingAddress<
H extends MutationHook<AddShippingAddressHook<any>> = MutationHook<AddShippingAddressHook>
> = ReturnType<H['useHook']>

export const fetcher: HookFetcherFn<AddShippingAddressHook> = mutationFetcher

const fn = (provider: Provider) => provider.cart?.useAddShippingAddress!

const useRemoveItem: UseAddShippingAddress = (input) => {
const hook = useHook(fn)
return useMutationHook({ fetcher, ...hook })(input)
}

export default useRemoveItem
1 change: 1 addition & 0 deletions packages/commerce/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Provider = CommerceConfig & {
cart?: {
useCart?: SWRHook<Cart.GetCartHook>
useAddItem?: MutationHook<Cart.AddItemHook>
useAddShippingAddress?: MutationHook<Cart.AddShippingAddressHook>
useUpdateItem?: MutationHook<Cart.UpdateItemHook>
useRemoveItem?: MutationHook<Cart.RemoveItemHook>
}
Expand Down
30 changes: 30 additions & 0 deletions packages/commerce/src/types/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type ProductVariant = {
// The variant's depth. If a depth was not explicitly specified on the
// variant, this will be the product's depth.
depth?: Measurement
options: ProductOption[]
}

// Shopping cart, a.k.a Checkout
Expand All @@ -80,6 +81,8 @@ export type Cart = {
totalPrice: number
// Discounts that have been applied on the cart.
discounts?: Discount[]
// The total for taxes
taxes?: number
}

/**
Expand All @@ -89,6 +92,24 @@ export type CartItemBody = {
variantId: string
productId?: string
quantity?: number
pricing?: {
amount: number
currencyCode: string
}
}

export type Address = {
cardholderName: string
firstName: string
lastName: string
company: string
addressLine1: string
addressLine2: string
postalCode: string
city: string
region: string
country: string
phone: string
}

/**
Expand All @@ -99,6 +120,7 @@ export type CartTypes = {
cart?: Cart
item: LineItem
itemBody: CartItemBody
address: Address
}

export type CartHooks<T extends CartTypes = CartTypes> = {
Expand Down Expand Up @@ -139,6 +161,14 @@ export type RemoveItemHook<T extends CartTypes = CartTypes> = {
actionInput: { id: string }
}

export type AddShippingAddressHook<T extends CartTypes = CartTypes> = {
data: T['cart'] | null
input: { address?: T['address'] }
fetcherInput: { address: Address }
body: { itemId: string }
actionInput: { id: string }
}

/**
* API Schema
*/
Expand Down
24 changes: 13 additions & 11 deletions packages/kibocommerce/src/cart/use-add-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ export const handler: MutationHook<AddItemHook> = {

return data
},
useHook: ({ fetch }) => () => {
const { mutate } = useCart()
useHook:
({ fetch }) =>
() => {
const { mutate } = useCart()

return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
return useCallback(
async function addItem(input) {
const data = await fetch({ input })
await mutate(data, false)
return data
},
[fetch, mutate]
)
},
}
34 changes: 18 additions & 16 deletions packages/kibocommerce/src/cart/use-cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ export const handler: SWRHook<any> = {
async fetcher({ options, fetch }) {
return await fetch({ ...options })
},
useHook: ({ useData }) => (input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})
useHook:
({ useData }) =>
(input) => {
const response = useData({
swrOptions: { revalidateOnFocus: false, ...input?.swrOptions },
})

return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
return useMemo(
() =>
Object.create(response, {
isEmpty: {
get() {
return (response.data?.lineItems.length ?? 0) <= 0
},
enumerable: true,
},
enumerable: true,
},
}),
[response]
)
},
}),
[response]
)
},
}
38 changes: 18 additions & 20 deletions packages/kibocommerce/src/cart/use-remove-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,25 @@ export const handler = {
}: HookFetcherContext<RemoveItemHook>) {
return await fetch({ ...options, body: { itemId } })
},
useHook: ({ fetch }: MutationHookContext<RemoveItemHook>) => <
T extends LineItem | undefined = undefined
>(
ctx: { item?: T } = {}
) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {
const itemId = input?.id ?? item?.id
useHook:
({ fetch }: MutationHookContext<RemoveItemHook>) =>
<T extends LineItem | undefined = undefined>(ctx: { item?: T } = {}) => {
const { item } = ctx
const { mutate } = useCart()
const removeItem: RemoveItemFn<LineItem> = async (input) => {
const itemId = input?.id ?? item?.id

if (!itemId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}
if (!itemId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}

const data = await fetch({ input: { itemId } })
await mutate(data, false)
return data
}
const data = await fetch({ input: { itemId } })
await mutate(data, false)
return data
}

return useCallback(removeItem as RemoveItemFn<T>, [fetch, mutate])
},
return useCallback(removeItem as RemoveItemFn<T>, [fetch, mutate])
},
}
64 changes: 32 additions & 32 deletions packages/kibocommerce/src/cart/use-update-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@ export const handler = {
body: { itemId, item },
})
},
useHook: ({ fetch }: MutationHookContext<UpdateItemHook>) => <
T extends LineItem | undefined = undefined
>(
ctx: {
item?: T
wait?: number
} = {}
) => {
const { item } = ctx
const { mutate } = useCart() as any
useHook:
({ fetch }: MutationHookContext<UpdateItemHook>) =>
<T extends LineItem | undefined = undefined>(
ctx: {
item?: T
wait?: number
} = {}
) => {
const { item } = ctx
const { mutate } = useCart() as any

return useCallback(
debounce(async (input: UpdateItemActionInput<T>) => {
const itemId = input.id ?? item?.id
const productId = input.productId ?? item?.productId
const variantId = input.productId ?? item?.variantId
return useCallback(
debounce(async (input: UpdateItemActionInput<T>) => {
const itemId = input.id ?? item?.id
const productId = input.productId ?? item?.productId
const variantId = input.productId ?? item?.variantId

if (!itemId || !productId || !variantId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}
if (!itemId || !productId || !variantId) {
throw new ValidationError({
message: 'Invalid input used for this operation',
})
}

const data = await fetch({
input: {
itemId,
item: { productId, variantId, quantity: input.quantity },
},
})
await mutate(data, false)
return data
}, ctx.wait ?? 500),
[fetch, mutate]
)
},
const data = await fetch({
input: {
itemId,
item: { productId, variantId, quantity: input.quantity },
},
})
await mutate(data, false)
return data
}, ctx.wait ?? 500),
[fetch, mutate]
)
},
}
18 changes: 10 additions & 8 deletions packages/kibocommerce/src/customer/use-customer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export const handler: SWRHook<CustomerHook> = {
const data = await fetch(options)
return data?.customer ?? null
},
useHook: ({ useData }) => (input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
})
},
useHook:
({ useData }) =>
(input) => {
return useData({
swrOptions: {
revalidateOnFocus: false,
...input?.swrOptions,
},
})
},
}
10 changes: 4 additions & 6 deletions packages/kibocommerce/src/wishlist/use-wishlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ export const handler: SWRHook<any> = {
get() {
return (response.data?.items?.length || 0) <= 0
},
enumerable: true,
},
}),
[response]
)
},
}),
[response]
)
},
}
2 changes: 2 additions & 0 deletions packages/reactioncommerce/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REACTION_API_DOMAIN=
REACTION_SHOP_ID=
Loading