From 41f8a651f71c5d0460b03b3e0a51d4fb77d26524 Mon Sep 17 00:00:00 2001 From: cond0r <1243434+cond0r@users.noreply.github.com> Date: Mon, 25 Jul 2022 13:16:09 +0300 Subject: [PATCH] Fix errors & styles --- packages/shopify/package.json | 1 - packages/shopify/src/const.ts | 3 ++- packages/shopify/src/utils/metafields.ts | 14 +++++++++++++- packages/shopify/src/utils/normalize.ts | 3 +-- site/components/common/Head/Head.tsx | 5 ++++- .../ProductCustomFields/ProductCustomFields.tsx | 4 ++-- .../ProductDetails/ProductDetails.module.css | 5 +++-- .../components/product/ProductView/ProductView.tsx | 8 +++++--- yarn.lock | 12 ------------ 9 files changed, 30 insertions(+), 25 deletions(-) diff --git a/packages/shopify/package.json b/packages/shopify/package.json index ba14ea1f7..8f7d11cd2 100644 --- a/packages/shopify/package.json +++ b/packages/shopify/package.json @@ -51,7 +51,6 @@ "dependencies": { "@vercel/commerce": "^0.0.1", "@vercel/fetch": "^6.1.1", - "humanize-string": "^3.0.0", "lodash.debounce": "^4.0.8" }, "peerDependencies": { diff --git a/packages/shopify/src/const.ts b/packages/shopify/src/const.ts index 14fccf84b..77bb340bb 100644 --- a/packages/shopify/src/const.ts +++ b/packages/shopify/src/const.ts @@ -6,7 +6,8 @@ export const SHOPIFY_CART_URL_COOKIE = 'shopify_cartUrl' export const SHOPIFY_CUSTOMER_TOKEN_COOKIE = 'shopify_customerToken' -export const STORE_DOMAIN = process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN +export const STORE_DOMAIN = + process.env.NEXT_PUBLIC_SHOPIFY_STORE_DOMAIN?.replace(/(^\w+:|^)\/\//, '') export const SHOPIFY_COOKIE_EXPIRE = 30 diff --git a/packages/shopify/src/utils/metafields.ts b/packages/shopify/src/utils/metafields.ts index 1fee04d21..4b65cf1b4 100644 --- a/packages/shopify/src/utils/metafields.ts +++ b/packages/shopify/src/utils/metafields.ts @@ -46,7 +46,7 @@ export const getMetafieldValue = ( ) => { switch (type) { case 'boolean': - return value === 'true' ? '✓' : 'No' + return value === 'true' ? '✓' : '✕' case 'number_integer': return parseInt(value).toLocaleString(locale) case 'number_decimal': @@ -88,3 +88,15 @@ export const getMetafieldValue = ( return value } } + +export const humanizeString = (string: string) => { + string = string + .toLowerCase() + .replace(/[_-]+/g, ' ') + .replace(/\s{2,}/g, ' ') + .trim() + + string = string.charAt(0).toUpperCase() + string.slice(1) + + return string +} diff --git a/packages/shopify/src/utils/normalize.ts b/packages/shopify/src/utils/normalize.ts index 802a360e3..31616b4cf 100644 --- a/packages/shopify/src/utils/normalize.ts +++ b/packages/shopify/src/utils/normalize.ts @@ -16,11 +16,10 @@ import type { CartDetailsFragment, } from '../../schema' -import humanizeString from 'humanize-string' import { CommerceError } from '@vercel/commerce/utils/errors' import { colorMap } from './colors' -import { getMetafieldValue, parseJson } from './metafields' +import { getMetafieldValue, parseJson, humanizeString } from './metafields' type MoneyProps = MoneyV2 & { retailPrice?: string | number } diff --git a/site/components/common/Head/Head.tsx b/site/components/common/Head/Head.tsx index 33b2b25f7..07f257567 100644 --- a/site/components/common/Head/Head.tsx +++ b/site/components/common/Head/Head.tsx @@ -13,7 +13,10 @@ const Head: VFC = () => { {process.env.COMMERCE_PROVIDER === '@vercel/commerce-shopify' && ( )} diff --git a/site/components/product/ProductCustomFields/ProductCustomFields.tsx b/site/components/product/ProductCustomFields/ProductCustomFields.tsx index 3b08909de..816a2b302 100644 --- a/site/components/product/ProductCustomFields/ProductCustomFields.tsx +++ b/site/components/product/ProductCustomFields/ProductCustomFields.tsx @@ -2,10 +2,10 @@ import type { ProductCustomField } from '@commerce/types/product' const ProductCustomFields = ({ fields }: { fields: ProductCustomField[] }) => { return ( -