store
1 year ago
AddonRow.jsx
1 year ago
App.jsx
1 year ago
Metabox.jsx
1 year ago
Modal.jsx
1 year ago
Notices.jsx
1 year ago
Select2.jsx
1 year ago
Settings.jsx
1 year ago
Step1.jsx
1 year ago
Step2.jsx
1 year ago
Step3.jsx
1 year ago
StepWrapper.jsx
1 year ago
main.js
1 year ago
AddonRow.jsx
92 lines
| 1 | /** |
| 2 | * External Dependencies |
| 3 | */ |
| 4 | import jQuery from 'jquery'; |
| 5 | import classnames from 'classnames'; |
| 6 | |
| 7 | /** |
| 8 | * WordPress Dependencies |
| 9 | */ |
| 10 | import { useContext } from '@wordpress/element'; |
| 11 | |
| 12 | /** |
| 13 | * Internal Dependencies |
| 14 | */ |
| 15 | import { OneClickContext } from './store/context'; |
| 16 | import { noticeSuccess, noticeError, removeAllNotices } from './Notices'; |
| 17 | |
| 18 | export default function AddonRow() { |
| 19 | const { addonRow } = advancedAds.oneclick; |
| 20 | const { isConnected, toggleMetabox, disconnect } = useContext(OneClickContext); |
| 21 | |
| 22 | const buttonRow = classnames('cta', { |
| 23 | primary: !isConnected, |
| 24 | secondary: isConnected, |
| 25 | }); |
| 26 | |
| 27 | const onDisconnect = () => { |
| 28 | jQuery.ajax({ |
| 29 | url: advancedAds.endpoints.ajaxUrl, |
| 30 | type: 'POST', |
| 31 | data: { |
| 32 | action: 'pubguru_disconnect', |
| 33 | nonce: advancedAds.oneclick.security, |
| 34 | }, |
| 35 | success: (response) => { |
| 36 | if (response.success) { |
| 37 | noticeSuccess( |
| 38 | response.data.message |
| 39 | ); |
| 40 | disconnect(); |
| 41 | } else { |
| 42 | noticeError( |
| 43 | response.data.message |
| 44 | ); |
| 45 | } |
| 46 | }, |
| 47 | error: (error) => { |
| 48 | noticeError( |
| 49 | 'Error disconnecting: ' + error.statusText |
| 50 | ); |
| 51 | }, |
| 52 | }) |
| 53 | }; |
| 54 | |
| 55 | return ( |
| 56 | <div className="single-item add-on js-pubguru-connect"> |
| 57 | <div className="item-details"> |
| 58 | <div className="icon"> |
| 59 | <img src={addonRow.icon} alt="" /> |
| 60 | </div> |
| 61 | <span></span> |
| 62 | <div className="name">{addonRow.title}</div> |
| 63 | <span></span> |
| 64 | <div className="description">{addonRow.content}</div> |
| 65 | <span></span> |
| 66 | <div className={buttonRow}> |
| 67 | {isConnected ? ( |
| 68 | <button |
| 69 | className="button" |
| 70 | onClick={onDisconnect} |
| 71 | > |
| 72 | <i className="dashicons dashicons-dismiss"></i> |
| 73 | {addonRow.disconnect} |
| 74 | </button> |
| 75 | ) : ( |
| 76 | <button |
| 77 | className="button" |
| 78 | onClick={() => { |
| 79 | removeAllNotices(); |
| 80 | toggleMetabox(true); |
| 81 | }} |
| 82 | > |
| 83 | <i className="dashicons dashicons-plus"></i> |
| 84 | {addonRow.connect} |
| 85 | </button> |
| 86 | )} |
| 87 | </div> |
| 88 | </div> |
| 89 | </div> |
| 90 | ); |
| 91 | } |
| 92 |