import { useState } from "react"; import { useTranslate } from "@/utils/i18n"; import { toast } from "react-hot-toast"; import { useGlobalStore } from "@/store/module"; import * as api from "@/helpers/api"; import Textarea from "@mui/joy/Textarea/Textarea"; import Icon from "./Icon"; import { generateDialog } from "./Dialog"; import LocaleSelect from "./LocaleSelect"; import AppearanceSelect from "./AppearanceSelect"; type Props = DialogProps; const UpdateCustomizedProfileDialog: React.FC = ({ destroy }: Props) => { const t = useTranslate(); const globalStore = useGlobalStore(); const [state, setState] = useState(globalStore.state.systemStatus.customizedProfile); const handleCloseButtonClick = () => { destroy(); }; const setPartialState = (partialState: Partial) => { setState((state) => { return { ...state, ...partialState, }; }); }; const handleNameChanged = (e: React.ChangeEvent) => { setPartialState({ name: e.target.value as string, }); }; const handleLogoUrlChanged = (e: React.ChangeEvent) => { setPartialState({ logoUrl: e.target.value as string, }); }; const handleDescriptionChanged = (e: React.ChangeEvent) => { setPartialState({ description: e.target.value as string, }); }; const handleLocaleSelectChange = (locale: Locale) => { setPartialState({ locale: locale, }); }; const handleAppearanceSelectChange = (appearance: Appearance) => { setPartialState({ appearance: appearance, }); }; const handleRestoreButtonClick = () => { setPartialState({ name: "memos", logoUrl: "/logo.webp", description: "", locale: "en", appearance: "system", externalUrl: "", }); }; const handleSaveButtonClick = async () => { if (state.name === "") { toast.error(t("message.fill-server-name")); return; } try { await api.upsertSystemSetting({ name: "customized-profile", value: JSON.stringify(state), }); await globalStore.fetchSystemStatus(); } catch (error) { console.error(error); return; } toast.success(t("message.succeed-update-customized-profile")); destroy(); }; return ( <>

{t("setting.system-section.customize-server.title")}

{t("setting.system-section.server-name")} ({t("setting.system-section.customize-server.default")})

{t("setting.system-section.customize-server.icon-url")}

{t("setting.system-section.customize-server.description")}