diff --git a/web/components/core/modals/gpt-assistant-modal.tsx b/web/components/core/modals/gpt-assistant-modal.tsx index d677e7daa..82b082c29 100644 --- a/web/components/core/modals/gpt-assistant-modal.tsx +++ b/web/components/core/modals/gpt-assistant-modal.tsx @@ -92,7 +92,7 @@ export const GptAssistantModal: React.FC = (props) => { .catch((err) => { const error = err?.data?.error; - if (err.status === 429) + if (err?.status === 429) setToastAlert({ type: "error", title: "Error!", diff --git a/web/components/issues/draft-issue-form.tsx b/web/components/issues/draft-issue-form.tsx index e80c4609a..be9857dc8 100644 --- a/web/components/issues/draft-issue-form.tsx +++ b/web/components/issues/draft-issue-form.tsx @@ -31,6 +31,8 @@ import type { IUser, IIssue, ISearchIssueResponse } from "types"; // components import { RichTextEditorWithRef } from "@plane/rich-text-editor"; 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 fileService = new FileService(); @@ -89,7 +91,7 @@ interface IssueFormProps { )[]; } -export const DraftIssueForm: FC = (props) => { +export const DraftIssueForm: FC = observer((props) => { const { handleFormSubmit, data, @@ -100,30 +102,30 @@ export const DraftIssueForm: FC = (props) => { createMore, setCreateMore, status, - user, fieldsToShow, handleDiscard, } = props; - + // states const [stateModal, setStateModal] = useState(false); const [labelModal, setLabelModal] = useState(false); const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false); const [selectedParentIssue, setSelectedParentIssue] = useState(null); - const [gptAssistantModal, setGptAssistantModal] = useState(false); const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); - + // hooks const { setValue: setLocalStorageValue } = useLocalStorage("draftedIssue", {}); - + const { setToastAlert } = useToast(); + const editorSuggestions = useEditorSuggestions(); + // refs const editorRef = useRef(null); - + // router const router = useRouter(); const { workspaceSlug } = router.query; - - const { setToastAlert } = useToast(); - - const editorSuggestions = useEditorSuggestions(); - + // store + const { + appConfig: { envConfig }, + } = useMobxStore(); + // form info const { formState: { errors, isSubmitting }, handleSubmit, @@ -440,21 +442,23 @@ export const DraftIssueForm: FC = (props) => { /> )} /> - { - setGptAssistantModal(false); - // this is done so that the title do not reset after gpt popover closed - reset(getValues()); - }} - inset="top-2 left-0" - content="" - htmlContent={watch("description_html")} - onResponse={(response) => { - handleAiAssistance(response); - }} - projectId={projectId} - /> + {envConfig?.has_openai_configured && ( + { + setGptAssistantModal(false); + // this is done so that the title do not reset after gpt popover closed + reset(getValues()); + }} + inset="top-2 left-0" + content="" + htmlContent={watch("description_html")} + onResponse={(response) => { + handleAiAssistance(response); + }} + projectId={projectId} + /> + )} )}
@@ -623,4 +627,4 @@ export const DraftIssueForm: FC = (props) => { ); -}; +}); diff --git a/web/components/issues/form.tsx b/web/components/issues/form.tsx index f33d8e6be..454647bfb 100644 --- a/web/components/issues/form.tsx +++ b/web/components/issues/form.tsx @@ -94,28 +94,29 @@ export const IssueForm: FC = observer((props) => { fieldsToShow, handleFormDirty, } = props; - + // states const [stateModal, setStateModal] = useState(false); const [labelModal, setLabelModal] = useState(false); const [parentIssueListModalOpen, setParentIssueListModalOpen] = useState(false); const [selectedParentIssue, setSelectedParentIssue] = useState(null); - const [gptAssistantModal, setGptAssistantModal] = useState(false); const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); - + // refs const editorRef = useRef(null); - + // router const router = useRouter(); const { workspaceSlug } = router.query; - - const { user: userStore } = useMobxStore(); - + // store + const { + user: userStore, + appConfig: { envConfig }, + } = useMobxStore(); const user = userStore.currentUser; - + console.log("envConfig", envConfig); + // hooks const editorSuggestion = useEditorSuggestions(); - const { setToastAlert } = useToast(); - + // form info const { formState: { errors, isSubmitting, isDirty }, handleSubmit, @@ -396,21 +397,23 @@ export const IssueForm: FC = observer((props) => { /> )} /> - { - setGptAssistantModal(false); - // this is done so that the title do not reset after gpt popover closed - reset(getValues()); - }} - inset="top-2 left-0" - content="" - htmlContent={watch("description_html")} - onResponse={(response) => { - handleAiAssistance(response); - }} - projectId={projectId} - /> + {envConfig?.has_openai_configured && ( + { + setGptAssistantModal(false); + // this is done so that the title do not reset after gpt popover closed + reset(getValues()); + }} + inset="top-2 left-0" + content="" + htmlContent={watch("description_html")} + onResponse={(response) => { + handleAiAssistance(response); + }} + projectId={projectId} + /> + )}
)}
diff --git a/web/components/pages/create-update-block-inline.tsx b/web/components/pages/create-update-block-inline.tsx index d2533a967..a18ca204c 100644 --- a/web/components/pages/create-update-block-inline.tsx +++ b/web/components/pages/create-update-block-inline.tsx @@ -19,6 +19,7 @@ import { IUser, IPageBlock } from "types"; // fetch-keys import { PAGE_BLOCKS_LIST } from "constants/fetch-keys"; import useEditorSuggestions from "hooks/use-editor-suggestions"; +import { useMobxStore } from "lib/mobx/store-provider"; type Props = { handleClose: () => void; @@ -40,19 +41,24 @@ const pagesService = new PageService(); const issueService = new IssueService(); const fileService = new FileService(); -export const CreateUpdateBlockInline: FC = ({ handleClose, data, handleAiAssistance, setIsSyncing, focus }) => { +export const CreateUpdateBlockInline: FC = (props) => { + const { handleClose, data, handleAiAssistance, setIsSyncing, focus } = props; + // states const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); const [gptAssistantModal, setGptAssistantModal] = useState(false); - + // store + const { + appConfig: { envConfig }, + } = useMobxStore(); + // refs const editorRef = useRef(null); - + // router const router = useRouter(); const { workspaceSlug, projectId, pageId } = router.query; - + // hooks const editorSuggestion = useEditorSuggestions(); - const { setToastAlert } = useToast(); - + // form info const { handleSubmit, control, @@ -222,9 +228,7 @@ export const CreateUpdateBlockInline: FC = ({ handleClose, data, handleAi else handleSubmit(createPageBlock)(); } }; - window.addEventListener("keydown", submitForm); - return () => { window.removeEventListener("keydown", submitForm); }; @@ -345,26 +349,28 @@ export const CreateUpdateBlockInline: FC = ({ handleClose, data, handleAi
- setGptAssistantModal(false)} - inset="top-8 left-0" - content={watch("description_html")} - htmlContent={watch("description_html")} - onResponse={(response) => { - if (data && handleAiAssistance) { - handleAiAssistance(response); - editorRef.current?.setEditorValue(`${watch("description_html")}

${response}

` ?? ""); - } else { - setValue("description", {}); - setValue("description_html", `${watch("description_html")}

${response}

`); + {envConfig?.has_openai_configured && ( + setGptAssistantModal(false)} + inset="top-8 left-0" + content={watch("description_html")} + htmlContent={watch("description_html")} + onResponse={(response) => { + if (data && handleAiAssistance) { + handleAiAssistance(response); + editorRef.current?.setEditorValue(`${watch("description_html")}

${response}

` ?? ""); + } else { + setValue("description", {}); + setValue("description_html", `${watch("description_html")}

${response}

`); - editorRef.current?.setEditorValue(watch("description_html") ?? ""); - } - }} - projectId={projectId?.toString() ?? ""} - /> + editorRef.current?.setEditorValue(watch("description_html") ?? ""); + } + }} + projectId={projectId?.toString() ?? ""} + /> + )} ); }; diff --git a/web/components/web-hooks/webhooks-list-item.tsx b/web/components/web-hooks/webhooks-list-item.tsx index 4d99e1d22..549caf024 100644 --- a/web/components/web-hooks/webhooks-list-item.tsx +++ b/web/components/web-hooks/webhooks-list-item.tsx @@ -1,10 +1,10 @@ -import { FC, useState } from "react"; +import { FC } from "react"; import { ToggleSwitch } from "@plane/ui"; -import { Pencil, XCircle } from "lucide-react"; -import { IWebhook } from "types"; import Link from "next/link"; import { RootStore } from "store/root"; import { useMobxStore } from "lib/mobx/store-provider"; +// types +import { IWebhook } from "types"; interface IWebhookListItem { workspaceSlug: string; diff --git a/web/types/app.d.ts b/web/types/app.d.ts index d5a7953b1..05f0fc7e5 100644 --- a/web/types/app.d.ts +++ b/web/types/app.d.ts @@ -11,4 +11,6 @@ export interface IAppConfig { slack_client_id: string | null; posthog_api_key: string | null; posthog_host: string | null; + has_openai_configured: boolean; + has_unsplash_configured: boolean; }