From 5e8217dd8cd75030e4fd9fc01cf3a496be44d341 Mon Sep 17 00:00:00 2001 From: Jason Adams Date: Tue, 10 Oct 2023 16:51:33 -0600 Subject: [PATCH] feature: specify which goal types are currency --- .../ViewModels/FormBuilderViewModel.php | 14 +++++++++--- .../form-builder/src/common/getWindowData.ts | 1 + .../src/settings/donation-goal/index.tsx | 22 ++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/FormBuilder/ViewModels/FormBuilderViewModel.php b/src/FormBuilder/ViewModels/FormBuilderViewModel.php index b0ee216804..1e48c5a927 100644 --- a/src/FormBuilder/ViewModels/FormBuilderViewModel.php +++ b/src/FormBuilder/ViewModels/FormBuilderViewModel.php @@ -86,12 +86,18 @@ public function isRecurringEnabled(): bool /** * @since 3.0.0-rc.6 */ - public function getGoalTypeOption(string $value, string $label, string $description): array + public function getGoalTypeOption( + string $value, + string $label, + string $description, + bool $isCurrency = false + ): array { return [ 'value' => $value, 'label' => $label, 'description' => $description, + 'isCurrency' => $isCurrency, ]; } @@ -104,7 +110,8 @@ public function getGoalTypeOptions(): array $this->getGoalTypeOption( GoalType::AMOUNT, __('Amount Raised', 'give'), - __('The total amount raised for the form', 'give') + __('The total amount raised for the form', 'give'), + true ), $this->getGoalTypeOption( GoalType::DONATIONS, @@ -123,7 +130,8 @@ public function getGoalTypeOptions(): array $this->getGoalTypeOption( GoalType::AMOUNT_FROM_SUBSCRIPTIONS, __('Subscription Amount Raised', 'give'), - __('The total amount raised for the form through subscriptions', 'give') + __('The total amount raised for the form through subscriptions', 'give'), + true ), $this->getGoalTypeOption( GoalType::SUBSCRIPTIONS, diff --git a/src/FormBuilder/resources/js/form-builder/src/common/getWindowData.ts b/src/FormBuilder/resources/js/form-builder/src/common/getWindowData.ts index 557ff8a253..d15ace1536 100644 --- a/src/FormBuilder/resources/js/form-builder/src/common/getWindowData.ts +++ b/src/FormBuilder/resources/js/form-builder/src/common/getWindowData.ts @@ -14,6 +14,7 @@ type GoalTypeOption = { value: string; label: string; description: string; + isCurrency: boolean; }; /** diff --git a/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx b/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx index 20405acf79..c31b5b18af 100644 --- a/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx @@ -1,6 +1,7 @@ import {setFormSettings, useFormState, useFormStateDispatch} from '@givewp/form-builder/stores/form-state'; import {__} from '@wordpress/i18n'; import { + __experimentalNumberControl as NumberControl, PanelBody, PanelRow, SelectControl, @@ -69,12 +70,21 @@ const DonationGoalSettings = () => { /> - dispatch(setFormSettings({goalAmount})), 500)} - /> + {selectedGoalType.isCurrency ? ( + dispatch(setFormSettings({goalAmount})), 500)} + /> + ) : ( + dispatch(setFormSettings({goalAmount}))} + /> + )} )}