diff --git a/src/DonationForms/Actions/ConvertDonationAmountBlockToFieldsApi.php b/src/DonationForms/Actions/ConvertDonationAmountBlockToFieldsApi.php index c59c5b7f5d..6e2737e3b2 100644 --- a/src/DonationForms/Actions/ConvertDonationAmountBlockToFieldsApi.php +++ b/src/DonationForms/Actions/ConvertDonationAmountBlockToFieldsApi.php @@ -10,7 +10,7 @@ use Give\DonationForms\Rules\SubscriptionInstallmentsRule; use Give\DonationForms\Rules\SubscriptionPeriodRule; use Give\Donations\ValueObjects\DonationType; -use Give\Framework\Blocks\BlockModel; +use Give\FormBuilder\BlockModels\DonationAmountBlockModel; use Give\Framework\FieldsAPI\Amount; use Give\Framework\FieldsAPI\DonationAmount; use Give\Framework\FieldsAPI\Exceptions\EmptyNameException; @@ -32,19 +32,19 @@ class ConvertDonationAmountBlockToFieldsApi * @throws EmptyNameException * @throws NameCollisionException */ - public function __invoke(BlockModel $block, string $currency): DonationAmount + public function __invoke(DonationAmountBlockModel $block, string $currency): DonationAmount { $amountField = DonationAmount::make('donationAmount')->tap(function (Group $group) use ($block, $currency) { $amountRules = ['required', 'numeric']; - if (!$block->getAttribute('customAmount') && - $block->getAttribute('priceOption') === 'set') { - $size = $block->getAttribute('setPrice'); + if (!$block->isCustomAmountEnabled() && + $block->getPriceOption() === 'set') { + $size = $block->getSetPrice(); $amountRules[] = new Size($size); } - if ($block->getAttribute('customAmount')) { + if ($block->isCustomAmountEnabled()) { if ($block->hasAttribute('customAmountMin')) { $amountRules[] = new Min($block->getAttribute('customAmountMin')); } @@ -56,16 +56,16 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount /** @var Amount $amountNode */ $amountNode = $group->getNodeByName('amount'); - $defaultLevel = (float)$block->getAttribute('defaultLevel') > 0 ? (float)$block->getAttribute('defaultLevel') : 10; + $defaultLevel = (float)$block->getDefaultLevel() > 0 ? (float)$block->getDefaultLevel() : 10; $amountNode - ->label($block->getAttribute('label')) - ->levels(...array_map('absint', $block->getAttribute('levels'))) - ->allowLevels($block->getAttribute('priceOption') === 'multi') - ->allowCustomAmount($block->getAttribute('customAmount')) - ->fixedAmountValue($block->getAttribute('setPrice')) + ->label($block->getLabel()) + ->levels(...$block->getLevels()) + ->allowLevels($block->getPriceOption() === 'multi') + ->allowCustomAmount($block->isCustomAmountEnabled()) + ->fixedAmountValue($block->getSetPrice()) ->defaultValue( - $block->getAttribute('priceOption') === 'set' ? - $block->getAttribute('setPrice') : $defaultLevel + $block->getPriceOption() === 'set' ? + $block->getSetPrice() : $defaultLevel ) ->rules(...$amountRules); @@ -76,7 +76,7 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount ->rules('required', 'currency'); }); - if (!$block->getAttribute('recurringEnabled')) { + if (!$block->isRecurringEnabled()) { $donationType = Hidden::make('donationType') ->defaultValue(DonationType::SINGLE()->getValue()) ->rules(new DonationTypeRule()); @@ -92,20 +92,17 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount ->defaultValue($donationTypeDefault) ->rules(new DonationTypeRule()); - $billingInterval = (int)$block->getAttribute('recurringBillingInterval'); - $lengthOfTime = (int)$block->getAttribute('recurringLengthOfTime'); - $subscriptionFrequency = Hidden::make('subscriptionFrequency') - ->defaultValue($billingInterval) + ->defaultValue($block->getRecurringBillingInterval()) ->rules(new SubscriptionFrequencyRule()); $subscriptionInstallments = Hidden::make('subscriptionInstallments') - ->defaultValue($lengthOfTime) + ->defaultValue($block->getRecurringLengthOfTime()) ->rules(new SubscriptionInstallmentsRule()); $amountField ->enableSubscriptions() - ->subscriptionDetailsAreFixed($block->getAttribute('recurringDonationChoice') === 'admin') + ->subscriptionDetailsAreFixed($block->isRecurringFixed()) ->donationType($donationType) ->subscriptionPeriod($subscriptionPeriod) ->subscriptionFrequency($subscriptionFrequency) @@ -120,32 +117,40 @@ public function __invoke(BlockModel $block, string $currency): DonationAmount * * @throws EmptyNameException */ - protected function getRecurringAmountPeriodField(BlockModel $block): Field + protected function getRecurringAmountPeriodField(DonationAmountBlockModel $block): Field { - $donationChoice = $block->getAttribute('recurringDonationChoice'); + $recurringBillingPeriodOptions = $block->getRecurringBillingPeriodOptions(); + + // if recurring is fixed - fields are all hidden + if ($block->isRecurringFixed()) { + $fixedBillingPeriod = $recurringBillingPeriodOptions[0]; - // if admin - fields are all hidden - if ($donationChoice === 'admin') { - $recurringBillingPeriod = new SubscriptionPeriod($block->getAttribute('recurringBillingPeriod')); + $subscriptionPeriodDefaultValue = SubscriptionPeriod::isValid( + $fixedBillingPeriod + ) ? (new SubscriptionPeriod($fixedBillingPeriod))->getValue() : SubscriptionPeriod::MONTH()->getValue(); return Hidden::make('subscriptionPeriod') - ->defaultValue($recurringBillingPeriod->getValue()) + ->defaultValue($subscriptionPeriodDefaultValue) ->rules(new SubscriptionPeriodRule()); } - $recurringBillingPeriodOptions = $block->getAttribute('recurringBillingPeriodOptions'); + if ($block->isRecurringEnableOneTimeDonations()) { + $recurringBillingPeriodOptions = array_merge(['one-time'], $recurringBillingPeriodOptions); + } - $options = $this->mergePeriodOptionsWithOneTime( - array_map(static function ($option) { + $options = array_map(static function ($option) { + if (SubscriptionPeriod::isValid($option)) { $subscriptionPeriod = new SubscriptionPeriod($option); return new Option($subscriptionPeriod->getValue(), $subscriptionPeriod->label(0)); - }, $recurringBillingPeriodOptions) - ); + } + + return new Option($option, $option === 'one-time' ? __('One Time', 'give') : ucfirst($option)); + }, $recurringBillingPeriodOptions); - $recurringOptInDefault = $block->getAttribute('recurringOptInDefaultBillingPeriod'); + $recurringOptInDefault = $block->getRecurringOptInDefaultBillingPeriod(); - if (!empty($recurringOptInDefault) && $recurringOptInDefault !== 'one-time') { + if (SubscriptionPeriod::isValid($recurringOptInDefault)) { $subscriptionPeriod = new SubscriptionPeriod($recurringOptInDefault); $defaultValue = $subscriptionPeriod->getValue(); @@ -159,14 +164,4 @@ protected function getRecurringAmountPeriodField(BlockModel $block): Field ->options(...$options) ->rules(new SubscriptionPeriodRule()); } - - /** - * @since 3.0.0 - */ - protected function mergePeriodOptionsWithOneTime(array $options): array - { - return array_merge([ - new Option('one-time', __('One Time', 'give')) - ], $options); - } } diff --git a/src/DonationForms/Actions/ConvertDonationFormBlocksToFieldsApi.php b/src/DonationForms/Actions/ConvertDonationFormBlocksToFieldsApi.php index 1f375301fc..0aef46a64a 100644 --- a/src/DonationForms/Actions/ConvertDonationFormBlocksToFieldsApi.php +++ b/src/DonationForms/Actions/ConvertDonationFormBlocksToFieldsApi.php @@ -8,6 +8,7 @@ use Give\DonationForms\Rules\BillingAddressStateRule; use Give\DonationForms\Rules\BillingAddressZipRule; use Give\DonationForms\Rules\GatewayRule; +use Give\FormBuilder\BlockModels\DonationAmountBlockModel; use Give\Framework\Blocks\BlockCollection; use Give\Framework\Blocks\BlockModel; use Give\Framework\FieldsAPI\Authentication; @@ -167,13 +168,13 @@ protected function createNodeFromBlockWithUniqueAttributes(BlockModel $block, in }); case "givewp/payment-gateways": - $defaultGatewayId = give( DonationFormRepository::class )->getDefaultEnabledGatewayId( $this->formId ); + $defaultGatewayId = give(DonationFormRepository::class)->getDefaultEnabledGatewayId($this->formId); - return PaymentGateways::make( 'gatewayId' ) - ->testMode( give_is_test_mode() ) - ->rules( new GatewayRule() ) - ->required() - ->defaultValue( $defaultGatewayId ); + return PaymentGateways::make('gatewayId') + ->testMode(give_is_test_mode()) + ->rules(new GatewayRule()) + ->required() + ->defaultValue($defaultGatewayId); case "givewp/donation-summary": return DonationSummary::make('donation-summary'); @@ -206,7 +207,7 @@ protected function createNodeFromBlockWithUniqueAttributes(BlockModel $block, in ->loginConfirmation($block->getAttribute('loginConfirmation')) ->tapNode('login', function ($field) use ($block) { if ($block->getAttribute('required')) { - if ( ! is_user_logged_in()) { + if (!is_user_logged_in()) { $field->required(); } @@ -350,7 +351,8 @@ protected function createNodeFromBillingAddressBlock(BlockModel $block): Node */ protected function createNodeFromAmountBlock(BlockModel $block): Node { - return (new ConvertDonationAmountBlockToFieldsApi())($block, $this->currency); + $donationAmountBlockModel = new DonationAmountBlockModel($block); + return (new ConvertDonationAmountBlockToFieldsApi())($donationAmountBlockModel, $this->currency); } /** diff --git a/src/FormBuilder/BlockModels/DonationAmountBlockModel.php b/src/FormBuilder/BlockModels/DonationAmountBlockModel.php new file mode 100644 index 0000000000..0d896ade6b --- /dev/null +++ b/src/FormBuilder/BlockModels/DonationAmountBlockModel.php @@ -0,0 +1,146 @@ +block = $block; + } + + /** + * @unreleased + */ + public function getAttribute($name) + { + return $this->block->getAttribute($name); + } + + /** + * @unreleased + */ + public function hasAttribute($name): bool + { + return $this->block->hasAttribute($name); + } + + /** + * @unreleased + */ + public function getLabel(): string + { + return $this->block->getAttribute('label'); + } + + /** + * @unreleased + */ + public function getLevels(): array + { + return array_map('absint', $this->block->getAttribute('levels')); + } + + /** + * @unreleased + * + * @return string|null + */ + public function getDefaultLevel() + { + return $this->block->getAttribute('defaultLevel'); + } + + /** + * @return bool + */ + public function isRecurringFixed(): bool + { + return count($this->block->getAttribute('recurringBillingPeriodOptions')) === 1 && $this->block->getAttribute('recurringEnableOneTimeDonations') === false; + } + + /** + * @unreleased + */ + public function getRecurringBillingInterval(): int + { + return (int)$this->block->getAttribute('recurringBillingInterval'); + } + + /** + * @unreleased + */ + public function getRecurringLengthOfTime(): int + { + return (int)$this->block->getAttribute('recurringLengthOfTime'); + } + + /** + * @unreleased + */ + public function getRecurringOptInDefaultBillingPeriod(): string + { + return $this->block->getAttribute('recurringOptInDefaultBillingPeriod'); + } + + /** + * @unreleased + */ + public function getRecurringBillingPeriodOptions(): array + { + return $this->block->getAttribute('recurringBillingPeriodOptions'); + } + + /** + * @unreleased + */ + public function isRecurringEnableOneTimeDonations(): bool + { + return $this->block->getAttribute('recurringEnableOneTimeDonations') === true; + } + + /** + * @unreleased + */ + public function isRecurringEnabled(): bool + { + return $this->block->getAttribute('recurringEnabled') === true; + } + + /** + * @unreleased + */ + public function isCustomAmountEnabled(): bool + { + return $this->block->getAttribute('customAmount') === true; + } + + /** + * @unreleased + */ + public function getPriceOption(): string + { + return $this->block->getAttribute('priceOption'); + } + + /** + * @unreleased + */ + public function getSetPrice(): int + { + return $this->block->getAttribute('setPrice'); + } +} \ No newline at end of file diff --git a/src/FormBuilder/resources/js/form-builder/src/blocks.json b/src/FormBuilder/resources/js/form-builder/src/blocks.json index ffb112d00a..2f2e0980bb 100644 --- a/src/FormBuilder/resources/js/form-builder/src/blocks.json +++ b/src/FormBuilder/resources/js/form-builder/src/blocks.json @@ -25,17 +25,16 @@ "defaultLevel": "10", "priceOption": "multi", "setPrice": 25, - "customAmount": "true", + "customAmount": true, "customAmountMin": 1, "recurringBillingPeriodOptions": [ "month" ], - "recurringBillingPeriod": "month", "recurringBillingInterval": 1, - "recurringDonationChoice": "admin", "recurringEnabled": false, "recurringLengthOfTime": "0", "recurringOptInDefaultBillingPeriod": "month", + "recurringEnableOneTimeDonations": true, "lock": { "remove": true } diff --git a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/Edit.tsx b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/Edit.tsx index 6d4130e7b0..3d87e04eec 100644 --- a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/Edit.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/Edit.tsx @@ -8,8 +8,46 @@ import {CurrencyControl, formatCurrencyAmount} from '../../../common/currency'; import {BaseControl, RadioControl} from '@wordpress/components'; import {OneTimeAmountMessage, RecurringAmountMessage} from '@givewp/forms/shared/AmountMessages'; import Notice from './notice'; - import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData'; +import {DonationAmountAttributes} from '@givewp/form-builder/blocks/fields/amount/types'; + +const DonationLevels = ({levels}: {levels: DonationAmountAttributes['levels']}) => ( + + {levels.map((level: string, index: number) => { + const levelAmount = formatCurrencyAmount(level); + + return {levelAmount}; + })} + +); + +const CustomAmount = ({amount}: {amount: DonationAmountAttributes['setPrice']}) => ( + +); + +const FixedPriceMessage = ({amount}: {amount: string}) => ( + + + +); + +const BillingPeriodControl = ({options, defaultSelected}: {options: string[], defaultSelected?: string}) => { + return ( + { + return { + label: 'one-time' === option ? __('One Time', 'give') : periodLookup[option].adjective, + value: option, + }; + })} + onChange={(value) => null} + /> + ); +}; const Edit = ({attributes, setAttributes}) => { const { @@ -19,13 +57,12 @@ const Edit = ({attributes, setAttributes}) => { setPrice, customAmount, recurringEnabled, - recurringDonationChoice, recurringBillingInterval, - recurringBillingPeriod, recurringBillingPeriodOptions, recurringLengthOfTime, recurringOptInDefaultBillingPeriod, - } = attributes; + recurringEnableOneTimeDonations, + } = attributes as DonationAmountAttributes; const {gateways} = getFormBuilderWindowData(); @@ -33,86 +70,50 @@ const Edit = ({attributes, setAttributes}) => { const isRecurring = isRecurringSupported && recurringEnabled; const isMultiLevel = priceOption === 'multi'; const isFixedAmount = priceOption === 'set'; - const isRecurringAdmin = isRecurring && 'admin' === recurringDonationChoice; - const isRecurringDonor = isRecurring && 'donor' === recurringDonationChoice; - - const amountFormatted = formatCurrencyAmount(setPrice.toString()); - - const DonationLevels = () => ( - - {levels.map((level: string, index: number) => { - const levelAmount = formatCurrencyAmount(level); - - return {levelAmount}; - })} - - ); - - const CustomAmount = () => ( - - ); - - const FixedPriceMessage = () => ( - - - - ); - - const FixedRecurringMessage = () => { - const installments = parseInt(recurringLengthOfTime); - const frequency = parseInt(recurringBillingInterval); - - return ( - - - - ); - }; - - const BillingPeriodControl = ({options}) => { - return ( - { - return { - label: 'one-time' === option ? __('One Time', 'give') : periodLookup[option].adjective, - value: option, - }; - })} - onChange={(value) => null} - /> - ); - }; - + const isRecurringDonor = + isRecurring && (recurringBillingPeriodOptions.length > 1 || recurringEnableOneTimeDonations); + const isRecurringAdmin = isRecurring && !isRecurringDonor; const displayFixedMessage = isFixedAmount && !customAmount; - const displayFixedRecurringMessage = isRecurring && - (displayFixedMessage || isRecurringAdmin || recurringLengthOfTime > 0 || recurringBillingInterval > 1); - + (displayFixedMessage || + isRecurringAdmin || + Number(recurringLengthOfTime) > 0 || + Number(recurringBillingInterval) > 1); const displayFixedPriceMessage = displayFixedMessage && !displayFixedRecurringMessage; + const amountFormatted = formatCurrencyAmount(setPrice.toString()); return (
- {isRecurringDonor && } - - {isMultiLevel && } - - {customAmount && } - - {displayFixedRecurringMessage && } - - {displayFixedPriceMessage && } + {isRecurringDonor && ( + + )} + + {isMultiLevel && } + + {customAmount && } + + {displayFixedRecurringMessage && ( + + + + )} + + {displayFixedPriceMessage && }
diff --git a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/inspector/index.tsx b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/inspector/index.tsx index 8031c748dd..2a41b1a942 100644 --- a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/inspector/index.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/inspector/index.tsx @@ -16,6 +16,9 @@ import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowDat import {useCallback, useState} from '@wordpress/element'; import Options from '@givewp/form-builder/components/OptionsPanel'; import {OptionProps} from '@givewp/form-builder/components/OptionsPanel/types'; +import {useEffect} from 'react'; +import {DonationAmountAttributes} from '@givewp/form-builder/blocks/fields/amount/types'; +import {subscriptionPeriod} from '@givewp/forms/registrars/templates/groups/DonationAmount/subscriptionPeriod'; const compareBillingPeriods = (val1: string, val2: string): number => { const index1 = Object.keys(periodLookup).indexOf(val1); @@ -24,6 +27,35 @@ const compareBillingPeriods = (val1: string, val2: string): number => { return index1 - index2; }; +type billingPeriodControlOption = { + label: string; + value: subscriptionPeriod; +}; + +const billingPeriodControlOptions: billingPeriodControlOption[] = [ + {label: __('Daily', 'give'), value: 'day'}, + {label: __('Weekly', 'give'), value: 'week'}, + {label: __('Monthly', 'give'), value: 'month'}, + {label: __('Quarterly', 'give'), value: 'quarter'}, + {label: __('Yearly', 'give'), value: 'year'}, +]; + +const billingIntervalControlOptions = [ + {label: __('Every', 'give'), value: '1'}, + {label: __('Every 2nd', 'give'), value: '2'}, + {label: __('Every 3rd', 'give'), value: '3'}, + {label: __('Every 4th', 'give'), value: '4'}, + {label: __('Every 5th', 'give'), value: '5'}, + {label: __('Every 6th', 'give'), value: '6'}, +]; + +const numberOfDonationsControlOptions = [{label: __('Ongoing', 'give'), value: '0'}].concat( + [...Array(24 + 1).keys()].slice(2).map((value) => ({ + label: sprintf(__('%d donations', 'give'), value), + value: value.toString(), + })) +); + const Inspector = ({attributes, setAttributes}) => { const { label = __('Donation Amount', 'give'), @@ -35,13 +67,23 @@ const Inspector = ({attributes, setAttributes}) => { customAmountMin, customAmountMax, recurringEnabled, - recurringDonationChoice, recurringBillingInterval, - recurringBillingPeriod, recurringBillingPeriodOptions, recurringLengthOfTime, recurringOptInDefaultBillingPeriod, - } = attributes; + recurringEnableOneTimeDonations = true, + } = attributes as DonationAmountAttributes; + + const shouldShowDefaultBillingPeriod = recurringBillingPeriodOptions.length > 1 || recurringEnableOneTimeDonations; + + useEffect(() => { + // update recurringOptInDefaultBillingPeriod based on the available options + if (recurringOptInDefaultBillingPeriod === 'one-time' && !recurringEnableOneTimeDonations) { + setAttributes({recurringOptInDefaultBillingPeriod: recurringBillingPeriodOptions[0]}); + } else if (!['one-time'].concat(recurringBillingPeriodOptions).includes(recurringOptInDefaultBillingPeriod)) { + setAttributes({recurringOptInDefaultBillingPeriod: recurringBillingPeriodOptions[0]}); + } + }, [recurringBillingPeriodOptions, recurringEnableOneTimeDonations]); const addBillingPeriodOption = useCallback( (value) => { @@ -94,6 +136,7 @@ const Inspector = ({attributes, setAttributes}) => { } const checkedLevel = options.filter((option) => option.checked); + if (!!checkedLevel && checkedLevel.length === 1) { setAttributes({defaultLevel: checkedLevel[0].value}); } else if (options.length > 0) { @@ -105,6 +148,22 @@ const Inspector = ({attributes, setAttributes}) => { setAttributes({levels: newLevels}); }; + const getDefaultBillingPeriodOptions = useCallback( + (options) => { + if (recurringEnableOneTimeDonations) { + options = ['one-time'].concat(options); + } + + return options.map((value) => ({ + label: periodLookup[value].singular + .toLowerCase() + .replace(/\w/, (firstLetter) => firstLetter.toUpperCase()), + value: value, + })); + }, + [recurringBillingPeriodOptions, recurringEnableOneTimeDonations] + ); + return ( @@ -166,6 +225,7 @@ const Inspector = ({attributes, setAttributes}) => { )} + {priceOption === 'multi' && ( { /> )} + {!isRecurringSupported && (recurringAddonData.isInstalled ? ( @@ -209,62 +270,31 @@ const Inspector = ({attributes, setAttributes}) => { ))} {isRecurringSupported && ( - - setAttributes({recurringEnabled: !recurringEnabled})} - /> - - )} - {!!isRecurring && ( - - setAttributes({recurringDonationChoice})} - /> - - )} - {!!isRecurring && ( - - setAttributes({recurringBillingInterval})} - /> - + <> + + setAttributes({recurringEnabled: !recurringEnabled})} + /> + + )} {!!isRecurring && ( - - {'admin' === recurringDonationChoice && ( - setAttributes({recurringBillingPeriod})} + <> + + { + setAttributes({ + recurringEnableOneTimeDonations: !recurringEnableOneTimeDonations, + }); + }} /> - )} - {'donor' === recurringDonationChoice && ( - + + +
{ gridTemplateColumns: '1fr 1fr', }} > - {[ - {label: __('Day', 'give'), value: 'day'}, - {label: __('Week', 'give'), value: 'week'}, - {label: __('Month', 'give'), value: 'month'}, - {label: __('Quarter', 'give'), value: 'quarter'}, - {label: __('Year', 'give'), value: 'year'}, - ].map((option) => ( + {billingPeriodControlOptions.map((option) => ( { recurringBillingPeriodOptions.length === 1 && recurringBillingPeriodOptions.includes(option.value) // This is the last checked option. } - //@ts-ignore __nextHasNoMarginBottom={true} /> ))}
+
+ {shouldShowDefaultBillingPeriod && ( + + + setAttributes({recurringOptInDefaultBillingPeriod}) + } + /> + )} -
- )} - {isRecurring && 'donor' === recurringDonationChoice && ( - - ({ - label: periodLookup[value].singular - .toLowerCase() - .replace(/\w/, (firstLetter) => firstLetter.toUpperCase()), - value: value, - }))} - onChange={(recurringOptInDefaultBillingPeriod) => - setAttributes({recurringOptInDefaultBillingPeriod}) - } - /> - - )} - {isRecurring && ( - - ({ - label: sprintf(__('%d payments', 'give'), value), - value: value, - })) - )} - value={recurringLengthOfTime} - onChange={(recurringLengthOfTime) => setAttributes({recurringLengthOfTime})} - /> - + + + setAttributes({recurringBillingInterval}) + } + /> + + + setAttributes({recurringLengthOfTime})} + /> + + )}
diff --git a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/settings.tsx b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/settings.tsx index 079db3fdce..d3d998f359 100644 --- a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/settings.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/settings.tsx @@ -8,12 +8,11 @@ import getDefaultBlockAttributes from '@givewp/form-builder/common/getDefaultBlo import {Path, SVG} from '@wordpress/components'; const { - recurringDonationChoice, recurringBillingInterval, - recurringBillingPeriod, recurringBillingPeriodOptions, recurringLengthOfTime, recurringEnabled, + recurringEnableOneTimeDonations, customAmountMin, customAmount, setPrice, @@ -67,18 +66,10 @@ const settings: FieldBlock['settings'] = { type: 'boolean', default: recurringEnabled, }, - recurringDonationChoice: { - type: 'string', - default: recurringDonationChoice, - }, recurringBillingInterval: { type: 'number', default: recurringBillingInterval, }, - recurringBillingPeriod: { - type: 'string', - default: recurringBillingPeriod, - }, recurringBillingPeriodOptions: { type: 'array', default: recurringBillingPeriodOptions, @@ -87,6 +78,10 @@ const settings: FieldBlock['settings'] = { type: 'string', default: recurringLengthOfTime, // ongoing }, + recurringEnableOneTimeDonations: { + type: 'boolean', + default: recurringEnableOneTimeDonations, + }, }, edit: Edit, icon: () => ( diff --git a/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/types.ts b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/types.ts new file mode 100644 index 0000000000..b89918574b --- /dev/null +++ b/src/FormBuilder/resources/js/form-builder/src/blocks/fields/amount/types.ts @@ -0,0 +1,18 @@ +import type {subscriptionPeriod} from "@givewp/forms/registrars/templates/groups/DonationAmount/subscriptionPeriod"; + +export interface DonationAmountAttributes { + label: string; + levels: string[]; + defaultLevel: string; + priceOption: string; + setPrice: number; + customAmount: boolean; + customAmountMin: number; + customAmountMax: number; + recurringEnabled: boolean; + recurringBillingInterval: string; + recurringBillingPeriodOptions: subscriptionPeriod[]; + recurringLengthOfTime: string; + recurringOptInDefaultBillingPeriod: subscriptionPeriod | 'one-time'; + recurringEnableOneTimeDonations: boolean +} \ No newline at end of file diff --git a/src/FormBuilder/resources/js/form-builder/src/styles/_components.scss b/src/FormBuilder/resources/js/form-builder/src/styles/_components.scss index f6a95fa4d5..b49a05b95d 100644 --- a/src/FormBuilder/resources/js/form-builder/src/styles/_components.scss +++ b/src/FormBuilder/resources/js/form-builder/src/styles/_components.scss @@ -208,12 +208,6 @@ This creates a consistent separator between the tabs and the rest of the sidebar border-color: black; } -.components-checkbox-control__label { - font-size: 1rem; - font-weight: 500; - color: #595959; -} - .givewp-options-header { display: flex; align-items: center; diff --git a/tests/Unit/DataTransferObjects/DonateFormRouteDataTest.php b/tests/Unit/DataTransferObjects/DonateFormRouteDataTest.php index 359d634042..becf5d5f5a 100644 --- a/tests/Unit/DataTransferObjects/DonateFormRouteDataTest.php +++ b/tests/Unit/DataTransferObjects/DonateFormRouteDataTest.php @@ -147,6 +147,7 @@ public function testValidatedShouldReturnValidatedDataWithSubscriptionData() "250", "500" ], + "defaultLevel": "100", "priceOption": "multi", "setPrice": "100", "customAmount": "true", diff --git a/tests/Unit/DonationForms/Actions/StoreBackwardsCompatibleFormMetaTest.php b/tests/Unit/DonationForms/Actions/StoreBackwardsCompatibleFormMetaTest.php index bdd66f64c8..562de4aa64 100644 --- a/tests/Unit/DonationForms/Actions/StoreBackwardsCompatibleFormMetaTest.php +++ b/tests/Unit/DonationForms/Actions/StoreBackwardsCompatibleFormMetaTest.php @@ -88,9 +88,8 @@ public function testRecurringMetaIsStoredOnUpdate() 'customAmount' => 'true', 'customAmountMin' => 1, 'recurringBillingPeriodOptions' => ['month'], - 'recurringBillingPeriod' => 'month', + 'recurringEnableOneTimeDonations' => false, 'recurringBillingInterval' => 1, - 'recurringDonationChoice' => 'admin', 'recurringEnabled' => true, 'recurringLengthOfTime' => '0', 'recurringOptInDefaultBillingPeriod' => 'month', @@ -138,9 +137,8 @@ public function testRecurringMetaIsStoredOnInsert() 'customAmount' => 'true', 'customAmountMin' => 1, 'recurringBillingPeriodOptions' => ['month'], - 'recurringBillingPeriod' => 'month', + 'recurringEnableOneTimeDonations' => false, 'recurringBillingInterval' => 1, - 'recurringDonationChoice' => 'admin', 'recurringEnabled' => true, 'recurringLengthOfTime' => '0', 'recurringOptInDefaultBillingPeriod' => 'month', diff --git a/tsconfig.json b/tsconfig.json index abd658df3f..09e043b1f6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -38,6 +38,9 @@ "@givewp/forms/app/*": [ "./src/DonationForms/resources/app/*" ], + "@givewp/forms/registrars/*": [ + "./src/DonationForms/resources/registrars/*" + ], "@givewp/forms/shared/*": [ "./src/DonationForms/resources/shared/*" ], diff --git a/wordpress-scripts-webpack.config.js b/wordpress-scripts-webpack.config.js index ff9fb1ea70..1b4ab7a2e7 100644 --- a/wordpress-scripts-webpack.config.js +++ b/wordpress-scripts-webpack.config.js @@ -20,6 +20,7 @@ module.exports = { '@givewp/forms/types': srcPath('DonationForms/resources/types.ts'), '@givewp/forms/propTypes': srcPath('DonationForms/resources/propTypes.ts'), '@givewp/forms/app': srcPath('DonationForms/resources/app'), + '@givewp/forms/registrars': srcPath('DonationForms/resources/registrars'), '@givewp/forms/shared': srcPath('DonationForms/resources/shared'), '@givewp/form-builder': srcPath('FormBuilder/resources/js/form-builder/src'), '@givewp/form-builder/registrars': srcPath('FormBuilder/resources/js/registrars/index.ts'),