This commit is contained in:
Henrik Larsson
2023-08-08 11:46:46 +02:00
parent 6527974989
commit 3e513eaf99
27 changed files with 449 additions and 760 deletions

View File

@@ -8,8 +8,6 @@ import dynamic from 'next/dynamic';
import Link from 'next/link';
import { FC } from 'react';
const WishlistButton = dynamic(() => import('components/ui/wishlist-button'));
const SanityImage = dynamic(() => import('components/ui/sanity-image'));
interface Props {
@@ -30,11 +28,6 @@ const ProductCard: FC<Props> = ({ product, className, variant = 'default' }) =>
>
{variant === 'default' && (
<div className={'relative flex h-full w-full flex-col justify-center'}>
<WishlistButton
className={'absolute right-4 top-4 z-10'}
productId={product.id}
variant={product?.variants ? (product.variants[0] as any) : null}
/>
<div className="relative h-full w-full overflow-hidden">
{product?.images && (
<SanityImage

View File

@@ -1 +0,0 @@
export { default } from './wishlist-button';

View File

@@ -1,79 +0,0 @@
import type { Product, ProductVariant } from 'lib/storm/types/product'
import { cn } from 'lib/utils'
import { Heart } from 'lucide-react'
import { useTranslations } from 'next-intl'
import React, { FC, useState } from 'react'
type Props = {
productId: Product['id']
variant: ProductVariant
} & React.ButtonHTMLAttributes<HTMLButtonElement>
const WishlistButton: FC<Props> = ({
productId,
variant,
className,
...props
}) => {
const [loading, setLoading] = useState(false)
const t = useTranslations('ui.button')
// @ts-ignore Wishlist is not always enabled
// const itemInWishlist = data?.items?.find(
// // @ts-ignore Wishlist is not always enabled
// (item) => item.product_id === productId && item.variant_id === variant.id
// )
const handleWishlistChange = async (e: any) => {
e.preventDefault()
if (loading) return
// A login is required before adding an item to the wishlist
// if (!customer) {
// setModalView('LOGIN_VIEW')
// return openModal()
// }
// setLoading(true)
// try {
// if (itemInWishlist) {
// await removeItem({ id: itemInWishlist.id! })
// } else {
// await addItem({
// productId,
// variantId: variant?.id!,
// })
// }
// setLoading(false)
// } catch (err) {
// setLoading(false)
// }
}
return (
<button
aria-label={t('wishList')}
className={cn(
'w-10 h-10 text-high-contrast bg-app border border-high-contrast flex items-center justify-center font-semibold cursor-pointer text-sm duration-200 ease-in-out transition-[color,background-color,opacity] ',
className
)}
// onClick={handleWishlistChange}
{...props}
>
<Heart
className={cn(
'duration-200 ease-in-out w-5 h-5 transition-[transform,fill] text-current',
{
['fill-low-contrast']: loading,
// ['fill-high-contrast']: itemInWishlist,
}
)}
/>
</button>
)
}
export default WishlistButton