File size: 1,790 Bytes
1e92f2d |
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 |
import { recordTracksEvent } from '@automattic/calypso-analytics';
import DOMPurify from 'dompurify';
import React from 'react';
import TwentyPercentImageCoupon from 'calypso/assets/images/customer-home/notice-home-limited-time-coupon-20-percent.svg';
import ThirtyPercentImageCoupon from 'calypso/assets/images/customer-home/notice-home-limited-time-coupon-30-percent.svg';
import { NOTICE_HOME_LIMITED_TIME_OFFER_COUPON } from 'calypso/my-sites/customer-home/cards/constants';
import Task from 'calypso/my-sites/customer-home/cards/tasks/task';
// Sanitize HTML content to allow only <b> tags and escape other tags.
const sanitizeHTMLWithBTags = ( html ) => {
// Getting an instance of DOMPurify this way is needed to fix a related JEST test.
return DOMPurify.sanitize( html, {
ALLOWED_TAGS: [ 'b' ],
} );
};
export default function HomeTaskTemplate( { id, CTA, tracks, ...props } ) {
const jitmProps = { id, cta_name: id, jitm: true };
const tracksClickProperties = { ...jitmProps, ...tracks?.click?.props };
const illustration =
props.featureClass === 'limited_time_30_off_home_card'
? ThirtyPercentImageCoupon
: TwentyPercentImageCoupon;
const handleClick = () => {
if ( id ) {
recordTracksEvent?.( 'calypso_home_task_cta_click', {
cta_name: id,
...tracksClickProperties,
} );
}
};
return (
<Task
title={ props.message }
description={
<>
<span
// eslint-disable-next-line react/no-danger
dangerouslySetInnerHTML={ { __html: sanitizeHTMLWithBTags( props.description ) } }
/>
</>
}
actionText={ CTA.message }
actionUrl={ CTA.link }
actionOnClick={ handleClick }
illustration={ illustration }
customClass="notice-offer-coupon"
taskId={ NOTICE_HOME_LIMITED_TIME_OFFER_COUPON }
/>
);
}
|