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');
\ No newline at end of file
<?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
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 {
],
'action' => [
'type' => 'string',
'enum' => ['info', 'register'],
'enum' => ['info', 'register', 'transact'],
'default' => 'info',
],
'hijack' => [
'type' => 'boolean',
'default' => FALSE,
'default' => 0,
],
'extra_attributes' => [
'type' => 'array',
......@@ -379,10 +379,22 @@ class CiviCRM_Gutenberg_Blocks {
ob_start();
$_REQUEST['id'] = $atts['id'];
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) {
return $e->getMessage();
......@@ -556,6 +568,7 @@ class CiviCRM_Gutenberg_Blocks {
switch ($attributes['component']) {
case 'profile':
unset($attributes['action'], $attributes['id']);
$attributes['gid'] = $attributes['gid'] ?? 1;
break;
case 'contribution':
......@@ -573,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;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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' }}>
......
......@@ -22,14 +22,19 @@ const SelectProfileControl = ({ gid, setAttributes }) => {
useEffect(() => {
CRM.api4('UFGroup', 'get', {
select: ['title', 'group_type'],
select: ['title', 'group_type', 'is_reserved'],
where: [
['is_active', '=', '1'],
['is_reserved', '=', '0'],
],
}).then((result) => {
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) => {
return {
...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