| 1 |
import {__} from '@wordpress/i18n'; |
| 2 |
import styles from './CreateCampaignModal.module.scss'; |
| 3 |
import CampaignFormModal from '../CampaignFormModal'; |
| 4 |
import {getGiveCampaignsListTableWindowData} from '../CampaignsListTable'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Create Campaign Modal component |
| 8 |
* |
| 9 |
* @since 4.0.0 |
| 10 |
*/ |
| 11 |
export default function CreateCampaignModal({isOpen, setOpen}) { |
| 12 |
|
| 13 |
const openModal = () => setOpen(true); |
| 14 |
const closeModal = (response: ResponseProps = {}) => { |
| 15 |
setOpen(false); |
| 16 |
|
| 17 |
if (response?.id) { |
| 18 |
window.location.href = |
| 19 |
getGiveCampaignsListTableWindowData().adminUrl + |
| 20 |
'edit.php?post_type=give_forms&page=give-campaigns&id=' + |
| 21 |
response?.id; |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
const apiSettings = getGiveCampaignsListTableWindowData(); |
| 26 |
// Remove the /list-table from the apiRoot. This is a hack to make the API work while we don't refactor other list tables. |
| 27 |
apiSettings.apiRoot = apiSettings.apiRoot.replace('/list-table', ''); |
| 28 |
|
| 29 |
return ( |
| 30 |
<> |
| 31 |
<a |
| 32 |
style={{borderRadius: '4px'}} |
| 33 |
className={`button button-primary ${styles.createCampaignButton}`} |
| 34 |
onClick={openModal} |
| 35 |
> |
| 36 |
{__('Create campaign', 'give')} |
| 37 |
</a> |
| 38 |
<CampaignFormModal isOpen={isOpen} handleClose={closeModal} apiSettings={apiSettings} /> |
| 39 |
</> |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
type ResponseProps = { |
| 44 |
id?: string; |
| 45 |
}; |
| 46 |
|