Commit 4448c927 authored by Andrei Mondoc's avatar Andrei Mondoc
Browse files

Merge branch 'fixes' into 'master'

Fix defaults and handle PCP 'info' and 'transact' modes

See merge request !4
parents e9363cf1 5c428f2d
<?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-server-side-render'), 'version' => 'f2a8769655af43f753dd776336b12e01'); <?php return array('dependencies' => array('react', 'react-dom', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-date', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-server-side-render'), 'version' => '407ec2171a2183693f1681f29f084c48');
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -111,12 +111,12 @@ class CiviCRM_Gutenberg_Blocks { ...@@ -111,12 +111,12 @@ class CiviCRM_Gutenberg_Blocks {
], ],
'action' => [ 'action' => [
'type' => 'string', 'type' => 'string',
'enum' => ['info', 'register'], 'enum' => ['info', 'register', 'transact'],
'default' => 'info', 'default' => 'info',
], ],
'hijack' => [ 'hijack' => [
'type' => 'boolean', 'type' => 'boolean',
'default' => FALSE, 'default' => 0,
], ],
'extra_attributes' => [ 'extra_attributes' => [
'type' => 'array', 'type' => 'array',
...@@ -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();
...@@ -556,6 +568,7 @@ class CiviCRM_Gutenberg_Blocks { ...@@ -556,6 +568,7 @@ class CiviCRM_Gutenberg_Blocks {
switch ($attributes['component']) { switch ($attributes['component']) {
case 'profile': case 'profile':
unset($attributes['action'], $attributes['id']); unset($attributes['action'], $attributes['id']);
$attributes['gid'] = $attributes['gid'] ?? 1;
break; break;
case 'contribution': case 'contribution':
...@@ -573,9 +586,12 @@ class CiviCRM_Gutenberg_Blocks { ...@@ -573,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;
......
This diff is collapsed.
...@@ -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' }}>
......
...@@ -22,14 +22,19 @@ const SelectProfileControl = ({ gid, setAttributes }) => { ...@@ -22,14 +22,19 @@ const SelectProfileControl = ({ gid, setAttributes }) => {
useEffect(() => { useEffect(() => {
CRM.api4('UFGroup', 'get', { CRM.api4('UFGroup', 'get', {
select: ['title', 'group_type'], select: ['title', 'group_type', 'is_reserved'],
where: [ where: [
['is_active', '=', '1'], ['is_active', '=', '1'],
['is_reserved', '=', '0'],
], ],
}).then((result) => { }).then((result) => {
if (!result && !result.length) return if (!result && !result.length) return
// Since is_reserved can be either
// true|false|null and I cannot seem
// to make API4 to return the appropriate
// (already) filtered result, filter it here.
result = result.filter((item) => !item.is_reserved)
const options = result.map((ufGroup) => { const options = result.map((ufGroup) => {
return { return {
...ufGroup, ...ufGroup,
......
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