diff --git a/assets/src/css/admin/settings.scss b/assets/src/css/admin/settings.scss index a5707b5931..7037306357 100644 --- a/assets/src/css/admin/settings.scss +++ b/assets/src/css/admin/settings.scss @@ -383,6 +383,90 @@ div.give-field-description { } } +.give_option_based_form_editor_notice { + display: flex; + margin: -2rem 0; + gap: 0.3rem; + padding: 0.5rem; + background-color: #fffaf2; + border-radius: 4px; + border: 1px solid #f29718; + border-left-width: 4px; + font-size: 0.875rem; + font-weight: 500; + color: #1a0f00; + line-height: 1.25rem; + max-width: 60rem; + width: 100%; + + svg { + margin: 0.4rem 0.3rem; + height: 1.25rem; + width: 1.25rem; + } +} + +.give-setting-tab-body-general, +.give-setting-tab-body-display, +.give-settings-advanced-tab { + label { + display: flex; + gap: 0.4rem; + padding: 1.25rem 1rem; + position: relative; + + .give-settings-section-group-helper { + --popout-display: none; + display: flex; + cursor: help; + + img { + max-width: 18.9px; + } + + &:hover { + --popout-display: block; + } + + &__popout { + background-color: #fff; + border: 1px solid #e6e6e6; + border-radius: 4px; + box-shadow: 0 4px 8px 0 #0000000D; + color: #404040; + display: var(--popout-display, none); + left: 100%; + overflow: hidden; + position: absolute; + top: 0; + transform: translateX(10px); + z-index: 9999; + + img { + max-width: initial; + display: block; + } + + h5 { + font-size: 0.875rem; + font-weight: 700; + line-height: 1.5; + margin: 0; + padding: 1rem 1.5rem 0.5rem; + } + + p { + font-size: 0.75rem; + font-weight: 500; + line-height: 1.5; + margin: 0; + padding: 0 1.5rem 1.5rem; + } + } + } + } +} + .give-payment-gateways-settings { &.give-settings-section-content { .give-settings-section-group-menu { diff --git a/give.php b/give.php index ea9b49de04..29eac092e4 100644 --- a/give.php +++ b/give.php @@ -242,6 +242,7 @@ final class Give Give\FormTaxonomies\ServiceProvider::class, Give\DonationSpam\ServiceProvider::class, Give\Campaigns\ServiceProvider::class, + Give\FeatureFlags\OptionBasedFormEditor\ServiceProvider::class, ]; /** diff --git a/includes/admin/class-admin-settings.php b/includes/admin/class-admin-settings.php index c409c39c9e..2a32021503 100644 --- a/includes/admin/class-admin-settings.php +++ b/includes/admin/class-admin-settings.php @@ -948,7 +948,9 @@ class="give-input-field > - + > diff --git a/includes/post-types.php b/includes/post-types.php index 44f556a905..60edcc2002 100644 --- a/includes/post-types.php +++ b/includes/post-types.php @@ -56,8 +56,8 @@ function give_setup_post_types() { 'name' => __( 'Donation Forms', 'give' ), 'singular_name' => __( 'Form', 'give' ), 'add_new' => __( 'Add Form', 'give' ), - 'add_new_item' => __( 'Add New Donation Form', 'give' ), - 'edit_item' => __( 'Edit Donation Form', 'give' ), + 'add_new_item' => __( 'Add New Campaign Form', 'give' ), + 'edit_item' => __( 'Edit Campaign Form', 'give' ), 'new_item' => __( 'New Form', 'give' ), 'all_items' => __( 'All Forms', 'give' ), 'view_item' => __( 'View Form', 'give' ), diff --git a/src/Campaigns/Actions/AddCampaignFormFromRequest.php b/src/Campaigns/Actions/AddCampaignFormFromRequest.php index 0794999d7c..9b0bccf0a1 100644 --- a/src/Campaigns/Actions/AddCampaignFormFromRequest.php +++ b/src/Campaigns/Actions/AddCampaignFormFromRequest.php @@ -6,6 +6,7 @@ use Give\Campaigns\Models\Campaign; use Give\Campaigns\Repositories\CampaignRepository; use Give\DonationForms\Models\DonationForm; +use WP_Post; /** * @unreleased @@ -13,12 +14,26 @@ class AddCampaignFormFromRequest { /** + * @unreleased + * * @throws Exception */ - public function __invoke(DonationForm $donationForm) + public function optionBasedFormEditor(int $formId, WP_Post $post, bool $update) + { + if ( ! $update && isset($_GET['campaignId']) && $campaign = Campaign::find(absint($_GET['campaignId']))) { + give(CampaignRepository::class)->addCampaignForm($campaign, $formId); + } + } + + /** + * @unreleased + * + * @throws Exception + */ + public function visualFormBuilder(DonationForm $donationForm) { if (isset($_GET['campaignId']) && $campaign = Campaign::find(absint($_GET['campaignId']))) { - give(CampaignRepository::class)->addCampaignForm($campaign, $donationForm); + give(CampaignRepository::class)->addCampaignForm($campaign, $donationForm->id); } } } diff --git a/src/Campaigns/Actions/CreateDefaultCampaignForm.php b/src/Campaigns/Actions/CreateDefaultCampaignForm.php index db47267409..e3d0259791 100644 --- a/src/Campaigns/Actions/CreateDefaultCampaignForm.php +++ b/src/Campaigns/Actions/CreateDefaultCampaignForm.php @@ -31,6 +31,6 @@ public function __invoke(Campaign $campaign) ]), ]); - give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm, true); + give(CampaignRepository::class)->addCampaignForm($campaign, $defaultCampaignForm->id, true); } } diff --git a/src/Campaigns/Models/Campaign.php b/src/Campaigns/Models/Campaign.php index e1e3816c51..bb56e5477b 100644 --- a/src/Campaigns/Models/Campaign.php +++ b/src/Campaigns/Models/Campaign.php @@ -115,9 +115,9 @@ public static function find($id): ?Campaign * * @unreleased */ - public static function findByFormId($id): ?Campaign + public static function findByFormId(int $formId): ?Campaign { - return give(CampaignRepository::class)->getByFormId($id); + return give(CampaignRepository::class)->getByFormId($formId); } /** diff --git a/src/Campaigns/Repositories/CampaignRepository.php b/src/Campaigns/Repositories/CampaignRepository.php index e620f8139f..fa32e2a6a2 100644 --- a/src/Campaigns/Repositories/CampaignRepository.php +++ b/src/Campaigns/Repositories/CampaignRepository.php @@ -5,7 +5,6 @@ use Exception; use Give\Campaigns\Models\Campaign; use Give\Campaigns\ValueObjects\CampaignType; -use Give\DonationForms\Models\DonationForm; use Give\Framework\Database\DB; use Give\Framework\Exceptions\Primitives\InvalidArgumentException; use Give\Framework\Models\ModelQueryBuilder; @@ -29,6 +28,8 @@ class CampaignRepository ]; /** + * @unreleased + * * Get Campaign by ID * * @unreleased @@ -41,15 +42,15 @@ public function getById(int $id) } /** - * Get Campaign by Form ID - * * @unreleased + * + * Get Campaign by Form ID */ - public function getByFormId(int $id) + public function getByFormId(int $formId) { return $this->prepareQuery() ->leftJoin('give_campaign_forms', 'campaigns.id', 'forms.campaign_id', 'forms') - ->where('forms.form_id', $id) + ->where('forms.form_id', $formId) ->get(); } @@ -160,9 +161,9 @@ public function update(Campaign $campaign): void * * @throws Exception */ - public function addCampaignForm(Campaign $campaign, DonationForm $donationForm, bool $isDefault = false) + public function addCampaignForm(Campaign $campaign, int $donationFormId, bool $isDefault = false) { - Hooks::doAction('givewp_campaign_form_relationship_creating', $campaign, $donationForm, $isDefault); + Hooks::doAction('givewp_campaign_form_relationship_creating', $campaign, $donationFormId, $isDefault); DB::query('START TRANSACTION'); @@ -180,7 +181,7 @@ public function addCampaignForm(Campaign $campaign, DonationForm $donationForm, DB::query( DB::prepare("INSERT INTO {$table} (form_id, campaign_id, is_default ) VALUES (%d, %d, %d)", [ - $donationForm->id, + $donationFormId, $campaign->id, $isDefault, ]) @@ -195,7 +196,7 @@ public function addCampaignForm(Campaign $campaign, DonationForm $donationForm, DB::query('COMMIT'); - Hooks::doAction('givewp_campaign_form_relationship_created', $campaign, $donationForm, $isDefault); + Hooks::doAction('givewp_campaign_form_relationship_created', $campaign, $donationFormId, $isDefault); } /** diff --git a/src/Campaigns/ServiceProvider.php b/src/Campaigns/ServiceProvider.php index 07fe5aab8e..e46e6baa92 100644 --- a/src/Campaigns/ServiceProvider.php +++ b/src/Campaigns/ServiceProvider.php @@ -138,8 +138,9 @@ private function setupCampaignForms() if ( ! defined('GIVE_IS_ALL_STATS_COLUMNS_ASYNC_ON_ADMIN_FORM_LIST_VIEWS')) { define('GIVE_IS_ALL_STATS_COLUMNS_ASYNC_ON_ADMIN_FORM_LIST_VIEWS', false); } - - Hooks::addAction('givewp_donation_form_created', AddCampaignFormFromRequest::class); + + Hooks::addAction('save_post_give_forms', AddCampaignFormFromRequest::class, 'optionBasedFormEditor', 10, 3); + Hooks::addAction('givewp_donation_form_created', AddCampaignFormFromRequest::class, 'visualFormBuilder'); Hooks::addAction('givewp_campaign_created', CreateDefaultCampaignForm::class); } } diff --git a/src/DonationForms/V2/DonationFormsAdminPage.php b/src/DonationForms/V2/DonationFormsAdminPage.php index f67869764b..bd51e51bac 100644 --- a/src/DonationForms/V2/DonationFormsAdminPage.php +++ b/src/DonationForms/V2/DonationFormsAdminPage.php @@ -3,7 +3,9 @@ namespace Give\DonationForms\V2; use Give\Campaigns\CampaignsAdminPage; +use Give\Campaigns\Models\Campaign; use Give\DonationForms\V2\ListTable\DonationFormsListTable; +use Give\FeatureFlags\OptionBasedFormEditor\OptionBasedFormEditor; use Give\Helpers\EnqueueScript; use WP_Post; use WP_REST_Request; @@ -106,6 +108,7 @@ public function loadScripts() 'showUpgradedTooltip' => !get_user_meta(get_current_user_id(), 'givewp-show-upgraded-tooltip', true), 'supportedAddons' => $this->getSupportedAddons(), 'supportedGateways' => $this->getSupportedGateways(), + 'isOptionBasedFormEditorEnabled' => OptionBasedFormEditor::isEnabled(), ]; EnqueueScript::make('give-admin-donation-forms', 'assets/dist/js/give-admin-donation-forms.js') @@ -145,6 +148,8 @@ public function loadMigrationScripts() } if ($this->isShowingEditV2FormPage()) { + $formId = (int)$_GET['post']; + $campaign = Campaign::findByFormId($formId); EnqueueScript::make('give-edit-v2form', 'assets/dist/js/give-edit-v2form.js') ->loadInFooter() ->registerTranslations() @@ -153,7 +158,8 @@ public function loadMigrationScripts() 'supportedGateways' => $this->getSupportedGateways(), 'migrationApiRoot' => $this->migrationApiRoot, 'apiNonce' => $this->apiNonce, - 'isMigrated' => _give_is_form_migrated((int)$_GET['post']), + 'isMigrated' => _give_is_form_migrated($formId), + 'campaignUrl' => $campaign ? admin_url('edit.php?post_type=give_forms&page=give-campaigns&id=' . $campaign->id) : '', ]) ->enqueue(); diff --git a/src/DonationForms/V2/resources/add-v2form.tsx b/src/DonationForms/V2/resources/add-v2form.tsx index ed8e3aeb1c..9f5e8ecee4 100644 --- a/src/DonationForms/V2/resources/add-v2form.tsx +++ b/src/DonationForms/V2/resources/add-v2form.tsx @@ -1,7 +1,7 @@ import {StrictMode} from 'react'; import {createRoot} from 'react-dom/client'; -import AddForm from './components/Onboarding/Components/AddForm'; import './colors.scss'; +import AddForm from './components/Onboarding/Components/AddForm'; const appContainer = document.createElement('div'); const target = document.querySelector('.wp-header-end'); diff --git a/src/DonationForms/V2/resources/components/AddCampaignFormModal/AddCampaignFormModal.module.scss b/src/DonationForms/V2/resources/components/AddCampaignFormModal/AddCampaignFormModal.module.scss new file mode 100644 index 0000000000..5ae2348e71 --- /dev/null +++ b/src/DonationForms/V2/resources/components/AddCampaignFormModal/AddCampaignFormModal.module.scss @@ -0,0 +1,135 @@ +.addFormModal { + + :global { + .givewp-modal-dialog { + width: 100%; + max-width: 60rem; + + .givewp-modal-header { + font-size: 1.25rem; + font-weight: 600; + line-height: 1.6; + } + + .givewp-modal-close { + translateY: 4.5px; + } + + .givewp-editor-options { + display: flex; + + justify-content: space-between; + gap: 1rem; + + &__option_recommended { + width: 112px; + height: 22px; + flex-grow: 0; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + gap: 4px; + padding: 2px 12px; + border-radius: 24px; + background-color: var(--givewp-purple-500); + + font-size: 12px; + font-weight: 600; + font-stretch: normal; + font-style: normal; + line-height: 1.5; + letter-spacing: normal; + text-align: left; + color: var(--givewp-purple-25); + + position: relative; + margin: -3.3rem 0 1.75rem 0.3rem; + } + + &__option_selected_icon { + display: flex; + justify-content: flex-end; + width: 100%; + + svg { + margin-top: -1.5rem; + margin-right: -1.4rem; + margin-bottom: 0.2rem; + display: none; + } + } + + &__option { + background-color: #f9fafb; + max-width: 28.25rem; + width: 100%; + padding: 1.5rem 1.5rem 0 1.5rem; + border: 1px solid #ddd; + border-radius: 0.5rem; + cursor: pointer; + + /* Hide the radio button input */ + input { + position: absolute; + opacity: 0; + cursor: pointer; + height: 0; + width: 0; + } + + img { + width: 100%; + max-height: 15rem; + object-fit: cover; + object-position: 0 0; + margin-bottom: 1rem; + } + + label { + font-size: 1rem; + font-weight: 500; + color: #060c1a; + } + + p { + font-size: 0.875rem; + margin-top: 0.4rem; + color: #4b5563; + } + + &:hover { + border-color: var(--givewp-green-500); + } + } + + &__option_selected { + border: 2px solid var(--givewp-green-500); + + svg { + display: block; + } + } + } + + .givewp-editor-actions { + + display: flex; + justify-content: flex-end; + gap: 1rem; + width: 100%; + margin-top: 2.5rem; + + &__button { + border-radius: 0.5rem; + font-size: 1rem; + font-weight: 600; + line-height: 1.25rem; + padding: 1.1rem; + width: 22.5rem; + text-align: center; + } + } + } + } +} diff --git a/src/DonationForms/V2/resources/components/AddCampaignFormModal/index.tsx b/src/DonationForms/V2/resources/components/AddCampaignFormModal/index.tsx new file mode 100644 index 0000000000..ac27e2bd1d --- /dev/null +++ b/src/DonationForms/V2/resources/components/AddCampaignFormModal/index.tsx @@ -0,0 +1,150 @@ +import ModalDialog from '@givewp/components/AdminUI/ModalDialog'; +import styles from './AddCampaignFormModal.module.scss'; +import {__} from '@wordpress/i18n'; +import {useRef, useState} from 'react'; + +export type EditorTypeOptionProps = { + editorType: string; + label: string; + description: string; + editorSelected: string; + handleEditorSelected: any; +}; + +const EditorSelectedIcon = () => { + return ( + + + + ); +}; + +/** + * Editor Type Option component + * + * @unreleased + */ +const EditorTypeOption = ({ + editorType, + label, + description, + editorSelected, + handleEditorSelected, +}: EditorTypeOptionProps) => { + const divRef = useRef(null); + const labelRef = useRef(null); + + const handleDivClick = () => { + labelRef.current.click(); + }; + + return ( +
+ {label} + {editorType === 'visualFormBuilder' && ( + {__('Recommended', 'give')} + )} + +

{description}

+
+ +
+
+ ); +}; + +/** + * Form Modal component that renders a modal with a styled form inside + * + * @unreleased + */ +export default function AddCampaignFormModal({isOpen, handleClose, title, campaignId}: FormModalProps) { + const [editorSelected, setEditorSelected] = useState(''); + + const handleEditorSelected = (event) => { + setEditorSelected(event.target.value); + }; + + return ( + + <> +
+ + +
+
+ + {__('Proceed', 'give')} + +
+ +
+ ); +} + +interface FormModalProps { + isOpen: boolean; + handleClose: () => void; + title: string; + campaignId: string; +} diff --git a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx index 38f2a68acd..bd37c33cd6 100644 --- a/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx +++ b/src/DonationForms/V2/resources/components/DonationFormsListTable.tsx @@ -10,6 +10,7 @@ import {Interweave} from 'interweave'; import InterweaveSSR from '@givewp/components/ListTable/InterweaveSSR'; import BlankSlate from '@givewp/components/ListTable/BlankSlate'; import {CubeIcon} from '@givewp/components/AdminUI/Icons'; +import AddCampaignFormModal from './AddCampaignFormModal'; declare global { interface Window { @@ -26,6 +27,8 @@ declare global { isMigrated: boolean; supportedAddons: Array; supportedGateways: Array; + isOptionBasedFormEditorEnabled: boolean; + campaignUrl: string; }; GiveNextGen?: { @@ -264,6 +267,10 @@ export default function DonationFormsListTable() { showFeatureNoticeDialog: false, }); + const [isOpen, setOpen] = useState(false); + const openModal = () => setOpen(true); + const closeModal = () => setOpen(false); + return ( {isCampaignDetailsPage ? (
- - {__('Add campaign form', 'give')} - + {window.GiveDonationForms.isOptionBasedFormEditorEnabled ? ( + <> + + + + ) : ( + <> + + {__('Add campaign form', 'give')} + + + )}
) : ( <> diff --git a/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButton.tsx b/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButton.tsx index d032fa0165..f6a827635d 100644 --- a/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButton.tsx +++ b/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButton.tsx @@ -4,11 +4,8 @@ import styles from '../style.module.scss'; export default function FormBuilderButton({onClick}) { return ( - - ) + ); } diff --git a/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButtonPortal.tsx b/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButtonPortal.tsx index f48097893f..5bbbba744f 100644 --- a/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButtonPortal.tsx +++ b/src/DonationForms/V2/resources/components/Onboarding/Components/FormBuilderButtonPortal.tsx @@ -1,27 +1,37 @@ import {useEffect} from 'react'; import {createPortal} from 'react-dom'; import {FeatureNoticeDialog} from '../Dialogs'; -import FormBuilderButton from './FormBuilderButton'; import styles from '../style.module.scss'; +import FormBuilderButton from './FormBuilderButton'; +import {__} from '@wordpress/i18n'; const portalContainer = document.createElement('div'); export default function FormBuilderButtonPortal({isUpgrading = false, isEditing = false, showDialog, setShowDialog}) { - useEffect(() => { const target = document.querySelector('.wp-header-end'); target.parentNode.insertBefore(portalContainer, target); }, [portalContainer]); - const ButtonPortal = () => createPortal( -
- setShowDialog({ - show: true, - upgrading: false - })} /> -
, - portalContainer - ); + const ButtonPortal = () => + createPortal( +
+
+ + setShowDialog({ + show: true, + upgrading: false, + }) + } + /> +
+ {window.GiveDonationForms.campaignUrl && ( + {__('Manage Campaign', 'give')} + )} +
, + portalContainer + ); return ( <> @@ -35,5 +45,5 @@ export default function FormBuilderButtonPortal({isUpgrading = false, isEditing /> )} - ) + ); } diff --git a/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/HeaderExtension.module.scss b/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/HeaderExtension.module.scss new file mode 100644 index 0000000000..9abbd90ea0 --- /dev/null +++ b/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/HeaderExtension.module.scss @@ -0,0 +1,11 @@ +.container { + display: flex; + justify-content: space-between; + background: red; + gap: 1rem; + width: 100%; + max-width: 700px; + position: absolute; + top: 18px; + right: 12%; +} diff --git a/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/index.tsx b/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/index.tsx new file mode 100644 index 0000000000..43797a23b1 --- /dev/null +++ b/src/DonationForms/V2/resources/components/Onboarding/Components/HeaderExtension/index.tsx @@ -0,0 +1,10 @@ +import styles from './HeaderExtension.module.scss'; + +export default function HeaderExtension() { + return ( +
+
Item 1
+
Item 2
+
+ ); +} diff --git a/src/DonationForms/V2/resources/components/Onboarding/style.module.scss b/src/DonationForms/V2/resources/components/Onboarding/style.module.scss index 6514e25171..110c815958 100644 --- a/src/DonationForms/V2/resources/components/Onboarding/style.module.scss +++ b/src/DonationForms/V2/resources/components/Onboarding/style.module.scss @@ -153,13 +153,29 @@ } } -.tryNewFormBuilderBtnContainer { +.actionsContainer { + display: flex; + justify-content: space-between; + width: 100%; + max-width: 60%; position: absolute; top: 18px; - left: 50%; - transform: translate(-50%, 0); + right: 1.8%; + + + a { + font-weight: bold; + margin-top: 22px; + } } +/*.tryNewFormBuilderBtnContainer { + position: absolute; + top: 18px; + left: 50%; + transform: translate(-50%, 0); +}*/ + .formName { color: #459948; } diff --git a/src/FeatureFlags/FeatureFlags.php b/src/FeatureFlags/FeatureFlags.php new file mode 100644 index 0000000000..8298ca44bc --- /dev/null +++ b/src/FeatureFlags/FeatureFlags.php @@ -0,0 +1,14 @@ + + +
+ +
%3$s
+

%4$s

+
+ ', + esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/help-circle.svg'), + esc_url(GIVE_PLUGIN_URL . 'assets/dist/images/admin/give-settings-gateways-v2.jpg'), + __('Only for Option-Based Form Editor', 'give'), + __('Uses the traditional settings options for creating and customizing a donation form.', + 'give') + ); + } + + /** + * @unreleased + */ + public static function existOptionBasedFormsOnDb(): bool + { + return (bool)give(DonationFormsRepository::class)->prepareQuery() + ->whereNotExists(function ( + QueryBuilder $builder + ) { + $builder + ->select(['meta_value', 'formBuilderSettings']) + ->from(DB::raw(DB::prefix('give_formmeta'))) + ->where('meta_key', 'formBuilderSettings') + ->whereRaw('AND form_id = ID'); + })->count(); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php b/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php new file mode 100644 index 0000000000..7994229fe5 --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/ServiceProvider.php @@ -0,0 +1,60 @@ +maybeDisableOptionBasedFormEditorSettings(); + } + + /** + * @return void + */ + private function maybeDisableOptionBasedFormEditorSettings() + { + // General Tab + Hooks::addFilter('give_get_sections_general', GeneralSettings::class, 'maybeDisableSections', 999); + Hooks::addFilter('give_get_settings_general', GeneralSettings::class, 'maybeDisableOptions', 999); + + // Payment Gateways Tab + add_filter('give_settings_payment_gateways_menu_groups', function ($groups) { + if ( ! OptionBasedFormEditor::isEnabled() && isset($groups['v2'])) { + unset($groups['v2']); + } + + return $groups; + }); + + // Default Options Tab + Hooks::addFilter('give_default_setting_tab_section_display', DefaultOptionsSettings::class, + 'maybeSetNewDefaultSection', + 999); + Hooks::addFilter('give_get_sections_display', DefaultOptionsSettings::class, 'maybeDisableSections', 999); + Hooks::addFilter('give_get_settings_display', DefaultOptionsSettings::class, 'maybeDisableOptions', 999); + + // Advance Tab + Hooks::addFilter('give_get_sections_advanced', AdvancedSettings::class, 'maybeDisableSections', 999); + Hooks::addFilter('give_get_settings_advanced', AdvancedSettings::class, 'maybeDisableOptions', 999); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php new file mode 100644 index 0000000000..14d621b2b6 --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/AbstractOptionBasedFormEditorSettings.php @@ -0,0 +1,100 @@ + $value) { + if (in_array($key, $this->getDisabledSectionIds())) { + unset($sections[$key]); + } + } + + return $sections; + } + + /** + * @unreleased + */ + final public function maybeDisableOptions(array $options): array + { + foreach ($options as $key => $value) { + if ( ! $this->isOptionDisabled($value['id']) && ! $this->isCurrentSectionDisabled()) { + continue; + } + + if (OptionBasedFormEditor::isEnabled()) { + $options[$key]['name'] .= isset($value['name']) ? OptionBasedFormEditor::helperText() : ''; + } else { + unset($options[$key]); + } + } + + return $options; + } + + /** + * @unreleased + */ + final public function maybeSetNewDefaultSection($currentSection) + { + if (OptionBasedFormEditor::isEnabled()) { + return $currentSection; + } + + $newDefaultSection = $this->getNewDefaultSection(); + + return ! empty($newDefaultSection) && $newDefaultSection != $currentSection ? $newDefaultSection : $currentSection; + } + + /** + * @unreleased + */ + private function isOptionDisabled($option): bool + { + return $option && in_array($option, $this->getDisabledOptionIds()); + } + + /** + * @unreleased + */ + private function isCurrentSectionDisabled(): bool + { + return in_array(give_get_current_setting_section(), $this->getDisabledSectionIds()); + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php new file mode 100644 index 0000000000..746234eccf --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/Advanced.php @@ -0,0 +1,26 @@ +routeForm->getOptionName(), + // Stripe Section + 'stripe_js_fallback', + 'stripe_styles', + ]; + } +} diff --git a/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php b/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php new file mode 100644 index 0000000000..d8303d31ff --- /dev/null +++ b/src/FeatureFlags/OptionBasedFormEditor/Settings/DefaultOptions.php @@ -0,0 +1,44 @@ + get_user_meta(get_current_user_id(), 'givewp-additional-payment-gateways-notice-dismissed', true), ]); + /** + * @unreleased + */ + if ($campaign = Campaign::findByFormId($donationFormId)) { + wp_localize_script('@givewp/form-builder/script', 'headerContainer', [ + 'campaignUrl' => admin_url('edit.php?post_type=give_forms&page=give-campaigns&id=' . $campaign->id), + ]); + } + + View::render('FormBuilder.admin-form-builder'); } diff --git a/src/FormBuilder/resources/js/form-builder/src/containers/HeaderContainer.tsx b/src/FormBuilder/resources/js/form-builder/src/containers/HeaderContainer.tsx index 5278a1146e..c138fb3f02 100644 --- a/src/FormBuilder/resources/js/form-builder/src/containers/HeaderContainer.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/containers/HeaderContainer.tsx @@ -19,6 +19,14 @@ import {cleanForSlug} from '@wordpress/url'; import cn from 'classnames'; import EmbedFormModal from '@givewp/form-builder/components/EmbedForm'; +declare global { + interface Window { + headerContainer?: { + campaignUrl: string; + }; + } +} + const Logo = () => (
(
); +const BackToCampaignOverview = () => ( + +); + /** * @since 3.1.0 dispatch page slug from form title on initial publish. */ @@ -107,7 +131,7 @@ const HeaderContainer = ({SecondarySidebarButtons = null, showSidebar, toggleSho ], }); } - } + }; const {mode} = useEditorState(); const dispatchEditorState = useEditorStateDispatch(); @@ -123,7 +147,7 @@ const HeaderContainer = ({SecondarySidebarButtons = null, showSidebar, toggleSho
- + {window.headerContainer ? : } {SecondarySidebarButtons && } create(); $newDefaultForm = DonationForm::factory()->create(); - give(CampaignRepository::class)->addCampaignForm($campaign, $newDefaultForm, true); + give(CampaignRepository::class)->addCampaignForm($campaign, $newDefaultForm->id, true); $this->assertEquals($newDefaultForm->id, $campaign->defaultForm()->id); } diff --git a/tests/includes/legacy/tests-post-types.php b/tests/includes/legacy/tests-post-types.php index d584ab0e6f..044db89e99 100644 --- a/tests/includes/legacy/tests-post-types.php +++ b/tests/includes/legacy/tests-post-types.php @@ -29,8 +29,8 @@ public function test_give_post_type_labels() { $this->assertEquals( 'Donation Forms', $wp_post_types['give_forms']->labels->name ); $this->assertEquals( 'Form', $wp_post_types['give_forms']->labels->singular_name ); $this->assertEquals( 'Add Form', $wp_post_types['give_forms']->labels->add_new ); - $this->assertEquals( 'Add New Donation Form', $wp_post_types['give_forms']->labels->add_new_item ); - $this->assertEquals( 'Edit Donation Form', $wp_post_types['give_forms']->labels->edit_item ); + $this->assertEquals('Add New Campaign Form', $wp_post_types['give_forms']->labels->add_new_item); + $this->assertEquals('Edit Campaign Form', $wp_post_types['give_forms']->labels->edit_item); $this->assertEquals( 'New Form', $wp_post_types['give_forms']->labels->new_item ); $this->assertEquals( 'All Forms', $wp_post_types['give_forms']->labels->all_items ); $this->assertEquals( 'View Form', $wp_post_types['give_forms']->labels->view_item );