Skip to content

Commit 2d2fdfa

Browse files
show correct currency symbol (website elements)
1 parent 326e467 commit 2d2fdfa

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/forms/components/PaymentEdit.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from "react";
22
import { FormControl, InputAdornment, InputLabel, MenuItem, Select, TextField, type SelectChangeEvent } from "@mui/material";
3-
import { type QuestionInterface } from "@churchapps/helpers";
3+
import { CurrencyHelper, type QuestionInterface } from "@churchapps/helpers";
44
import { ApiHelper, Locale } from "@churchapps/apphelper";
55
import { type FundInterface } from "@churchapps/helpers";
66

@@ -13,6 +13,7 @@ export const PaymentEdit: React.FC<Props> = (props) => {
1313
const [funds, setFunds] = React.useState([]);
1414
const [fundId, setFundId] = React.useState(props.question.choices?.find((c: any) => c.text === "FundId")?.value || "");
1515
const [amount, setAmount] = React.useState(props.question.choices?.find((c: any) => c.text === "Amount")?.value || 0);
16+
const [currency, setCurrency] = React.useState<string>("usd");
1617

1718
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement> | SelectChangeEvent) => {
1819
e.preventDefault();
@@ -46,6 +47,12 @@ export const PaymentEdit: React.FC<Props> = (props) => {
4647
});
4748
}, [fundId, props.question, props.updatedFunction]);
4849

50+
React.useEffect(() => {
51+
CurrencyHelper.loadCurrency().then((result) => {
52+
setCurrency(result);
53+
})
54+
}, []);
55+
4956
const getFundOptions = () =>
5057
funds.map((fund: FundInterface) => (
5158
<MenuItem key={fund.id} value={fund.id}>
@@ -68,7 +75,11 @@ export const PaymentEdit: React.FC<Props> = (props) => {
6875
type="number"
6976
value={amount}
7077
onChange={handleChange}
71-
InputProps={{ startAdornment: <InputAdornment position="start">$</InputAdornment> }}
78+
slotProps={{
79+
input: {
80+
startAdornment: <InputAdornment position="start">{CurrencyHelper.getCurrencySymbol(currency)}</InputAdornment>
81+
}
82+
}}
7283
/>
7384
</>
7485
);

src/site/admin/elements/DonateLinkEdit.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22
import type { SelectChangeEvent } from "@mui/material";
33
import { 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

66
type 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

Comments
 (0)