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