Fix category & color normalization

This commit is contained in:
cond0r 2021-06-01 09:48:05 +03:00
parent 9f6dd278d7
commit 5aa36dfcd4
3 changed files with 17 additions and 12 deletions

View File

@ -44,14 +44,15 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & SwatchProps> = ({
className={swatchClassName} className={swatchClassName}
style={color ? { backgroundColor: color } : {}} style={color ? { backgroundColor: color } : {}}
aria-label="Variant Swatch" aria-label="Variant Swatch"
{...(label && color && { title: label })}
{...props} {...props}
> >
{variant === 'color' && active && ( {color && active && (
<span> <span>
<Check /> <Check />
</span> </span>
)} )}
{variant !== 'color' ? label : null} {!color ? label : null}
</Button> </Button>
) )
} }

View File

@ -14,6 +14,7 @@ import {
ProductOption, ProductOption,
Page as ShopifyPage, Page as ShopifyPage,
PageEdge, PageEdge,
Collection,
} from '../schema' } from '../schema'
import { colorMap } from '@lib/colors' import { colorMap } from '@lib/colors'
@ -38,7 +39,7 @@ const normalizeProductOption = ({
label: value, label: value,
} }
if (displayName.match(/colou?r/gi)) { if (displayName.match(/colou?r/gi)) {
const mapedColor = colorMap[value] const mapedColor = colorMap[value.toLowerCase().replace(/ /g, '')]
if (mapedColor) { if (mapedColor) {
output = { output = {
...output, ...output,
@ -183,10 +184,13 @@ export const normalizePage = (
export const normalizePages = (edges: PageEdge[], locale: string): Page[] => export const normalizePages = (edges: PageEdge[], locale: string): Page[] =>
edges?.map((edge) => normalizePage(edge.node, locale)) edges?.map((edge) => normalizePage(edge.node, locale))
export const normalizeCategory = (category: any): Category => ({ export const normalizeCategory = ({
id: category.id, title: name,
name: category.name, handle,
slug: category.handle, id,
path: `/${category.handle}`, }: Collection): Category => ({
id,
name,
slug: handle,
path: `/${handle}`,
}) })

View File

@ -22,8 +22,8 @@
"@components/*": ["components/*"], "@components/*": ["components/*"],
"@commerce": ["framework/commerce"], "@commerce": ["framework/commerce"],
"@commerce/*": ["framework/commerce/*"], "@commerce/*": ["framework/commerce/*"],
"@framework": ["framework/bigcommerce"], "@framework": ["framework/shopify"],
"@framework/*": ["framework/bigcommerce/*"] "@framework/*": ["framework/shopify/*"]
} }
}, },
"include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"], "include": ["next-env.d.ts", "**/*.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],