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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | 8x 8x 8x 8x 8x 8x 8x 8x | import { Coupon, GiftCertificate } from '@bigcommerce/checkout-sdk';
import React, { memo, useCallback, FunctionComponent } from 'react';
import { AppliedCoupon } from '../coupon';
import { AppliedGiftCertificate } from '../giftCertificate';
import AppliedRedeemable from './AppliedRedeemable';
interface AppliedCouponProps {
coupon: Coupon;
isRemoving?: boolean;
onRemoved(code: string): void;
}
const AppliedCouponChecklistItem: FunctionComponent<AppliedCouponProps> = ({
coupon,
onRemoved,
isRemoving = false,
}) => {
const handleRemove = useCallback(() => {
onRemoved(coupon.code);
}, [
coupon,
onRemoved,
]);
return (
<li className="form-checklist-item optimizedCheckout-form-checklist-item">
<AppliedRedeemable
isRemoving={ isRemoving }
onRemove={ handleRemove }
>
<AppliedCoupon coupon={ coupon } />
</AppliedRedeemable>
</li>
);
};
interface AppliedGiftCertificateProps {
giftCertificate: GiftCertificate;
isRemoving?: boolean;
onRemoved(code: string): void;
}
const AppliedGiftCertificateChecklistItem: FunctionComponent<AppliedGiftCertificateProps> = ({
giftCertificate,
onRemoved,
isRemoving = false,
}) => {
const handleRemove = useCallback(() => {
onRemoved(giftCertificate.code);
}, [
giftCertificate,
onRemoved,
]);
return (
<li className="form-checklist-item optimizedCheckout-form-checklist-item">
<AppliedRedeemable
isRemoving={ isRemoving }
onRemove={ handleRemove }
>
<AppliedGiftCertificate giftCertificate={ giftCertificate } />
</AppliedRedeemable>
</li>
);
};
export interface AppliedRedeemablesProps {
coupons?: Coupon[];
giftCertificates?: GiftCertificate[];
isRemovingGiftCertificate?: boolean;
isRemovingCoupon?: boolean;
onRemovedCoupon(code: string): void;
onRemovedGiftCertificate(code: string): void;
}
const AppliedRedeemables: FunctionComponent<AppliedRedeemablesProps> = ({
coupons = [],
giftCertificates = [],
isRemovingCoupon = false,
isRemovingGiftCertificate = false,
onRemovedCoupon,
onRemovedGiftCertificate,
}) => {
if (!coupons.length && !giftCertificates.length) {
return null;
}
return (
<ul className="form-checklist optimizedCheckout-form-checklist" data-test="redeemables-list">
{ coupons.map(coupon => (
<AppliedCouponChecklistItem
coupon={ coupon }
isRemoving={ isRemovingCoupon }
key={ coupon.code }
onRemoved={ onRemovedCoupon }
/>
)) }
{ giftCertificates.map(giftCertificate => (
<AppliedGiftCertificateChecklistItem
giftCertificate={ giftCertificate }
isRemoving={ isRemovingGiftCertificate }
key={ giftCertificate.code }
onRemoved={ onRemovedGiftCertificate }
/>
)) }
</ul>
);
};
export default memo(AppliedRedeemables);
|