';
foreach ($groups as $slug => $group) :
diff --git a/includes/admin/settings/class-settings-general.php b/includes/admin/settings/class-settings-general.php
index 6990a498d6..f8ea838453 100644
--- a/includes/admin/settings/class-settings-general.php
+++ b/includes/admin/settings/class-settings-general.php
@@ -667,7 +667,7 @@ public function _render_give_currency_preview($field, $value)
+ echo wp_kses_post($field['name']); ?>
>
|
|
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 (
+
+
+ {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 (
+
+ <>
+
+
+
+
+
+ >
+
+ );
+}
+
+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 ? (
) : (
<>
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 (
- |