import React, { useCallback, useEffect, useState } from "react"; import { makeStyles } from "@material-ui/core/styles"; import Typography from "@material-ui/core/Typography"; import InputLabel from "@material-ui/core/InputLabel"; import FormControl from "@material-ui/core/FormControl"; import Input from "@material-ui/core/Input"; import FormHelperText from "@material-ui/core/FormHelperText"; import Button from "@material-ui/core/Button"; import API from "../../../middleware/Api"; import { useDispatch } from "react-redux"; import Select from "@material-ui/core/Select"; import MenuItem from "@material-ui/core/MenuItem"; import Switch from "@material-ui/core/Switch"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import AlertDialog from "../Dialogs/Alert"; import Alert from "@material-ui/lab/Alert"; import FileSelector from "../Common/FileSelector"; import { toggleSnackbar } from "../../../redux/explorer"; import { useTranslation } from "react-i18next"; const useStyles = makeStyles((theme) => ({ root: { [theme.breakpoints.up("md")]: { marginLeft: 100, }, marginBottom: 40, }, form: { maxWidth: 400, marginTop: 20, marginBottom: 20, }, formContainer: { [theme.breakpoints.up("md")]: { padding: "0px 24px 0 24px", }, }, })); export default function Access() { const { t } = useTranslation("dashboard", { keyPrefix: "settings" }); const { t: tVas } = useTranslation("dashboard", { keyPrefix: "vas" }); const classes = useStyles(); const [loading, setLoading] = useState(false); const [initCompleted, setInitComplete] = useState(false); const [options, setOptions] = useState({ register_enabled: "1", default_group: "1", email_active: "0", login_captcha: "0", reg_captcha: "0", forget_captcha: "0", qq_login: "0", qq_direct_login: "0", qq_login_id: "", qq_login_key: "", authn_enabled: "0", mail_domain_filter: "0", mail_domain_filter_list: "", initial_files: "[]", }); const [siteURL, setSiteURL] = useState(""); const [groups, setGroups] = useState([]); const [httpAlert, setHttpAlert] = useState(false); const handleChange = (name) => (event) => { let value = event.target.value; if (event.target.checked !== undefined) { value = event.target.checked ? "1" : "0"; } setOptions({ ...options, [name]: value, }); }; const handleInputChange = (name) => (event) => { const value = event.target.value; setOptions({ ...options, [name]: value, }); }; const dispatch = useDispatch(); const ToggleSnackbar = useCallback( (vertical, horizontal, msg, color) => dispatch(toggleSnackbar(vertical, horizontal, msg, color)), [dispatch] ); useEffect(() => { API.post("/admin/setting", { keys: [...Object.keys(options), "siteURL"], }) .then((response) => { setSiteURL(response.data.siteURL); delete response.data.siteURL; setOptions(response.data); setInitComplete(true); }) .catch((error) => { ToggleSnackbar("top", "right", error.message, "error"); }); API.get("/admin/groups") .then((response) => { setGroups(response.data); }) .catch((error) => { ToggleSnackbar("top", "right", error.message, "error"); }); // eslint-disable-next-line }, []); const submit = (e) => { e.preventDefault(); setLoading(true); const option = []; Object.keys(options).forEach((k) => { option.push({ key: k, value: options[k], }); }); API.patch("/admin/setting", { options: option, }) .then(() => { ToggleSnackbar("top", "right", t("saved"), "success"); }) .catch((error) => { ToggleSnackbar("top", "right", error.message, "error"); }) .then(() => { setLoading(false); }); }; return (