diff --git a/apps/client/src/features/workspace/components/settings/components/ai-chat-settings.tsx b/apps/client/src/features/workspace/components/settings/components/ai-chat-settings.tsx new file mode 100644 index 00000000..e09f169a --- /dev/null +++ b/apps/client/src/features/workspace/components/settings/components/ai-chat-settings.tsx @@ -0,0 +1,61 @@ +import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts"; +import { useAtom } from "jotai"; +import { useState } from "react"; +import { updateWorkspace } from "@/features/workspace/services/workspace-service.ts"; +import { Switch, Stack } from "@mantine/core"; +import { notifications } from "@mantine/notifications"; +import useUserRole from "@/hooks/use-user-role.tsx"; +import { useTranslation } from "react-i18next"; + +export default function AiChatSettings() { + const { t } = useTranslation(); + const [workspace, setWorkspace] = useAtom(workspaceAtom); + const { isAdmin } = useUserRole(); + + const [checked, setChecked] = useState( + workspace?.settings?.ai?.chat ?? false, + ); + const [isLoading, setIsLoading] = useState(false); + + async function handleToggle(value: boolean) { + setIsLoading(true); + const previous = checked; + setChecked(value); // optimistic update + try { + const updated = await updateWorkspace({ aiChat: value }); + // Force settings.ai.chat to the new value so the atom is consistent + // even if the response shape omits it. + setWorkspace({ + ...updated, + settings: { + ...updated.settings, + ai: { ...updated.settings?.ai, chat: value }, + }, + }); + notifications.show({ message: t("Updated successfully") }); + } catch (err) { + console.log(err); + setChecked(previous); // revert on failure + notifications.show({ + message: t("Failed to update data"), + color: "red", + }); + } finally { + setIsLoading(false); + } + } + + return ( + + handleToggle(event.currentTarget.checked)} + /> + + ); +} diff --git a/apps/client/src/features/workspace/types/workspace.types.ts b/apps/client/src/features/workspace/types/workspace.types.ts index c556cea1..7ea544cc 100644 --- a/apps/client/src/features/workspace/types/workspace.types.ts +++ b/apps/client/src/features/workspace/types/workspace.types.ts @@ -23,6 +23,7 @@ export interface IWorkspace { generativeAi?: boolean; disablePublicSharing?: boolean; mcpEnabled?: boolean; + aiChat?: boolean; trashRetentionDays?: number; restrictApiToAdmins?: boolean; allowMemberTemplates?: boolean; diff --git a/apps/client/src/pages/settings/workspace/workspace-settings.tsx b/apps/client/src/pages/settings/workspace/workspace-settings.tsx index bed8f6f8..ca697bf2 100644 --- a/apps/client/src/pages/settings/workspace/workspace-settings.tsx +++ b/apps/client/src/pages/settings/workspace/workspace-settings.tsx @@ -3,6 +3,7 @@ import WorkspaceNameForm from "@/features/workspace/components/settings/componen import WorkspaceIcon from "@/features/workspace/components/settings/components/workspace-icon.tsx"; import McpSettings from "@/features/workspace/components/settings/components/mcp-settings.tsx"; import AiProviderSettings from "@/features/workspace/components/settings/components/ai-provider-settings.tsx"; +import AiChatSettings from "@/features/workspace/components/settings/components/ai-chat-settings.tsx"; import AiMcpServers from "@/features/workspace/components/settings/components/ai-mcp-servers.tsx"; import { useTranslation } from "react-i18next"; import { getAppName } from "@/lib/config.ts"; @@ -36,6 +37,11 @@ export default function WorkspaceSettings() { + + + + +