PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.10.0
GiveWP – Donation Plugin and Fundraising Platform v3.10.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / EventTickets / resources / admin / components / CreateEventModal / index.tsx
index.tsx
59 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {useState} from 'react';
2 import {__} from '@wordpress/i18n';
3 import styles from './CreateEventModal.module.scss';
4 import EventFormModal from '../EventFormModal';
5
6 /**
7 * Auto open modal if the URL has the query parameter id as new
8 *
9 * @since 3.6.0
10 */
11 const autoOpenModal = () => {
12 const queryParams = new URLSearchParams(window.location.search);
13 const newParam = queryParams.get('new');
14
15 return newParam === 'event';
16 };
17
18 /**
19 * Create Event Modal component
20 *
21 * @since 3.6.0
22 */
23 export default function CreateEventModal() {
24 const [isOpen, setOpen] = useState<boolean>(autoOpenModal());
25 const openModal = () => setOpen(true);
26 const closeModal = (response: ResponseProps = {}) => {
27 setOpen(false);
28
29 if (response?.id) {
30 window.location.href =
31 window.GiveEventTickets.adminUrl +
32 'edit.php?post_type=give_forms&page=give-event-tickets&id=' +
33 response?.id;
34 }
35 };
36
37 const apiSettings = window.GiveEventTickets;
38 // Remove the /list-table from the apiRoot. This is a hack to make the API work while we don't refactor other list tables.
39 apiSettings.apiRoot = apiSettings.apiRoot.replace('/list-table', '');
40
41 return (
42 <>
43 <a className={`button button-primary ${styles.createEventButton}`} onClick={openModal}>
44 {__('Create event', 'give')}
45 </a>
46 <EventFormModal
47 isOpen={isOpen}
48 handleClose={closeModal}
49 title={__('Create your event', 'give')}
50 apiSettings={apiSettings}
51 />
52 </>
53 );
54 }
55
56 type ResponseProps = {
57 id?: string;
58 };
59