| 1 | import { OnboardingModes } from "core/protocol/core"; |
| 2 | import { useAppSelector } from "../../redux/hooks"; |
| 3 | import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; |
| 4 | import { ReusableCard } from "../ReusableCard"; |
| 5 | import { |
| 6 | OnboardingCardLanding, |
| 7 | OnboardingCardTabs, |
| 8 | OnboardingLocalTab, |
| 9 | OnboardingProvidersTab, |
| 10 | } from "./components"; |
| 11 | import { useOnboardingCard } from "./hooks"; |
| 12 | |
| 13 | export interface OnboardingCardState { |
| 14 | show?: boolean; |
| 15 | activeTab?: OnboardingModes; |
| 16 | } |
| 17 | |
| 18 | interface OnboardingCardProps { |
| 19 | isDialog?: boolean; |
| 20 | } |
| 21 | |
| 22 | export function OnboardingCard({ isDialog }: OnboardingCardProps) { |
| 23 | const { activeTab, close, setActiveTab } = useOnboardingCard(); |
| 24 | const config = useAppSelector((store) => store.config.config); |
| 25 | |
| 26 | if (getLocalStorage("onboardingStatus") === undefined) { |
| 27 | setLocalStorage("onboardingStatus", "Started"); |
| 28 | } |
| 29 | |
| 30 | function renderTabContent() { |
| 31 | switch (activeTab) { |
| 32 | case OnboardingModes.API_KEY: |
| 33 | return <OnboardingProvidersTab />; |
| 34 | case OnboardingModes.LOCAL: |
| 35 | return <OnboardingLocalTab />; |
| 36 | default: |
| 37 | return <OnboardingProvidersTab />; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if (activeTab) { |
| 42 | return ( |
| 43 | <ReusableCard |
| 44 | showCloseButton={!isDialog && !!config.modelsByRole.chat.length} |
| 45 | onClose={close} |
| 46 | testId="onboarding-card" |
| 47 | > |
| 48 | <OnboardingCardTabs activeTab={activeTab} onTabClick={setActiveTab} /> |
| 49 | {renderTabContent()} |
| 50 | </ReusableCard> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | return ( |
| 55 | <ReusableCard |
| 56 | showCloseButton={!isDialog && !!config.modelsByRole.chat.length} |
| 57 | onClose={close} |
| 58 | > |
| 59 | <div className="flex h-full w-full items-center justify-center"> |
| 60 | <OnboardingCardLanding |
| 61 | onSelectConfigure={() => setActiveTab(OnboardingModes.API_KEY)} |
| 62 | isDialog={isDialog} |
| 63 | /> |
| 64 | </div> |
| 65 | </ReusableCard> |
| 66 | ); |
| 67 | } |