From 409d9ed6babac342ac5703dfa1ae89efd90c6435 Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 12:52:50 -0700 Subject: [PATCH 1/7] refactor: add descriptions to DonationAmountAttributes types --- .../js/form-builder/src/blocks/fields/amount/types.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 2a0d945172..c328f90422 100644 --- 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 @@ -3,6 +3,7 @@ import type {subscriptionPeriod} from "@givewp/forms/registrars/templates/groups export interface DonationAmountAttributes { label: string; levels: number[]; + descriptions: string[]; defaultLevel: number; priceOption: string; setPrice: number; @@ -15,4 +16,4 @@ export interface DonationAmountAttributes { recurringLengthOfTime: string; recurringOptInDefaultBillingPeriod: subscriptionPeriod | 'one-time'; recurringEnableOneTimeDonations: boolean -} \ No newline at end of file +} From d88338282c1702c139d50eb938cea7c7d73a2d3e Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 12:53:44 -0700 Subject: [PATCH 2/7] refactor: add descriptions array to donation amount block attributes --- .../js/form-builder/src/blocks/fields/amount/settings.tsx | 5 +++++ 1 file changed, 5 insertions(+) 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 b27bfb9e20..2f50ac7444 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 @@ -18,6 +18,7 @@ const { setPrice, priceOption, levels, + descriptions, defaultLevel, } = getDefaultBlockAttributes('givewp/donation-amount'); @@ -39,6 +40,10 @@ const settings: FieldBlock['settings'] = { type: 'array', default: levels, }, + descriptions: { + type: 'array', + default: descriptions, + }, defaultLevel: { type: 'number', default: defaultLevel, From 98f4b7c867df6784875f89d9b22a2fff36f1153e Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 12:57:21 -0700 Subject: [PATCH 3/7] refactor: update donation amount settings to handle descriptions --- .../blocks/fields/amount/inspector/index.tsx | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) 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 848c11061c..a15a0c0c1f 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 @@ -60,6 +60,7 @@ const Inspector = ({attributes, setAttributes}) => { const { label = __('Donation Amount', 'give'), levels, + descriptions, defaultLevel, priceOption, setPrice, @@ -120,11 +121,12 @@ const Inspector = ({attributes, setAttributes}) => { const isRecurring = isRecurringSupported && recurringEnabled; const [donationLevels, setDonationLevels] = useState( - levels.map((level) => ({ + levels.map((level, index) => ({ id: String(Math.floor(Math.random() * 1000000)), label: formatCurrencyAmount(level.toString()), value: level.toString(), checked: defaultLevel === level, + description: descriptions[index] || '', })) ); @@ -163,9 +165,14 @@ const Inspector = ({attributes, setAttributes}) => { const handleLevelsChange = (options: OptionProps[]) => { const checkedLevel = options.filter((option) => option.checked); const newLevels = options.filter((option) => option.value).map((option) => Number(option.value)); - - setDonationLevels(options); - setAttributes({levels: newLevels, defaultLevel: Number(checkedLevel[0].value)}); + const newDescriptions = options.map((option) => option.description); + + setDonationLevels(donationLevels); + setAttributes({ + levels: newLevels, + defaultLevel: Number(checkedLevel[0].value), + descriptions: newDescriptions, + }); }; const getDefaultBillingPeriodOptions = useCallback( @@ -220,6 +227,18 @@ const Inspector = ({attributes, setAttributes}) => { onValueChange={(setPrice) => setAttributes({setPrice: setPrice ? parseInt(setPrice) : 0})} /> )} + {priceOption === 'multi' && ( + + )} { )} - {priceOption === 'multi' && ( - - - - )} - {!isRecurringSupported && (recurringAddonData.isInstalled ? ( From d72334b352ef1246e587d93140c99c0de61b394c Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 15:35:43 -0700 Subject: [PATCH 4/7] refactor: replace descriptions with label --- .../src/blocks/fields/amount/inspector/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 a15a0c0c1f..99876078cb 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 @@ -123,10 +123,9 @@ const Inspector = ({attributes, setAttributes}) => { const [donationLevels, setDonationLevels] = useState( levels.map((level, index) => ({ id: String(Math.floor(Math.random() * 1000000)), - label: formatCurrencyAmount(level.toString()), + label: descriptions[index] || '', value: level.toString(), checked: defaultLevel === level, - description: descriptions[index] || '', })) ); @@ -165,7 +164,7 @@ const Inspector = ({attributes, setAttributes}) => { const handleLevelsChange = (options: OptionProps[]) => { const checkedLevel = options.filter((option) => option.checked); const newLevels = options.filter((option) => option.value).map((option) => Number(option.value)); - const newDescriptions = options.map((option) => option.description); + const newDescriptions = options.map((option) => option.label); setDonationLevels(donationLevels); setAttributes({ @@ -236,7 +235,7 @@ const Inspector = ({attributes, setAttributes}) => { onAddOption={handleLevelAdded} onRemoveOption={handleLevelRemoved} defaultControlsTooltip={__('Default Level', 'give')} - hasDescriptions={!!descriptions} + toggleLabel={__('Enable amount description', 'give')} /> )} From 251fd5b8c0ad53c5b52f1c7643741c276ad73f39 Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 15:47:46 -0700 Subject: [PATCH 5/7] refactor: revert donationlevels state change --- .../form-builder/src/blocks/fields/amount/inspector/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 99876078cb..b72c4b8eab 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 @@ -166,7 +166,7 @@ const Inspector = ({attributes, setAttributes}) => { const newLevels = options.filter((option) => option.value).map((option) => Number(option.value)); const newDescriptions = options.map((option) => option.label); - setDonationLevels(donationLevels); + setDonationLevels(options); setAttributes({ levels: newLevels, defaultLevel: Number(checkedLevel[0].value), From d46e63fb4c8d11a497ab8a0a23956feafa7c5b49 Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 16:09:14 -0700 Subject: [PATCH 6/7] refactor:add toggle attributes --- .../src/blocks/fields/amount/inspector/index.tsx | 3 +++ .../js/form-builder/src/blocks/fields/amount/types.ts | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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 b72c4b8eab..0ddc7fa553 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 @@ -61,6 +61,7 @@ const Inspector = ({attributes, setAttributes}) => { label = __('Donation Amount', 'give'), levels, descriptions, + descriptionsEnabled = false, defaultLevel, priceOption, setPrice, @@ -236,6 +237,8 @@ const Inspector = ({attributes, setAttributes}) => { onRemoveOption={handleLevelRemoved} defaultControlsTooltip={__('Default Level', 'give')} toggleLabel={__('Enable amount description', 'give')} + toggleEnabled={descriptionsEnabled} + onHandleToggle={(value) => setAttributes({descriptionsEnabled: value})} /> )} 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 index c328f90422..e8ef518f01 100644 --- 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 @@ -1,9 +1,10 @@ -import type {subscriptionPeriod} from "@givewp/forms/registrars/templates/groups/DonationAmount/subscriptionPeriod"; +import type {subscriptionPeriod} from '@givewp/forms/registrars/templates/groups/DonationAmount/subscriptionPeriod'; export interface DonationAmountAttributes { label: string; levels: number[]; descriptions: string[]; + descriptionsEnabled: boolean; defaultLevel: number; priceOption: string; setPrice: number; @@ -15,5 +16,5 @@ export interface DonationAmountAttributes { recurringBillingPeriodOptions: subscriptionPeriod[]; recurringLengthOfTime: string; recurringOptInDefaultBillingPeriod: subscriptionPeriod | 'one-time'; - recurringEnableOneTimeDonations: boolean + recurringEnableOneTimeDonations: boolean; } From b117bd9b7f4b077fa43c9e0f868fe7463d432faa Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 16:20:27 -0700 Subject: [PATCH 7/7] doc: add unreleased tags --- .../form-builder/src/blocks/fields/amount/inspector/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) 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 0ddc7fa553..a59671177b 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 @@ -56,6 +56,10 @@ const numberOfDonationsControlOptions = [{label: __('Ongoing', 'give'), value: ' })) ); +/** + * @unreleased add description fields to levels. + * @since 3.0.0 + */ const Inspector = ({attributes, setAttributes}) => { const { label = __('Donation Amount', 'give'),