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 { ...@@ -111,7 +111,7 @@ class CiviCRM_Gutenberg_Blocks {
], ],
'action' => [ 'action' => [
'type' => 'string', 'type' => 'string',
'enum' => ['info', 'register'], 'enum' => ['info', 'register', 'transact'],
'default' => 'info', 'default' => 'info',
], ],
'hijack' => [ 'hijack' => [
...@@ -379,10 +379,22 @@ class CiviCRM_Gutenberg_Blocks { ...@@ -379,10 +379,22 @@ class CiviCRM_Gutenberg_Blocks {
ob_start(); ob_start();
$_REQUEST['id'] = $atts['id'];
try { try {
(new CRM_PCP_Page_PCPInfo())->run(); 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) { catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
...@@ -574,9 +586,12 @@ class CiviCRM_Gutenberg_Blocks { ...@@ -574,9 +586,12 @@ class CiviCRM_Gutenberg_Blocks {
break; break;
case 'petition': case 'petition':
case 'pcp':
unset($attributes['gid'], $attributes['action']); unset($attributes['gid'], $attributes['action']);
break; break;
case 'pcp':
unset($attributes['gid']);
break;
} }
return $attributes; return $attributes;
......
...@@ -12,7 +12,8 @@ import SelectPCPControl from './components/SelectPCPControl' ...@@ -12,7 +12,8 @@ import SelectPCPControl from './components/SelectPCPControl'
import SelectPetitionControl from './components/SelectPetitionControl' import SelectPetitionControl from './components/SelectPetitionControl'
import ProfileModeControl from './components/ProfileModeControl' import ProfileModeControl from './components/ProfileModeControl'
import ModeControl from './components/ModeControl' 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 ExtraAttributesListControl from './components/ExtraAttributesListControl'
import NoPreview from './components/NoPreview' import NoPreview from './components/NoPreview'
...@@ -29,6 +30,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => { ...@@ -29,6 +30,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
const profileModes = ['create', 'edit', 'view', 'search'] const profileModes = ['create', 'edit', 'view', 'search']
const pageModes = ['live', 'test'] const pageModes = ['live', 'test']
let selectControl, actionControl
switch (component) { switch (component) {
case 'profile': case 'profile':
selectControl = <SelectProfileControl {...{ gid, setAttributes }} /> selectControl = <SelectProfileControl {...{ gid, setAttributes }} />
...@@ -37,6 +40,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => { ...@@ -37,6 +40,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
case 'event': case 'event':
selectControl = <SelectEventControl {...{ id, setAttributes }} /> selectControl = <SelectEventControl {...{ id, setAttributes }} />
actionControl = <EventActionControl {...{ action, setAttributes }} />
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' }) if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break break
...@@ -49,6 +53,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => { ...@@ -49,6 +53,7 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
case 'pcp': case 'pcp':
selectControl = <SelectPCPControl {...{ id, setAttributes }} /> selectControl = <SelectPCPControl {...{ id, setAttributes }} />
actionControl = <PcpActionControl {...{ action, setAttributes }} />
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' }) if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break break
...@@ -57,12 +62,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => { ...@@ -57,12 +62,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
break break
} }
let selectControl, let profileModeControl = <ProfileModeControl {...{ mode, setAttributes }} />
profileModeControl = ( let modeControl = <ModeControl {...{ mode, setAttributes }} />
<ProfileModeControl {...{ mode, setAttributes }} />
),
modeControl = <ModeControl {...{ mode, setAttributes }} />,
actionControl = <ActionControl {...{ action, setAttributes }} />
return ( return (
<> <>
...@@ -72,10 +73,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => { ...@@ -72,10 +73,8 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
{selectControl} {selectControl}
<span style={{ height: '10px', display: 'block' }}></span> <span style={{ height: '10px', display: 'block' }}></span>
{component == 'profile' ? profileModeControl : ''} {component == 'profile' ? profileModeControl : ''}
{component == 'event' ? actionControl : ''} {['event', 'pcp'].includes(component) ? actionControl : ''}
{['event', 'contribution', 'pcp'].includes(component) {['event', 'contribution', 'pcp'].includes(component) ? modeControl : ''}
? modeControl
: ''}
<HijackControl {...{ hijack, setAttributes }} /> <HijackControl {...{ hijack, setAttributes }} />
</PanelBody> </PanelBody>
<ExtraAttributesListControl <ExtraAttributesListControl
......
import { __ } from '@wordpress/i18n' import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components' import { RadioControl } from '@wordpress/components'
const ActionControl = ({ action, setAttributes }) => { const EventActionControl = ({ action, setAttributes }) => {
const onChangeAction = (action) => setAttributes({ action }) const onChangeAction = (action) => setAttributes({ action })
const options = [ const options = [
{ label: __('Event Info Page', 'civicrm'), value: 'info' }, { label: __('Event Info Page', 'civicrm'), value: 'info' },
...@@ -19,4 +19,4 @@ const ActionControl = ({ action, setAttributes }) => { ...@@ -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' ...@@ -4,7 +4,7 @@ import Select, { components } from 'react-select'
const PCPOption = (props) => { const PCPOption = (props) => {
const { data } = props const { data } = props
console.log(data)
return ( return (
<components.Option {...props}> <components.Option {...props}>
<span style={{ fontWeight: 'bold', display: 'block' }}> <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