commerce/components/cart/core-charge-badge.tsx
Chloe 59c3f07beb
feat: adding more information warranty, part number, sku, speciall offers
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
2024-04-25 14:14:20 +07:00

22 lines
663 B
TypeScript

import CoreCharge from 'components/core-charge';
import { ProductVariant } from 'lib/shopify/types';
type CoreChargeBadgeProps = {
selectedOptions: {
name: string;
value: string;
}[];
variants: ProductVariant[];
};
const CoreChargeBadge = ({ variants, selectedOptions }: CoreChargeBadgeProps) => {
const selectedOptionsMap = new Map(selectedOptions.map((option) => [option.name, option.value]));
const variant = variants.find((variant: ProductVariant) =>
variant.selectedOptions.every((option) => option.value === selectedOptionsMap.get(option.name))
);
return <CoreCharge variant={variant} sm />;
};
export default CoreChargeBadge;