From d07b23cdbfbc9463a69f8c7892c10e070e1c65f5 Mon Sep 17 00:00:00 2001 From: BetaHuhn Date: Wed, 30 Aug 2023 18:20:22 +0200 Subject: [PATCH] fix: show notification if api key missing --- src/components/Layout.tsx | 10 ++++++++++ src/components/Prompts.tsx | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 52d8a10..125c258 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -32,6 +32,7 @@ import { SettingsModal } from "./SettingsModal"; import { config } from "../utils/config"; import { ChatContext, ChatsContext, PromptsContext, SettingsContext } from "../hooks/contexts"; import { ChatHeader } from "./ChatHeader"; +import { notifications } from "@mantine/notifications"; declare global { interface Window { @@ -236,6 +237,15 @@ export function Layout() { fullWidth leftIcon={} onClick={async () => { + if (!settings?.openAiApiKey) { + notifications.show({ + title: "Error", + color: "red", + message: "OpenAI API Key is not defined. Please set your API Key", + }); + return; + }; + const item = await detaDB.chats.put({ description: "New Chat", totalTokens: 0, diff --git a/src/components/Prompts.tsx b/src/components/Prompts.tsx index 7eb73b1..3cda42d 100644 --- a/src/components/Prompts.tsx +++ b/src/components/Prompts.tsx @@ -6,6 +6,7 @@ import { Chat, detaDB, generateKey } from "../db"; import { DeletePromptModal } from "./DeletePromptModal"; import { EditPromptModal } from "./EditPromptModal"; import { useChats, usePrompts, useSettings } from "../hooks/contexts"; +import { notifications } from "@mantine/notifications"; export function Prompts({ onPlay, @@ -82,7 +83,14 @@ export function Prompts({ { - if (!settings?.openAiApiKey) return; + if (!settings?.openAiApiKey) { + notifications.show({ + title: "Error", + color: "red", + message: "OpenAI API Key is not defined. Please set your API Key", + }); + return; + }; const item = await detaDB.chats.put({ description: prompt.title ? `New ${prompt.title} Chat` : "New Chat",