mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 06:56:59 +00:00
Move to components, and updates
This commit is contained in:
parent
c46ac015ef
commit
0968c0268a
@ -130,7 +130,7 @@ export interface ProductMetafield {
|
|||||||
* {
|
* {
|
||||||
* // Namespace, the container for a set of metadata
|
* // Namespace, the container for a set of metadata
|
||||||
* reviews: {
|
* reviews: {
|
||||||
* // Key of the metafield, used to differentiate between metafields of the same namespace
|
* // Key of the metafield
|
||||||
* rating: {
|
* rating: {
|
||||||
* key: 'rating',
|
* key: 'rating',
|
||||||
* value: 5,
|
* value: 5,
|
||||||
@ -216,7 +216,7 @@ export interface Product {
|
|||||||
* {
|
* {
|
||||||
* // Namespace, the container for a set of metadata
|
* // Namespace, the container for a set of metadata
|
||||||
* reviews: {
|
* reviews: {
|
||||||
* // Key of the metafield, used to differentiate between metafields of the same namespace
|
* // Key of the metafield
|
||||||
* rating: {
|
* rating: {
|
||||||
* key: 'rating',
|
* key: 'rating',
|
||||||
* value: 4,
|
* value: 4,
|
||||||
|
@ -156,7 +156,7 @@ export function normalizeMetafields(
|
|||||||
type,
|
type,
|
||||||
namespace,
|
namespace,
|
||||||
value,
|
value,
|
||||||
html: getMetafieldValue(type, value, locale),
|
valueHtml: getMetafieldValue(type, value, locale),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output[namespace]) {
|
if (!output[namespace]) {
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
import { ProductCustomField } from '@commerce/types/product'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
customFields: ProductCustomField[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductCustomFields: React.FC<Props> = ({ customFields }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{customFields.map((field) => (
|
||||||
|
<div
|
||||||
|
key={field.id}
|
||||||
|
className="flex gap-2 border-b py-3 border-accent-2 border-dashed last:border-b-0"
|
||||||
|
>
|
||||||
|
<strong className="leading-7">{field.name}:</strong>
|
||||||
|
<span>{field.value}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProductCustomFields
|
1
site/components/product/ProductCustomFields/index.ts
Normal file
1
site/components/product/ProductCustomFields/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as ProductCustomFields } from './ProductCustomFields'
|
@ -0,0 +1,29 @@
|
|||||||
|
import type { FC } from 'react'
|
||||||
|
import type { ProductMetafields as IProductMetafields } from '@commerce/types/product'
|
||||||
|
import Text from '@components/ui/Text'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
metafields: IProductMetafields
|
||||||
|
/**
|
||||||
|
* The namespace of the metafields to display.
|
||||||
|
*/
|
||||||
|
namespace: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProductMetafields: FC<Props> = ({ metafields, namespace }) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Object.values(metafields[namespace] ?? {}).map((field) => (
|
||||||
|
<div
|
||||||
|
key={field.key}
|
||||||
|
className="flex gap-2 border-b py-3 border-accent-2 border-dashed last:border-b-0"
|
||||||
|
>
|
||||||
|
<strong className="leading-7">{field.name}:</strong>
|
||||||
|
<Text html={field.valueHtml || field.value} className="!mx-0" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ProductMetafields
|
1
site/components/product/ProductMetafields/index.ts
Normal file
1
site/components/product/ProductMetafields/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as ProductMetafields } from './ProductMetafields'
|
@ -10,6 +10,8 @@ import {
|
|||||||
SelectedOptions,
|
SelectedOptions,
|
||||||
} from '../helpers'
|
} from '../helpers'
|
||||||
import ErrorMessage from '@components/ui/ErrorMessage'
|
import ErrorMessage from '@components/ui/ErrorMessage'
|
||||||
|
import { ProductCustomFields } from '../ProductCustomFields'
|
||||||
|
import { ProductMetafields } from '../ProductMetafields'
|
||||||
|
|
||||||
interface ProductSidebarProps {
|
interface ProductSidebarProps {
|
||||||
product: Product
|
product: Product
|
||||||
@ -94,32 +96,25 @@ const ProductSidebar: FC<ProductSidebarProps> = ({ product, className }) => {
|
|||||||
This is a limited edition production run. Printing starts when the
|
This is a limited edition production run. Printing starts when the
|
||||||
drop ends.
|
drop ends.
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|
||||||
<Collapse title="Details">
|
<Collapse title="Details">
|
||||||
This is a limited edition production run. Printing starts when the
|
This is a limited edition production run. Printing starts when the
|
||||||
drop ends. Reminder: Bad Boys For Life. Shipping may take 10+ days due
|
drop ends. Reminder: Bad Boys For Life. Shipping may take 10+ days due
|
||||||
to COVID-19.
|
to COVID-19.
|
||||||
</Collapse>
|
</Collapse>
|
||||||
{(product.customFields || product.metafields) && (
|
|
||||||
<Collapse title="Specifications">
|
|
||||||
{product.customFields?.map((field) => (
|
|
||||||
<div
|
|
||||||
key={field.id}
|
|
||||||
className="flex gap-2 border-b py-3 border-accent-2 border-dashed last:border-b-0"
|
|
||||||
>
|
|
||||||
<strong className="leading-7">{field.name}:</strong>
|
|
||||||
<span>{field.value}</span>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{Object.values(product.metafields?.my_fields ?? {}).map((field) => (
|
{product.customFields && product.customFields?.length > 0 && (
|
||||||
<div
|
<Collapse title="Specifications">
|
||||||
key={field.key}
|
<ProductCustomFields customFields={product.customFields} />
|
||||||
className="flex gap-2 border-b py-3 border-accent-2 border-dashed last:border-b-0"
|
</Collapse>
|
||||||
>
|
)}
|
||||||
<strong className="leading-7">{field.name}:</strong>
|
|
||||||
<Text html={field.valueHtml || field.value} className="!mx-0" />
|
{product.metafields?.my_fields && (
|
||||||
</div>
|
<Collapse title="Specifications">
|
||||||
))}
|
<ProductMetafields
|
||||||
|
metafields={product.metafields}
|
||||||
|
namespace="my_fields"
|
||||||
|
/>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -13,11 +13,10 @@ import { ProductView } from '@components/product'
|
|||||||
// Used by the Shopify Example
|
// Used by the Shopify Example
|
||||||
const withMetafields = [
|
const withMetafields = [
|
||||||
{ namespace: 'reviews', key: 'rating' },
|
{ namespace: 'reviews', key: 'rating' },
|
||||||
{ namespace: 'descriptors', key: 'care_guide' },
|
{ namespace: 'reviews', key: 'count' },
|
||||||
{ namespace: 'my_fields', key: 'weight' },
|
|
||||||
{ namespace: 'my_fields', key: 'width' },
|
{ namespace: 'my_fields', key: 'width' },
|
||||||
|
{ namespace: 'my_fields', key: 'weight' },
|
||||||
{ namespace: 'my_fields', key: 'length' },
|
{ namespace: 'my_fields', key: 'length' },
|
||||||
{ namespace: 'my_fields', key: 'manufacturer_url' },
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export async function getStaticProps({
|
export async function getStaticProps({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user