give
/
src
/
DonorDashboards
/
resources
/
js
/
app
/
components
/
subscription-receipt
Last commit date
index.js
4 years ago
index.js
65 lines
| 1 | import {Fragment} from 'react'; |
| 2 | import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 3 | |
| 4 | const SubscriptionReceipt = ({subscription}) => { |
| 5 | if (subscription === undefined) { |
| 6 | return null; |
| 7 | } |
| 8 | |
| 9 | const {receipt} = subscription; |
| 10 | |
| 11 | let donationSection; |
| 12 | |
| 13 | const sections = receipt.map((section, sectionIndex) => { |
| 14 | const lineItems = section.lineItems.map((item, itemIndex) => { |
| 15 | const value = |
| 16 | typeof item.value === 'object' && item.value.color ? ( |
| 17 | <Fragment> |
| 18 | <div |
| 19 | className="give-donor-dashboard-donation-receipt__status-indicator" |
| 20 | style={{background: item.value.color}} |
| 21 | /> |
| 22 | {item.value.label} |
| 23 | </Fragment> |
| 24 | ) : ( |
| 25 | item.value |
| 26 | ); |
| 27 | |
| 28 | return ( |
| 29 | <div |
| 30 | className={`give-donor-dashboard-donation-receipt__row${ |
| 31 | item.class.includes('total') ? ' give-donor-dashboard-donation-receipt__row--footer' : '' |
| 32 | }`} |
| 33 | key={itemIndex} |
| 34 | > |
| 35 | <div className="give-donor-dashboard-donation-receipt__detail"> |
| 36 | {item.icon && <FontAwesomeIcon icon={item.icon} fixedWidth={true} />} {item.label} |
| 37 | </div> |
| 38 | <div className="give-donor-dashboard-donation-receipt__value">{value}</div> |
| 39 | </div> |
| 40 | ); |
| 41 | }); |
| 42 | |
| 43 | if (section.id === 'Donation') { |
| 44 | donationSection = ( |
| 45 | <div className="give-donor-dashboard-donation-receipt__table" key={sectionIndex}> |
| 46 | {lineItems} |
| 47 | </div> |
| 48 | ); |
| 49 | return null; |
| 50 | } else { |
| 51 | return ( |
| 52 | <div className="give-donor-dashboard-donation-receipt__table" key={sectionIndex}> |
| 53 | {lineItems} |
| 54 | </div> |
| 55 | ); |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | // Ensure that "Donation" section is last |
| 60 | sections.push(donationSection); |
| 61 | |
| 62 | return sections; |
| 63 | }; |
| 64 | export default SubscriptionReceipt; |
| 65 |