Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Feature: add "default level" option to the Donation amount and levels block #217

Merged
merged 28 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2d57358
feature: add default level option
glaubersilva Jul 17, 2023
081caa5
feature: add OptionsPanel component
glaubersilva Aug 1, 2023
a50a4a8
feature: add levelOptions attribute
glaubersilva Aug 1, 2023
2eeb86d
feature: load options
glaubersilva Aug 1, 2023
4747914
fix: apply style in the proper way
glaubersilva Aug 2, 2023
614098f
feature: update default level when options change
glaubersilva Aug 2, 2023
59504c4
feature: add currency option
glaubersilva Aug 2, 2023
1a46a6e
feature: add defaultValue to blocks.json
glaubersilva Aug 2, 2023
caf089f
refactor: update levels when new options are added
glaubersilva Aug 2, 2023
3ce0d1b
fix: prevent undefined levels
glaubersilva Aug 2, 2023
678af5d
refactor: remove levelOptions prop
glaubersilva Aug 3, 2023
0706cd4
refactor: remove unnecessary conditions
glaubersilva Aug 3, 2023
a27cff3
refactor: clear value and label before delete
glaubersilva Aug 3, 2023
521f74c
refactor: change CSS class names
glaubersilva Aug 3, 2023
c926cdd
chore: remove unused module CSS file
glaubersilva Aug 3, 2023
76c9b0d
fix: adjust currency margin bottom
glaubersilva Aug 3, 2023
7ef9e5d
refactor: remove select control for defaultLevel
glaubersilva Aug 3, 2023
73a543a
refactor: set the first level as default if none is selected
glaubersilva Aug 3, 2023
dd618b2
feature: allow reorder the levels
glaubersilva Aug 3, 2023
fd2f386
refactor: add fallback to defaultValue
glaubersilva Aug 3, 2023
3425a2c
refactor: add type to parameter from setNewLevels method
glaubersilva Aug 4, 2023
05e7078
chore: remove commented code
glaubersilva Aug 4, 2023
5e84a46
Merge branch 'develop' into feature/default-amount
Aug 8, 2023
9fde0d7
refactor: prevent re-render with useEffect
glaubersilva Aug 10, 2023
d890176
refactor: remove useEffect
glaubersilva Aug 10, 2023
cb060aa
refactor: parse number to defaultValue
glaubersilva Aug 10, 2023
0697745
refactor: set new level value automatically
glaubersilva Aug 10, 2023
4130888
fix: prevent error when there is no levels
glaubersilva Aug 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount
->fixedAmountValue($block->getAttribute('setPrice'))
->defaultValue(
$block->getAttribute('priceOption') === 'set' ?
$block->getAttribute('setPrice') : 50
$block->getAttribute('setPrice') : $block->getAttribute('defaultLevel')
)
->rules(...$amountRules);

Expand Down Expand Up @@ -137,7 +137,7 @@ protected function getRecurringAmountPeriodField(BlockModel $block): Field
$options = $this->mergePeriodOptionsWithOneTime(
array_map(static function ($option) {
$subscriptionPeriod = new SubscriptionPeriod($option);

return new Option($subscriptionPeriod->getValue(), $subscriptionPeriod->label(0));
}, $recurringBillingPeriodOptions)
);
Expand Down Expand Up @@ -168,4 +168,4 @@ protected function mergePeriodOptionsWithOneTime(array $options): array
new Option('one-time', __('One Time', 'give'))
], $options);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Edit = ({attributes, setAttributes}) => {
const {
label = __('Donation Amount', 'give'),
levels,
defaultLevel,
priceOption,
setPrice,
customAmount,
Expand All @@ -37,7 +38,7 @@ const Edit = ({attributes, setAttributes}) => {
const isFixedAmount = priceOption === 'set';
const isRecurringAdmin = isRecurring && 'admin' === recurringDonationChoice;
const isRecurringDonor = isRecurring && 'donor' === recurringDonationChoice;

const amountFormatted = formatCurrencyAmount(setPrice.toString());

const DonationLevels = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {__, sprintf} from '@wordpress/i18n';
import {InspectorControls} from '@wordpress/block-editor';
import DeleteButton from './delete-button';
import AddButton from './add-button';
import {CurrencyControl} from '@givewp/form-builder/common/currency';
import {CurrencyControl, formatCurrencyAmount} from '@givewp/form-builder/common/currency';
import periodLookup from '../period-lookup';
import RecurringDonationsPromo from '@givewp/form-builder/promos/recurring-donations';
import {getFormBuilderData} from '@givewp/form-builder/common/getWindowData';
Expand All @@ -28,6 +28,7 @@ const Inspector = ({attributes, setAttributes}) => {
const {
label = __('Donation Amount', 'give'),
levels,
defaultLevel,
priceOption,
setPrice,
customAmount,
Expand Down Expand Up @@ -102,6 +103,17 @@ const Inspector = ({attributes, setAttributes}) => {
: __('The donation amount is fixed to the following amount:', 'give')
}
/>
{priceOption === 'multi' && (
<SelectControl
label={__('Default Level', 'give')}
options={levels.map((level, index) => ({
label: formatCurrencyAmount(level),
value: level,
}))}
value={defaultLevel}
onChange={(defaultLevel) => setAttributes({defaultLevel})}
/>
)}
{priceOption === 'set' && (
<CurrencyControl
label={__('Set Donation', 'give')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
setPrice,
priceOption,
levels,
defaultLevel,
} = getDefaultBlockAttributes('givewp/donation-amount');

const settings: FieldBlock['settings'] = {
Expand All @@ -38,6 +39,10 @@ const settings: FieldBlock['settings'] = {
type: 'array',
default: levels,
},
defaultLevel: {
type: 'number',
default: defaultLevel,
},
priceOption: {
type: 'string',
default: priceOption,
Expand Down