chore: comment almost everything, build

This commit is contained in:
Reza Babaei
2021-09-18 22:09:54 +03:00
parent 6ef1d554e9
commit 8a6e5932c8
60 changed files with 825 additions and 1039 deletions

View File

@@ -2,10 +2,10 @@ import React, { FC, useState } from 'react'
import cn from 'classnames'
import { useUI } from '@components/ui'
import { Heart } from '@components/icons'
import useAddItem from '@framework/wishlist/use-add-item'
import useCustomer from '@framework/customer/use-customer'
import useWishlist from '@framework/wishlist/use-wishlist'
import useRemoveItem from '@framework/wishlist/use-remove-item'
// import useAddItem from '@framework/wishlist/use-add-item'
// import useCustomer from '@framework/customer/use-customer'
// import useWishlist from '@framework/wishlist/use-wishlist'
// import useRemoveItem from '@framework/wishlist/use-remove-item'
import s from './WishlistButton.module.css'
import type { Product, ProductVariant } from '@commerce/types/product'
@@ -20,10 +20,10 @@ const WishlistButton: FC<Props> = ({
className,
...props
}) => {
const { data } = useWishlist()
const addItem = useAddItem()
const removeItem = useRemoveItem()
const { data: customer } = useCustomer()
// const { data } = useWishlist()
// const addItem = useAddItem()
// const removeItem = useRemoveItem()
// const { data: customer } = useCustomer()
const { openModal, setModalView } = useUI()
const [loading, setLoading] = useState(false)
@@ -41,22 +41,22 @@ const WishlistButton: FC<Props> = ({
if (loading) return
// A login is required before adding an item to the wishlist
if (!customer) {
setModalView('LOGIN_VIEW')
return openModal()
}
// if (!customer) {
// setModalView('LOGIN_VIEW')
// return openModal()
// }
setLoading(true)
try {
if (itemInWishlist) {
await removeItem({ id: itemInWishlist.id! })
} else {
await addItem({
productId,
variantId: variant?.id!,
})
}
// if (itemInWishlist) {
// await removeItem({ id: itemInWishlist.id! })
// } else {
// await addItem({
// productId,
// variantId: variant?.id!,
// })
// }
setLoading(false)
} catch (err) {

View File

@@ -8,9 +8,9 @@ import { Button, Text } from '@components/ui'
import { useUI } from '@components/ui/context'
import type { Product } from '@commerce/types/product'
import usePrice from '@framework/product/use-price'
import useAddItem from '@framework/cart/use-add-item'
import useRemoveItem from '@framework/wishlist/use-remove-item'
// import usePrice from '@framework/product/use-price'
// import useAddItem from '@framework/cart/use-add-item'
// import useRemoveItem from '@framework/wishlist/use-remove-item'
interface Props {
product: Product
@@ -19,11 +19,11 @@ interface Props {
const placeholderImg = '/product-img-placeholder.svg'
const WishlistCard: FC<Props> = ({ product }) => {
const { price } = usePrice({
amount: product.price?.value,
baseAmount: product.price?.retailPrice,
currencyCode: product.price?.currencyCode!,
})
// const { price } = usePrice({
// amount: product.price?.value,
// baseAmount: product.price?.retailPrice,
// currencyCode: product.price?.currencyCode!,
// })
// @ts-ignore Wishlist is not always enabled
const removeItem = useRemoveItem({ wishlist: { includeProducts: true } })
const [loading, setLoading] = useState(false)
@@ -71,7 +71,7 @@ const WishlistCard: FC<Props> = ({ product }) => {
</div>
<div className="col-span-7">
<h3 className="text-2xl mb-2">
<h3 className="mb-2 text-2xl">
<Link href={`/product${product.path}`}>
<a>{product.name}</a>
</Link>
@@ -91,8 +91,8 @@ const WishlistCard: FC<Props> = ({ product }) => {
Add to Cart
</Button>
</div>
<div className="col-span-2 flex flex-col justify-between">
<div className="flex justify-end font-bold">{price}</div>
<div className="flex flex-col justify-between col-span-2">
{/* <div className="flex justify-end font-bold">{price}</div> */}
<div className="flex justify-end">
<button onClick={handleRemove}>
<Trash />