fix: show notification if api key missing

This commit is contained in:
BetaHuhn 2023-08-30 18:20:22 +02:00
parent 066c697438
commit d07b23cdbf
2 changed files with 19 additions and 1 deletions

View file

@ -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={<IconPlus size={20} />}
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,

View file

@ -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({
<ActionIcon
size="lg"
onClick={async () => {
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",