4
0
forked from crowetic/commerce

Updates to wishlist feature

This commit is contained in:
Luis Alvarez 2021-02-22 19:06:03 -05:00
parent 4b4d804d03
commit a8607f24cd
10 changed files with 20 additions and 15 deletions

View File

@ -58,11 +58,10 @@ const Layout: FC<Props> = ({
} = useUI() } = useUI()
const { acceptedCookies, onAcceptCookies } = useAcceptCookies() const { acceptedCookies, onAcceptCookies } = useAcceptCookies()
const { locale = 'en-US' } = useRouter() const { locale = 'en-US' } = useRouter()
const isWishlistEnabled = commerceFeatures.wishlist
return ( return (
<CommerceProvider locale={locale}> <CommerceProvider locale={locale}>
<div className={cn(s.root)}> <div className={cn(s.root)}>
<Navbar wishlist={isWishlistEnabled} /> <Navbar wishlist={!!process.env.WISHLIST_ENABLED} />
<main className="fit">{children}</main> <main className="fit">{children}</main>
<Footer pages={pageProps.pages} /> <Footer pages={pageProps.pages} />
@ -73,7 +72,7 @@ const Layout: FC<Props> = ({
</Modal> </Modal>
<Sidebar open={displaySidebar} onClose={closeSidebar}> <Sidebar open={displaySidebar} onClose={closeSidebar}>
<CartSidebarView wishlist={isWishlistEnabled} /> <CartSidebarView wishlist={!!process.env.WISHLIST_ENABLED} />
</Sidebar> </Sidebar>
<FeatureBar <FeatureBar

View File

@ -59,11 +59,11 @@ const ProductCard: FC<Props> = ({
{product.price.currencyCode} {product.price.currencyCode}
</span> </span>
</div> </div>
{wishlist && ( {process.env.WISHLIST_ENABLED && (
<WishlistButton <WishlistButton
className={s.wishlistButton} className={s.wishlistButton}
productId={product.id} productId={product.id}
variant={product.variants[0]} variant={product.variants[0] as any}
/> />
)} )}
</div> </div>

View File

@ -152,11 +152,11 @@ const ProductView: FC<Props> = ({ product, wishlist = false }) => {
</Button> </Button>
</div> </div>
</div> </div>
{wishlist && ( {process.env.WISHLIST_ENABLED && (
<WishlistButton <WishlistButton
className={s.wishlistButton} className={s.wishlistButton}
productId={product.id} productId={product.id}
variant={product.variants[0]!} variant={product.variants[0]! as any}
/> />
)} )}
</div> </div>

View File

@ -7,7 +7,7 @@ import type { Product, ProductVariant } from '@commerce/types'
import useCustomer from '@framework/customer/use-customer' import useCustomer from '@framework/customer/use-customer'
import useAddItem from '@framework/wishlist/use-add-item' import useAddItem from '@framework/wishlist/use-add-item'
import useRemoveItem from '@framework/wishlist/use-remove-item' import useRemoveItem from '@framework/wishlist/use-remove-item'
import useWishlist from '@framework/wishlist/use-add-item' import useWishlist from '@framework/wishlist/use-wishlist'
type Props = { type Props = {
productId: Product['id'] productId: Product['id']
@ -28,7 +28,8 @@ const WishlistButton: FC<Props> = ({
const [loading, setLoading] = useState(false) const [loading, setLoading] = useState(false)
const itemInWishlist = data?.items?.find( const itemInWishlist = data?.items?.find(
(item) => item.product_id === productId && item.variant_id === variant.id (item) =>
item.product_id === productId && (item.variant_id as any) === variant.id
) )
const handleWishlistChange = async (e: any) => { const handleWishlistChange = async (e: any) => {

View File

@ -1,4 +1,4 @@
import commerceProviderConfig from '@framework/config.json' import commerceProviderConfig from '../config.json'
import type { CommerceProviderConfig } from '../types' import type { CommerceProviderConfig } from '../types'
import memo from 'lodash.memoize' import memo from 'lodash.memoize'

View File

@ -6,6 +6,9 @@ module.exports = {
locales: ['en-US', 'es'], locales: ['en-US', 'es'],
defaultLocale: 'en-US', defaultLocale: 'en-US',
}, },
env: {
WISHLIST_ENABLED: false,
},
rewrites() { rewrites() {
return [ return [
{ {

View File

@ -11,6 +11,7 @@
"generate": "graphql-codegen", "generate": "graphql-codegen",
"generate:definitions": "node framework/bigcommerce/scripts/generate-definitions.js" "generate:definitions": "node framework/bigcommerce/scripts/generate-definitions.js"
}, },
"sideEffects": false,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": "12.x" "node": "12.x"

View File

@ -57,7 +57,7 @@ export default function Home({
width: i === 0 ? 1080 : 540, width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540, height: i === 0 ? 1080 : 540,
}} }}
wishlist={commerceFeatures.wishlist} wishlist={!!process.env.WISHLIST_ENABLED}
/> />
))} ))}
</Grid> </Grid>
@ -71,7 +71,7 @@ export default function Home({
width: 320, width: 320,
height: 320, height: 320,
}} }}
wishlist={commerceFeatures.wishlist} wishlist={!!process.env.WISHLIST_ENABLED}
/> />
))} ))}
</Marquee> </Marquee>
@ -94,7 +94,7 @@ export default function Home({
width: i === 0 ? 1080 : 540, width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540, height: i === 0 ? 1080 : 540,
}} }}
wishlist={commerceFeatures.wishlist} wishlist={!!process.env.WISHLIST_ENABLED}
/> />
))} ))}
</Grid> </Grid>
@ -108,7 +108,7 @@ export default function Home({
width: 320, width: 320,
height: 320, height: 320,
}} }}
wishlist={commerceFeatures.wishlist} wishlist={!!process.env.WISHLIST_ENABLED}
/> />
))} ))}
</Marquee> </Marquee>

View File

@ -71,7 +71,7 @@ export default function Slug({
) : ( ) : (
<ProductView <ProductView
product={product as any} product={product as any}
wishlist={commerceFeatures.wishlist} wishlist={!!process.env.WISHLIST_ENABLED}
/> />
) )
} }

View File

@ -34,6 +34,7 @@ import {
getDesignerPath, getDesignerPath,
useSearchMeta, useSearchMeta,
} from '@lib/search' } from '@lib/search'
import { Product } from '@commerce/types'
export async function getStaticProps({ export async function getStaticProps({
preview, preview,