Skip to content

Commit

Permalink
fix: transaction fee toggle (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Himali-Malvawala committed Aug 15, 2023
1 parent 599f722 commit a1d8474
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/helpers/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -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 }
26 changes: 10 additions & 16 deletions src/settings/components/GivingSettingsEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -11,8 +11,7 @@ export const GivingSettingsEdit: React.FC<Props> = (props) => {
const [provider, setProvider] = React.useState("");
const [publicKey, setPublicKey] = React.useState("");
const [privateKey, setPrivateKey] = React.useState("");
const [payFeeSettings, setPayFeeSettings] = React.useState<GenericSettingInterface>(null);
const [payFee, setPayFee] = React.useState("false");
const [payFees, setPayFees] = React.useState<boolean>(false);

const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement> | SelectChangeEvent<string>) => {
e.preventDefault();
Expand Down Expand Up @@ -41,10 +40,9 @@ export const GivingSettingsEdit: React.FC<Props> = (props) => {
</IconButton>
</Tooltip>
<Switch
checked={payFee === "true"}
checked={payFees === true}
onChange={(e) => {
if (e.target.checked === true) setPayFee("true");
else setPayFee("false");
setPayFees(e.target.checked);
}}
/>
</Stack>
Expand All @@ -57,15 +55,16 @@ export const GivingSettingsEdit: React.FC<Props> = (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");
}
}
}

Expand All @@ -75,22 +74,17 @@ export const GivingSettingsEdit: React.FC<Props> = (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("");
}
Expand Down

0 comments on commit a1d8474

Please sign in to comment.