From 98f4b7c867df6784875f89d9b22a2fff36f1153e Mon Sep 17 00:00:00 2001 From: Joshua Dinh Date: Mon, 15 Apr 2024 12:57:21 -0700 Subject: [PATCH] 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 ? (