forked from github/plane
fix: AI Assistance hide/unhide depending on the configuration (#2825)
* fix: gpt error handlijng * fix: enabling ai assistance only when it is configured.
This commit is contained in:
parent
734f27122b
commit
666d46de58
@ -92,7 +92,7 @@ export const GptAssistantModal: React.FC<Props> = (props) => {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
const error = err?.data?.error;
|
const error = err?.data?.error;
|
||||||
|
|
||||||
if (err.status === 429)
|
if (err?.status === 429)
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
|
@ -31,6 +31,8 @@ import type { IUser, IIssue, ISearchIssueResponse } from "types";
|
|||||||
// components
|
// components
|
||||||
import { RichTextEditorWithRef } from "@plane/rich-text-editor";
|
import { RichTextEditorWithRef } from "@plane/rich-text-editor";
|
||||||
import useEditorSuggestions from "hooks/use-editor-suggestions";
|
import useEditorSuggestions from "hooks/use-editor-suggestions";
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
|
||||||
const aiService = new AIService();
|
const aiService = new AIService();
|
||||||
const fileService = new FileService();
|
const fileService = new FileService();
|
||||||
@ -89,7 +91,7 @@ interface IssueFormProps {
|
|||||||
)[];
|
)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
export const DraftIssueForm: FC<IssueFormProps> = observer((props) => {
|
||||||
const {
|
const {
|
||||||
handleFormSubmit,
|
handleFormSubmit,
|
||||||
data,
|
data,
|
||||||
@ -100,30 +102,30 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
createMore,
|
createMore,
|
||||||
setCreateMore,
|
setCreateMore,
|
||||||
status,
|
status,
|
||||||
user,
|
|
||||||
fieldsToShow,
|
fieldsToShow,
|
||||||
handleDiscard,
|
handleDiscard,
|
||||||
} = props;
|
} = props;
|
||||||
|
// states
|
||||||
const [stateModal, setStateModal] = useState(false);
|
const [stateModal, setStateModal] = useState(false);
|
||||||
const [labelModal, setLabelModal] = useState(false);
|
const [labelModal, setLabelModal] = useState(false);
|
||||||
const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false);
|
const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false);
|
||||||
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
||||||
|
|
||||||
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
||||||
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
||||||
|
// hooks
|
||||||
const { setValue: setLocalStorageValue } = useLocalStorage("draftedIssue", {});
|
const { setValue: setLocalStorageValue } = useLocalStorage("draftedIssue", {});
|
||||||
|
const { setToastAlert } = useToast();
|
||||||
|
const editorSuggestions = useEditorSuggestions();
|
||||||
|
// refs
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
|
// router
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug } = router.query;
|
const { workspaceSlug } = router.query;
|
||||||
|
// store
|
||||||
const { setToastAlert } = useToast();
|
const {
|
||||||
|
appConfig: { envConfig },
|
||||||
const editorSuggestions = useEditorSuggestions();
|
} = useMobxStore();
|
||||||
|
// form info
|
||||||
const {
|
const {
|
||||||
formState: { errors, isSubmitting },
|
formState: { errors, isSubmitting },
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -440,6 +442,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{envConfig?.has_openai_configured && (
|
||||||
<GptAssistantModal
|
<GptAssistantModal
|
||||||
isOpen={gptAssistantModal}
|
isOpen={gptAssistantModal}
|
||||||
handleClose={() => {
|
handleClose={() => {
|
||||||
@ -455,6 +458,7 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
}}
|
}}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
@ -623,4 +627,4 @@ export const DraftIssueForm: FC<IssueFormProps> = (props) => {
|
|||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
@ -94,28 +94,29 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
|
|||||||
fieldsToShow,
|
fieldsToShow,
|
||||||
handleFormDirty,
|
handleFormDirty,
|
||||||
} = props;
|
} = props;
|
||||||
|
// states
|
||||||
const [stateModal, setStateModal] = useState(false);
|
const [stateModal, setStateModal] = useState(false);
|
||||||
const [labelModal, setLabelModal] = useState(false);
|
const [labelModal, setLabelModal] = useState(false);
|
||||||
const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false);
|
const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false);
|
||||||
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
const [selectedParentIssue, setSelectedParentIssue] = useState<ISearchIssueResponse | null>(null);
|
||||||
|
|
||||||
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
||||||
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
||||||
|
// refs
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
|
// router
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug } = router.query;
|
const { workspaceSlug } = router.query;
|
||||||
|
// store
|
||||||
const { user: userStore } = useMobxStore();
|
const {
|
||||||
|
user: userStore,
|
||||||
|
appConfig: { envConfig },
|
||||||
|
} = useMobxStore();
|
||||||
const user = userStore.currentUser;
|
const user = userStore.currentUser;
|
||||||
|
console.log("envConfig", envConfig);
|
||||||
|
// hooks
|
||||||
const editorSuggestion = useEditorSuggestions();
|
const editorSuggestion = useEditorSuggestions();
|
||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
// form info
|
||||||
const {
|
const {
|
||||||
formState: { errors, isSubmitting, isDirty },
|
formState: { errors, isSubmitting, isDirty },
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -396,6 +397,7 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
{envConfig?.has_openai_configured && (
|
||||||
<GptAssistantModal
|
<GptAssistantModal
|
||||||
isOpen={gptAssistantModal}
|
isOpen={gptAssistantModal}
|
||||||
handleClose={() => {
|
handleClose={() => {
|
||||||
@ -411,6 +413,7 @@ export const IssueForm: FC<IssueFormProps> = observer((props) => {
|
|||||||
}}
|
}}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
@ -19,6 +19,7 @@ import { IUser, IPageBlock } from "types";
|
|||||||
// fetch-keys
|
// fetch-keys
|
||||||
import { PAGE_BLOCKS_LIST } from "constants/fetch-keys";
|
import { PAGE_BLOCKS_LIST } from "constants/fetch-keys";
|
||||||
import useEditorSuggestions from "hooks/use-editor-suggestions";
|
import useEditorSuggestions from "hooks/use-editor-suggestions";
|
||||||
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
@ -40,19 +41,24 @@ const pagesService = new PageService();
|
|||||||
const issueService = new IssueService();
|
const issueService = new IssueService();
|
||||||
const fileService = new FileService();
|
const fileService = new FileService();
|
||||||
|
|
||||||
export const CreateUpdateBlockInline: FC<Props> = ({ handleClose, data, handleAiAssistance, setIsSyncing, focus }) => {
|
export const CreateUpdateBlockInline: FC<Props> = (props) => {
|
||||||
|
const { handleClose, data, handleAiAssistance, setIsSyncing, focus } = props;
|
||||||
|
// states
|
||||||
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
||||||
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
||||||
|
// store
|
||||||
|
const {
|
||||||
|
appConfig: { envConfig },
|
||||||
|
} = useMobxStore();
|
||||||
|
// refs
|
||||||
const editorRef = useRef<any>(null);
|
const editorRef = useRef<any>(null);
|
||||||
|
// router
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, pageId } = router.query;
|
const { workspaceSlug, projectId, pageId } = router.query;
|
||||||
|
// hooks
|
||||||
const editorSuggestion = useEditorSuggestions();
|
const editorSuggestion = useEditorSuggestions();
|
||||||
|
|
||||||
const { setToastAlert } = useToast();
|
const { setToastAlert } = useToast();
|
||||||
|
// form info
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
@ -222,9 +228,7 @@ export const CreateUpdateBlockInline: FC<Props> = ({ handleClose, data, handleAi
|
|||||||
else handleSubmit(createPageBlock)();
|
else handleSubmit(createPageBlock)();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("keydown", submitForm);
|
window.addEventListener("keydown", submitForm);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener("keydown", submitForm);
|
window.removeEventListener("keydown", submitForm);
|
||||||
};
|
};
|
||||||
@ -345,6 +349,7 @@ export const CreateUpdateBlockInline: FC<Props> = ({ handleClose, data, handleAi
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
{envConfig?.has_openai_configured && (
|
||||||
<GptAssistantModal
|
<GptAssistantModal
|
||||||
block={data ? data : undefined}
|
block={data ? data : undefined}
|
||||||
isOpen={gptAssistantModal}
|
isOpen={gptAssistantModal}
|
||||||
@ -365,6 +370,7 @@ export const CreateUpdateBlockInline: FC<Props> = ({ handleClose, data, handleAi
|
|||||||
}}
|
}}
|
||||||
projectId={projectId?.toString() ?? ""}
|
projectId={projectId?.toString() ?? ""}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { FC, useState } from "react";
|
import { FC } from "react";
|
||||||
import { ToggleSwitch } from "@plane/ui";
|
import { ToggleSwitch } from "@plane/ui";
|
||||||
import { Pencil, XCircle } from "lucide-react";
|
|
||||||
import { IWebhook } from "types";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { RootStore } from "store/root";
|
import { RootStore } from "store/root";
|
||||||
import { useMobxStore } from "lib/mobx/store-provider";
|
import { useMobxStore } from "lib/mobx/store-provider";
|
||||||
|
// types
|
||||||
|
import { IWebhook } from "types";
|
||||||
|
|
||||||
interface IWebhookListItem {
|
interface IWebhookListItem {
|
||||||
workspaceSlug: string;
|
workspaceSlug: string;
|
||||||
|
2
web/types/app.d.ts
vendored
2
web/types/app.d.ts
vendored
@ -11,4 +11,6 @@ export interface IAppConfig {
|
|||||||
slack_client_id: string | null;
|
slack_client_id: string | null;
|
||||||
posthog_api_key: string | null;
|
posthog_api_key: string | null;
|
||||||
posthog_host: string | null;
|
posthog_host: string | null;
|
||||||
|
has_openai_configured: boolean;
|
||||||
|
has_unsplash_configured: boolean;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user