4
0
forked from crowetic/commerce

Moved the features to be environment variable only

This commit is contained in:
Luis Alvarez 2021-02-23 11:32:54 -05:00
parent a8607f24cd
commit 67d05ea165
7 changed files with 4 additions and 35 deletions

View File

@ -11,7 +11,6 @@ interface Props {
product: Product
variant?: 'slim' | 'simple'
imgProps?: Omit<ImageProps, 'src'>
wishlist?: boolean
}
const placeholderImg = '/product-img-placeholder.svg'
@ -21,7 +20,6 @@ const ProductCard: FC<Props> = ({
product,
variant,
imgProps,
wishlist = false,
...props
}) => (
<Link href={`/product/${product.slug}`} {...props}>

View File

@ -19,10 +19,9 @@ interface Props {
className?: string
children?: any
product: Product
wishlist?: boolean
}
const ProductView: FC<Props> = ({ product, wishlist = false }) => {
const ProductView: FC<Props> = ({ product }) => {
const addItem = useAddItem()
const { price } = usePrice({
amount: product.price.value,

View File

@ -7,7 +7,7 @@ module.exports = {
defaultLocale: 'en-US',
},
env: {
WISHLIST_ENABLED: false,
WISHLIST_ENABLED: true,
},
rewrites() {
return [

View File

@ -8,7 +8,6 @@ import { getConfig } from '@framework/api'
import getAllProducts from '@framework/product/get-all-products'
import getSiteInfo from '@framework/common/get-site-info'
import getAllPages from '@framework/common/get-all-pages'
import Features from '@commerce/utils/features'
export async function getStaticProps({
preview,
@ -24,7 +23,6 @@ export async function getStaticProps({
const { categories, brands } = await getSiteInfo({ config, preview })
const { pages } = await getAllPages({ config, preview })
const isWishlistEnabled = Features.isEnabled('wishlist')
return {
props: {
@ -32,9 +30,6 @@ export async function getStaticProps({
categories,
brands,
pages,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
revalidate: 14400,
}
@ -44,7 +39,6 @@ export default function Home({
products,
brands,
categories,
commerceFeatures,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<>
@ -57,7 +51,6 @@ export default function Home({
width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Grid>
@ -71,7 +64,6 @@ export default function Home({
width: 320,
height: 320,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Marquee>
@ -94,7 +86,6 @@ export default function Home({
width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Grid>
@ -108,7 +99,6 @@ export default function Home({
width: 320,
height: 320,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Marquee>

View File

@ -11,14 +11,12 @@ import { getConfig } from '@framework/api'
import getProduct from '@framework/product/get-product'
import getAllPages from '@framework/common/get-all-pages'
import getAllProductPaths from '@framework/product/get-all-product-paths'
import Features from '@commerce/utils/features'
export async function getStaticProps({
params,
locale,
preview,
}: GetStaticPropsContext<{ slug: string }>) {
const isWishlistEnabled = Features.isEnabled('wishlist')
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
const { product } = await getProduct({
@ -35,9 +33,6 @@ export async function getStaticProps({
props: {
pages,
product,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
revalidate: 200,
}
@ -62,17 +57,13 @@ export async function getStaticPaths({ locales }: GetStaticPathsContext) {
export default function Slug({
product,
commerceFeatures,
}: InferGetStaticPropsType<typeof getStaticProps>) {
const router = useRouter()
return router.isFallback ? (
<h1>Loading...</h1> // TODO (BC) Add Skeleton Views
) : (
<ProductView
product={product as any}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
<ProductView product={product as any} />
)
}

View File

@ -26,8 +26,6 @@ const SORT = Object.entries({
'price-desc': 'Price: High to low',
})
import Features from '@commerce/utils/features'
import {
filterQuery,
getCategoryPath,
@ -43,15 +41,11 @@ export async function getStaticProps({
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
const { categories, brands } = await getSiteInfo({ config, preview })
const isWishlistEnabled = Features.isEnabled('wishlist')
return {
props: {
pages,
categories,
brands,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
}
}
@ -59,7 +53,6 @@ export async function getStaticProps({
export default function Search({
categories,
brands,
commerceFeatures: { wishlist },
}: InferGetStaticPropsType<typeof getStaticProps>) {
const [activeFilter, setActiveFilter] = useState('')
const [toggleFilter, setToggleFilter] = useState(false)
@ -359,7 +352,6 @@ export default function Search({
width: 480,
height: 480,
}}
wishlist={wishlist}
/>
))}
</Grid>

View File

@ -11,14 +11,13 @@ import { useCustomer } from '@framework/customer'
import { WishlistCard } from '@components/wishlist'
import useWishlist from '@framework/wishlist/use-wishlist'
import getAllPages from '@framework/common/get-all-pages'
import Features from '@commerce/utils/features'
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
// Disabling page if Feature is not available
if (Features.isEnabled('wishlist')) {
if (!process.env.WISHLIST_ENABLED) {
return {
notFound: true,
}