import { Button, IconButton, Input } from "@mui/joy"; import Textarea from "@mui/joy/Textarea/Textarea"; import { useState } from "react"; import { toast } from "react-hot-toast"; import { workspaceSettingNamePrefix, useWorkspaceSettingStore } from "@/store/v1"; import { WorkspaceCustomProfile, WorkspaceGeneralSetting } 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 Icon from "./Icon"; import LocaleSelect from "./LocaleSelect"; type Props = DialogProps; const UpdateCustomizedProfileDialog: React.FC = ({ destroy }: Props) => { const t = useTranslate(); const workspaceSettingStore = useWorkspaceSettingStore(); const workspaceGeneralSetting = WorkspaceGeneralSetting.fromPartial( workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.GENERAL)?.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 workspaceSettingStore.setWorkspaceSetting({ 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")}