-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add event tickets block, field template (#7217)
- Loading branch information
1 parent
1d56278
commit aa4a940
Showing
26 changed files
with
891 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/EventTickets/resources/blocks/EventTicketsBlock/Edit/BlockInspectorControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {InspectorControls} from '@wordpress/block-editor'; | ||
import {PanelBody, PanelRow, SelectControl} from '@wordpress/components'; | ||
import {createInterpolateElement} from '@wordpress/element'; | ||
import {__} from '@wordpress/i18n'; | ||
import CreateEventNotice from './components/CreateEventNotice'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function BlockInspectorControls({attributes, setAttributes}) { | ||
const {events} = window.eventTicketsBlockSettings; | ||
const {eventId} = attributes; | ||
|
||
const eventOptions = | ||
events.map((event) => { | ||
return {label: event.title, value: `${event.id}`}; | ||
}) ?? []; | ||
|
||
return ( | ||
<InspectorControls> | ||
<PanelBody title={__('Event', 'give')} initialOpen={true}> | ||
{events.length === 0 ? ( | ||
<CreateEventNotice /> | ||
) : ( | ||
<PanelRow> | ||
<SelectControl | ||
label={__('Event Name', 'give')} | ||
help={createInterpolateElement( | ||
__('Add or edit an event in the <a>events page</a>.', 'give'), | ||
{ | ||
a: <a href={window.eventTicketsBlockSettings.listEventsUrl} target="_blank" />, | ||
} | ||
)} | ||
value={`${eventId}`} | ||
options={[{label: 'Select', value: ''}, ...eventOptions]} | ||
onChange={(value: string) => setAttributes({eventId: Number(value)})} | ||
/> | ||
</PanelRow> | ||
)} | ||
</PanelBody> | ||
</InspectorControls> | ||
); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/EventTickets/resources/blocks/EventTicketsBlock/Edit/BlockPlaceholder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import EventTicketsHeader from '../../../components/EventTicketsHeader'; | ||
import EventTicketsDescription from '../../../components/EventTicketsDescription'; | ||
import EventTicketsList from '../../../components/EventTicketsList'; | ||
import {getWindowData} from '@givewp/form-builder/common'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function BlockPlaceholder({attributes}) { | ||
const {events, ticketsLabel, soldOutMessage} = window.eventTicketsBlockSettings; | ||
const event = events.find((event) => event.id === attributes.eventId); | ||
const {currency} = getWindowData(); | ||
|
||
if (!event || !event.tickets.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={'givewp-event-tickets-block__placeholder'}> | ||
<div className={'givewp-event-tickets'}> | ||
<EventTicketsHeader title={event.title} date={event.date} /> | ||
|
||
{event.description && <EventTicketsDescription description={event.description} />} | ||
|
||
<EventTicketsList | ||
tickets={event.tickets} | ||
ticketsLabel={ticketsLabel} | ||
soldOutMessage={soldOutMessage} | ||
currency={currency} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/EventTickets/resources/blocks/EventTicketsBlock/Edit/BlockPlaceholderNoEvents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {__} from '@wordpress/i18n'; | ||
import {createInterpolateElement} from '@wordpress/element'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function BlockPlaceholderNoEvents() { | ||
return ( | ||
<div className={'givewp-event-tickets-block__placeholder--no-events'}> | ||
<p> | ||
{createInterpolateElement( | ||
__( | ||
'No events created yet. Go to the <a>events page</a> to create and manage your own event.', | ||
'give' | ||
), | ||
{ | ||
a: <a href={window.eventTicketsBlockSettings.listEventsUrl} target="_blank" />, | ||
} | ||
)} | ||
</p> | ||
</div> | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
src/EventTickets/resources/blocks/EventTicketsBlock/Edit/BlockPlaceholderSelectEvent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {__} from '@wordpress/i18n'; | ||
import {SelectControl} from '@wordpress/components'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function BlockPlaceholderSelectEvent({attributes, setAttributes}) { | ||
const {events} = window.eventTicketsBlockSettings; | ||
const eventOptions = | ||
events.map((event) => { | ||
return {label: event.title, value: `${event.id}`}; | ||
}) ?? []; | ||
|
||
return ( | ||
<div className={'givewp-event-tickets-block__placeholder--select-event'}> | ||
<p> | ||
<strong>{__('No event selected yet', 'give')}</strong> | ||
</p> | ||
<SelectControl | ||
label={__('Select your preferred event for this donation form', 'give')} | ||
value={`${attributes.eventId}`} | ||
options={[{label: 'Select', value: ''}, ...eventOptions]} | ||
onChange={(value: string) => setAttributes({eventId: Number(value)})} | ||
/> | ||
</div> | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
...entTickets/resources/blocks/EventTicketsBlock/Edit/components/CreateEventNotice/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {__} from '@wordpress/i18n'; | ||
import {Notice} from '@wordpress/components'; | ||
import {createInterpolateElement} from '@wordpress/element'; | ||
|
||
import './styles.scss'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function CreateEventNotice() { | ||
return ( | ||
<div className={`givewp-event-tickets-block__create-event-notice`}> | ||
<Notice isDismissible={false} status="warning"> | ||
<h4>{__('No event created yet', 'give')}</h4> | ||
<p>{__('Donors will not be able to see any event on this form', 'give')}</p> | ||
<p>{createInterpolateElement( | ||
__('<a>Create an event</a>', 'give'), | ||
{ | ||
a: <a href={window.eventTicketsBlockSettings.createEventUrl} target="_blank" />, | ||
} | ||
)}</p> | ||
</Notice> | ||
</div> | ||
); | ||
} |
31 changes: 31 additions & 0 deletions
31
...tTickets/resources/blocks/EventTicketsBlock/Edit/components/CreateEventNotice/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.givewp-event-tickets-block__create-event-notice { | ||
margin-bottom: var(--givewp-spacing-4); | ||
|
||
.components-notice { | ||
margin: 0; | ||
padding: var(--givewp-spacing-3) var(--givewp-spacing-4); | ||
|
||
&__content { | ||
margin: 0; | ||
|
||
h4, p { | ||
font-size: 0.75rem; | ||
line-height: 1.5; | ||
margin: 0; | ||
} | ||
|
||
p { | ||
color: var(--givewp-grey-700); | ||
margin-top: var(--givewp-spacing-2); | ||
|
||
a { | ||
color: var(--givewp-grey-900); | ||
|
||
&:hover { | ||
text-decoration: none; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/EventTickets/resources/blocks/EventTicketsBlock/Edit/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import BlockInspectorControls from './BlockInspectorControls'; | ||
import BlockPlaceholderNoEvents from './BlockPlaceholderNoEvents'; | ||
import BlockPlaceholder from './BlockPlaceholder'; | ||
import BlockPlaceholderSelectEvent from './BlockPlaceholderSelectEvent'; | ||
|
||
import './styles.scss'; | ||
|
||
/** | ||
* @unreleased | ||
*/ | ||
export default function Edit(props) { | ||
const {events} = window.eventTicketsBlockSettings; | ||
const { | ||
attributes: {eventId}, | ||
} = props; | ||
|
||
const eventIds = events.map((event) => event.id); | ||
|
||
return ( | ||
<> | ||
{events.length === 0 ? ( | ||
<BlockPlaceholderNoEvents /> | ||
) : !eventId || !eventIds.includes(eventId) ? ( | ||
<BlockPlaceholderSelectEvent {...props} /> | ||
) : ( | ||
<BlockPlaceholder {...props} /> | ||
)} | ||
|
||
<BlockInspectorControls {...props} /> | ||
</> | ||
); | ||
} |
Oops, something went wrong.