import { Button, Checkbox, Input, Textarea } from "@mui/joy"; import { isEqual } from "lodash-es"; import { useRef, useState } from "react"; import toast from "react-hot-toast"; import { useTranslation } from "react-i18next"; import { workspaceServiceClient } from "@/grpcweb"; import useWorkspaceStore from "@/stores/v1/workspace"; import { WorkspaceSetting } from "@/types/proto/api/v1/workspace_service"; const WorkspaceSection: React.FC = () => { const { t } = useTranslation(); const workspaceStore = useWorkspaceStore(); const [workspaceSetting, setWorkspaceSetting] = useState(workspaceStore.setting); const originalWorkspaceSetting = useRef(workspaceStore.setting); const allowSave = !isEqual(originalWorkspaceSetting.current, workspaceSetting); const handleEnableSignUpChange = async (value: boolean) => { setWorkspaceSetting({ ...workspaceSetting, enableSignup: value, }); }; const handleInstanceUrlChange = async (value: string) => { setWorkspaceSetting({ ...workspaceSetting, instanceUrl: value, }); }; const handleCustomStyleChange = async (value: string) => { setWorkspaceSetting({ ...workspaceSetting, customStyle: value, }); }; const handleSaveWorkspaceSetting = async () => { const updateMask: string[] = []; if (!isEqual(originalWorkspaceSetting.current.enableSignup, workspaceSetting.enableSignup)) { updateMask.push("enable_signup"); } if (!isEqual(originalWorkspaceSetting.current.instanceUrl, workspaceSetting.instanceUrl)) { updateMask.push("instance_url"); } if (!isEqual(originalWorkspaceSetting.current.customStyle, workspaceSetting.customStyle)) { updateMask.push("custom_style"); } if (updateMask.length === 0) { toast.error("No changes made"); return; } try { const setting = ( await workspaceServiceClient.updateWorkspaceSetting({ setting: workspaceSetting, updateMask: updateMask, }) ).setting as WorkspaceSetting; setWorkspaceSetting(setting); originalWorkspaceSetting.current = setting; toast.success("Workspace setting saved successfully"); } catch (error: any) { toast.error(error.details); } }; return (

{t("settings.workspace.self")}

Instance URL

handleInstanceUrlChange(event.target.value)} />

{t("settings.workspace.custom-style")}