-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: support church field in settings (#300)
- Loading branch information
1 parent
b96e89c
commit 4d13b4b
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> = (props) => { | ||
const [value, setValue] = useState<string>(""); | ||
const [setting, setSetting] = useState<GenericSettingInterface>(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 ( | ||
<div style={{ marginTop: 10, marginBottom: 10 }}> | ||
<Stack direction="row" alignItems="center"> | ||
<Typography>{Locale.label("settings.supportContactSettingsEdit.supportContact")}</Typography> | ||
<Tooltip arrow title={Locale.label("settings.supportContactSettingsEdit.forceMsg")}> | ||
<Icon fontSize="small" sx={{ cursor: "pointer", color: "#757575", paddingLeft: "2px" }}>help</Icon> | ||
</Tooltip> | ||
</Stack> | ||
<TextField | ||
fullWidth | ||
name="supportContact" | ||
label={Locale.label("settings.supportContactSettingsEdit.link")} | ||
value={value || ""} | ||
onChange={(e) => { e.preventDefault(); setValue(e.target.value); }} | ||
helperText={Locale.label("settings.supportContactSettingsEdit.linkHelperText")} | ||
/> | ||
</div> | ||
); | ||
}; |