import Textarea from "@mui/joy/Textarea/Textarea"; import { Button, Input } from "@usememos/mui"; import { XIcon } from "lucide-react"; import { useState } from "react"; import { toast } from "react-hot-toast"; import { workspaceSettingNamePrefix } from "@/store/v1"; import { workspaceStore } from "@/store/v2"; import { WorkspaceCustomProfile } from "@/types/proto/api/v1/workspace_setting_service"; import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting"; import { useTranslate } from "@/utils/i18n"; import AppearanceSelect from "./AppearanceSelect"; import { generateDialog } from "./Dialog"; import LocaleSelect from "./LocaleSelect"; type Props = DialogProps; const UpdateCustomizedProfileDialog = ({ destroy }: Props) => { const t = useTranslate(); const workspaceGeneralSetting = workspaceStore.state.generalSetting; const [customProfile, setCustomProfile] = useState( WorkspaceCustomProfile.fromPartial(workspaceGeneralSetting.customProfile || {}), ); const handleCloseButtonClick = () => { destroy(); }; const setPartialState = (partialState: Partial) => { setCustomProfile((state) => { return { ...state, ...partialState, }; }); }; const handleNameChanged = (e: React.ChangeEvent) => { setPartialState({ title: 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({ title: "Memos", logoUrl: "/logo.webp", description: "", locale: "en", appearance: "system", }); }; const handleSaveButtonClick = async () => { if (customProfile.title === "") { toast.error("Title cannot be empty."); return; } try { await workspaceStore.upsertWorkspaceSetting({ name: `${workspaceSettingNamePrefix}${WorkspaceSettingKey.GENERAL}`, generalSetting: { ...workspaceGeneralSetting, customProfile: customProfile, }, }); } catch (error) { console.error(error); return; } toast.success(t("message.update-succeed")); destroy(); }; return ( <>

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

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

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

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