mirror of
https://github.com/vercel/commerce.git
synced 2025-03-31 01:05:53 +00:00
* Initial work, copied from the Shopify provider * Added basis setup and type generation for the products queries * refactor: adjust the types * task: relax the Node.js constraint * fix: page/product properties * disable unknown fields * mention Saleor in the README * setup debugging for Next.js * Check nextjs-commerce bug if no images are added for a product * fix: client/server pecularities for env visibility Must prefix with `NEXT_PUBLIC_` so that the API URL is visible on the client * re: make search work with Saleor API (WIP) * task: update deps * task: move to Webpack 5.x * saleor: initial cart integration * update deps * saleor: shall the cart appear! * task: remove deprecated packages * saleor: adding/removing from the cart * saleor: preliminary signup process * saleor: fix the prices in the cart * update deps * update deps * Added the options for a variant to the product page * Mapped options to variants * Mapped options to variants * saleor: refine the auth process * saleor: remove unused code * saleor: handle customer find via refresh temporary solution * saleor: update deps * saleor: fix the session handling * saleor: fix the variants * saleor: simplify the naming for GraphQL statements * saleor: fix the type for collection * saleor: arrange the error codes * saleor: integrate collections * saleor: fix product sorting * saleor: set cookie location * saleor: update the schema * saleor: attach checkout to customer * saleor: fix the checkout flow * saleor: unify GraphQL naming approach * task: update deps * Add the env variables for saleor to the template * task: prettier * saleor: stub API for build/typescript compilation thanks @cond0r * task: temporarily disable for the `build` * saleor: refactor GraphQL queries * saleor: adjust the config * task: update dependencies * revert: Next.js to `10.0.9` * saleor: fix the checkout fetch query * task: update dependencies * saleor: adapt for displaying featured products * saleor: update the provider structure * saleor: make the home page representable * feature/cart: display the variant name (cond) Co-authored-by: Patryk Zawadzki <patrys@room-303.com> Co-authored-by: royderks <10717410+royderks@users.noreply.github.com>
89 lines
2.7 KiB
TypeScript
89 lines
2.7 KiB
TypeScript
import { FC } from 'react'
|
|
import cn from 'classnames'
|
|
import Link from 'next/link'
|
|
import type { Product } from '@commerce/types/product'
|
|
import s from './ProductCard.module.css'
|
|
import Image, { ImageProps } from 'next/image'
|
|
import WishlistButton from '@components/wishlist/WishlistButton'
|
|
|
|
interface Props {
|
|
className?: string
|
|
product: Product
|
|
variant?: 'slim' | 'simple'
|
|
imgProps?: Omit<any, 'src'>
|
|
}
|
|
|
|
const placeholderImg = '/product-img-placeholder.svg'
|
|
|
|
const ProductCard: FC<Props> = ({
|
|
className,
|
|
product,
|
|
variant,
|
|
imgProps,
|
|
...props
|
|
}) => (
|
|
<Link href={`/product/${product.slug}`} {...props}>
|
|
<a className={cn(s.root, { [s.simple]: variant === 'simple' }, className)}>
|
|
{variant === 'slim' ? (
|
|
<div className="relative overflow-hidden box-border">
|
|
<div className="absolute inset-0 flex items-center justify-end mr-8 z-20">
|
|
<span className="bg-black text-white inline-block p-3 font-bold text-xl break-words">
|
|
{product.name}
|
|
</span>
|
|
</div>
|
|
{product?.images && (
|
|
<Image
|
|
quality="85"
|
|
src={product.images[0]?.url || placeholderImg}
|
|
alt={product.name || 'Product Image'}
|
|
height={320}
|
|
width={320}
|
|
layout="fixed"
|
|
{...imgProps}
|
|
/>
|
|
)}
|
|
</div>
|
|
) : (
|
|
<>
|
|
<div className={s.squareBg} />
|
|
<div className="flex flex-row justify-between box-border w-full z-20 absolute">
|
|
<div className="absolute top-0 left-0 pr-16 max-w-full">
|
|
<h3 className={s.productTitle}>
|
|
<span>{product.name}</span>
|
|
</h3>
|
|
<span className={s.productPrice}>
|
|
{product.price.value}
|
|
|
|
{product.price.currencyCode}
|
|
</span>
|
|
</div>
|
|
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
|
<WishlistButton
|
|
className={s.wishlistButton}
|
|
productId={product.id}
|
|
variant={product.variants[0] as any}
|
|
/>
|
|
)}
|
|
</div>
|
|
<div className={s.imageContainer}>
|
|
{product?.images && (
|
|
<Image
|
|
alt={product.name || 'Product Image'}
|
|
className={s.productImage}
|
|
src={product.images[0]?.url || placeholderImg}
|
|
height={540}
|
|
width={540}
|
|
quality="85"
|
|
layout="responsive"
|
|
{...imgProps}
|
|
/>
|
|
)}
|
|
</div>
|
|
</>
|
|
)}
|
|
</a>
|
|
</Link>
|
|
)
|
|
|
|
export default ProductCard
|