From 526b291f4fd4e14fc0d6fff56c7c11169a3d56d4 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Sat, 17 Oct 2020 17:56:38 -0300 Subject: [PATCH] Adding Correct Sizes and Colors --- .../product/ProductView/ProductView.tsx | 82 ++++++++--------- components/product/Swatch/Swatch.tsx | 2 +- components/product/helpers.ts | 2 +- lib/bigcommerce/schema.d.ts | 87 ++++++++++++++----- pages/search.tsx | 57 ++++++------ 5 files changed, 139 insertions(+), 91 deletions(-) diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 887f606c7..e8f91c99b 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -22,7 +22,7 @@ interface Choices { const ProductView: FC = ({ product, className }) => { const options = getProductOptions(product) - console.log(options) + // console.log(options) const addItem = useAddItem() const { openSidebar } = useUI() @@ -102,46 +102,48 @@ const ProductView: FC = ({ product, className }) => {
- {options?.map((opt: any) => ( -
-

{opt.displayName}

-
- {opt.values.map((v: any) => { - return ( - - setChoices((choices) => { - return { - ...choices, - [opt.displayName]: v.label, - } - }) - } - /> - ) - })} +
+ {options?.map((opt: any) => ( +
+

{opt.displayName}

+
+ {opt.values.map((v: any) => { + return ( + + setChoices((choices) => { + return { + ...choices, + [opt.displayName]: v.label, + } + }) + } + /> + ) + })} +
-
-
- -
-
- ))} + ))} +
+
+ +
+
diff --git a/components/product/Swatch/Swatch.tsx b/components/product/Swatch/Swatch.tsx index 7b9919005..3085e6e0a 100644 --- a/components/product/Swatch/Swatch.tsx +++ b/components/product/Swatch/Swatch.tsx @@ -24,7 +24,7 @@ const Swatch: FC = ({ }) => { variant = variant?.toLowerCase() label = label?.toLowerCase() - console.log(variant) + // console.log(variant) const rootClassName = cn( s.root, { diff --git a/components/product/helpers.ts b/components/product/helpers.ts index 414aa6019..8d40a74dd 100644 --- a/components/product/helpers.ts +++ b/components/product/helpers.ts @@ -1,7 +1,7 @@ import type { Product } from '@lib/bigcommerce/api/operations/get-product' export function getProductOptions(product: Product) { - console.log(product) + // console.log(product) const options = product.productOptions.edges?.map(({ node }: any) => ({ displayName: node.displayName.toLowerCase(), values: node.values.edges?.map(({ node }: any) => node), diff --git a/lib/bigcommerce/schema.d.ts b/lib/bigcommerce/schema.d.ts index dbc010ceb..6bd4ee8e0 100644 --- a/lib/bigcommerce/schema.d.ts +++ b/lib/bigcommerce/schema.d.ts @@ -1670,6 +1670,40 @@ export type ResponsiveImageFragment = { __typename?: 'Image' } & Pick< urlXL: Image['url'] } +export type SwatchOptionFragment = { __typename?: 'SwatchOptionValue' } & Pick< + SwatchOptionValue, + 'isDefault' | 'hexColors' +> + +export type MultipleChoiceOptionFragment = { + __typename?: 'MultipleChoiceOption' +} & Pick & { + values: { __typename?: 'ProductOptionValueConnection' } & { + edges?: Maybe< + Array< + Maybe< + { __typename?: 'ProductOptionValueEdge' } & { + node: + | ({ __typename?: 'MultipleChoiceOptionValue' } & Pick< + MultipleChoiceOptionValue, + 'label' + >) + | ({ __typename?: 'ProductPickListOptionValue' } & Pick< + ProductPickListOptionValue, + 'label' + >) + | ({ __typename?: 'SwatchOptionValue' } & Pick< + SwatchOptionValue, + 'label' + > & + SwatchOptionFragment) + } + > + > + > + } + } + export type ProductInfoFragment = { __typename?: 'Product' } & Pick< Product, 'entityId' | 'name' | 'path' | 'description' @@ -1709,30 +1743,41 @@ export type ProductInfoFragment = { __typename?: 'Product' } & Pick< > > } - options: { __typename?: 'OptionConnection' } & { + productOptions: { __typename?: 'ProductOptionConnection' } & { edges?: Maybe< Array< Maybe< - { __typename?: 'OptionEdge' } & { - node: { __typename?: 'ProductOption' } & Pick< - ProductOption, - 'entityId' | 'displayName' | 'isRequired' - > & { - values: { __typename?: 'OptionValueConnection' } & { - edges?: Maybe< - Array< - Maybe< - { __typename?: 'OptionValueEdge' } & { - node: { __typename?: 'ProductOptionValue' } & Pick< - ProductOptionValue, - 'entityId' | 'label' - > - } - > - > - > - } - } + { __typename?: 'ProductOptionEdge' } & { + node: + | ({ __typename?: 'CheckboxOption' } & Pick< + CheckboxOption, + 'entityId' | 'displayName' + >) + | ({ __typename?: 'DateFieldOption' } & Pick< + DateFieldOption, + 'entityId' | 'displayName' + >) + | ({ __typename?: 'FileUploadFieldOption' } & Pick< + FileUploadFieldOption, + 'entityId' | 'displayName' + >) + | ({ __typename?: 'MultiLineTextFieldOption' } & Pick< + MultiLineTextFieldOption, + 'entityId' | 'displayName' + >) + | ({ __typename?: 'MultipleChoiceOption' } & Pick< + MultipleChoiceOption, + 'entityId' | 'displayName' + > & + MultipleChoiceOptionFragment) + | ({ __typename?: 'NumberFieldOption' } & Pick< + NumberFieldOption, + 'entityId' | 'displayName' + >) + | ({ __typename?: 'TextFieldOption' } & Pick< + TextFieldOption, + 'entityId' | 'displayName' + >) } > > diff --git a/pages/search.tsx b/pages/search.tsx index 51f927acc..24238768c 100644 --- a/pages/search.tsx +++ b/pages/search.tsx @@ -1,21 +1,21 @@ -import { GetStaticPropsContext, InferGetStaticPropsType } from 'next' -import { useRouter } from 'next/router' -import Link from 'next/link' import cn from 'classnames' +import Link from 'next/link' +import { range } from 'lodash' +import { useRouter } from 'next/router' +import { GetStaticPropsContext, InferGetStaticPropsType } from 'next' +import { Layout } from '@components/core' +import { ProductCard } from '@components/product' +import { Container, Grid, Skeleton } from '@components/ui' +import getSlug from '@utils/get-slug' +import useSearch from '@lib/bigcommerce/products/use-search' import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages' import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info' -import useSearch from '@lib/bigcommerce/products/use-search' -import { Layout } from '@components/core' -import { Container, Grid, Skeleton } from '@components/ui' -import { ProductCard } from '@components/product' -import getSlug from '@utils/get-slug' import { filterQuery, getCategoryPath, getDesignerPath, useSearchMeta, } from '@utils/search' -import { range } from 'lodash' export async function getStaticProps({ preview }: GetStaticPropsContext) { const { pages } = await getAllPages() @@ -138,25 +138,26 @@ export default function Search({ )} - ( - - ) - : () => ( - - ) - } - /> + + {data ? ( + + {data.products.map((p: any) => ( + + ))} + + ) : ( + + {range(12).map(() => ( + + ))} + + )}