give
/
src
/
DonorDashboards
/
resources
/
js
/
app
/
components
/
subscription-row
Last commit date
index.tsx
1 year ago
style.scss
1 year ago
index.tsx
89 lines
| 1 | import {useState} from 'react'; |
| 2 | import {Link} from 'react-router-dom'; |
| 3 | import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; |
| 4 | import {__} from '@wordpress/i18n'; |
| 5 | |
| 6 | import {useWindowSize} from '../../hooks'; |
| 7 | import SubscriptionCancelModal from '../subscription-cancel-modal'; |
| 8 | |
| 9 | import './style.scss'; |
| 10 | |
| 11 | const SubscriptionRow = ({subscription}) => { |
| 12 | const [isCancelModalOpen, setIsCancelModalOpen] = useState<boolean>(false); |
| 13 | |
| 14 | const {width} = useWindowSize(); |
| 15 | const {id, payment, form, gateway} = subscription; |
| 16 | |
| 17 | const gatewayCanUpdateSubscription = gateway.can_update || gateway.can_update_payment_method; |
| 18 | |
| 19 | return ( |
| 20 | <div className="give-donor-dashboard-table__row"> |
| 21 | <div className="give-donor-dashboard-table__column"> |
| 22 | {width < 920 && <div className="give-donor-dashboard-table__mobile-header">{__('Amount', 'give')}</div>} |
| 23 | <div className="give-donor-dashboard-table__donation-amount"> |
| 24 | {payment.amount.formatted} / {payment.frequency} |
| 25 | </div> |
| 26 | {form.title} |
| 27 | </div> |
| 28 | <div className="give-donor-dashboard-table__column"> |
| 29 | {width < 920 && <div className="give-donor-dashboard-table__mobile-header">{__('Status', 'give')}</div>} |
| 30 | <div className="give-donor-dashboard-table__donation-status"> |
| 31 | <div |
| 32 | className="give-donor-dashboard-table__donation-status-indicator" |
| 33 | style={{background: payment.status.color}} |
| 34 | /> |
| 35 | <div className="give-donor-dashboard-table__donation-status-label">{payment.status.label}</div> |
| 36 | </div> |
| 37 | </div> |
| 38 | <div className="give-donor-dashboard-table__column"> |
| 39 | {width < 920 && ( |
| 40 | <div className="give-donor-dashboard-table__mobile-header">{__('Next Renewal', 'give')}</div> |
| 41 | )} |
| 42 | {payment.renewalDate} |
| 43 | </div> |
| 44 | <div className="give-donor-dashboard-table__column"> |
| 45 | {width < 920 && ( |
| 46 | <div className="give-donor-dashboard-table__mobile-header">{__('Progress', 'give')}</div> |
| 47 | )} |
| 48 | {payment.progress} |
| 49 | </div> |
| 50 | <div className="give-donor-dashboard-table__pill"> |
| 51 | <div className="give-donor-dashboard-table__donation-id">ID: {payment.serialCode}</div> |
| 52 | <div className="give-donor-dashboard-table__donation-receipt"> |
| 53 | <Link to={`/recurring-donations/receipt/${id}`}> |
| 54 | {__('View Subscription', 'give')} <FontAwesomeIcon icon="arrow-right" /> |
| 55 | </Link> |
| 56 | </div> |
| 57 | {gatewayCanUpdateSubscription && ( |
| 58 | <div className="give-donor-dashboard-table__donation-receipt"> |
| 59 | <Link to={`/recurring-donations/manage/${id}`}> |
| 60 | {__('Manage Subscription', 'give')} <FontAwesomeIcon icon="arrow-right" /> |
| 61 | </Link> |
| 62 | </div> |
| 63 | )} |
| 64 | {gateway.can_cancel && !gatewayCanUpdateSubscription && ( |
| 65 | <> |
| 66 | {isCancelModalOpen && ( |
| 67 | <SubscriptionCancelModal |
| 68 | id={id} |
| 69 | isOpen={isCancelModalOpen} |
| 70 | toggleModal={() => setIsCancelModalOpen(!isCancelModalOpen)} |
| 71 | /> |
| 72 | )} |
| 73 | <div className="give-donor-dashboard-table__donation-receipt"> |
| 74 | <a |
| 75 | className={'give-donor-dashboard-table__donation-receipt__cancel'} |
| 76 | onClick={() => setIsCancelModalOpen(true)} |
| 77 | > |
| 78 | {__('Cancel Subscription', 'give')} |
| 79 | </a> |
| 80 | </div> |
| 81 | </> |
| 82 | )} |
| 83 | </div> |
| 84 | </div> |
| 85 | ); |
| 86 | }; |
| 87 | |
| 88 | export default SubscriptionRow; |
| 89 |