forked from crowetic/commerce
Normalized Options and Swatches
This commit is contained in:
parent
dccc5ef430
commit
4fdaae2197
@ -25,8 +25,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ProductView: FC<Props> = ({ product }) => {
|
const ProductView: FC<Props> = ({ product }) => {
|
||||||
console.log(product)
|
|
||||||
|
|
||||||
const addItem = useAddItem()
|
const addItem = useAddItem()
|
||||||
const { price } = usePrice({
|
const { price } = usePrice({
|
||||||
amount: product.price.value,
|
amount: product.price.value,
|
||||||
@ -36,8 +34,6 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
|
|
||||||
const { openSidebar } = useUI()
|
const { openSidebar } = useUI()
|
||||||
|
|
||||||
// const options = getProductOptions(product)
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [choices, setChoices] = useState<SelectedOptions>({
|
const [choices, setChoices] = useState<SelectedOptions>({
|
||||||
size: null,
|
size: null,
|
||||||
@ -111,16 +107,16 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
|
|
||||||
<div className={s.sidebar}>
|
<div className={s.sidebar}>
|
||||||
<section>
|
<section>
|
||||||
{/* {options?.map((opt: any) => (
|
{product.options?.map((opt) => (
|
||||||
<div className="pb-4" key={opt.displayName}>
|
<div className="pb-4" key={opt.displayName}>
|
||||||
<h2 className="uppercase font-medium">{opt.displayName}</h2>
|
<h2 className="uppercase font-medium">{opt.displayName}</h2>
|
||||||
<div className="flex flex-row py-4">
|
<div className="flex flex-row py-4">
|
||||||
{opt.values.map((v: any, i: number) => {
|
{opt.values.map((v, i: number) => {
|
||||||
const active = (choices as any)[opt.displayName]
|
const active = (choices as any)[opt.displayName]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Swatch
|
<Swatch
|
||||||
key={`${v.entityId}-${i}`}
|
key={`${opt.id}-${i}`}
|
||||||
active={v.label === active}
|
active={v.label === active}
|
||||||
variant={opt.displayName}
|
variant={opt.displayName}
|
||||||
color={v.hexColors ? v.hexColors[0] : ''}
|
color={v.hexColors ? v.hexColors[0] : ''}
|
||||||
@ -138,7 +134,7 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))} */}
|
))}
|
||||||
|
|
||||||
<div className="pb-14 break-words w-full max-w-xl">
|
<div className="pb-14 break-words w-full max-w-xl">
|
||||||
<Text html={product.description} />
|
<Text html={product.description} />
|
||||||
|
@ -8,6 +8,7 @@ export function normalizeProduct(productNode: BCProduct): Product {
|
|||||||
productOptions,
|
productOptions,
|
||||||
prices,
|
prices,
|
||||||
path,
|
path,
|
||||||
|
options: _,
|
||||||
...rest
|
...rest
|
||||||
} = productNode
|
} = productNode
|
||||||
|
|
||||||
@ -29,8 +30,20 @@ export function normalizeProduct(productNode: BCProduct): Product {
|
|||||||
...rest,
|
...rest,
|
||||||
}))
|
}))
|
||||||
: [],
|
: [],
|
||||||
productOptions: productOptions.edges
|
options: productOptions.edges
|
||||||
? productOptions.edges.map(({ node }: any) => node)
|
? productOptions.edges.map(
|
||||||
|
({
|
||||||
|
node: {
|
||||||
|
entityId,
|
||||||
|
values: { edges },
|
||||||
|
...rest
|
||||||
|
},
|
||||||
|
}: any) => ({
|
||||||
|
id: entityId,
|
||||||
|
values: edges.map(({ node }: any) => node),
|
||||||
|
...rest,
|
||||||
|
})
|
||||||
|
)
|
||||||
: [],
|
: [],
|
||||||
price: {
|
price: {
|
||||||
value: prices?.price.value,
|
value: prices?.price.value,
|
||||||
|
12
framework/types.d.ts
vendored
12
framework/types.d.ts
vendored
@ -11,7 +11,19 @@ interface Product extends Entity {
|
|||||||
images: ProductImage[]
|
images: ProductImage[]
|
||||||
variants: ProductVariant[]
|
variants: ProductVariant[]
|
||||||
price: ProductPrice
|
price: ProductPrice
|
||||||
|
options: ProductOption[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ProductOption extends Entity {
|
||||||
|
displayName: string
|
||||||
|
values: ProductOptionValues[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ProductOptionValues {
|
||||||
|
label: string
|
||||||
|
hexColors?: string[]
|
||||||
|
}
|
||||||
|
|
||||||
interface ProductImage {
|
interface ProductImage {
|
||||||
url: string
|
url: string
|
||||||
alt?: string
|
alt?: string
|
||||||
|
@ -26,6 +26,12 @@
|
|||||||
"@framework": ["framework/bigcommerce"]
|
"@framework": ["framework/bigcommerce"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"],
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"./framework/types.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
"**/*.js"
|
||||||
|
],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user