1- import { useCallback } from 'react' ;
2- import { withTemplateWrapper } from '../templates' ;
3- import type { GoalType } from '@givewp/forms/propTypes' ;
4- import amountFormatter from '@givewp/forms/app/utilities/amountFormatter' ;
51import DonationFormErrorBoundary from '@givewp/forms/app/errors/boundaries/DonationFormErrorBoundary' ;
6- import type { Form as DonationForm } from '@givewp/forms/types' ;
2+ import amountFormatter from '@givewp/forms/app/utilities/amountFormatter' ;
3+ import type { GoalType } from '@givewp/forms/propTypes' ;
4+ import type { Form as DonationForm } from '@givewp/forms/types' ;
5+ import { useCallback , useMemo } from 'react' ;
6+ import { withTemplateWrapper } from '../templates' ;
77
88const formTemplates = window . givewp . form . templates ;
99
@@ -15,12 +15,32 @@ const GoalTemplate = withTemplateWrapper(formTemplates.layouts.goal);
1515const HeaderImageTemplate = withTemplateWrapper ( formTemplates . layouts . headerImage ) ;
1616
1717/**
18+ * @unreleased Make the goal currency use the base currency always
1819 * @since 3.0.0
1920 */
2021export default function Header ( { form} : { form : DonationForm } ) {
22+
23+ // Get the base currency for goal formatting
24+ // The goal progress bar should always use the form's base currency, not the selected currency
25+ // This matches the behavior of legacy forms where only donation amounts are converted
26+ const goalCurrency = useMemo ( ( ) => {
27+ // If currency switcher is enabled, find the base currency (exchangeRate === 0)
28+ if ( form . currencySwitcherSettings && form . currencySwitcherSettings . length > 0 ) {
29+ const baseCurrencySetting = form . currencySwitcherSettings . find (
30+ ( setting ) => setting . exchangeRate === 0
31+ ) ;
32+ if ( baseCurrencySetting ) {
33+ return baseCurrencySetting . id ;
34+ }
35+ }
36+ // Fallback to form's default currency
37+ return form . currency ;
38+ } , [ form . currencySwitcherSettings , form . currency ] ) ;
39+
2140 const formatGoalAmount = useCallback ( ( amount : number ) => {
22- return amountFormatter ( form . currency ) . format ( amount ) ;
23- } , [ ] ) ;
41+ // Use the base currency for goal amounts, not the selected currency
42+ return amountFormatter ( goalCurrency ) . format ( amount ) ;
43+ } , [ goalCurrency ] ) ;
2444
2545 return (
2646 < DonationFormErrorBoundary >
@@ -43,7 +63,7 @@ export default function Header({form}: {form: DonationForm}) {
4363 Goal = { ( ) =>
4464 form . goal ?. show && (
4565 < GoalTemplate
46- currency = { form . currency }
66+ currency = { goalCurrency }
4767 type = { form . goal . type as GoalType }
4868 goalLabel = { form . goal . label }
4969 progressPercentage = { Math . round ( ( form . goal . currentAmount / form . goal . targetAmount ) * 100 ) }
0 commit comments