Skip to content

Commit

Permalink
Moved the features to be environment variable only
Browse files Browse the repository at this point in the history
  • Loading branch information
lfades committed Feb 23, 2021
1 parent a8607f2 commit 67d05ea
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 35 deletions.
2 changes: 0 additions & 2 deletions components/product/ProductCard/ProductCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface Props {
product: Product
variant?: 'slim' | 'simple'
imgProps?: Omit<ImageProps, 'src'>
wishlist?: boolean
}

const placeholderImg = '/product-img-placeholder.svg'
Expand All @@ -21,7 +20,6 @@ const ProductCard: FC<Props> = ({
product,
variant,
imgProps,
wishlist = false,
...props
}) => (
<Link href={`/product/${product.slug}`} {...props}>
Expand Down
3 changes: 1 addition & 2 deletions components/product/ProductView/ProductView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
defaultLocale: 'en-US',
},
env: {
WISHLIST_ENABLED: false,
WISHLIST_ENABLED: true,
},
rewrites() {
return [
Expand Down
10 changes: 0 additions & 10 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,17 +23,13 @@ export async function getStaticProps({

const { categories, brands } = await getSiteInfo({ config, preview })
const { pages } = await getAllPages({ config, preview })
const isWishlistEnabled = Features.isEnabled('wishlist')

return {
props: {
products,
categories,
brands,
pages,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
revalidate: 14400,
}
Expand All @@ -44,7 +39,6 @@ export default function Home({
products,
brands,
categories,
commerceFeatures,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<>
Expand All @@ -57,7 +51,6 @@ export default function Home({
width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Grid>
Expand All @@ -71,7 +64,6 @@ export default function Home({
width: 320,
height: 320,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Marquee>
Expand All @@ -94,7 +86,6 @@ export default function Home({
width: i === 0 ? 1080 : 540,
height: i === 0 ? 1080 : 540,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Grid>
Expand All @@ -108,7 +99,6 @@ export default function Home({
width: 320,
height: 320,
}}
wishlist={!!process.env.WISHLIST_ENABLED}
/>
))}
</Marquee>
Expand Down
11 changes: 1 addition & 10 deletions pages/product/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -35,9 +33,6 @@ export async function getStaticProps({
props: {
pages,
product,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
revalidate: 200,
}
Expand All @@ -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} />
)
}

Expand Down
8 changes: 0 additions & 8 deletions pages/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const SORT = Object.entries({
'price-desc': 'Price: High to low',
})

import Features from '@commerce/utils/features'

import {
filterQuery,
getCategoryPath,
Expand All @@ -43,23 +41,18 @@ 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,
},
},
}
}

export default function Search({
categories,
brands,
commerceFeatures: { wishlist },
}: InferGetStaticPropsType<typeof getStaticProps>) {
const [activeFilter, setActiveFilter] = useState('')
const [toggleFilter, setToggleFilter] = useState(false)
Expand Down Expand Up @@ -359,7 +352,6 @@ export default function Search({
width: 480,
height: 480,
}}
wishlist={wishlist}
/>
))}
</Grid>
Expand Down
3 changes: 1 addition & 2 deletions pages/wishlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 67d05ea

Please sign in to comment.