give
/
src
/
EventTickets
/
resources
/
blocks
/
EventTicketsBlock
/
Edit
/
BlockInspectorControls.tsx
components
2 years ago
BlockInspectorControls.tsx
2 years ago
BlockPlaceholder.tsx
1 year ago
BlockPlaceholderNoEvents.tsx
2 years ago
BlockPlaceholderSelectEvent.tsx
2 years ago
index.tsx
2 years ago
styles.scss
1 year ago
BlockInspectorControls.tsx
44 lines
| 1 | import {InspectorControls} from '@wordpress/block-editor'; |
| 2 | import {PanelBody, PanelRow, SelectControl} from '@wordpress/components'; |
| 3 | import {createInterpolateElement} from '@wordpress/element'; |
| 4 | import {__} from '@wordpress/i18n'; |
| 5 | import CreateEventNotice from './components/CreateEventNotice'; |
| 6 | |
| 7 | /** |
| 8 | * @since 3.6.0 |
| 9 | */ |
| 10 | export default function BlockInspectorControls({attributes, setAttributes}) { |
| 11 | const {events} = window.eventTicketsBlockSettings; |
| 12 | const {eventId} = attributes; |
| 13 | |
| 14 | const eventOptions = |
| 15 | events.map((event) => { |
| 16 | return {label: event.title, value: `${event.id}`}; |
| 17 | }) ?? []; |
| 18 | |
| 19 | return ( |
| 20 | <InspectorControls> |
| 21 | <PanelBody title={__('Event', 'give')} initialOpen={true}> |
| 22 | {events.length === 0 ? ( |
| 23 | <CreateEventNotice /> |
| 24 | ) : ( |
| 25 | <PanelRow> |
| 26 | <SelectControl |
| 27 | label={__('Event Name', 'give')} |
| 28 | help={createInterpolateElement( |
| 29 | __('Add or edit an event in the <a>events page</a>.', 'give'), |
| 30 | { |
| 31 | a: <a href={window.eventTicketsBlockSettings.listEventsUrl} target="_blank" />, |
| 32 | } |
| 33 | )} |
| 34 | value={`${eventId}`} |
| 35 | options={[{label: 'Select', value: ''}, ...eventOptions]} |
| 36 | onChange={(value: string) => setAttributes({eventId: Number(value)})} |
| 37 | /> |
| 38 | </PanelRow> |
| 39 | )} |
| 40 | </PanelBody> |
| 41 | </InspectorControls> |
| 42 | ); |
| 43 | } |
| 44 |