forked from crowetic/commerce
updates
This commit is contained in:
parent
bbfca29217
commit
bcd1d46e30
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["esbenp.prettier-vscode"]
|
||||||
|
}
|
@ -30,7 +30,7 @@ const UserNav: FC<Props> = ({ className }) => {
|
|||||||
<Bag />
|
<Bag />
|
||||||
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>}
|
{itemsCount > 0 && <span className={s.bagCount}>{itemsCount}</span>}
|
||||||
</li>
|
</li>
|
||||||
{process.env.WISHLIST_ENABLED && (
|
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
||||||
<li className={s.item}>
|
<li className={s.item}>
|
||||||
<Link href="/wishlist">
|
<Link href="/wishlist">
|
||||||
<a onClick={closeSidebarIfPresent} aria-label="Wishlist">
|
<a onClick={closeSidebarIfPresent} aria-label="Wishlist">
|
||||||
|
@ -57,7 +57,7 @@ const ProductCard: FC<Props> = ({
|
|||||||
{product.price.currencyCode}
|
{product.price.currencyCode}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{process.env.WISHLIST_ENABLED && (
|
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
||||||
<WishlistButton
|
<WishlistButton
|
||||||
className={s.wishlistButton}
|
className={s.wishlistButton}
|
||||||
productId={product.id}
|
productId={product.id}
|
||||||
|
@ -151,7 +151,7 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{process.env.WISHLIST_ENABLED && (
|
{process.env.COMMERCE_WISHLIST_ENABLED && (
|
||||||
<WishlistButton
|
<WishlistButton
|
||||||
className={s.wishlistButton}
|
className={s.wishlistButton}
|
||||||
productId={product.id}
|
productId={product.id}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import type { MutationHook } from '@commerce/utils/types'
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
import { CommerceError } from '@commerce/utils/errors'
|
import { CommerceError } from '@commerce/utils/errors'
|
||||||
import useLogin, { UseLogin } from '@commerce/use-login'
|
import useLogin, { UseLogin } from '@commerce/auth/use-login'
|
||||||
import type { LoginBody } from '../api/customers/login'
|
import type { LoginBody } from '../api/customers/login'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import type { MutationHook } from '@commerce/utils/types'
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
import useLogout, { UseLogout } from '@commerce/use-logout'
|
import useLogout, { UseLogout } from '@commerce/auth/use-logout'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
|
|
||||||
export default useLogout as UseLogout<typeof handler>
|
export default useLogout as UseLogout<typeof handler>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useCallback } from 'react'
|
import { useCallback } from 'react'
|
||||||
import type { MutationHook } from '@commerce/utils/types'
|
import type { MutationHook } from '@commerce/utils/types'
|
||||||
import { CommerceError } from '@commerce/utils/errors'
|
import { CommerceError } from '@commerce/utils/errors'
|
||||||
import useSignup, { UseSignup } from '@commerce/use-signup'
|
import useSignup, { UseSignup } from '@commerce/auth/use-signup'
|
||||||
import type { SignupBody } from '../api/customers/signup'
|
import type { SignupBody } from '../api/customers/signup'
|
||||||
import useCustomer from '../customer/use-customer'
|
import useCustomer from '../customer/use-customer'
|
||||||
|
|
||||||
|
37
framework/bigcommerce/next.config.js
Normal file
37
framework/bigcommerce/next.config.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
module.exports = {
|
||||||
|
images: {
|
||||||
|
domains: ['cdn11.bigcommerce.com'],
|
||||||
|
},
|
||||||
|
i18n: {
|
||||||
|
locales: ['en-US', 'es'],
|
||||||
|
defaultLocale: 'en-US',
|
||||||
|
},
|
||||||
|
rewrites() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/checkout',
|
||||||
|
destination: '/api/bigcommerce/checkout',
|
||||||
|
},
|
||||||
|
// The logout is also an action so this route is not required, but it's also another way
|
||||||
|
// you can allow a logout!
|
||||||
|
{
|
||||||
|
source: '/logout',
|
||||||
|
destination: '/api/bigcommerce/customers/logout?redirect_to=/',
|
||||||
|
},
|
||||||
|
// Rewrites for /search
|
||||||
|
{
|
||||||
|
source: '/search/designers/:name',
|
||||||
|
destination: '/search',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
source: '/search/designers/:name/:category',
|
||||||
|
destination: '/search',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// This rewrite will also handle `/search/designers`
|
||||||
|
source: '/search/:category',
|
||||||
|
destination: '/search',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
@ -1,2 +1,2 @@
|
|||||||
export * from '@commerce/use-price'
|
export * from '@commerce/product/use-price'
|
||||||
export { default } from '@commerce/use-price'
|
export { default } from '@commerce/product/use-price'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useHook, useMutationHook } from './utils/use-hook'
|
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||||
import { mutationFetcher } from './utils/default-fetcher'
|
import { mutationFetcher } from '../utils/default-fetcher'
|
||||||
import type { MutationHook, HookFetcherFn } from './utils/types'
|
import type { MutationHook, HookFetcherFn } from '../utils/types'
|
||||||
import type { Provider } from '.'
|
import type { Provider } from '..'
|
||||||
|
|
||||||
export type UseLogin<
|
export type UseLogin<
|
||||||
H extends MutationHook<any, any, any> = MutationHook<null, {}, {}>
|
H extends MutationHook<any, any, any> = MutationHook<null, {}, {}>
|
@ -1,7 +1,7 @@
|
|||||||
import { useHook, useMutationHook } from './utils/use-hook'
|
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||||
import { mutationFetcher } from './utils/default-fetcher'
|
import { mutationFetcher } from '../utils/default-fetcher'
|
||||||
import type { HookFetcherFn, MutationHook } from './utils/types'
|
import type { HookFetcherFn, MutationHook } from '../utils/types'
|
||||||
import type { Provider } from '.'
|
import type { Provider } from '..'
|
||||||
|
|
||||||
export type UseLogout<
|
export type UseLogout<
|
||||||
H extends MutationHook<any, any, any> = MutationHook<null>
|
H extends MutationHook<any, any, any> = MutationHook<null>
|
@ -1,7 +1,7 @@
|
|||||||
import { useHook, useMutationHook } from './utils/use-hook'
|
import { useHook, useMutationHook } from '../utils/use-hook'
|
||||||
import { mutationFetcher } from './utils/default-fetcher'
|
import { mutationFetcher } from '../utils/default-fetcher'
|
||||||
import type { HookFetcherFn, MutationHook } from './utils/types'
|
import type { HookFetcherFn, MutationHook } from '../utils/types'
|
||||||
import type { Provider } from '.'
|
import type { Provider } from '..'
|
||||||
|
|
||||||
export type UseSignup<
|
export type UseSignup<
|
||||||
H extends MutationHook<any, any, any> = MutationHook<null>
|
H extends MutationHook<any, any, any> = MutationHook<null>
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"features": {
|
|
||||||
"wishlist": true
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import { useCommerce } from '.'
|
import { useCommerce } from '..'
|
||||||
|
|
||||||
export function formatPrice({
|
export function formatPrice({
|
||||||
amount,
|
amount,
|
@ -2,8 +2,10 @@ import type { Wishlist as BCWishlist } from '@framework/api/wishlist'
|
|||||||
import type { Customer as BCCustomer } from '@framework/api/customers'
|
import type { Customer as BCCustomer } from '@framework/api/customers'
|
||||||
import type { SearchProductsData as BCSearchProductsData } from '@framework/api/catalog/products'
|
import type { SearchProductsData as BCSearchProductsData } from '@framework/api/catalog/products'
|
||||||
|
|
||||||
|
export type Features = 'wishlist' | 'checkout' | string
|
||||||
|
|
||||||
export type CommerceProviderConfig = {
|
export type CommerceProviderConfig = {
|
||||||
features: Record<string, boolean>
|
features: Record<Features, boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Discount = {
|
export type Discount = {
|
||||||
|
11
framework/commerce/utils/bootstrap.js
vendored
Normal file
11
framework/commerce/utils/bootstrap.js
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
module.exports = ({ features }) => {
|
||||||
|
let output = {
|
||||||
|
env: {},
|
||||||
|
}
|
||||||
|
if (!!Object.keys(features).length) {
|
||||||
|
Object.keys(features).map(
|
||||||
|
(r) => (output.env[`COMMERCE_${r.toUpperCase()}_ENABLED`] = features[r])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
@ -14,6 +14,16 @@ function isFeatureEnabled(config: CommerceProviderConfig) {
|
|||||||
.includes(desideredFeature)
|
.includes(desideredFeature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toEnvConfig(
|
||||||
|
configMap: CommerceProviderConfig['features']
|
||||||
|
): Map<string, boolean> {
|
||||||
|
let toEnvConfigMap = new Map<string, boolean>()
|
||||||
|
Object.keys(configMap).map((r) =>
|
||||||
|
toEnvConfigMap.set(`${r.toUpperCase()}_ENABLED`, configMap[r])
|
||||||
|
)
|
||||||
|
return toEnvConfigMap
|
||||||
|
}
|
||||||
|
|
||||||
function boostrap(): FeaturesAPI {
|
function boostrap(): FeaturesAPI {
|
||||||
const basis = {
|
const basis = {
|
||||||
isEnabled: () => false,
|
isEnabled: () => false,
|
||||||
|
@ -1,40 +1,6 @@
|
|||||||
module.exports = {
|
const providerConfig = require('./framework/bigcommerce/config.json')
|
||||||
images: {
|
const providerNextConfig = require('./framework/bigcommerce/next.config')
|
||||||
domains: ['cdn11.bigcommerce.com'],
|
const bootstrap = require('./framework/commerce/utils/bootstrap')
|
||||||
},
|
const d = require('deepmerge')
|
||||||
i18n: {
|
|
||||||
locales: ['en-US', 'es'],
|
module.exports = d(providerNextConfig, bootstrap(providerConfig))
|
||||||
defaultLocale: 'en-US',
|
|
||||||
},
|
|
||||||
env: {
|
|
||||||
WISHLIST_ENABLED: false,
|
|
||||||
},
|
|
||||||
rewrites() {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
source: '/checkout',
|
|
||||||
destination: '/api/bigcommerce/checkout',
|
|
||||||
},
|
|
||||||
// The logout is also an action so this route is not required, but it's also another way
|
|
||||||
// you can allow a logout!
|
|
||||||
{
|
|
||||||
source: '/logout',
|
|
||||||
destination: '/api/bigcommerce/customers/logout?redirect_to=/',
|
|
||||||
},
|
|
||||||
// Rewrites for /search
|
|
||||||
{
|
|
||||||
source: '/search/designers/:name',
|
|
||||||
destination: '/search',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
source: '/search/designers/:name/:category',
|
|
||||||
destination: '/search',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// This rewrite will also handle `/search/designers`
|
|
||||||
source: '/search/:category',
|
|
||||||
destination: '/search',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
@ -66,6 +66,7 @@
|
|||||||
"@types/lodash.throttle": "^4.1.6",
|
"@types/lodash.throttle": "^4.1.6",
|
||||||
"@types/node": "^14.14.16",
|
"@types/node": "^14.14.16",
|
||||||
"@types/react": "^17.0.0",
|
"@types/react": "^17.0.0",
|
||||||
|
"deepmerge": "^4.2.2",
|
||||||
"graphql": "^15.4.0",
|
"graphql": "^15.4.0",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"lint-staged": "^10.5.3",
|
"lint-staged": "^10.5.3",
|
||||||
|
@ -17,7 +17,7 @@ export async function getStaticProps({
|
|||||||
locale,
|
locale,
|
||||||
}: GetStaticPropsContext) {
|
}: GetStaticPropsContext) {
|
||||||
// Disabling page if Feature is not available
|
// Disabling page if Feature is not available
|
||||||
if (!process.env.WISHLIST_ENABLED) {
|
if (!process.env.COMMERCE_WISHLIST_ENABLED) {
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
}
|
}
|
||||||
|
@ -2532,6 +2532,11 @@ deep-is@~0.1.3:
|
|||||||
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
|
resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
|
||||||
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
|
integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
|
||||||
|
|
||||||
|
deepmerge@^4.2.2:
|
||||||
|
version "4.2.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.2.2.tgz#44d2ea3679b8f4d4ffba33f03d865fc1e7bf4955"
|
||||||
|
integrity sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==
|
||||||
|
|
||||||
defaults@^1.0.3:
|
defaults@^1.0.3:
|
||||||
version "1.0.3"
|
version "1.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
|
resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.3.tgz#c656051e9817d9ff08ed881477f3fe4019f3ef7d"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user