aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/new/onboarding/page.tsx
blob: 1b4962e4f53308c5d3fca46cf6af62c7b196bbcf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
"use client"

import { useSearchParams } from "next/navigation"
import { motion, AnimatePresence } from "motion/react"
import { useState, useEffect } from "react"
import { useAuth } from "@lib/auth-context"
import { cn } from "@lib/utils"

import { InputStep } from "../../../components/new/onboarding/welcome/input-step"
import { GreetingStep } from "../../../components/new/onboarding/welcome/greeting-step"
import { WelcomeStep } from "../../../components/new/onboarding/welcome/welcome-step"
import { ContinueStep } from "../../../components/new/onboarding/welcome/continue-step"
import { FeaturesStep } from "../../../components/new/onboarding/welcome/features-step"
import { ProfileStep } from "../../../components/new/onboarding/welcome/profile-step"
import { RelatableQuestion } from "../../../components/new/onboarding/setup/relatable-question"
import { IntegrationsStep } from "../../../components/new/onboarding/setup/integrations-step"

import { InitialHeader } from "@/components/initial-header"
import { SetupHeader } from "../../../components/new/onboarding/setup/header"
import { ChatSidebar } from "../../../components/new/onboarding/setup/chat-sidebar"
import { Logo } from "@ui/assets/Logo"
import NovaOrb from "@/components/nova/nova-orb"
import { AnimatedGradientBackground } from "@/components/new/animated-gradient-background"

function UserSupermemory({ name }: { name: string }) {
	return (
		<motion.div
			className="absolute inset-0 top-[-34px] flex items-center justify-center z-10"
			initial={{ opacity: 0, y: 0 }}
			animate={{ opacity: 1, y: 0 }}
			exit={{ opacity: 0, y: 0 }}
			transition={{ duration: 1, ease: "easeOut" }}
		>
			<Logo className="h-14 text-white" />
			<div className="flex flex-col items-start justify-center ml-4">
				<p className="text-white text-[25px] font-medium leading-none">
					{name.split(" ")[0]}'s
				</p>
				<p className="text-white font-bold text-4xl leading-none -mt-2">
					supermemory
				</p>
			</div>
		</motion.div>
	)
}

