feat: add system setting to allow user signup (#407)

This commit is contained in:
boojack
2022-11-03 21:47:36 +08:00
committed by GitHub
parent 4ed987229b
commit cf75054106
21 changed files with 755 additions and 45 deletions

View File

@ -0,0 +1,65 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import Switch from "@mui/joy/Switch";
import * as api from "../../helpers/api";
import { globalService, userService } from "../../services";
import Selector from "../common/Selector";
import "../../less/settings/preferences-section.less";
const localeSelectorItems = [
{
text: "English",
value: "en",
},
{
text: "中文",
value: "zh",
},
{
text: "Tiếng Việt",
value: "vi",
},
];
interface State {
allowSignUp: boolean;
}
const SystemSection = () => {
const { t } = useTranslation();
const [state, setState] = useState<State>({
allowSignUp: false,
});
useEffect(() => {
api.getSystemStatus().then(({ data }) => {
const { data: status } = data;
setState({
allowSignUp: status.allowSignUp,
});
});
}, []);
const handleAllowSignUpChanged = async (value: boolean) => {
setState({
...state,
allowSignUp: value,
});
await api.upsertSystemSetting({
name: "allowSignUp",
value: JSON.stringify(value),
});
};
return (
<div className="section-container preferences-section-container">
<p className="title-text">{t("common.basic")}</p>
<label className="form-label selector">
<span className="normal-text">Allow user signUp</span>
<Switch size="sm" checked={state.allowSignUp} onChange={(event) => handleAllowSignUpChanged(event.target.checked)} />
</label>
</div>
);
};
export default SystemSection;