Commit 829adc03 authored by Kevin Cristiano's avatar Kevin Cristiano 🌎
Browse files

Merge branch 'master' into 'master'

PCP, Petition and other fixes

Closes #3

See merge request !3
parents ad86c243 8c96736d
module.exports = {
singleQuote: true,
semi: false,
tabs: true,
tabWidth: 4,
bracketSpacing: true
}
<?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' => 'fb086dbfa0b1641a4085d9fe0884dc53');
\ 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' => 'f2a8769655af43f753dd776336b12e01');
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -245,6 +245,14 @@ class CiviCRM_Gutenberg_Blocks {
case 'user-dashboard':
return $this->render_user_dashboard( $atts );
break;
case 'pcp':
return $this->render_pcp( $atts );
break;
case 'petition':
return $this->render_petition( $atts );
break;
}
}
......@@ -269,13 +277,21 @@ class CiviCRM_Gutenberg_Blocks {
$atts['mode']
];
$_REQUEST['gid'] = $atts['gid'];
$_GET['gid'] = $_REQUEST['gid'] = $atts['gid'];
ob_start();
try {
if ( $atts['mode'] == 'view' ) {
( new CRM_Profile_Page_View )->run();
} elseif ( $atts['mode'] == 'search' ) {
$_GET['reset'] = 1;
( new CRM_Profile_Page_Listings )->run();
} else {
( new CRM_Profile_Page_Router )->run( $args );
}
} catch ( Exception $e ) {
// silence
return $e->getMessage();
}
return ob_get_clean();
......@@ -304,8 +320,8 @@ class CiviCRM_Gutenberg_Blocks {
'CiviContribute',
CRM_Core_Action::ADD
) )->run();
} catch (Exception $e) {
// silence
} catch ( Exception $e ) {
return $e->getMessage();
}
return ob_get_clean();
......@@ -332,12 +348,12 @@ class CiviCRM_Gutenberg_Blocks {
try {
if ( $atts['action'] == 'register' ) {
( new CRM_Event_Controller_Registration() )->run();
( new CRM_Event_Controller_Registration )->run();
} else {
( new CRM_Event_Page_EventInfo )->run();
}
} catch ( Exception $e ) {
// silence
return $e->getMessage();
}
return ob_get_clean();
......@@ -359,9 +375,61 @@ class CiviCRM_Gutenberg_Blocks {
ob_start();
try {
( new CRM_Contact_Page_View_UserDashBoard() )->run();
( new CRM_Contact_Page_View_UserDashBoard )->run();
} catch ( Exception $e ) {
// silence
return $e->getMessage();
}
return ob_get_clean();
}
/**
* Renders a PCP's html.
*
* @since 0.1
*
* @param array $atts The block attributes
* @return string $html
*/
public function render_pcp( array $atts ) {
ob_start();
$_REQUEST['id'] = $atts['id'];
try {
( new CRM_PCP_Page_PCPInfo )->run();
} catch ( Exception $e ) {
return $e->getMessage();
}
return ob_get_clean();
}
/**
* Renders a Petition's html.
*
* @since 0.1
*
* @param array $atts The block attributes
* @return string $html
*/
public function render_petition( array $atts ) {
ob_start();
$_REQUEST['sid'] = $atts['id'];
try {
(new CRM_Utils_Wrapper )->run( 'CRM_Campaign_Form_Petition_Signature', 'Sign Petition', null );
} catch ( Exception $e ) {
return $e->getMessage();
}
return ob_get_clean();
......@@ -520,6 +588,11 @@ class CiviCRM_Gutenberg_Blocks {
case 'user-dashboard':
$attributes = ['component' => 'user-dashboard', 'hijack' => $attributes['hijack']];
break;
case 'petition':
case 'pcp':
unset( $attributes['gid'], $attributes['action'] );
break;
}
return $attributes;
......@@ -582,5 +655,3 @@ function civicrm_gutenberg_blocks() {
// Init plugin.
add_action( 'plugins_loaded', 'civicrm_gutenberg_blocks' );
This diff is collapsed.
......@@ -4,13 +4,13 @@
"license": "GPL-2.0-or-later",
"main": "index.js",
"devDependencies": {
"@wordpress/scripts": "^6.0.0"
"@wordpress/scripts": "^6.2.0"
},
"scripts": {
"build": "wp-scripts build",
"start": "wp-scripts start"
},
"dependencies": {
"react-select": "^3.0.8"
"react-select": "^3.1.0"
}
}
import { __ } from '@wordpress/i18n'
import { InspectorControls } from '@wordpress/block-editor'
import { PanelBody } from '@wordpress/components'
import ServerSideRender from '@wordpress/server-side-render'
import ComponentControl from './components/ComponentControl'
......@@ -7,6 +8,8 @@ import HijackControl from './components/HijackControl'
import SelectProfileControl from './components/SelectProfileControl'
import SelectEventControl from './components/SelectEventControl'
import SelectContributionPageControl from './components/SelectContributionPageControl'
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'
......@@ -14,7 +17,15 @@ import ExtraAttributesListControl from './components/ExtraAttributesListControl'
import NoPreview from './components/NoPreview'
const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
const { component, gid, id, mode, action, hijack, extra_attributes } = attributes
const {
component,
gid,
id,
mode,
action,
hijack,
extra_attributes,
} = attributes
const profileModes = ['create', 'edit', 'view', 'search']
const pageModes = ['live', 'test']
......@@ -30,31 +41,51 @@ const CiviCRMContentBlock = ({ attributes, setAttributes }) => {
break
case 'contribution':
selectControl = <SelectContributionPageControl {...{ id, setAttributes }} />
selectControl = (
<SelectContributionPageControl {...{ id, setAttributes }} />
)
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break
case 'pcp':
selectControl = <SelectPCPControl {...{ id, setAttributes }} />
if (!pageModes.includes(mode)) setAttributes({ mode: 'live' })
break
case 'petition':
selectControl = <SelectPetitionControl {...{ id, setAttributes }} />
break
}
let selectControl,
profileModeControl = <ProfileModeControl {...{ mode, setAttributes }} />,
profileModeControl = (
<ProfileModeControl {...{ mode, setAttributes }} />
),
modeControl = <ModeControl {...{ mode, setAttributes }} />,
actionControl = <ActionControl {...{ action, setAttributes }} />
return (
<>
<InspectorControls key='inspector'>
<InspectorControls key="inspector">
<PanelBody>
<ComponentControl {...{ component, setAttributes }} />
{selectControl}
<span style={{ height: '10px', display: 'block' }}></span>
{component == 'profile' ? profileModeControl : ''}
{component == 'event' ? actionControl : ''}
{['event', 'contribution'].includes(component) ? modeControl : ''}
{['event', 'contribution', 'pcp'].includes(component)
? modeControl
: ''}
<HijackControl {...{ hijack, setAttributes }} />
<ExtraAttributesListControl {...{ extra_attributes, setAttributes }} />
</PanelBody>
<ExtraAttributesListControl
{...{ extra_attributes, setAttributes }}
/>
</InspectorControls>
<ServerSideRender
block='civicrm/civicrm-content-block'
block="civicrm/civicrm-content-block"
attributes={attributes}
className='civicrm-content-block'
className="civicrm-content-block"
ErrorResponsePlaceholder={NoPreview}
EmptyResponsePlaceholder={NoPreview}
/>
......
import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components'
const ActionControl = ({action, setAttributes}) => {
const onChangeAction = action => setAttributes({ action })
const ActionControl = ({ action, setAttributes }) => {
const onChangeAction = (action) => setAttributes({ action })
const options = [
{ label: __('Event Info Page', 'civicrm'), value: 'info' },
{ label: __('Event Registration Page', 'civicrm'), value: 'register' },
]
return <RadioControl
return (
<RadioControl
label={__('Action', 'civicrm')}
value={action}
options={options}
selected={action || 'info'}
onChange={onChangeAction}
/>
)
}
export default ActionControl
import { __ } from '@wordpress/i18n'
import { useState, useEffect } from "@wordpress/element";
import { useState, useEffect } from '@wordpress/element'
import { SelectControl } from '@wordpress/components'
const ComponentControl = ({ component, setAttributes }) => {
const onChangeComponent = component => setAttributes({ component })
const onChangeComponent = (component) => setAttributes({ component })
const [components, setComponents] = useState([
{ label: __('User Dashboard', 'civicrm'), value: 'user-dashboard' },
{ label: __('Profile', 'civicrm'), value: 'profile' },
{ label: __('Contribution Page', 'civicrm'), value: 'contribution', component: 'CiviContribute' },
{ label: __('Event Page', 'civicrm'), value: 'event', component: 'CiviEvent' },
{ label: __('Petition', 'civicrm'), value: 'petition', component: 'CiviCampaign' },
{
label: __('Contribution Page', 'civicrm'),
value: 'contribution',
component: 'CiviContribute',
},
{
label: __('Personal Campaign Page', 'civicrm'),
value: 'pcp',
component: 'CiviContribute',
},
{
label: __('Event Page', 'civicrm'),
value: 'event',
component: 'CiviEvent',
},
{
label: __('Petition', 'civicrm'),
value: 'petition',
component: 'CiviCampaign',
},
])
useEffect(() => {
CRM.api4('Setting', 'get', {
select: ['enable_components']
})
.then(function(result) {
select: ['enable_components'],
}).then(function (result) {
const setting = result[0]
if (!setting.value || !setting.value.length) return;
if (!setting.value || !setting.value.length) return
const filteredComponents = components.filter(component => {
const isEnabled = setting.value.includes(
component.component
);
return !component.component || isEnabled;
});
const filteredComponents = components.filter((component) => {
const isEnabled = setting.value.includes(component.component)
return !component.component || isEnabled
})
setComponents(filteredComponents)
})
}, [])
return <SelectControl
return (
<SelectControl
label={__('Component', 'civicrm')}
value={component}
options={components}
onChange={onChangeComponent}
/>
)
}
export default ComponentControl
import { __ } from '@wordpress/i18n'
import { BaseControl, IconButton } from '@wordpress/components'
const ExtraAttributeItemControl = ({ attribute, index, extra_attributes, setAttributes }) => {
const updateAttribute = e => {
const ExtraAttributeItemControl = ({
attribute,
index,
extra_attributes,
setAttributes,
}) => {
const updateAttribute = (e) => {
const newAttrs = [...extra_attributes]
newAttrs[index] = {
...attribute,
[e.target.name]: e.target.value
[e.target.name]: e.target.value,
}
setAttributes({
extra_attributes: [...newAttrs]
extra_attributes: [...newAttrs],
})
}
......@@ -18,35 +22,39 @@ const ExtraAttributeItemControl = ({ attribute, index, extra_attributes, setAttr
const newAttrs = [...extra_attributes]
newAttrs.splice(index, 1)
setAttributes({
extra_attributes: [...newAttrs]
extra_attributes: [...newAttrs],
})
}
return <>
<strong>{__('Attribute', 'civicrm')} {index + 1}</strong>
return (
<>
<strong>
{__('Attribute', 'civicrm')} {index + 1}
</strong>
<BaseControl label={__('Attribute name', 'civicrm')}>
<input
className='components-text-control__input'
type='text'
name='name'
className="components-text-control__input"
type="text"
name="name"
value={attribute.name}
onChange={updateAttribute}
/>
</BaseControl>
<BaseControl label={__('Attribute value', 'civicrm')}>
<input
className='components-text-control__input'
type='text'
name='value'
className="components-text-control__input"
type="text"
name="value"
value={attribute.value}
onChange={updateAttribute}
/>
</BaseControl>
<IconButton icon='trash' onClick={() => deleteAttribute()}>
<IconButton icon="trash" onClick={() => deleteAttribute()}>
{__('Delete attribute', 'civicrm')} {index + 1}
</IconButton>
<hr />
</>
)
}
export default ExtraAttributeItemControl
......@@ -3,36 +3,48 @@ import { PanelBody, PanelRow, IconButton } from '@wordpress/components'
import ExtraAttributeItemControl from './ExtraAttributeItemControl'
const ExtraAttributesListControl = ({ extra_attributes, setAttributes }) => {
const addAttribute = () => {
setAttributes({
extra_attributes: [
...extra_attributes,
{
name: '',
value: ''
}
]
value: '',
},
],
})
}
return <PanelBody title={__('Extra attributes', 'civicrm')} initialOpen={false}>
return (
<PanelBody
title={__('Extra shortcode attributes', 'civicrm')}
initialOpen={false}
>
<PanelRow>
<IconButton icon="insert" isDefault isLarge onClick={addAttribute}>
<IconButton
icon="insert"
isDefault
isLarge
onClick={addAttribute}
>
{__('Add attribute', 'civicrm')}
</IconButton>
</PanelRow>
{
extra_attributes.length
? extra_attributes.map(
(attribute, index) => <ExtraAttributeItemControl
{extra_attributes.length
? extra_attributes.map((attribute, index) => (
<ExtraAttributeItemControl
key={index}
{...{attribute, index, extra_attributes, setAttributes}}
{...{
attribute,
index,
extra_attributes,
setAttributes,
}}
/>
)
: ''
}
))
: ''}
</PanelBody>
)
}
export default ExtraAttributesListControl
......@@ -3,12 +3,17 @@ import { ToggleControl } from '@wordpress/components'
const HijackControl = ({ hijack, setAttributes }) => {
const onChangeHijack = () => setAttributes({ hijack: !hijack })
return <ToggleControl
return (
<ToggleControl
label={__('Override page content')}
help={__('If you only insert one shortcode, you can choose to override all page content with the content of the shortcode.', 'civicrm')}
help={__(
'If you only insert one shortcode, you can choose to override all page content with the content of the shortcode.',
'civicrm'
)}
checked={hijack}
onChange={onChangeHijack}
/>
)
}
export default HijackControl
......@@ -2,19 +2,21 @@ import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components'
const ModeControl = ({ mode, setAttributes }) => {
const onChangeMode = mode => setAttributes({ mode })
const onChangeMode = (mode) => setAttributes({ mode })
const options = [
{ label: __('Live Mode', 'civicrm'), value: 'live' },
{ label: __('Test Mode', 'civicrm'), value: 'test' },
]
return <RadioControl
return (
<RadioControl
label={__('Mode', 'civicrm')}
value={mode}
options={options}
selected={mode || 'live'}
onChange={onChangeMode}
/>
)
}
export default ModeControl
......@@ -2,7 +2,7 @@ import { __ } from '@wordpress/i18n'
import { RadioControl } from '@wordpress/components'
const ProfileModeControl = ({ mode, setAttributes }) => {
const onChangeMode = mode => setAttributes({ mode })
const onChangeMode = (mode) => setAttributes({ mode })
const options = [
{ label: __('Create', 'civicrm'), value: 'create' },
{ label: __('Edit', 'civicrm'), value: 'edit' },
......@@ -10,13 +10,15 @@ const ProfileModeControl = ({ mode, setAttributes }) => {
{ label: __('Search/Public Directory', 'civicrm'), value: 'search' },
]
return <RadioControl
return (
<RadioControl
label={__('Mode', 'civicrm')}
value={mode}
options={options}
selected={mode || 'create'}
onChange={onChangeMode}
/>
)
}
export default ProfileModeControl