| 1 | import { OnboardingModes } from "core/protocol/core"; |
| 2 | import { useAppSelector } from "../../redux/hooks"; |
| 3 | import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; |
| 4 | import Alert from "../gui/Alert"; |
| 5 | import { ReusableCard } from "../ReusableCard"; |
| 6 | import { OnboardingCardLanding } from "./components/OnboardingCardLanding"; |
| 7 | import { OnboardingCardTabs } from "./components/OnboardingCardTabs"; |
| 8 | import { OnboardingLocalTab } from "./components/OnboardingLocalTab"; |
| 9 | import { OnboardingModelsAddOnTab } from "./components/OnboardingModelsAddOnTab"; |
| 10 | import { OnboardingProvidersTab } from "./components/OnboardingProvidersTab"; |
| 11 | import { useOnboardingCard } from "./hooks/useOnboardingCard"; |
| 12 | |
| 13 | export interface OnboardingCardState { |
| 14 | show?: boolean; |
| 15 | activeTab?: OnboardingModes; |
| 16 | } |
| 17 | |
| 18 | interface OnboardingCardProps { |
| 19 | isDialog?: boolean; |
| 20 | showFreeTrialExceededAlert?: boolean; |
| 21 | } |
| 22 | |
| 23 | export function OnboardingCard({ |
| 24 | isDialog, |
| 25 | showFreeTrialExceededAlert, |
| 26 | }: OnboardingCardProps) { |
| 27 | const { activeTab, close, setActiveTab } = useOnboardingCard(); |
| 28 | const config = useAppSelector((store) => store.config.config); |
| 29 | |
| 30 | if (getLocalStorage("onboardingStatus") === undefined) { |
| 31 | setLocalStorage("onboardingStatus", "Started"); |
| 32 | } |
| 33 | |
| 34 | function renderTabContent() { |
| 35 | switch (activeTab) { |
| 36 | case OnboardingModes.API_KEY: |
| 37 | return <OnboardingProvidersTab />; |
| 38 | case OnboardingModes.LOCAL: |
| 39 | return <OnboardingLocalTab />; |
| 40 | case OnboardingModes.MODELS_ADD_ON: |
| 41 | return <OnboardingModelsAddOnTab />; |
| 42 | default: |
| 43 | return <OnboardingProvidersTab />; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (activeTab) { |
| 48 | return ( |
| 49 | <ReusableCard |
| 50 | showCloseButton={!isDialog && !!config.modelsByRole.chat.length} |
| 51 | onClose={close} |
| 52 | testId="onboarding-card" |
| 53 | > |
| 54 | {showFreeTrialExceededAlert && ( |
| 55 | <div className="mb-3 mt-4"> |
| 56 | <Alert> |
| 57 | <h4 className="mb-1 mt-0 text-sm font-semibold"> |
| 58 | Free trial completed |
| 59 | </h4> |
| 60 | <span className="text-xs"> |
| 61 | To keep using Continue, select an option below to setup your |
| 62 | models |
| 63 | </span> |
| 64 | </Alert> |
| 65 | </div> |
| 66 | )} |
| 67 | <OnboardingCardTabs |
| 68 | activeTab={activeTab} |
| 69 | onTabClick={setActiveTab} |
| 70 | showFreeTrialExceededAlert |
| 71 | /> |
| 72 | {renderTabContent()} |
| 73 | </ReusableCard> |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | return ( |
| 78 | <ReusableCard |
| 79 | showCloseButton={!isDialog && !!config.modelsByRole.chat.length} |
| 80 | onClose={close} |
| 81 | > |
| 82 | <div className="flex h-full w-full items-center justify-center"> |
| 83 | <OnboardingCardLanding |
| 84 | onSelectConfigure={() => setActiveTab(OnboardingModes.API_KEY)} |
| 85 | isDialog={isDialog} |
| 86 | /> |
| 87 | </div> |
| 88 | </ReusableCard> |
| 89 | ); |
| 90 | } |