diff --git a/public/locales/en.json b/public/locales/en.json index a8e3eec..7ae3366 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -730,6 +730,12 @@ "none": "None", "noGroups": "No Groups available" }, + "supportContactSettingsEdit": { + "supportContact": "Support Contact", + "forceMsg": "This link will be used by users to contact the church", + "link": "Link", + "linkHelperText": "It must be either church's email or a link to the church's contact form" + }, "imageEditor": { "crop": "Crop", "upload": "Upload" diff --git a/src/settings/components/ChurchSettingsEdit.tsx b/src/settings/components/ChurchSettingsEdit.tsx index 87366a9..aa8d15e 100644 --- a/src/settings/components/ChurchSettingsEdit.tsx +++ b/src/settings/components/ChurchSettingsEdit.tsx @@ -4,6 +4,7 @@ import { GivingSettingsEdit } from "./GivingSettingsEdit"; import { TextField, Grid } from "@mui/material"; import { DomainSettingsEdit } from "./DomainSettingsEdit"; import { DirectoryApproveSettingsEdit } from "./DirectoryApproveSettingsEdit"; +import { SupportContactSettingsEdit } from "./SupportContactSettingsEdit"; interface Props { church: ChurchInterface, updatedFunction: () => void } @@ -89,6 +90,7 @@ export const ChurchSettingsEdit: React.FC = (props) => { + {giveSection()} diff --git a/src/settings/components/SupportContactSettingsEdit.tsx b/src/settings/components/SupportContactSettingsEdit.tsx new file mode 100644 index 0000000..59726fb --- /dev/null +++ b/src/settings/components/SupportContactSettingsEdit.tsx @@ -0,0 +1,51 @@ +import React, { useEffect, useState } from "react"; +import { Icon, Stack, TextField, Tooltip, Typography } from "@mui/material"; +import { GenericSettingInterface, UniqueIdHelper, ApiHelper, Locale } from "@churchapps/apphelper"; + +interface Props { churchId: string; saveTrigger: Date | null; } + +export const SupportContactSettingsEdit: React.FC = (props) => { + const [value, setValue] = useState(""); + const [setting, setSetting] = useState(null); + + const save = () => { + const s: GenericSettingInterface = setting === null ? { churchId: props.churchId, public: 1, keyName: "supportContact" } : setting; + s.value = value; + ApiHelper.post("/settings", [s], "MembershipApi"); + }; + + const checkSave = () => { + if (props.saveTrigger !== null) save(); + }; + + const loadData = async () => { + const publicSettings = await ApiHelper.get("/settings", "MembershipApi"); + const contactSetting = publicSettings.filter((c: GenericSettingInterface) => c.keyName === "supportContact"); + if (contactSetting.length > 0) { + setSetting(contactSetting[0]); + setValue(contactSetting[0].value); + } + }; + + useEffect(() => { if (!UniqueIdHelper.isMissing(props.churchId)) loadData(); }, [props.churchId]); //eslint-disable-line + useEffect(checkSave, [props.saveTrigger]); //eslint-disable-line + + return ( +
+ + {Locale.label("settings.supportContactSettingsEdit.supportContact")} + + help + + + { e.preventDefault(); setValue(e.target.value); }} + helperText={Locale.label("settings.supportContactSettingsEdit.linkHelperText")} + /> +
+ ); +};