Skip to content

Commit

Permalink
Feature: Use currency control for goal amount (#7022)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Waldstein <[email protected]>
  • Loading branch information
JasonTheAdams and jonwaldstein authored Oct 25, 2023
1 parent 33cffa1 commit 3e9a81f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/FormBuilder/ViewModels/FormBuilderViewModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ public function isRecurringEnabled(): bool
/**
* @since 3.0.0
*/
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,
];
}

Expand All @@ -105,7 +111,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,
Expand All @@ -124,7 +131,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type GoalTypeOption = {
value: string;
label: string;
description: string;
isCurrency: boolean;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '@wordpress/components';
import debounce from 'lodash.debounce';
import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData';
import {CurrencyControl} from '@givewp/form-builder/components/CurrencyControl';

const {goalTypeOptions} = getFormBuilderWindowData();

Expand Down Expand Up @@ -69,12 +70,21 @@ const DonationGoalSettings = () => {
/>
</PanelRow>
<PanelRow>
<NumberControl
label={__('Goal Amount', 'give')}
min={0}
value={goalAmount}
onChange={debounce((goalAmount) => dispatch(setFormSettings({goalAmount})), 100)}
/>
{selectedGoalType.isCurrency ? (
<CurrencyControl
label={__('Goal Amount', 'give')}
min={0}
value={goalAmount}
onValueChange={debounce((goalAmount) => dispatch(setFormSettings({goalAmount})), 500)}
/>
) : (
<NumberControl
label={__('Goal Amount', 'give')}
min={0}
value={goalAmount}
onChange={(goalAmount) => dispatch(setFormSettings({goalAmount}))}
/>
)}
</PanelRow>
</>
)}
Expand Down

0 comments on commit 3e9a81f

Please sign in to comment.