import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { useGlobalStore } from "../store/module"; import * as api from "../helpers/api"; import Icon from "./Icon"; import { generateDialog } from "./Dialog"; import toastHelper from "./Toast"; type Props = DialogProps; const UpdateCustomizedProfileDialog: React.FC = ({ destroy }: Props) => { const { t } = useTranslation(); const globalStore = useGlobalStore(); const [state, setState] = useState(globalStore.state.systemStatus.customizedProfile); useEffect(() => { // do nth }, []); const handleCloseBtnClick = () => { destroy(); }; const handleNameChanged = (e: React.ChangeEvent) => { setState((state) => { return { ...state, name: e.target.value as string, }; }); }; const handleIconUrlChanged = (e: React.ChangeEvent) => { setState((state) => { return { ...state, iconUrl: e.target.value as string, }; }); }; const handleSaveBtnClick = async () => { if (state.name === "" || state.iconUrl === "") { toastHelper.error(t("message.fill-all")); return; } try { await api.upsertSystemSetting({ name: "customizedProfile", value: JSON.stringify(state), }); await globalStore.fetchSystemStatus(); } catch (error) { console.error(error); return; } toastHelper.success("Succeed to update customized profile"); destroy(); }; return ( <>

Customize server

Server Name(Default is memos)

Icon URL

{t("common.cancel")} {t("common.save")}
); }; function showUpdateCustomizedProfileDialog() { generateDialog( { className: "update-customized-profile-dialog", dialogName: "update-customized-profile-dialog", }, UpdateCustomizedProfileDialog ); } export default showUpdateCustomizedProfileDialog;