From 0789307fa43e19fd20c273e2fd7802e77990c860 Mon Sep 17 00:00:00 2001 From: alaca Date: Wed, 25 Oct 2023 10:26:44 +0200 Subject: [PATCH] refactor: add publishGoalType function --- .../app/utilities/useDonationFormPubSub.ts | 24 ++++++++----------- .../src/settings/donation-goal/index.tsx | 6 ++--- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/DonationForms/resources/app/utilities/useDonationFormPubSub.ts b/src/DonationForms/resources/app/utilities/useDonationFormPubSub.ts index ce1b904463..31880c0c03 100644 --- a/src/DonationForms/resources/app/utilities/useDonationFormPubSub.ts +++ b/src/DonationForms/resources/app/utilities/useDonationFormPubSub.ts @@ -72,6 +72,15 @@ export default function useDonationFormPubSub() { publish(PREVIEW_EVENTS.GOAL, data, iframeRef) } + const publishGoalType = (type: string) => { + publish(PREVIEW_EVENTS.GOAL, { + type, + label: type, + typeIsCount: 'amount' !== type, + typeIsMoney: 'amount' === type + }, iframeRef) + } + const publishColors = (data: RequireAtLeastOne) => { publish(PREVIEW_EVENTS.COLORS, data, iframeRef) } @@ -112,6 +121,7 @@ export default function useDonationFormPubSub() { unsubscribe, unsubscribeAll, publishGoal, + publishGoalType, publishColors, publishSettings, subscribeToGoal, @@ -119,17 +129,3 @@ export default function useDonationFormPubSub() { subscribeToSettings, } } - -/** - * Helper function for setting goal props in design mode - * - * @param type - */ -export const setGoalType = (type: string) => { - return { - type, - label: type, - typeIsCount: 'amount' !== type, - typeIsMoney: 'amount' === type - } -} diff --git a/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx b/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx index 70c34c4b92..7b43917adf 100644 --- a/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx +++ b/src/FormBuilder/resources/js/form-builder/src/settings/donation-goal/index.tsx @@ -10,7 +10,7 @@ import { } from '@wordpress/components'; import debounce from 'lodash.debounce'; import {getFormBuilderWindowData} from '@givewp/form-builder/common/getWindowData'; -import useDonationFormPubSub, {setGoalType} from '@givewp/forms/app/utilities/useDonationFormPubSub'; +import useDonationFormPubSub from '@givewp/forms/app/utilities/useDonationFormPubSub'; const {goalTypeOptions} = getFormBuilderWindowData(); @@ -19,7 +19,7 @@ const DonationGoalSettings = () => { settings: {enableDonationGoal, enableAutoClose, goalAchievedMessage, goalType, goalAmount}, } = useFormState(); const dispatch = useFormStateDispatch(); - const {publishGoal} = useDonationFormPubSub(); + const {publishGoal, publishGoalType} = useDonationFormPubSub(); const selectedGoalType = goalTypeOptions.find((option) => option.value === goalType); const selectedGoalDescription = selectedGoalType ? selectedGoalType.description : ''; @@ -69,7 +69,7 @@ const DonationGoalSettings = () => { options={goalTypeOptions} onChange={(goalType: string) => { dispatch(setFormSettings({goalType})) - publishGoal(setGoalType(goalType)); + publishGoalType(goalType); }} help={selectedGoalDescription} />