mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36:58 +00:00
24 lines
740 B
TypeScript
24 lines
740 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]));
|
|
console.log({ selectedOptionsMap, variants });
|
|
const variant = variants.find((variant: ProductVariant) =>
|
|
variant.selectedOptions.every((option) => option.value === selectedOptionsMap.get(option.name))
|
|
);
|
|
|
|
console.log({ variant });
|
|
return <CoreCharge variant={variant} sm />;
|
|
};
|
|
|
|
export default CoreChargeBadge;
|