All files / app/order mapFromDigital.tsx

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49  9x   9x   9x       25x               23x                   25x 1x           24x                         9x  
import { DigitalItem } from '@bigcommerce/checkout-sdk';
import React from 'react';
 
import { TranslatedString } from '../locale';
 
import getOrderSummaryItemImage from './getOrderSummaryItemImage';
import { OrderSummaryItemOption, OrderSummaryItemProps } from './OrderSummaryItem';
 
function mapFromDigital(item: DigitalItem): OrderSummaryItemProps {
    return {
        id: item.id,
        quantity: item.quantity,
        amount: item.extendedListPrice,
        amountAfterDiscount: item.extendedSalePrice,
        name: item.name,
        image: getOrderSummaryItemImage(item),
        productOptions: [
            ...(item.options || []).map(option => ({
                testId: 'cart-item-product-option',
                content: `${option.name} ${option.value}`,
            })),
            getDigitalItemDescription(item),
        ],
    };
}
 
function getDigitalItemDescription(item: DigitalItem): OrderSummaryItemOption {
    if (!item.downloadPageUrl) {
        return {
            testId: 'cart-item-digital-product',
            content: <TranslatedString id="cart.digital_item_text" />,
        };
    }
 
    return {
        testId: 'cart-item-digital-product-download',
        content:
            <a
                href={ item.downloadPageUrl }
                rel="noopener noreferrer"
                target="_blank"
            >
                <TranslatedString id="cart.downloads_action" />
            </a>,
    };
}
 
export default mapFromDigital;