Commit 4a3331e0 authored by Andrei Mondoc's avatar Andrei Mondoc
Browse files

handle PCP action ('info' or 'transact')

parent 8b17fde4
......@@ -111,7 +111,7 @@ class CiviCRM_Gutenberg_Blocks {
],
'action' => [
'type' => 'string',
'enum' => ['info', 'register'],
'enum' => ['info', 'register', 'transact'],
'default' => 'info',
],
'hijack' => [
......@@ -379,11 +379,23 @@ class CiviCRM_Gutenberg_Blocks {
ob_start();
$_REQUEST['id'] = $atts['id'];
try {
if ($atts['action'] == 'transact') {
$pcp = civicrm_api3('Pcp', 'getsingle', ['id' => $atts['id']]);
$_REQUEST['pcpId'] = $atts['id'];
$_REQUEST['id'] = $pcp['page_id'];
(new CRM_Contribute_Controller_Contribution(
'CiviContribute',
CRM_Core_Action::ADD
))->run();
}
else {
$_REQUEST['id'] = $atts['id'];
(new CRM_PCP_Page_PCPInfo())->run();
}
}
catch (Exception $e) {
return $e->getMessage();
}
......@@ -574,9 +586,12 @@ class CiviCRM_Gutenberg_Blocks {
break;
case 'petition':
case 'pcp':
unset($attributes['gid'], $attributes['action']);
break;
case 'pcp':
unset($attributes['gid']);
break;
}
return $attributes;
......
......@@ -12,7 +12,8 @@ import SelectPCPControl from './components/SelectPCPControl'
import SelectPetitionControl from './components/SelectPetitionControl'
import ProfileModeControl from './components/ProfileModeControl'
import ModeControl from './components/ModeControl'
import ActionControl from './components/ActionControl'
import EventActionControl from './components/EventActionControl'
import PcpActionControl from './components/PcpActionControl'
import ExtraAttributesListControl from './components/ExtraAttributesListControl'
import NoPreview from './components/NoPreview'
......@@ -29,6 +30,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
const profileModes = ['create', 'edit', 'view', 'search']
const pageModes = ['live', 'test']
let selectControl, actionControl
switch (component) {
case 'profile':
selectControl = <SelectProfileControl {...{ gid, setAttributes }} />
......@@ -37,6 +40,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
case 'event':
selectControl = <SelectEventControl {...{ id, setAttributes }} />
actionControl = <EventActionControl {...{ action, setAttributes }} />
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break
......@@ -49,6 +53,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
case 'pcp':
selectControl = <SelectPCPControl {...{ id, setAttributes }} />
actionControl = <PcpActionControl {...{ action, setAttributes }} />
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break
......@@ -57,12 +62,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
break
}
let selectControl,
profileModeControl = (
<ProfileModeControl {...{ mode, setAttributes }} />
),
modeControl = <ModeControl {...{ mode, setAttributes }} />,
actionControl = <ActionControl {...{ action, setAttributes }} />
let profileModeControl = <ProfileModeControl {...{ mode, setAttributes }} />
let modeControl = <ModeControl {...{ mode, setAttributes }} />
return (
<>
......@@ -72,10 +73,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
{selectControl}
<span style={{ height: '10px', display: 'block' }}></span>
{component == 'profile' ? profileModeControl : ''}
{component == 'event' ? actionControl : ''}
{['event', 'contribution', 'pcp'].includes(component)
? modeControl
: ''}
{['event', 'pcp'].includes(component) ? actionControl : ''}
{['event', 'contribution', 'pcp'].includes(component) ? modeControl : ''}
<HijackControl {...{ hijack, setAttributes }} />
</PanelBody>
<ExtraAttributesListControl
......
import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components'
const ActionControl = ({ action, setAttributes }) => {
const EventActionControl = ({ action, setAttributes }) => {
const onChangeAction = (action) => setAttributes({ action })
const options = [
{ label: __('Event Info Page', 'civicrm'), value: 'info' },
......@@ -19,4 +19,4 @@ const ActionControl = ({ action, setAttributes }) => {
)
}
export default ActionControl
export default EventActionControl
import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components'
const PcpActionControl = ({ action, setAttributes }) => {
const onChangeAction = (action) => setAttributes({ action })
const options = [
{ label: __('Info Page', 'civicrm'), value: 'info' },
{ label: __('Contribution Page', 'civicrm'), value: 'transact' },
]
return (
<RadioControl
label={__('Action', 'civicrm')}
value={action}
options={options}
selected={action || 'info'}
onChange={onChangeAction}
/>
)
}
export default PcpActionControl
......@@ -4,7 +4,7 @@ import Select, { components } from 'react-select'
const PCPOption = (props) => {
const { data } = props
console.log(data)
return (
<components.Option {...props}>
<span style={{ fontWeight: 'bold', display: 'block' }}>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment