This commit is contained in:
cond0r 2021-05-28 09:38:37 +03:00
parent f16cb7206b
commit af10abe3ba
7 changed files with 40 additions and 15 deletions

View File

@ -148,8 +148,11 @@ const ProductView: FC<Props> = ({ product }) => {
className={s.button} className={s.button}
onClick={addToCart} onClick={addToCart}
loading={loading} loading={loading}
disabled={variant?.availableForSale === false}
> >
Add to Cart {variant?.availableForSale === false
? 'Not Available'
: 'Add To Cart'}
</Button> </Button>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
.root { .root {
composes: root from 'components/ui/Button/Button.module.css'; composes: root from 'components/ui/Button/Button.module.css';
@apply h-12 py-0 px-3 bg-primary text-primary rounded-full mr-3 inline-flex @apply h-12 p-0 bg-primary text-primary rounded-full mr-3 inline-flex
items-center justify-center cursor-pointer transition duration-150 ease-in-out items-center justify-center cursor-pointer transition duration-150 ease-in-out
shadow-none border-gray-200 border box-border; shadow-none border-gray-200 border box-border;
@ -15,6 +15,10 @@
} }
} }
.size {
@apply px-3 leading-none;
}
.color { .color {
@apply text-black transition duration-150 ease-in-out; @apply text-black transition duration-150 ease-in-out;

View File

@ -21,14 +21,14 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
active, active,
...props ...props
}) => { }) => {
variant = variant?.toLowerCase()
label = label?.toLowerCase() label = label?.toLowerCase()
const isColor = color !== ''
const rootClassName = cn( const rootClassName = cn(
s.root, s.root,
{ {
[s.active]: active, [s.active]: active,
[s.size]: variant !== 'color', [s.size]: !isColor,
[s.color]: color, [s.color]: color,
[s.dark]: color ? isDark(color) : false, [s.dark]: color ? isDark(color) : false,
}, },
@ -38,17 +38,18 @@ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
return ( return (
<Button <Button
className={rootClassName} className={rootClassName}
style={color ? { backgroundColor: color } : {}} style={isColor ? { backgroundColor: color } : {}}
aria-label="Variant Swatch" aria-label="Variant Swatch"
{...(variant === 'color' && { title: label })} {...(isColor && { title: label })}
{...props} {...props}
> >
{variant === 'color' && active && ( {isColor ? (
<span> <span>
<Check /> <Check />
</span> </span>
) : (
label
)} )}
{variant !== 'color' ? label : null}
</Button> </Button>
) )
} }

View File

@ -28,6 +28,7 @@ export type ProductOptionValues = {
export type ProductVariant = { export type ProductVariant = {
id: string | number id: string | number
options: ProductOption[] options: ProductOption[]
availableForSale?: boolean
} }
export type Product = { export type Product = {

View File

@ -37,9 +37,12 @@ const normalizeProductOption = ({
label: value, label: value,
} }
if (displayName.match(/colou?r/gi)) { if (displayName.match(/colou?r/gi)) {
const mapedColor = colorMap[value]
if (mapedColor) {
output = { output = {
...output, ...output,
hexColors: [colorMap[value] || value], hexColors: [mapedColor],
}
} }
} }
return output return output
@ -56,7 +59,16 @@ const normalizeProductImages = ({ edges }: ImageConnection) =>
const normalizeProductVariants = ({ edges }: ProductVariantConnection) => { const normalizeProductVariants = ({ edges }: ProductVariantConnection) => {
return edges?.map( return edges?.map(
({ ({
node: { id, selectedOptions, sku, title, priceV2, compareAtPriceV2 }, node: {
id,
selectedOptions,
sku,
title,
priceV2,
compareAtPriceV2,
requiresShipping,
availableForSale,
},
}) => { }) => {
return { return {
id, id,
@ -64,7 +76,8 @@ const normalizeProductVariants = ({ edges }: ProductVariantConnection) => {
sku: sku ?? id, sku: sku ?? id,
price: +priceV2.amount, price: +priceV2.amount,
listPrice: +compareAtPriceV2?.amount, listPrice: +compareAtPriceV2?.amount,
requiresShipping: true, requiresShipping,
availableForSale,
options: selectedOptions.map(({ name, value }: SelectedOption) => { options: selectedOptions.map(({ name, value }: SelectedOption) => {
const options = normalizeProductOption({ const options = normalizeProductOption({
id, id,

View File

@ -3,6 +3,7 @@ const getProductQuery = /* GraphQL */ `
productByHandle(handle: $slug) { productByHandle(handle: $slug) {
id id
handle handle
availableForSale
title title
productType productType
vendor vendor
@ -33,6 +34,8 @@ const getProductQuery = /* GraphQL */ `
id id
title title
sku sku
availableForSale
requiresShipping
selectedOptions { selectedOptions {
name name
value value