diff --git a/src/helpers/Interfaces.ts b/src/helpers/Interfaces.ts index 2a139326..6a96d284 100644 --- a/src/helpers/Interfaces.ts +++ b/src/helpers/Interfaces.ts @@ -1,3 +1,3 @@ export * from "../appBase/interfaces"; -export interface PaymentGatewaysInterface { id?: string, churchId?: string, provider?: string, publicKey?: string, privateKey?: string } +export interface PaymentGatewaysInterface { id?: string, churchId?: string, provider?: string, publicKey?: string, privateKey?: string, payFees?: boolean } diff --git a/src/settings/components/GivingSettingsEdit.tsx b/src/settings/components/GivingSettingsEdit.tsx index 1fa5518f..834b87a1 100644 --- a/src/settings/components/GivingSettingsEdit.tsx +++ b/src/settings/components/GivingSettingsEdit.tsx @@ -2,7 +2,7 @@ import React from "react"; import { FormControl, InputLabel, MenuItem, Select, SelectChangeEvent, TextField, Grid, Stack, Switch, Typography, Tooltip, IconButton } from "@mui/material"; import HelpIcon from '@mui/icons-material/Help'; import { ApiHelper } from "."; -import { PaymentGatewaysInterface, UniqueIdHelper, GenericSettingInterface } from "../../helpers"; +import { PaymentGatewaysInterface, UniqueIdHelper } from "../../helpers"; interface Props { churchId: string, saveTrigger: Date | null } @@ -11,8 +11,7 @@ export const GivingSettingsEdit: React.FC = (props) => { const [provider, setProvider] = React.useState(""); const [publicKey, setPublicKey] = React.useState(""); const [privateKey, setPrivateKey] = React.useState(""); - const [payFeeSettings, setPayFeeSettings] = React.useState(null); - const [payFee, setPayFee] = React.useState("false"); + const [payFees, setPayFees] = React.useState(false); const handleChange = (e: React.ChangeEvent | SelectChangeEvent) => { e.preventDefault(); @@ -41,10 +40,9 @@ export const GivingSettingsEdit: React.FC = (props) => { { - if (e.target.checked === true) setPayFee("true"); - else setPayFee("false"); + setPayFees(e.target.checked); }} /> @@ -57,15 +55,16 @@ export const GivingSettingsEdit: React.FC = (props) => { if (!UniqueIdHelper.isMissing(gateway?.id)) ApiHelper.delete("/gateways/" + gateway.id, "GivingApi"); } else { const gw: PaymentGatewaysInterface = (gateway === null) ? { churchId: props.churchId } : gateway; - const pfs: GenericSettingInterface = (payFeeSettings === null) ? { churchId: props.churchId, keyName: "payFees" } : payFeeSettings; if (privateKey !== "") { gw.provider = provider; gw.publicKey = publicKey; gw.privateKey = privateKey; + gw.payFees = payFees; ApiHelper.post("/gateways", [gw], "GivingApi"); } - pfs.value = payFee; - ApiHelper.post("/settings", [pfs], "GivingApi"); + if (gw.payFees !== payFees) { + ApiHelper.patch(`/gateways/${gateway.id}`, { payFees : payFees }, "GivingApi"); + } } } @@ -75,22 +74,17 @@ export const GivingSettingsEdit: React.FC = (props) => { const loadData = async () => { const gateways = await ApiHelper.get("/gateways", "GivingApi"); - const feeSettings = await ApiHelper.get("/settings", "GivingApi").then((data) => data.filter((i: GenericSettingInterface) => i.keyName === "payFees")); if (gateways.length === 0) { setGateway(null); setProvider(""); setPublicKey(""); - setPayFeeSettings(null); - setPayFee("false"); + setPayFees(false); } else { setGateway(gateways[0]); setProvider(gateways[0].provider); setPublicKey(gateways[0].publicKey); - if (feeSettings.length > 0) { - setPayFeeSettings(feeSettings[0]); - setPayFee(feeSettings[0].value); - } + setPayFees(gateways[0].payFees) } setPrivateKey(""); }