import { useState } from "react"; import { toast } from "react-hot-toast"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { workspaceStore } from "@/store"; import { workspaceSettingNamePrefix } from "@/store/common"; import { WorkspaceSettingKey } from "@/store/workspace"; import { WorkspaceCustomProfile } from "@/types/proto/api/v1/workspace_service"; import { useTranslate } from "@/utils/i18n"; import AppearanceSelect from "./AppearanceSelect"; import LocaleSelect from "./LocaleSelect"; interface UpdateCustomizedProfileDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSuccess?: () => void; } export function UpdateCustomizedProfileDialog({ open, onOpenChange, onSuccess }: UpdateCustomizedProfileDialogProps) { const t = useTranslate(); const workspaceGeneralSetting = workspaceStore.state.generalSetting; const [customProfile, setCustomProfile] = useState( WorkspaceCustomProfile.fromPartial(workspaceGeneralSetting.customProfile || {}), ); const [isLoading, setIsLoading] = useState(false); const setPartialState = (partialState: Partial) => { setCustomProfile((state) => ({ ...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 handleCloseButtonClick = () => { onOpenChange(false); }; const handleSaveButtonClick = async () => { if (customProfile.title === "") { toast.error("Title cannot be empty."); return; } setIsLoading(true); try { await workspaceStore.upsertWorkspaceSetting({ name: `${workspaceSettingNamePrefix}${WorkspaceSettingKey.GENERAL}`, generalSetting: { ...workspaceGeneralSetting, customProfile: customProfile, }, }); toast.success(t("message.update-succeed")); onSuccess?.(); onOpenChange(false); } catch (error) { console.error(error); toast.error("Failed to update profile"); } finally { setIsLoading(false); } }; return ( {t("setting.system-section.customize-server.title")} Customize your workspace appearance and settings.