Skip to content

Commit

Permalink
feature: specify which goal types are currency
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonTheAdams committed Oct 10, 2023
1 parent 6764bcf commit 5e8217d
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 @@ -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,
];
}

Expand All @@ -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,
Expand All @@ -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,
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
@@ -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,
Expand Down Expand Up @@ -69,12 +70,21 @@ const DonationGoalSettings = () => {
/>
</PanelRow>
<PanelRow>
<CurrencyControl
label={__('Goal Amount', 'give')}
min={0}
value={goalAmount}
onValueChange={debounce((goalAmount) => dispatch(setFormSettings({goalAmount})), 500)}
/>
{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 5e8217d

Please sign in to comment.