Skip to content

Commit 01d68a3

Browse files
lfadescond0rokbel
authored
[WIP] Node.js provider for the API (vercel#252)
* Adding multiple initial files * Updated the default cart endpoint * Fixes * Updated CommerceAPI class for better usage * Adding more migration changes * Taking multiple steps into better API types * Adding more experimental types * Removed many testing types * Adding types, fixes and other updates * Updated commerce types * Updated types for hooks now using the API * Updated mutation types * Simplified cart types for the provider * Updated cart hooks * Remove normalizers from the hooks * Updated cart endpoint * Removed cart handlers * bug fixes * Improve quantity input behavior in cart item * Removed endpoints folder * Making progress on api operations * Moved method * Moved types * Changed the way ops are created * Added customer endpoint * Login endpoint * Added logout endpoint * Add missing logout files * Added signup endpoint * Removed customers old endpoints * Moved endpoints to nested folder * Removed old customer endpoint builders * Updated login operation * Updated login operation * Added getAllPages operation * Renamed endpoint operations to handlers * Changed import * Renamed operations to handlers in usage * Moved getAllPages everywhere * Moved getPage * Updated getPage usage * Moved getSiteInfo * Added def types for product * Updated type * moved products catalog endpoint * removed old catalog endpoint * Moved wishlist * Removed commerce.endpoint * Replaced references to commerce.endpoint * Updated catalog products * Moved checkout api * Added the get customer wishlist operation * Removed old wishlist stuff * Added getAllProductPaths operation * updated reference to operation * Moved getAllProducts * Updated getProduct operation * Removed old getConfig and references * Removed is-allowed-method from BC * Updated types for auth hooks * Updated useCustomer and core types * Updated useData and util hooks * Updated useSearch hook * Updated types for useWishlist * Added index for types * Fixes * Updated urls to the API * Renamed fetchInput to fetcherInput * Updated fetch type * Fixes in search hook * Updated Shopify Provider Structure (vercel#340) * Add codegen, update fragments & schemas * Update checkout-create.ts * Update checkout-create.ts * Update README.md * Update product mutations & queries * Uptate customer fetch types * Update schemas * Start updates * Moved Page, AllPages & Site Info * Moved product, all products (paths) * Add translations, update operations & fixes * Update api endpoints, types & fixes * Add api checkout endpoint * Updates * Fixes * Update commerce.config.json Co-authored-by: B <curciobelen@gmail.com> * Added category type and normalizer * updated init script to exclude other providers * Excluded swell and venture temporarily * Fix category & color normalization * Fixed category normalizer in shopify * Don't use getSlug for category on /search * Update colors.ts Co-authored-by: cond0r <pinte_catalin@yahoo.com> Co-authored-by: B <curciobelen@gmail.com>
1 parent f6f4229 commit 01d68a3

File tree

249 files changed

+4641
-2976
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+4641
-2976
lines changed

components/cart/CartItem/CartItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Link from 'next/link'
55
import s from './CartItem.module.css'
66
import { Trash, Plus, Minus } from '@components/icons'
77
import { useUI } from '@components/ui/context'
8-
import type { LineItem } from '@framework/types'
8+
import type { LineItem } from '@commerce/types/cart'
99
import usePrice from '@framework/product/use-price'
1010
import useUpdateItem from '@framework/cart/use-update-item'
1111
import useRemoveItem from '@framework/cart/use-remove-item'
@@ -35,18 +35,18 @@ const CartItem = ({
3535

3636
const updateItem = useUpdateItem({ item })
3737
const removeItem = useRemoveItem()
38-
const [quantity, setQuantity] = useState(item.quantity)
38+
const [quantity, setQuantity] = useState<number | ''>(item.quantity)
3939
const [removing, setRemoving] = useState(false)
4040

4141
const updateQuantity = async (val: number) => {
4242
await updateItem({ quantity: val })
4343
}
4444

4545
const handleQuantity = (e: ChangeEvent<HTMLInputElement>) => {
46-
const val = Number(e.target.value)
46+
const val = !e.target.value ? '' : Number(e.target.value)
4747

48-
if (Number.isInteger(val) && val >= 0) {
49-
setQuantity(Number(e.target.value))
48+
if (!val || (Number.isInteger(val) && val >= 0)) {
49+
setQuantity(val)
5050
}
5151
}
5252
const handleBlur = () => {

components/common/Footer/Footer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FC } from 'react'
22
import cn from 'classnames'
33
import Link from 'next/link'
44
import { useRouter } from 'next/router'
5-
import type { Page } from '@framework/common/get-all-pages'
5+
import type { Page } from '@commerce/types/page'
66
import getSlug from '@lib/get-slug'
77
import { Github, Vercel } from '@components/icons'
88
import { Logo, Container } from '@components/ui'

components/common/HomeAllProductsGrid/HomeAllProductsGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FC } from 'react'
22
import Link from 'next/link'
3-
import type { Product } from '@commerce/types'
3+
import type { Product } from '@commerce/types/product'
44
import { Grid } from '@components/ui'
55
import { ProductCard } from '@components/product'
66
import s from './HomeAllProductsGrid.module.css'

components/common/Layout/Layout.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import cn from 'classnames'
2-
import dynamic from 'next/dynamic'
3-
import s from './Layout.module.css'
4-
import { useRouter } from 'next/router'
51
import React, { FC } from 'react'
2+
import { useRouter } from 'next/router'
3+
import dynamic from 'next/dynamic'
4+
import cn from 'classnames'
5+
import type { Page } from '@commerce/types/page'
6+
import type { Category } from '@commerce/types/site'
7+
import { CommerceProvider } from '@framework'
8+
import { useAcceptCookies } from '@lib/hooks/useAcceptCookies'
69
import { useUI } from '@components/ui/context'
710
import { Navbar, Footer } from '@components/common'
8-
import { useAcceptCookies } from '@lib/hooks/useAcceptCookies'
911
import { Sidebar, Button, Modal, LoadingDots } from '@components/ui'
1012
import CartSidebarView from '@components/cart/CartSidebarView'
11-
import type { Page, Category } from '@commerce/types'
1213
import LoginView from '@components/auth/LoginView'
13-
import { CommerceProvider } from '@framework'
14+
import s from './Layout.module.css'
1415

1516
const Loading = () => (
1617
<div className="w-80 h-80 flex items-center text-center justify-center p-3">

components/common/Navbar/Navbar.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ const Navbar: FC<NavbarProps> = ({ links }) => (
2727
<Link href="/search">
2828
<a className={s.link}>All</a>
2929
</Link>
30-
{links
31-
? links.map((l) => (
32-
<Link href={l.href}>
33-
<a className={s.link}>{l.label}</a>
34-
</Link>
35-
))
36-
: null}
30+
{links?.map((l) => (
31+
<Link href={l.href} key={l.href}>
32+
<a className={s.link}>{l.label}</a>
33+
</Link>
34+
))}
3735
</nav>
3836
</div>
3937

components/common/UserNav/UserNav.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22
import Link from 'next/link'
33
import cn from 'classnames'
4-
import type { LineItem } from '@framework/types'
4+
import type { LineItem } from '@commerce/types/cart'
55
import useCart from '@framework/cart/use-cart'
66
import useCustomer from '@framework/customer/use-customer'
77
import { Avatar } from '@components/common'

components/product/ProductCard/ProductCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { FC } from 'react'
22
import cn from 'classnames'
33
import Link from 'next/link'
4-
import type { Product } from '@commerce/types'
4+
import type { Product } from '@commerce/types/product'
55
import s from './ProductCard.module.css'
66
import Image, { ImageProps } from 'next/image'
77
import WishlistButton from '@components/wishlist/WishlistButton'

components/product/ProductView/ProductView.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FC, useEffect, useState } from 'react'
55
import s from './ProductView.module.css'
66
import { Swatch, ProductSlider } from '@components/product'
77
import { Button, Container, Text, useUI } from '@components/ui'
8-
import type { Product } from '@commerce/types'
8+
import type { Product } from '@commerce/types/product'
99
import usePrice from '@framework/product/use-price'
1010
import { useAddItem } from '@framework/cart'
1111
import { getVariant, SelectedOptions } from '../helpers'
@@ -18,6 +18,8 @@ interface Props {
1818
}
1919

2020
const ProductView: FC<Props> = ({ product }) => {
21+
// TODO: fix this missing argument issue
22+
/* @ts-ignore */
2123
const addItem = useAddItem()
2224
const { price } = usePrice({
2325
amount: product.price.value,
@@ -146,8 +148,11 @@ const ProductView: FC<Props> = ({ product }) => {
146148
className={s.button}
147149
onClick={addToCart}
148150
loading={loading}
151+
disabled={variant?.availableForSale === false}
149152
>
150-
Add to Cart
153+
{variant?.availableForSale === false
154+
? 'Not Available'
155+
: 'Add To Cart'}
151156
</Button>
152157
</div>
153158
</div>

components/product/Swatch/Swatch.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & SwatchProps> = ({
4444
className={swatchClassName}
4545
style={color ? { backgroundColor: color } : {}}
4646
aria-label="Variant Swatch"
47+
{...(label && color && { title: label })}
4748
{...props}
4849
>
49-
{variant === 'color' && active && (
50+
{color && active && (
5051
<span>
5152
<Check />
5253
</span>
5354
)}
54-
{variant !== 'color' ? label : null}
55+
{!color ? label : null}
5556
</Button>
5657
)
5758
}

components/product/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Product } from '@commerce/types'
1+
import type { Product } from '@commerce/types/product'
22
export type SelectedOptions = Record<string, string | null>
33

44
export function getVariant(product: Product, opts: SelectedOptions) {

0 commit comments

Comments
 (0)