-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { Button, Divider, Text } from "@tremor/react"; | ||
import { Modal } from "../../Modal"; | ||
import Cookies from "js-cookie"; | ||
import { useRouter } from "next/navigation"; | ||
import { COMPLETED_WELCOME_FLOW_COOKIE } from "./constants"; | ||
import { useEffect, useState } from "react"; | ||
import { ApiKeyForm } from "@/components/llm/ApiKeyForm"; | ||
import { WellKnownLLMProviderDescriptor } from "@/app/admin/configuration/llm/interfaces"; | ||
import { checkLlmProvider } from "./lib"; | ||
import { User } from "@/lib/types"; | ||
import { useProviderStatus } from "@/components/chat_search/ProviderContext"; | ||
|
||
import { usePopup } from "@/components/admin/connectors/Popup"; | ||
|
||
function setWelcomeFlowComplete() { | ||
Cookies.set(COMPLETED_WELCOME_FLOW_COOKIE, "true", { expires: 365 }); | ||
} | ||
|
||
export function _CompletedWelcomeFlowDummyComponent() { | ||
setWelcomeFlowComplete(); | ||
return null; | ||
} | ||
|
||
export function _WelcomeModal({ user }: { user: User | null }) { | ||
const router = useRouter(); | ||
|
||
const [providerOptions, setProviderOptions] = useState< | ||
WellKnownLLMProviderDescriptor[] | ||
>([]); | ||
const { popup, setPopup } = usePopup(); | ||
|
||
const { refreshProviderInfo } = useProviderStatus(); | ||
const clientSetWelcomeFlowComplete = async () => { | ||
setWelcomeFlowComplete(); | ||
refreshProviderInfo(); | ||
router.refresh(); | ||
}; | ||
|
||
useEffect(() => { | ||
async function fetchProviderInfo() { | ||
const { options } = await checkLlmProvider(user); | ||
setProviderOptions(options); | ||
} | ||
|
||
fetchProviderInfo(); | ||
}, [user]); | ||
|
||
// We should always have options | ||
if (providerOptions.length === 0) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
{popup} | ||
|
||
<Modal | ||
title={"Welcome to Danswer!"} | ||
width="w-full max-h-[900px] overflow-y-scroll max-w-3xl" | ||
> | ||
<div> | ||
<Text className="mb-4"> | ||
Danswer brings all your company's knowledge to your fingertips, | ||
ready to be accessed instantly. | ||
</Text> | ||
<Text className="mb-4"> | ||
To get started, we need to set up an API key for the Language Model | ||
(LLM) provider. This key allows Danswer to interact with the AI | ||
model, enabling intelligent responses to your queries. | ||
</Text> | ||
|
||
<div className="max-h-[900px] overflow-y-scroll"> | ||
<ApiKeyForm | ||
// Don't show success message on initial setup | ||
hideSuccess | ||
setPopup={setPopup} | ||
onSuccess={clientSetWelcomeFlowComplete} | ||
providerOptions={providerOptions} | ||
/> | ||
</div> | ||
</div> | ||
</Modal> | ||
</> | ||
); | ||
} |
24 changes: 24 additions & 0 deletions
24
web/src/components/initialSetup/welcome/WelcomeModalWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { cookies } from "next/headers"; | ||
import { | ||
_CompletedWelcomeFlowDummyComponent, | ||
_WelcomeModal, | ||
} from "./WelcomeModal"; | ||
import { COMPLETED_WELCOME_FLOW_COOKIE } from "./constants"; | ||
import { User } from "@/lib/types"; | ||
|
||
export function hasCompletedWelcomeFlowSS() { | ||
const cookieStore = cookies(); | ||
return ( | ||
cookieStore.get(COMPLETED_WELCOME_FLOW_COOKIE)?.value?.toLowerCase() === | ||
"true" | ||
); | ||
} | ||
|
||
export function WelcomeModal({ user }: { user: User | null }) { | ||
const hasCompletedWelcomeFlow = hasCompletedWelcomeFlowSS(); | ||
if (hasCompletedWelcomeFlow) { | ||
return <_CompletedWelcomeFlowDummyComponent />; | ||
} | ||
|
||
return <_WelcomeModal user={user} />; | ||
} |