Skip to content

Commit

Permalink
feat: add transaction fee option (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Himali-Malvawala committed Jul 21, 2023
1 parent 8e6b03a commit c43933b
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions src/settings/components/GivingSettingsEdit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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 } from "../../helpers";
import { FormControl, InputLabel, MenuItem, Select, SelectChangeEvent, TextField, Grid } from "@mui/material";
import { PaymentGatewaysInterface, UniqueIdHelper, GenericSettingInterface } from "../../helpers";

interface Props { churchId: string, saveTrigger: Date | null }

Expand All @@ -10,6 +11,8 @@ 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 handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement> | SelectChangeEvent<string>) => {
e.preventDefault();
Expand All @@ -29,6 +32,23 @@ export const GivingSettingsEdit: React.FC<Props> = (props) => {
<Grid item md={4} xs={12}>
<TextField fullWidth name="privateKey" label="Secret Key" value={privateKey} placeholder="********" type="password" onChange={handleChange} />
</Grid>
<Grid item xs={12}>
<Stack direction="row" alignItems="center">
<Typography>Transaction Fees</Typography>
<Tooltip title="Automatically forces users to cover the transaction fees" arrow>
<IconButton>
<HelpIcon />
</IconButton>
</Tooltip>
<Switch
checked={payFee === "true"}
onChange={(e) => {
if (e.target.checked === true) setPayFee("true");
else setPayFee("false");
}}
/>
</Stack>
</Grid>
</>);
}

Expand All @@ -37,12 +57,15 @@ 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;
ApiHelper.post("/gateways", [gw], "GivingApi");
}
pfs.value = payFee;
ApiHelper.post("/settings", [pfs], "GivingApi");
}
}

Expand All @@ -52,15 +75,22 @@ 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");
}
else {
setGateway(gateways[0]);
setProvider(gateways[0].provider);
setPublicKey(gateways[0].publicKey);
if (feeSettings.length > 0) {
setPayFeeSettings(feeSettings[0]);
setPayFee(feeSettings[0].value);
}
}
setPrivateKey("");
}
Expand All @@ -71,7 +101,7 @@ export const GivingSettingsEdit: React.FC<Props> = (props) => {
return (
<>
<div className="subHead">Giving</div>
<Grid container spacing={3}>
<Grid container spacing={3} marginBottom={2}>
<Grid item md={4} xs={12}>
<FormControl fullWidth>
<InputLabel>Provider</InputLabel>
Expand Down

0 comments on commit c43933b

Please sign in to comment.