export default function OnboardingPage() {
	const searchParams = useSearchParams()
	const { user } = useAuth()

	const flow = searchParams.get("flow") as "welcome" | "setup" | null
	const step = searchParams.get("step") as string | null

	const [name, setName] = useState(user?.name ?? "")
	const [isSubmitting, setIsSubmitting] = useState(false)
	const [memoryFormData, setMemoryFormData] = useState<{
		twitter: string
		linkedin: string
		description: string
		otherLinks: string[]
	} | null>(null)
	const [showWelcomeContent, setShowWelcomeContent] = useState(false)

	const currentFlow = flow || "welcome"
	const currentStep = step || "input"

	useEffect(() => {
		if (user?.name) {
			setName(user.name)
			localStorage.setItem("username", user.name)
		}
	}, [user?.name])

	useEffect(() => {
		if (currentFlow === "welcome" && currentStep === "input") {
			setShowWelcomeContent(false)
			const timer = setTimeout(() => {
				setShowWelcomeContent(true)
			}, 1250)
			return () => clearTimeout(timer)
		}
	}, [currentFlow, currentStep])

	useEffect(() => {
		if (currentFlow !== "welcome") return

		const timers: NodeJS.Timeout[] = []

		switch (currentStep) {
			case "greeting":
				timers.push(
					setTimeout(() => {
						// Auto-advance to welcome step
						window.history.replaceState(
							null,
							"",
							"/new/onboarding?flow=welcome&step=welcome",
						)
					}, 2000),
				)
				break
			case "welcome":
				timers.push(
					setTimeout(() => {
						// Auto-advance to username step
						window.history.replaceState(
							null,
							"",
							"/new/onboarding?flow=welcome&step=username",
						)
					}, 2000),
				)
				break
		}

		return () => {
			timers.forEach(clearTimeout)
		}
	}, [currentStep, currentFlow])

	const handleSubmit = () => {
		localStorage.setItem("username", name)
		if (name.trim()) {
			setIsSubmitting(true)
			window.history.replaceState(
				null,
				"",
				"/new/onboarding?flow=welcome&step=greeting",
			)
			setIsSubmitting(false)
		}
	}

	const renderWelcomeStep = () => {
		switch (currentStep) {
			case "input":
				return (
					<InputStep
						key="input"
						name={name}
						setName={setName}
						handleSubmit={handleSubmit}
						isSubmitting={isSubmitting}
					/>
				)
			case "greeting":
				return <GreetingStep key="greeting" name={name} />
			case "welcome":
				return <WelcomeStep key="welcome" />
			case "username":
				return <ContinueStep key="username" />
			case "features":
				return <FeaturesStep key="features" />
			case "memories":
				return <ProfileStep key="profile" onSubmit={setMemoryFormData} />
			default:
				return null
		}
	}

	const renderSetupStep = () => {
		switch (currentStep) {
			case "relatable":
				return <RelatableQuestion key="relatable" />
			case "integrations":
				return <IntegrationsStep key="integrations" />
			default:
				return null
		}
	}

	const isWelcomeFlow = currentFlow === "welcome"
	const isSetupFlow = currentFlow === "setup"

	const minimizeNovaOrb =
		isWelcomeFlow && ["features", "memories"].includes(currentStep)
	const novaSize = currentStep === "memories" ? 150 : 300

	const showUserSupermemory = isWelcomeFlow && currentStep === "username"

	return (
		<div className="h-screen overflow-hidden bg-black">
			{isWelcomeFlow && (
				<InitialHeader
					showUserSupermemory={
						currentStep === "features" || currentStep === "memories"
					}
					name={name}
				/>
			)}
			{isSetupFlow && <SetupHeader />}

			{isSetupFlow && <AnimatedGradientBackground animateFromBottom={false} />}

			{isWelcomeFlow && currentStep === "input" && (
				<AnimatedGradientBackground animateFromBottom={true} />
			)}

			{isWelcomeFlow && showWelcomeContent && (
				<div className="fixed inset-0 flex flex-col items-center justify-center overflow-y-auto">
					<motion.div
						className="absolute inset-0 bg-[url('/bg-rectangle.png')] bg-cover bg-center bg-no-repeat pointer-events-none"
						transition={{ duration: 0.75, ease: "easeOut", bounce: 0 }}
						style={{
							mixBlendMode: "soft-light",
							opacity: 0.6,
						}}
					/>
					<motion.div
						className={cn(
							"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-10 flex flex-col items-center justify-center",
						)}
						animate={{
							gap: minimizeNovaOrb ? 0 : 16,
						}}
						transition={{
							duration: 0.6,
							ease: "easeOut",
						}}
					>
						<motion.div
							animate={{
								scale:
									currentStep === "features"
										? 0.7
										: currentStep === "memories"
											? 0.4
											: 1,
								padding: minimizeNovaOrb ? 0 : 48,
								paddingTop: 0,
							}}
							transition={{
								duration: 0.8,
								ease: "easeOut",
								delay: 0.2,
							}}
							className="relative"
						>
							<NovaOrb size={novaSize} />
							{showUserSupermemory && <UserSupermemory name={name} />}
						</motion.div>

						<AnimatePresence mode="wait">{renderWelcomeStep()}</AnimatePresence>
					</motion.div>
				</div>
			)}

			{isSetupFlow && (
				<main className="relative min-h-screen">
					<div className="relative z-10">
						<div className="flex flex-row h-[calc(100vh-90px)] relative">
							<div className="flex-1 flex flex-col items-center justify-start p-8">
								<AnimatePresence mode="wait">
									{renderSetupStep()}
								</AnimatePresence>
							</div>

							<AnimatePresence mode="popLayout">
								<ChatSidebar formData={memoryFormData} />
							</AnimatePresence>
						</div>
					</div>
				</main>
			)}
		</div>
	)
}