diff --git a/blocks/components/chosen-select/index.js b/blocks/components/chosen-select/index.js deleted file mode 100644 index d025f70353..0000000000 --- a/blocks/components/chosen-select/index.js +++ /dev/null @@ -1,100 +0,0 @@ -/** - * WordPress dependencies - */ -import { Component } from '@wordpress/element'; -import { BaseControl } from '@wordpress/components'; -import jquery from "jquery"; - -/** - * Render ChosenSelect Control -*/ -class ChosenSelect extends Component { - constructor( props ) { - super( props ); - - this.saveSetting = this.saveSetting.bind( this ); - this.saveState = this.saveState.bind( this ); - } - - saveSetting( name, value ) { - this.props.setAttributes( { - [ name ]: value, - } ); - } - - saveState( name, value ) { - this.setState( { - [ name ]: value, - } ); - } - - componentDidMount() { - const { value } = this.props; - - this.$el = jquery( this.el ); - this.$el.val( value ); - - this.$input = this.$el.chosen( { - width: '100%', - } ).data( 'chosen' ); - - this.handleChange = this.handleChange.bind( this ); - - this.$el.on( 'change', this.handleChange ); - } - - componentWillUnmount() { - this.$el.off( 'change', this.handleChange ); - this.$el.chosen( 'destroy' ); - } - - handleChange( e ) { - this.props.onChange( e.target.value ); - } - - componentDidUpdate() { - const $searchField = jquery( '.chosen-base-control' ).closest( '.chosen-container' ).find( '.chosen-search-input' ); - this.$input.search_field.autocomplete( { - source: function( request, response ) { - const data = { - action: 'give_block_donation_form_search_results', - search: request.term, - }; - const chosenBlock = jquery( '.give-block-chosen-select' ); - - jquery.post( ajaxurl, data, ( responseData ) => { - chosenBlock.empty(); - responseData = JSON.parse( responseData ); - - if ( responseData.length > 0 ) { - response( jquery.map( responseData, function( item ) { - chosenBlock.append( `` ); - } ) ); - - chosenBlock.trigger( 'chosen:updated' ); - $searchField.val( request.term ); - } - } ); - }, - } ); - } - - render() { - return ( - - - - ); - } -} - -export default ChosenSelect; diff --git a/blocks/components/select-form/index.js b/blocks/components/select-form/index.js deleted file mode 100644 index 94557b4776..0000000000 --- a/blocks/components/select-form/index.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n' -import {withSelect} from '@wordpress/data'; -import { Placeholder, Spinner } from '@wordpress/components'; - -/** - * Internal dependencies - */ -import './index.scss'; -import GiveBlankSlate from '../blank-slate'; -import NoForms from '../no-form'; -import ChosenSelect from '../chosen-select'; -import { getFormOptions } from '../../utils'; - -const SelectForm = ( { forms, setAttributes } ) => { - const setFormIdTo = id => { - setAttributes( { id: Number( id ) } ); - }; - - // Render Component UI - let componentUI; - - if ( ! forms ) { - componentUI = ; - } else if ( forms && forms.length === 0 ) { - componentUI = ; - } else { - componentUI = ( - - - - ); - } - - return componentUI; -}; - -/** - * Export with forms data - */ -export default withSelect( ( select ) => { - return { - forms: select( 'core' ).getEntityRecords( 'postType', 'give_forms', { per_page: 30 } ), - }; -} )( SelectForm ); diff --git a/blocks/components/select-form/index.scss b/blocks/components/select-form/index.scss deleted file mode 100644 index ac312db265..0000000000 --- a/blocks/components/select-form/index.scss +++ /dev/null @@ -1,8 +0,0 @@ -[data-type='give/donation-form'] { - .components-base-control__field { - max-width: 400px; - margin: 0 auto; - - text-align: left; - } -} diff --git a/blocks/donation-form/class-give-donation-form-block.php b/blocks/donation-form/class-give-donation-form-block.php index 3b4e17adaa..77d5e23079 100644 --- a/blocks/donation-form/class-give-donation-form-block.php +++ b/blocks/donation-form/class-give-donation-form-block.php @@ -2,16 +2,16 @@ /** * Give Donation Form Block Class * - * @package Give + * @since 2.0.2 * @subpackage Classes/Blocks * @copyright Copyright (c) 2018, GiveWP * @license https://opensource.org/licenses/gpl-license GNU Public License - * @since 2.0.2 + * @package Give */ // Exit if accessed directly. -if ( ! defined( 'ABSPATH' ) ) { - exit; +if (!defined('ABSPATH')) { + exit; } /** @@ -21,200 +21,211 @@ * * @since 2.0.2 */ -class Give_Donation_Form_Block { - /** - * Instance. - * - * @since - * @access private - * @var Give_Donation_Form_Block - */ - private static $instance; - - /** - * Singleton pattern. - * - * @since - * @access private - */ - private function __construct() { - } - - - /** - * Get instance. - * - * @since - * @access public - * @return Give_Donation_Form_Block - */ - public static function get_instance() { - if ( null === static::$instance ) { - self::$instance = new static(); - - self::$instance->init(); - } - - return self::$instance; - } - - /** - * Class Constructor - * - * Set up the Give Donation Grid Block class. - * - * @since 2.0.2 - * @access private - */ - private function init() { - add_action( 'init', array( $this, 'register_block' ), 999 ); - add_action( 'wp_ajax_give_block_donation_form_search_results', array( $this, 'block_donation_form_search_results' ) ); - add_filter( 'rest_prepare_give_forms', array( $this, 'addExtraDataToResponse' ), 10, 2 ); - } - - /** - * Add extra data to response. - * - * @since 2.7.0 - * @param WP_REST_Response $response - * @param WP_Post $form - * - * @return WP_REST_Response - */ - public function addExtraDataToResponse( $response, $form ) { - // Return extra data only if query in edit context. - if ( empty( $_REQUEST['context'] ) || $_REQUEST['context'] !== 'edit' ) { - return $response; - } - - $data = $response->get_data(); - $data['formTemplate'] = Give()->form_meta->get_meta( $form->ID, '_give_form_template', true ); - $response->set_data( $data ); - - return $response; - } - - /** - * Register block - * - * @since 2.1 - * @access public - * - * @access public - */ - public function register_block() { - // Bailout. - if ( ! function_exists( 'register_block_type' ) ) { - return; - } - - // Register block. - register_block_type( - 'give/donation-form', - array( - 'render_callback' => array( $this, 'render_donation_form' ), - 'attributes' => array( - 'id' => array( - 'type' => 'number', - ), - 'prevId' => array( - 'type' => 'number', - ), - 'displayStyle' => array( - 'type' => 'string', - 'default' => 'onpage', - ), - 'continueButtonTitle' => array( - 'type' => 'string', - 'default' => '', - ), - 'showTitle' => array( - 'type' => 'boolean', - 'default' => true, - ), - 'showGoal' => array( - 'type' => 'boolean', - 'default' => true, - ), - 'contentDisplay' => array( - 'type' => 'boolean', - 'default' => true, - ), - 'showContent' => array( - 'type' => 'string', - 'default' => 'above', - ), - ), - ) - ); - } - - /** - * Block render callback - * - * @param array $attributes Block parameters. - * - * @access public - * @return string; - */ - public function render_donation_form( $attributes ) { - // Bailout. - if ( empty( $attributes['id'] ) ) { - return ''; - } - - $parameters = array(); - - $parameters['id'] = absint( $attributes['id'] ); - $parameters['show_title'] = $attributes['showTitle']; - $parameters['show_goal'] = $attributes['showGoal']; - $parameters['show_content'] = ! empty( $attributes['contentDisplay'] ) ? $attributes['showContent'] : 'none'; - $parameters['display_style'] = $attributes['displayStyle']; - $parameters['continue_button_title'] = trim( $attributes['continueButtonTitle'] ); +class Give_Donation_Form_Block +{ + /** + * Instance. + * + * @since + * @access private + * @var Give_Donation_Form_Block + */ + private static $instance; + + /** + * Singleton pattern. + * + * @since + * @access private + */ + private function __construct() + { + } + + + /** + * Get instance. + * + * @since + * @access public + * @return Give_Donation_Form_Block + */ + public static function get_instance() + { + if (null === static::$instance) { + self::$instance = new static(); + + self::$instance->init(); + } + + return self::$instance; + } + + /** + * Class Constructor + * + * Set up the Give Donation Grid Block class. + * + * @since 2.0.2 + * @access private + */ + private function init() + { + add_action('init', array($this, 'register_block'), 999); + add_action('wp_ajax_give_block_donation_form_search_results', array($this, 'block_donation_form_search_results') + ); + add_filter('rest_prepare_give_forms', array($this, 'addExtraDataToResponse'), 10, 2); + } + + /** + * Add extra data to response. + * + * @since 2.7.0 + * @param WP_REST_Response $response + * @param WP_Post $form + * + * @return WP_REST_Response + */ + public function addExtraDataToResponse($response, $form) + { + // Return extra data only if query in edit context. + if (empty($_REQUEST['context']) || $_REQUEST['context'] !== 'edit') { + return $response; + } + + $data = $response->get_data(); + $data['formTemplate'] = Give()->form_meta->get_meta($form->ID, '_give_form_template', true); + $data['isLegacyForm'] = !Give()->form_meta->get_meta($form->ID, 'formBuilderSettings', true); + $response->set_data($data); + + return $response; + } + + /** + * Register block + * + * @since 2.1 + * @access public + * + * @access public + */ + public function register_block() + { + // Bailout. + if (!function_exists('register_block_type')) { + return; + } + + // Register block. + register_block_type( + 'give/donation-form', + array( + 'render_callback' => array($this, 'render_donation_form'), + 'attributes' => array( + 'id' => array( + 'type' => 'number', + ), + 'prevId' => array( + 'type' => 'number', + ), + 'displayStyle' => array( + 'type' => 'string', + 'default' => 'onpage', + ), + 'continueButtonTitle' => array( + 'type' => 'string', + 'default' => __('Donate now', 'give') + ), + 'showTitle' => array( + 'type' => 'boolean', + 'default' => true, + ), + 'showGoal' => array( + 'type' => 'boolean', + 'default' => true, + ), + 'contentDisplay' => array( + 'type' => 'boolean', + 'default' => true, + ), + 'showContent' => array( + 'type' => 'string', + 'default' => 'above', + ), + 'blockId' => array( + 'type' => 'string', + ), + ), + ) + ); + } + + /** + * Block render callback + * + * @param array $attributes Block parameters. + * + * @access public + * @return string; + */ + public function render_donation_form($attributes) + { + // Bailout. + if (empty($attributes['id'])) { + return ''; + } + $parameters = array(); + + $parameters['id'] = absint($attributes['id']); + $parameters['show_title'] = $attributes['showTitle']; + $parameters['show_goal'] = $attributes['showGoal']; + $parameters['show_content'] = !empty($attributes['contentDisplay']) ? $attributes['showContent'] : 'none'; + $parameters['display_style'] = $attributes['displayStyle']; + $parameters['continue_button_title'] = trim($attributes['continueButtonTitle']); _give_redirect_form_id($parameters['id']); - return give_form_shortcode( $parameters ); - } - - /** - * This function is used to fetch donation forms based on the chosen search in the donation form block. - * - * @since 2.5.3 - * @access public - * - * @return void - */ - public function block_donation_form_search_results() { - - // Define variables. - $result = array(); - $post_data = give_clean( $_POST ); - $search_keyword = ! empty( $post_data['search'] ) ? $post_data['search'] : ''; - - // Setup the arguments to fetch the donation forms. - $forms_query = new Give_Forms_Query( - array( - 's' => $search_keyword, - 'number' => 30, - 'post_status' => 'publish', - ) - ); - - // Fetch the donation forms. - $forms = $forms_query->get_forms(); - - // Loop through each donation form. - foreach ( $forms as $form ) { - $result[] = array( - 'id' => $form->ID, - 'name' => $form->post_title, - ); - } - - echo wp_json_encode( $result ); - give_die(); - } + return give_form_shortcode($parameters); + } + + /** + * This function is used to fetch donation forms based on the chosen search in the donation form block. + * + * @since 2.5.3 + * @access public + * + * @return void + */ + public function block_donation_form_search_results() + { + // Define variables. + $result = array(); + $post_data = give_clean($_POST); + $search_keyword = !empty($post_data['search']) ? $post_data['search'] : ''; + + // Setup the arguments to fetch the donation forms. + $forms_query = new Give_Forms_Query( + array( + 's' => $search_keyword, + 'number' => 30, + 'post_status' => 'publish', + ) + ); + + // Fetch the donation forms. + $forms = $forms_query->get_forms(); + + // Loop through each donation form. + foreach ($forms as $form) { + $result[] = array( + 'id' => $form->ID, + 'name' => $form->post_title, + ); + } + + echo wp_json_encode($result); + give_die(); + } } Give_Donation_Form_Block::get_instance(); diff --git a/blocks/donation-form/data/attributes.js b/blocks/donation-form/data/attributes.js index 6dca987b09..d4fd5bd8b2 100644 --- a/blocks/donation-form/data/attributes.js +++ b/blocks/donation-form/data/attributes.js @@ -1,38 +1,41 @@ /** * Block Attributes -*/ + */ const blockAttributes = { - id: { - type: 'number', - default: 0, - }, - prevId: { - type: 'number', - }, - displayStyle: { - type: 'string', - default: 'onpage', - }, - continueButtonTitle: { - type: 'string', - default: '', - }, - showTitle: { - type: 'boolean', - default: true, - }, - showGoal: { - type: 'boolean', - default: true, - }, - contentDisplay: { - type: 'boolean', - default: true, - }, - showContent: { - type: 'string', - default: 'above', - }, + id: { + type: 'number', + default: 0, + }, + prevId: { + type: 'number', + }, + displayStyle: { + type: 'string', + default: 'onpage', + }, + continueButtonTitle: { + type: 'string', + default: 'Donate now', + }, + showTitle: { + type: 'boolean', + default: true, + }, + showGoal: { + type: 'boolean', + default: true, + }, + contentDisplay: { + type: 'boolean', + default: true, + }, + showContent: { + type: 'string', + default: 'above', + }, + blockId: { + type: 'string', + }, }; export default blockAttributes; diff --git a/blocks/donation-form/data/options.js b/blocks/donation-form/data/options.js deleted file mode 100644 index b7951d4002..0000000000 --- a/blocks/donation-form/data/options.js +++ /dev/null @@ -1,26 +0,0 @@ -/* globals Give */ -/** - * WordPress dependencies -*/ -import { __ } from '@wordpress/i18n' - -/** - * Options data for various form selects - */ -const giveFormOptions = {}; - -// Form Display Styles -giveFormOptions.displayStyles = [ - { value: 'onpage', label: __( 'Full Form', 'give' ) }, - { value: 'modal', label: __( 'Modal', 'give' ) }, - { value: 'reveal', label: __( 'Reveal', 'give' ) }, - { value: 'button', label: __( 'One Button Launch', 'give' ) }, -]; - -// Form content Position -giveFormOptions.contentPosition = [ - { value: 'above', label: __( 'Above', 'give' ) }, - { value: 'below', label: __( 'Below', 'give' ) }, -]; - -export default giveFormOptions; diff --git a/blocks/donation-form/edit/block.js b/blocks/donation-form/edit/block.js deleted file mode 100644 index 2833eab5c3..0000000000 --- a/blocks/donation-form/edit/block.js +++ /dev/null @@ -1,38 +0,0 @@ -/** - * WordPress dependencies - */ -import ServerSideRender from '@wordpress/server-side-render'; - -/** - * Internal dependencies - */ -import './block.scss'; -import SelectForm from '../../components/select-form'; -import Inspector from './inspector'; - -/** - * Render Block UI For Editor - */ - -const GiveForm = ( props ) => { - const { attributes, isSelected, className } = props; - const { id } = attributes; - - // Render block UI - let blockUI; - - if ( ! id ) { - blockUI = ; - } else { - blockUI = ( -
- - -
- ); - } - - return blockUI; -}; - -export default GiveForm; diff --git a/blocks/donation-form/edit/block.scss b/blocks/donation-form/edit/block.scss deleted file mode 100644 index 98e857e293..0000000000 --- a/blocks/donation-form/edit/block.scss +++ /dev/null @@ -1,18 +0,0 @@ -.wp-block-give-donation-form { - position: relative; - - form[id*='give-form'] #give-gateway-radio-list > li input[type='radio'] { - display: inline-block; - } - - iframe { - pointer-events: none; - width: 100% !important; - } -} - -.give-change-donation-form-btn { - svg { - margin-top: 3px; - } -} diff --git a/blocks/donation-form/edit/inspector.js b/blocks/donation-form/edit/inspector.js deleted file mode 100644 index 43b51f8dc9..0000000000 --- a/blocks/donation-form/edit/inspector.js +++ /dev/null @@ -1,124 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n' -import { InspectorControls } from '@wordpress/block-editor'; -import { Dashicon, Button, PanelBody, SelectControl, ToggleControl, TextControl } from '@wordpress/components'; -import { Component } from '@wordpress/element'; -import {withSelect} from '@wordpress/data'; - -/** - * Internal dependencies - */ -import giveFormOptions from '../data/options'; -import { isLegacyForm } from '../../utils'; - -/** - * Render Inspector Controls -*/ -class Inspector extends Component { - constructor( props ) { - super( props ); - - this.state = { - continueButtonTitle: this.props.attributes.continueButtonTitle, - }; - - this.saveSetting = this.saveSetting.bind( this ); - this.saveState = this.saveState.bind( this ); - } - - saveSetting( name, value ) { - this.props.setAttributes( { - [ name ]: value, - } ); - } - - saveState( name, value ) { - this.setState( { - [ name ]: value, - } ); - } - - render() { - const { forms } = this.props; - - const { - id, - displayStyle, - showTitle, - showGoal, - showContent, - contentDisplay, - } = this.props.attributes; - - return ( - - - - - { - isLegacyForm( forms, id ) && ( -
- - this.saveSetting( 'displayStyle', value ) } /> - { - 'reveal' === displayStyle && ( - this.saveState( 'continueButtonTitle', value ) } - onBlur={ ( event ) => this.saveSetting( 'continueButtonTitle', event.target.value ) } /> - ) - } - - - this.saveSetting( 'showTitle', value ) } /> - this.saveSetting( 'showGoal', value ) } /> - this.saveSetting( 'contentDisplay', value ) } /> - { - contentDisplay && ( - this.saveSetting( 'showContent', value ) } /> - ) - } - -
- ) } -
- ); - } -} - -/** - * Export with forms data - */ -export default withSelect( ( select ) => { - return { - forms: select( 'core' ).getEntityRecords( 'postType', 'give_forms', { per_page: 30 } ), - }; -} )( Inspector ); diff --git a/blocks/donation-form/index.js b/blocks/donation-form/index.js index a3387c4640..c35de1d6ec 100644 --- a/blocks/donation-form/index.js +++ b/blocks/donation-form/index.js @@ -7,10 +7,9 @@ import {registerBlockType} from '@wordpress/blocks'; /** * Internal dependencies */ -import './style.scss'; import GiveIcon from '@givewp/components/GiveIcon'; import blockAttributes from './data/attributes'; -import GiveForm from './edit/block'; +import Edit from '../../src/DonationForms/Blocks/DonationFormBlock/resources/editor/Edit'; /** * Register Block @@ -29,7 +28,7 @@ export default registerBlockType('give/donation-form', { html: false, }, attributes: blockAttributes, - edit: GiveForm, + edit: Edit, save: () => { // Server side rendering via shortcode diff --git a/blocks/donation-form/style.scss b/blocks/donation-form/style.scss deleted file mode 100644 index 63f780b939..0000000000 --- a/blocks/donation-form/style.scss +++ /dev/null @@ -1,16 +0,0 @@ -.gutenberg__editor .give-blank-slate__image { - max-width: 96px; -} - -.give-chosen-base-control { - a.chosen-single { - box-shadow: none !important; - } - - ul.chosen-results { - margin: 0 !important; - text-align: left !important; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, - 'Helvetica Neue', sans-serif; - } -} diff --git a/blocks/utils/index.js b/blocks/utils/index.js deleted file mode 100644 index 78921baa6a..0000000000 --- a/blocks/utils/index.js +++ /dev/null @@ -1,64 +0,0 @@ -/** - * WordPress dependencies - */ -import {__} from '@wordpress/i18n'; - -/** - * getSiteUrl from API root - * @returns {string} siteurl - */ -export function getSiteUrl() { - return wpApiSettings.root.replace('/wp-json/', ''); -} - -/** - * Convert forms object in option - * - * @since 2.7.0 - * - * @param {object} forms - * - * @return {[]} - */ -export function getFormOptions(forms) { - let formOptions = []; - - if (forms) { - formOptions = forms.map(({id, title: {rendered: title}}) => { - return { - value: id, - label: title === '' ? `${id} : ${__('No form title', 'give')}` : title, - }; - }); - } - - // Add Default option - formOptions.unshift({value: '0', label: __('-- Select Form --', 'give')}); - - return formOptions; -} - -/** - * Returns whether or not the given form uses the legacy form template. - * - * Note: if selected form has legacy form template or empty (old forms) then it will return true otherwise false. - * - * @since 2.30.0 Filter v3 forms out of the form list. - * @since 2.7.0 - * - * @param {object} forms - * @param {number} SelectedFormId - * - * @return {boolean} - */ -export function isLegacyForm(forms, SelectedFormId) { - if (forms) { - const data = forms.find((form) => parseInt(form.id) === parseInt(SelectedFormId)); - - return ( - data && data.excerpt.rendered !== '

[]

\n' && (!data.formTemplate || data.formTemplate === 'legacy') - ); - } - - return false; -} diff --git a/includes/forms/functions.php b/includes/forms/functions.php index 4380ea3b6b..1a3a584348 100644 --- a/includes/forms/functions.php +++ b/includes/forms/functions.php @@ -1587,8 +1587,8 @@ function give_get_default_form_shortcode_args() { 'show_goal' => true, 'show_content' => '', 'float_labels' => '', - 'display_style' => '', - 'continue_button_title' => '', + 'display_style' => 'fullForm', + 'continue_button_title' => __('Donate now', 'give'), // This attribute belong to form template functionality. // You can use this attribute to set modal open button background color. diff --git a/src/DonationForms/Blocks/DonationFormBlock/Controllers/BlockRenderController.php b/src/DonationForms/Blocks/DonationFormBlock/Controllers/BlockRenderController.php index a5f9c8a9ed..88533b767d 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/Controllers/BlockRenderController.php +++ b/src/DonationForms/Blocks/DonationFormBlock/Controllers/BlockRenderController.php @@ -13,6 +13,7 @@ class BlockRenderController { /** + * @unreleased include form url for new tab format. * @since 3.0.0 * * @return string|null @@ -26,7 +27,7 @@ public function render(array $attributes) $blockAttributes = BlockAttributes::fromArray($attributes); - if ( ! $blockAttributes->formId) { + if (!$blockAttributes->formId) { return null; } @@ -39,11 +40,13 @@ public function render(array $attributes) $viewUrl = $this->getViewUrl($donationForm, $embedId); + $formUrl = add_query_arg(['p' => $blockAttributes->formId], site_url('?post_type=give_forms')); + /** * Note: iframe-resizer uses querySelectorAll so using a data attribute makes the most sense to target. * It will also generate a dynamic ID - so when we have multiple embeds on a page there will be no conflict. */ - return "
"; + return "
"; } /** diff --git a/src/DonationForms/Blocks/DonationFormBlock/block.json b/src/DonationForms/Blocks/DonationFormBlock/block.json index 754a139b84..93de63075b 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/block.json +++ b/src/DonationForms/Blocks/DonationFormBlock/block.json @@ -1,33 +1,25 @@ { - "$schema": "https://json.schemastore.org/block.json", - "apiVersion": 2, - "name": "givewp/donation-form", - "version": "1.0.0", - "title": "Donation Form", - "category": "give", - "icon": "superhero", - "description": "The GiveWP Donation Form block inserts an existing donation form into the page.", - "supports": { - "html": false, - "inserter": false + "$schema": "https://json.schemastore.org/block.json", + "apiVersion": 2, + "name": "givewp/donation-form", + "version": "1.0.0", + "title": "Donation Form", + "category": "give", + "icon": "superhero", + "description": "The GiveWP Donation Form block inserts an existing donation form into the page.", + "supports": { + "html": false, + "inserter": false + }, + "attributes": { + "formId": { + "type": "string" }, - "attributes": { - "formId": { - "type": "string" - }, - "blockId": { - "type": "string" - }, - "formFormat": { - "type": "string", - "default": "full" - }, - "openFormButton": { - "type": "string", - "default": "Donate now" - } - }, - "textdomain": "give", - "editorStyle": "file:../../../../build/donationFormBlock.css", - "editorScript": "file:../../../../build/donationFormBlock.js" + "blockId": { + "type": "string" + } + }, + "textdomain": "give", + "editorStyle": "file:../../../../build/donationFormBlock.css", + "editorScript": "file:../../../../build/donationFormBlock.js" } diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/ModalForm.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/ModalForm.tsx index a644615538..29f6a125ac 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/ModalForm.tsx +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/ModalForm.tsx @@ -1,11 +1,20 @@ import {useEffect, useRef, useState} from '@wordpress/element'; -import {createPortal} from 'react-dom'; import IframeResizer from 'iframe-resizer-react'; +import {createPortal} from 'react-dom'; + +import '../../editor/styles/index.scss'; + +type ModalFormProps = { + dataSrc: string; + embedId: string; + openFormButton: string; +}; /** + * @unreleased include types. update BEM classnames. * @since 3.0.0 */ -export default function ModalForm({dataSrc, embedId, openFormButton}) { +export default function ModalForm({dataSrc, embedId, openFormButton}: ModalFormProps) { const [isOpen, setIsOpen] = useState(false); const modalRef = useRef(null); @@ -15,37 +24,42 @@ export default function ModalForm({dataSrc, embedId, openFormButton}) { useEffect(() => { const {current: el} = modalRef; - if (isOpen) el.showModal(); + if (isOpen) { + el.showModal(); + } }, [isOpen]); return ( - <> - {isOpen && createPortal( - -
+ +
+ , document.body )} - + ); } diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/RevealForm.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/RevealForm.tsx deleted file mode 100644 index 97ddbb0ff5..0000000000 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/app/Components/RevealForm.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import {useState} from '@wordpress/element'; -import IframeResizer from 'iframe-resizer-react'; - -/** - * @since 3.0.0 - */ -export default function RevealForm({dataSrc, embedId, openFormButton}) { - const [isRevealed, setIsRevealed] = useState(false); - - const revealForm = () => { - setIsRevealed(!isRevealed); - }; - - return ( - <> - - - {isRevealed && ( - - )} - - ); -} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/app/index.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/app/index.tsx index a2e34f9a4c..91d093b2b0 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/app/index.tsx +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/app/index.tsx @@ -1,19 +1,31 @@ import {createRoot, render} from '@wordpress/element'; -import RevealForm from './Components/RevealForm'; import ModalForm from './Components/ModalForm'; import IframeResizer from 'iframe-resizer-react'; -import './styles/index.scss'; +import '../editor/styles/index.scss'; + +type DonationFormBlockAppProps = { + formFormat: 'fullForm' | 'newTab' | 'modal' | string; + dataSrc: string; + embedId: string; + openFormButton: string; + formUrl: string; +}; /** + * @unreleased replace form format reveal with new tab. * @since 3.0.0 */ -function DonationFormBlockApp({formFormat, dataSrc, embedId, openFormButton}) { - if (formFormat === 'reveal') { - return ; +function DonationFormBlockApp({formFormat, dataSrc, embedId, openFormButton, formUrl}: DonationFormBlockAppProps) { + if (formFormat === 'newTab') { + return ( + + {openFormButton} + + ); } - if (formFormat === 'modal') { + if (formFormat === 'modal' || formFormat === 'reveal') { return ; } @@ -38,6 +50,7 @@ roots.forEach((root) => { const embedId = root.getAttribute('data-givewp-embed-id'); const formFormat = root.getAttribute('data-form-format'); const openFormButton = root.getAttribute('data-open-form-button'); + const formUrl = root.getAttribute('data-form-url'); if (createRoot) { createRoot(root).render( @@ -46,6 +59,7 @@ roots.forEach((root) => { formFormat={formFormat} dataSrc={dataSrc} embedId={embedId} + formUrl={formUrl} /> ); } else { @@ -55,6 +69,7 @@ roots.forEach((root) => { formFormat={formFormat} dataSrc={dataSrc} embedId={embedId} + formUrl={formUrl} />, root ); diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/app/styles/index.scss b/src/DonationForms/Blocks/DonationFormBlock/resources/app/styles/index.scss deleted file mode 100644 index 788797d2c6..0000000000 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/app/styles/index.scss +++ /dev/null @@ -1,48 +0,0 @@ -.givewp-donation-form-modal { - width: fit-content; - min-width: 552px; - height: fit-content; - max-height: calc(100% - 5rem); - padding: 0; - border: none; - overflow-y: scroll; - z-index: 999; - - &::backdrop { - background-color: rgba(255, 255, 255, 0.8); - backdrop-filter: blur(3px); - } - - &__close { - border-radius: 0.5rem; - display: flex; - justify-content: center; - align-items: center; - background: rgba(255, 255, 255, 0.8); - color: #555; - font-size: 1.5rem; - line-height: 1; - width: 2.5rem; - height: 2.5rem; - position: absolute; - top: .5rem; - right: .5rem; - cursor: pointer; - } -} - -.givewp-donation-form-display__button { - font-size: 1rem; - color: #fff; - background: #2271b1; - padding: .5rem 1rem; - cursor: pointer; - border: none; - border-radius: 5px; - - &:hover { - background: #1a5d8b; - } -} - - diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/Edit.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/Edit.tsx index 18c8ea3092..cbffaec581 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/Edit.tsx +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/Edit.tsx @@ -1,174 +1,74 @@ -import {__} from '@wordpress/i18n'; -import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; -import {ExternalLink, PanelBody, PanelRow, SelectControl, TextControl} from '@wordpress/components'; -import {Fragment, useCallback, useEffect, useState} from '@wordpress/element'; -import useFormOptions from './hooks/useFormOptions'; -import ConfirmButton from './components/ConfirmButton'; -import Logo from './components/Logo'; +import {useEffect, useState} from 'react'; +import {useBlockProps} from '@wordpress/block-editor'; import {BlockEditProps} from '@wordpress/blocks'; -import ReactSelect from 'react-select'; -import BlockPreview from './components/BlockPreview'; +import ServerSideRender from '@wordpress/server-side-render'; +import DonationFormSelector from './components/DonationFormSelector'; +import useFormOptions from './hooks/useFormOptions'; +import DonationFormBlockControls from './components/DonationFormBlockControls'; +import DonationFormBlockPreview from './components/DonationFormBlockPreview'; import './styles/index.scss'; /** + * @unreleased updated to handle v2 forms. * @since 3.0.0 */ -export default function Edit({clientId, attributes, setAttributes}: BlockEditProps) { - const {formId, blockId, formFormat, openFormButton} = attributes; +export default function Edit({attributes, isSelected, setAttributes, className, clientId}: BlockEditProps) { + const {id, blockId, displayStyle, continueButtonTitle} = attributes; const {formOptions, isResolving} = useFormOptions(); - const [showPreview, setShowPreview] = useState(!!formId); + const [showPreview, setShowPreview] = useState(!!id); - const showOpenFormButton = formFormat === 'reveal' || formFormat === 'modal'; + const handleSelect = (id) => { + setShowPreview(true); + setAttributes({id}); + }; useEffect(() => { if (!blockId) { setAttributes({blockId: clientId}); } - }, []); - const getDefaultFormId = useCallback(() => { - if (!isResolving && formOptions.length > 0) { - return formId && formOptions?.find(({value}) => value === formId); + if (!isLegacyForm && displayStyle === 'reveal') { + setAttributes({displayStyle: 'modal'}); } - }, [isResolving, formId, JSON.stringify(formOptions)]); + }, []); - return ( - - {/*block controls*/} - - - - {!isResolving && formOptions.length === 0 ? ( -

{__('No forms were found using the GiveWP form builder.', 'give')}

- ) : ( - { - setAttributes({formId: newFormId}); - }} - /> - )} -
- - { - setAttributes({formFormat: value}); - }} - /> - - {showOpenFormButton && ( - - { - setAttributes({openFormButton: value}); - }} - /> - - )} - - {formId && ( - - {__('Edit donation form', 'give')} - - )} - -
-
+ const [isLegacyForm, isLegacyTemplate, link] = (() => { + const form = formOptions.find((form) => form.value == id); - {/*block preview*/} -
- {formId && showPreview ? ( - - ) : ( -
- + return [form?.isLegacyForm, form?.isLegacyTemplate, form?.link]; + })(); -
- + return ( +
+ {id && showPreview ? ( + <> + - { - if (option) { - setAttributes({formId: option.value}); - } - }} - noOptionsMessage={() => ( -

{__('No forms were found using the GiveWP form builder.', 'give')}

- )} - options={formOptions} - loadingMessage={() => <>{__('Loading Donation Forms...', 'give')}} - isLoading={isResolving} - theme={(theme) => ({ - ...theme, - colors: { - ...theme.colors, - primary: '#27ae60', - }, - })} - styles={{ - input: (provided, state) => ({ - ...provided, - height: '3rem', - }), - option: (provided, state) => ({ - ...provided, - paddingTop: '0.8rem', - paddingBottom: '0.8rem', - fontSize: '1rem', - }), - control: (provided, state) => ({ - ...provided, - fontSize: '1rem', - }), - }} - /> + {isLegacyForm ? ( +
+
- - setShowPreview(true)} /> -
- )} -
- + ) : ( + + )} + + ) : ( + + )} +
); } diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ConfirmButton.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ConfirmButton.tsx deleted file mode 100644 index 356d58d718..0000000000 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ConfirmButton.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import {__} from '@wordpress/i18n'; -import usePostState from '../hooks/usePostState'; -import {dispatch} from '@wordpress/data'; - -// @ts-ignore -const savePost = () => dispatch('core/editor').savePost(); - -export default function ConfirmButton({formId, enablePreview}) { - const {isSaving, isDisabled} = usePostState(); - - return ( -
- -
- ); -} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockControls.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockControls.tsx new file mode 100644 index 0000000000..5d8bc05e53 --- /dev/null +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockControls.tsx @@ -0,0 +1,178 @@ +import {ExternalLink, PanelBody, PanelRow, SelectControl, TextControl, ToggleControl} from '@wordpress/components'; +import {__} from '@wordpress/i18n'; +import {InspectorControls} from '@wordpress/block-editor'; +import {Option} from '../types'; + +interface DonationFormBlockControls { + attributes: Readonly; + setAttributes: (newAttributes: Record) => void; + formOptions: Option[]; + isResolving: boolean; + isLegacyTemplate: boolean; + isLegacyForm: boolean; +} + +/** + * @unreleased + */ +export default function DonationFormBlockControls({ + attributes, + setAttributes, + formOptions, + isResolving, + isLegacyTemplate, + isLegacyForm, +}: DonationFormBlockControls) { + const {id, displayStyle, continueButtonTitle, showTitle, contentDisplay, showGoal, showContent} = attributes; + const hasFormFormat = isLegacyTemplate || !isLegacyForm; + const showOpenFormButton = hasFormFormat && ['newTab', 'modal', 'reveal', 'button'].includes(displayStyle); + + const displayStyleOptions = ( + options: {label: string; value: string}[], + legacy: {label: string; value: string}[], + v3: {label: string; value: string}[] + ) => { + return isLegacyTemplate ? options.concat(legacy) : options.concat(v3); + }; + return ( + + + + {!isResolving && formOptions.length === 0 ? ( +

{__('No forms were found using the GiveWP form builder.', 'give')}

+ ) : ( + { + setAttributes({id: newFormId}); + }} + /> + )} +
+ {hasFormFormat && ( + + { + setAttributes({displayStyle: value}); + }} + /> + + )} + + {showOpenFormButton && ( + + { + setAttributes({continueButtonTitle: value}); + }} + /> + + )} + + {isLegacyTemplate && ( + <> + + { + setAttributes({showTitle: value}); + }} + /> + + + { + setAttributes({showGoal: value}); + }} + /> + + + { + setAttributes({contentDisplay: value}); + }} + /> + + + {contentDisplay && ( + + { + setAttributes({showContent: value}); + }} + /> + + )} + + )} + + {id && ( + + + {__('Edit donation form', 'give')} + + + )} +
+
+ ); +} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/BlockPreview.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockPreview.tsx similarity index 59% rename from src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/BlockPreview.tsx rename to src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockPreview.tsx index 8604f2e35b..41c501d516 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/BlockPreview.tsx +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/DonationFormBlockPreview.tsx @@ -1,32 +1,43 @@ import ModalPreview from './ModalPreview'; -import RevealPreview from './RevealPreview'; import IframeResizer from 'iframe-resizer-react'; import {useSelect} from '@wordpress/data'; +import '../styles/index.scss'; + interface BlockPreviewProps { formId: number; clientId: string; - formFormat: string; + formFormat: 'fullForm' | 'modal' | 'newTab' | 'reveal'; openFormButton: string; + link: string; } /** + * @unreleased replace reveal for newTab display. * @since 3.0.0 */ -export default function BlockPreview({clientId, formId, formFormat, openFormButton}: BlockPreviewProps) { +export default function DonationFormBlockPreview({ + clientId, + formId, + formFormat, + openFormButton, + link, +}: BlockPreviewProps) { // @ts-ignore const selectedBlock = useSelect((select) => select('core/block-editor').getSelectedBlock(), []); const isBlockSelected = selectedBlock?.clientId === clientId; const enableIframe = isBlockSelected ? 'auto' : 'none'; - const isModalDisplay = formFormat === 'modal'; - const isRevealDisplay = formFormat === 'reveal'; + const isModalDisplay = formFormat === 'modal' || formFormat === 'reveal'; + const isNewTabDisplay = formFormat === 'newTab'; - return isModalDisplay ? ( + return isNewTabDisplay ? ( + + {openFormButton} + + ) : isModalDisplay ? ( - ) : isRevealDisplay ? ( - ) : ( dispatch('core/editor').savePost(); + +/** + * @unreleased + */ +export default function DonationFormSelector({formOptions, isResolving, handleSelect}) { + const [selectedForm, setSelectedForm] = useState(null); + const form = formOptions.find(form => form.value == selectedForm); + const {isSaving, isDisabled} = usePostState(); + + return ( +
+ givewp-logo +
+ + + { + if (option) { + setSelectedForm(option.value); + } + }} + noOptionsMessage={() =>

{__('No forms were found using the GiveWP form builder.', 'give')}

} + options={formOptions} + loadingMessage={() => <>{__('Loading Donation Forms...', 'give')}} + isLoading={isResolving} + theme={reactSelectThemeStyles} + styles={reactSelectStyles} + /> +
+ + +
+ ); +} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/Logo.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/Logo.tsx deleted file mode 100644 index 5e3a736f43..0000000000 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/Logo.tsx +++ /dev/null @@ -1,12 +0,0 @@ -// @ts-ignore -import logo from '../images/givewp-logo.svg'; - -/** - * - * @since 3.0.0 - */ -export default function Logo() { - return
- givewp-logo -
-} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ModalPreview.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ModalPreview.tsx index 3b5985a836..44550085d8 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ModalPreview.tsx +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/ModalPreview.tsx @@ -1,11 +1,20 @@ import {useState} from '@wordpress/element'; -import {createPortal} from 'react-dom'; import IframeResizer from 'iframe-resizer-react'; +import {Modal} from '@wordpress/components'; + +import '../styles/index.scss'; + +type ModalPreviewProps = { + enableIframe: 'auto' | 'none'; + formId: number; + openFormButton: string; +}; /** + * @unreleased updated BEM classnames and included button component. * @since 3.0.0 */ -export default function ModalPreview({enableIframe, formId, openFormButton}) { +export default function ModalPreview({enableIframe, formId, openFormButton}: ModalPreviewProps) { const [isOpen, setIsOpen] = useState(false); const toggleModal = () => { @@ -13,42 +22,25 @@ export default function ModalPreview({enableIframe, formId, openFormButton}) { }; return ( - <> - - {isOpen && - createPortal( - -
- - - -
- -
, - document.body - )} - + {isOpen && ( + + + + )} +
); } diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/RevealPreview.tsx b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/RevealPreview.tsx deleted file mode 100644 index 23db13bf41..0000000000 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/components/RevealPreview.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import {useState} from '@wordpress/element'; -import IframeResizer from 'iframe-resizer-react'; - -/** - * @since 3.0.0 - */ -export default function RevealPreview({enableIframe, formId, openFormButton}: any) { - const [isRevealed, setIsRevealed] = useState(false); - - const revealForm = () => { - setIsRevealed(!isRevealed); - }; - - return ( - <> - - - {isRevealed && ( - - )} - - ); -} diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/hooks/useFormOptions.ts b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/hooks/useFormOptions.ts index 0755503d95..3bbca96eba 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/hooks/useFormOptions.ts +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/hooks/useFormOptions.ts @@ -1,32 +1,38 @@ import {__} from '@wordpress/i18n'; import {useSelect} from '@wordpress/data'; import type {Post} from '@wordpress/core-data/src/entity-types'; -import type {Option} from '../types'; +import type {Form, Option} from '../types'; + +type FormOption = Form & Option; /** + * unreleased include isLegacyForm, isLegacyFormTemplate & link. * @since 3.0.0 */ -export default function useFormOptions(): {formOptions: Option[] | []; isResolving: boolean} { +export default function useFormOptions(): { + formOptions: FormOption[]; + isResolving: boolean; +} { + const formOptions = []; + const {forms, isResolving} = useSelect((select) => { return { - forms: select('core') - // @ts-ignore - .getEntityRecords('postType', 'give_forms') - ?.filter(({excerpt}) => excerpt.rendered === '

[]

\n'), + // @ts-ignore + forms: select('core').getEntityRecords('postType', 'give_forms'), // @ts-ignore isResolving: select('core/data').getIsResolving('core', 'getEntityRecords', ['postType', 'give_forms']), }; }, []); - const formOptions = - forms && forms.length > 0 - ? forms.map(({id, title}) => { - return { - label: __(title.rendered, 'give'), - value: String(id), - }; - }) - : []; + forms?.map(({title, id, formTemplate, isLegacyForm, link}) => { + formOptions.push({ + label: __(title.rendered, 'give'), + value: id, + isLegacyForm, + isLegacyTemplate: isLegacyForm && formTemplate === 'legacy', + link: link, + }); + }); return { isResolving, diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/index.scss b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/index.scss index 398d642eab..a7fae6bb0e 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/index.scss +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/index.scss @@ -1,106 +1,128 @@ -.givewp-form-block { - &--container { - display: grid; - row-gap: 1rem; - padding: 2rem 4rem; - background: #f6f6f6; - border-radius: 5px; - box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1); - } +.givewp-donation-form-selector { + display: flex; + flex-direction: column; + gap: 1rem; + padding: 2rem 4rem; + background: #f6f6f6; + border-radius: 5px; + box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1); - &__option { - height: 48px; + &__select { + input[type="text"]:focus { + border-color: transparent; + box-shadow: 0 0 0 1px transparent; + outline: 2px solid transparent; } + } - &__select { - &__input { - &:focus { - box-shadow: none !important; - } - } + &__logo { + align-self: center; + } - &--label { - color: #4f4f4f; - } - } + &__open { + color: #fff; + background: #2271b1; + padding: .5rem 1rem; + cursor: pointer; + border: none; + border-radius: 5px; + } - &__logo { - &--container { - text-align: center; - } - } + &__submit { + width: 100%; + background-color: #27ae60; + color: #fff; + padding: 1rem; + border-radius: 5px; + font-weight: bold; + text-align: center; + outline: none; + border: 0; + transition: 0.2s; - &__submit-button { - width: 100%; - background-color: #27ae60; - color: #fff; - padding: 1rem; - border-radius: 5px; - font-weight: bold; - text-align: center; - outline: none; - border: 0; - transition: 0.2s; - - &:disabled { - background-color: #e0e0e0; - } - - &:hover:not(:disabled) { - cursor: pointer; - filter: brightness(1.2); - } - - &--container { - margin-top: 1rem; - } + &:disabled { + background-color: #e0e0e0; } - &__display-button { - color: #fff; - background: #2271b1; - padding: .5rem 1rem; - cursor: pointer; - border: none; - border-radius: 5px; + &:hover:not(:disabled) { + cursor: pointer; + filter: brightness(1.2); } + } +} + +.givewp-donation-form-link, .givewp-donation-form-modal__open { + color: var(--givewp-secondary-color, #ffffff) !important; + background: var(--givewp-primary-color, #2271b1); + padding: .75rem 1.25rem !important; + cursor: pointer; + border: none; + border-radius: 5px; + font-size: 1rem; + font-weight: 500 !important; + text-decoration: none !important; + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;; } .givewp-donation-form-modal { + border: none; + + &__dialog { + position: relative; + padding: 0 !important; + border: none !important; + } + + &__close { position: absolute; - top: 25%; - width: fit-content; - min-width: 552px; - height: fit-content; - max-height: calc(100% - 5rem); - padding: 0; - border: none; - overflow-y: scroll; - z-index: 999; + right: 3.5%; + top: 1.5%; + margin-right: auto; + padding: .5rem .5rem .25rem .5rem; + border: none !important; + background-color: transparent !important; + cursor: pointer; - &::backdrop { - background-color: rgba(255, 255, 255, 0.8); - backdrop-filter: blur(3px); - } - &__close { - border-radius: 0.5rem; - display: flex; - justify-content: center; - align-items: center; - background: rgba(255, 255, 255, 0.8); - color: #555; - font-size: 1.5rem; - line-height: 1; - width: 2.5rem; - height: 2.5rem; - position: absolute; - top: .5rem; - right: .5rem; - cursor: pointer; + &:hover { + path { + fill: #0073AA; + } } + } +} + +.components-modal__header { + padding-top: 0 !important; + padding-right: 1.5rem !important; + border-bottom: none !important; +} + +.components-modal__content { + margin-top: 0 !important; + padding: 0 !important; } .components-input-control__label { - width: 100%; + width: 100%; } + +.wp-block-give-donation-form { + position: relative; + + form[id*='give-form'] #give-gateway-radio-list > li input[type='radio'] { + display: inline-block; + } + + iframe { + pointer-events: none; + width: 100% !important; + } +} + +.give-change-donation-form-btn { + svg { + margin-top: 3px; + } +} + diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/reactSelectStyles.ts b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/reactSelectStyles.ts new file mode 100644 index 0000000000..2f1ad6b82a --- /dev/null +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/styles/reactSelectStyles.ts @@ -0,0 +1,24 @@ +export const reactSelectStyles = { + input: (provided, state) => ({ + ...provided, + height: '3rem', + }), + option: (provided, state) => ({ + ...provided, + paddingTop: '0.8rem', + paddingBottom: '0.8rem', + fontSize: '1rem', + }), + control: (provided, state) => ({ + ...provided, + fontSize: '1rem', + }), +}; + +export const reactSelectThemeStyles = (theme) => ({ + ...theme, + colors: { + ...theme.colors, + primary: '#27ae60', + }, +}); diff --git a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/types/index.ts b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/types/index.ts index cd6306fb68..234530432f 100644 --- a/src/DonationForms/Blocks/DonationFormBlock/resources/editor/types/index.ts +++ b/src/DonationForms/Blocks/DonationFormBlock/resources/editor/types/index.ts @@ -15,6 +15,10 @@ interface Option { disabled?: boolean; } -export type { - Option +interface Form { + isLegacyForm: boolean; + isLegacyTemplate: boolean; + link: string; } + +export type {Option, Form}; diff --git a/src/DonationForms/Shortcodes/GiveFormShortcode.php b/src/DonationForms/Shortcodes/GiveFormShortcode.php index d36a71ab75..e76e54871d 100644 --- a/src/DonationForms/Shortcodes/GiveFormShortcode.php +++ b/src/DonationForms/Shortcodes/GiveFormShortcode.php @@ -13,6 +13,7 @@ class GiveFormShortcode public static $instance = 0; /** + * @unreleased include v3 block attributes for shortcode. * @since 3.1.1 use static instance ID to simulate blockId attribute * @since 3.0.0 */ @@ -21,16 +22,21 @@ public function __invoke(string $output, array $atts): string self::$instance++; $formId = absint($atts['id']); - $isV3Form = (bool) give()->form_meta->get_meta($formId, 'formBuilderSettings', true); + $isV3Form = (bool)give()->form_meta->get_meta($formId, 'formBuilderSettings', true); if (!$formId || !$isV3Form) { return $output; } + $formFormat = $atts['display_style']; + $openFormButton = $atts['continue_button_title']; + $controller = new BlockRenderController(); $blockAttributes = [ 'formId' => $formId, 'blockId' => 'give-form-shortcode-' . self::$instance, + 'formFormat' => $formFormat, + 'openFormButton' => $openFormButton ]; $output = $controller->render($blockAttributes); diff --git a/tests/Unit/DataTransferObjects/BlockAttributesTest.php b/tests/Unit/DataTransferObjects/BlockAttributesTest.php index c9cbc34f31..4a643aa6ea 100644 --- a/tests/Unit/DataTransferObjects/BlockAttributesTest.php +++ b/tests/Unit/DataTransferObjects/BlockAttributesTest.php @@ -37,10 +37,10 @@ public function testShouldReturnAttributesArray() */ public function testFormIdShouldReturnIntFromString() { - $blockAttributes = BlockAttributes::fromArray([ - 'formId' => '1', - 'blockId' => '123' - ]); + $blockAttributes = BlockAttributes::fromArray([ + 'formId' => '1', + 'blockId' => '123' + ]); $this->assertSame(1, $blockAttributes->formId); }