mirror of
https://github.com/docmost/docmost.git
synced 2026-05-07 14:43:06 +08:00
b76f5adaad
* feat(ee): AI menu * - Add insert below and copy option * prebuild @editor-ext * sanitize output * clear existing output * switch to menu component * refactor directory * separator * refactor directory * support more languages * pass markdown to model * fix: close AI menu on page change * enhance text input and preview styling * fix: Use absolute positioning for the AI menu * make preview scrollable * activation controls * enhance bubble menu * sync * set width * fix line break * switch terminologies * cloud * buffer --------- Co-authored-by: Philipinho <16838612+Philipinho@users.noreply.github.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { Group, Text, Switch } from "@mantine/core";
|
|
import { useAtom } from "jotai";
|
|
import { workspaceAtom } from "@/features/user/atoms/current-user-atom.ts";
|
|
import React, { useState } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { updateWorkspace } from "@/features/workspace/services/workspace-service.ts";
|
|
import { notifications } from "@mantine/notifications";
|
|
import { useIsCloudEE } from "@/hooks/use-is-cloud-ee.tsx";
|
|
|
|
export default function EnableGenerativeAi() {
|
|
const { t } = useTranslation();
|
|
const [workspace, setWorkspace] = useAtom(workspaceAtom);
|
|
const [checked, setChecked] = useState(workspace?.settings?.ai?.generative);
|
|
const hasAccess = useIsCloudEE();
|
|
|
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
const value = event.currentTarget.checked;
|
|
try {
|
|
const updatedWorkspace = await updateWorkspace({ generativeAi: value });
|
|
setChecked(value);
|
|
setWorkspace(updatedWorkspace);
|
|
} catch (err) {
|
|
notifications.show({
|
|
message: err?.response?.data?.message,
|
|
color: "red",
|
|
});
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Group justify="space-between" wrap="nowrap" gap="xl">
|
|
<div>
|
|
<Text size="md">{t("Generative AI (Ask AI)")}</Text>
|
|
<Text size="sm" c="dimmed">
|
|
{t(
|
|
"Enable AI-powered content generation in the editor. Allows users to generate, improve, translate and transform text.",
|
|
)}
|
|
</Text>
|
|
</div>
|
|
|
|
<Switch
|
|
defaultChecked={checked}
|
|
onChange={handleChange}
|
|
disabled={!hasAccess}
|
|
/>
|
|
</Group>
|
|
);
|
|
}
|