11import { useEffect , useState } from "react" ;
22import type { SelectChangeEvent } from "@mui/material" ;
33import { Button , Chip , FormControl , Icon , InputAdornment , InputLabel , MenuItem , Select , TextField , Typography } from "@mui/material" ;
4- import { ApiHelper , Locale } from "@churchapps/apphelper" ;
4+ import { ApiHelper , CurrencyHelper , Locale } from "@churchapps/apphelper" ;
55
66type Props = {
77 parsedData : any ;
@@ -12,6 +12,7 @@ export function DonateLinkEdit({ parsedData, onRealtimeChange }: Props) {
1212 const [ funds , setFunds ] = useState ( null ) ;
1313 const [ amounts , setAmounts ] = useState < number [ ] > ( [ ] ) ;
1414 const [ amountValue , setAmountValue ] = useState < number > ( ) ;
15+ const [ currency , setCurrency ] = useState < string > ( "usd" ) ;
1516
1617 const handleChange = ( e : React . ChangeEvent < HTMLInputElement | HTMLTextAreaElement > | SelectChangeEvent < string > ) => {
1718 const data = { ...parsedData } ;
@@ -60,6 +61,10 @@ export function DonateLinkEdit({ parsedData, onRealtimeChange }: Props) {
6061 if ( parsedData ?. amounts ) {
6162 setAmounts ( JSON . parse ( parsedData . amounts ) ) ;
6263 }
64+
65+ CurrencyHelper . loadCurrency ( ) . then ( ( result ) => {
66+ setCurrency ( result ) ;
67+ } )
6368 } , [ ] ) ;
6469
6570 return (
@@ -106,9 +111,27 @@ export function DonateLinkEdit({ parsedData, onRealtimeChange }: Props) {
106111 { Locale . label ( "site.donateLink.donationAmountsHelper" ) }
107112 </ Typography >
108113 < div >
109- { amounts ?. map ( ( a ) => ( < Chip color = "primary" size = "small" label = { `$ ${ a } ` } onDelete = { ( ) => { handleAmountDelete ( a ) ; } } sx = { { mr : 1 , mt : 1 , minWidth : 70 } } deleteIcon = { < Icon sx = { { float : "right" , marginLeft : "auto !important" } } > cancel</ Icon > } data-testid = { `amount-chip-${ a } ` } aria-label = { `Remove $${ a } donation amount` } /> ) ) }
114+ { amounts ?. map ( ( a ) => ( < Chip color = "primary" size = "small" label = { `${ CurrencyHelper . getCurrencySymbol ( currency ) } ${ a } ` } onDelete = { ( ) => { handleAmountDelete ( a ) ; } } sx = { { mr : 1 , mt : 1 , minWidth : 70 } } deleteIcon = { < Icon sx = { { float : "right" , marginLeft : "auto !important" } } > cancel</ Icon > } data-testid = { `amount-chip-${ a } ` } aria-label = { `Remove ${ CurrencyHelper . getCurrencySymbol ( currency ) } ${ a } donation amount` } /> ) ) }
110115 </ div >
111- < TextField fullWidth size = "small" type = "number" placeholder = { Locale . label ( "site.donateLink.amountPlaceholder" ) } label = { Locale . label ( "site.donateLink.amount" ) } name = "amount" value = { amountValue } onChange = { handleChange } data-testid = "donate-amount-input" aria-label = { Locale . label ( "site.donateLink.donationAmount" ) } InputProps = { { startAdornment : < InputAdornment position = "start" > $</ InputAdornment > , endAdornment : < Button size = "small" variant = "contained" onClick = { handleAmountAdd } disabled = { ! amountValue || amountValue === 0 } data-testid = "add-amount-button" aria-label = { Locale . label ( "site.donateLink.addAmount" ) } > { Locale . label ( "site.donateLink.add" ) } </ Button > , inputProps : { min : 0 } } } />
116+ < TextField
117+ fullWidth
118+ size = "small"
119+ type = "number"
120+ placeholder = { Locale . label ( "site.donateLink.amountPlaceholder" ) }
121+ label = { Locale . label ( "site.donateLink.amount" ) }
122+ name = "amount"
123+ value = { amountValue }
124+ onChange = { handleChange }
125+ data-testid = "donate-amount-input"
126+ aria-label = { Locale . label ( "site.donateLink.donationAmount" ) }
127+ slotProps = { {
128+ input : {
129+ startAdornment : < InputAdornment position = "start" > { CurrencyHelper . getCurrencySymbol ( currency ) } </ InputAdornment > ,
130+ endAdornment : < Button size = "small" variant = "contained" onClick = { handleAmountAdd } disabled = { ! amountValue || amountValue === 0 } data-testid = "add-amount-button" aria-label = { Locale . label ( "site.donateLink.addAmount" ) } > { Locale . label ( "site.donateLink.add" ) } </ Button > ,
131+ inputProps : { min : 0 }
132+ }
133+ } }
134+ />
112135 </ >
113136 ) ;
114137}
0 commit comments