11"use client" ;
22
3- import { useState , useEffect } from "react" ;
4- import { useSession } from "@/lib/auth/auth-client " ;
3+ import { useQueryClient } from "@tanstack/ react-query " ;
4+ import { useCustomer } from "autumn-js/react " ;
55import { useRouter } from "next/navigation" ;
6+ import { useEffect , useState } from "react" ;
7+ import { toast } from "sonner" ;
8+ import { completeOnboarding , skipOnboarding } from "@/app/actions/onboarding" ;
9+ import ArrowBoldRight from "@/components/icons/arrow-bold-right" ;
10+ import ChevronDown from "@/components/icons/chevron-down" ;
11+ import CircleCheck from "@/components/icons/circle-check" ;
12+ import CirclePlay from "@/components/icons/circle-play" ;
13+ import Code2 from "@/components/icons/code-2" ;
14+ import Copy2 from "@/components/icons/copy-2" ;
15+ import Envelope2 from "@/components/icons/envelope-2" ;
16+ import Hide from "@/components/icons/hide" ;
17+ import Key2 from "@/components/icons/key-2" ;
18+ import Loader from "@/components/icons/loader" ;
19+ import View from "@/components/icons/view" ;
20+ import { Badge } from "@/components/ui/badge" ;
21+ import { Button } from "@/components/ui/button" ;
622import {
723 Card ,
824 CardContent ,
925 CardDescription ,
1026 CardHeader ,
1127 CardTitle ,
1228} from "@/components/ui/card" ;
13- import { Button } from "@/components/ui/button" ;
14- import { Badge } from "@/components/ui/badge" ;
15- import ArrowBoldRight from "@/components/icons/arrow-bold-right" ;
16- import CircleCheck from "@/components/icons/circle-check" ;
17- import Key2 from "@/components/icons/key-2" ;
18- import View from "@/components/icons/view" ;
19- import Hide from "@/components/icons/hide" ;
2029import { Input } from "@/components/ui/input" ;
2130import { Label } from "@/components/ui/label" ;
2231import { useCreateApiKeyMutation } from "@/features/settings/hooks" ;
23- import { useQueryClient } from "@tanstack/react-query" ;
24- import { toast } from "sonner" ;
25- import { completeOnboarding , skipOnboarding } from "@/app/actions/onboarding" ;
32+ import { client , getEdenErrorMessage } from "@/lib/api/client" ;
33+ import { useSession } from "@/lib/auth/auth-client" ;
2634import { trackSignupConversion } from "@/lib/utils/twitter-tracking" ;
27- import Copy2 from "@/components/icons/copy-2" ;
28- import Code2 from "@/components/icons/code-2" ;
29- import CirclePlay from "@/components/icons/circle-play" ;
30- import ChevronDown from "@/components/icons/chevron-down" ;
31- import Envelope2 from "@/components/icons/envelope-2" ;
32- import { useCustomer } from "autumn-js/react" ;
33- import Loader from "@/components/icons/loader" ;
3435
3536const UPGRADE_PRODUCT_ID = "inbound_default_test" ;
3637const FREE_TIER_PRODUCT_ID = "free_tier" ;
@@ -127,34 +128,30 @@ export default function OnboardingPage() {
127128 setDemoOutput ( "Running demo..." ) ;
128129
129130 try {
130- const response = await fetch ( "/api/v2/onboarding/demo" , {
131- method : "POST" ,
132- headers : { "Content-Type" : "application/json" } ,
133- body : JSON . stringify ( {
134- apiKey : apiKeyPlain ,
135- to : demoEmail ,
136- } ) ,
131+ const { data, error } = await client . api . e2 . onboarding . demo . post ( {
132+ apiKey : apiKeyPlain ,
133+ to : demoEmail ,
137134 } ) ;
138135
139- const result = await response . json ( ) ;
140-
141- if ( response . ok ) {
136+ if ( data && ! error ) {
142137 console . log ( "✅ [DEMO] Email sent successfully:" , {
143- emailId : result . id ,
138+ emailId : data . id ,
144139 sentTo : demoEmail ,
145140 userEmail : session ?. user ?. email ,
146141 } ) ;
147142
148143 setDemoOutput (
149- `✅ Success!\nEmail sent to ${ demoEmail } with ID: ${ result . id } , check your inbox!\n\n🎯 Waiting for your reply...\n\n$ inbound.emails.awaitReply( {demoEmail} )` ,
144+ `✅ Success!\nEmail sent to ${ demoEmail } with ID: ${ data . id } , check your inbox!\n\n🎯 Waiting for your reply...\n\n$ inbound.emails.awaitReply( {demoEmail} )` ,
150145 ) ;
151146 setIsListeningForReply ( true ) ;
152147
153148 console . log ( "🎯 [DEMO] Starting reply polling system..." ) ;
154149 startListeningForReply ( ) ;
155150 } else {
156- console . error ( "❌ [DEMO] Failed to send email:" , result ) ;
157- setDemoOutput ( `❌ Error: ${ result . error || "Unknown error" } ` ) ;
151+ console . error ( "❌ [DEMO] Failed to send email:" , error ) ;
152+ setDemoOutput (
153+ `❌ Error: ${ getEdenErrorMessage ( error , "Unknown error" ) } ` ,
154+ ) ;
158155 }
159156 } catch ( error ) {
160157 setDemoOutput (
@@ -233,15 +230,11 @@ export default function OnboardingPage() {
233230 console . log ( "🔄 [POLLING] Should still poll:" , shouldStillPoll ( ) ) ;
234231
235232 try {
236- const response = await fetch ( "/api/v2/onboarding/check-reply" ) ;
237- console . log (
238- "📡 [POLLING] Response status:" ,
239- response . status ,
240- response . statusText ,
241- ) ;
233+ const { data, error } =
234+ await client . api . e2 . onboarding [ "check-reply" ] . get ( ) ;
235+ console . log ( "📡 [POLLING] Response:" , error ? "error" : "success" ) ;
242236
243- if ( response . ok ) {
244- const data = await response . json ( ) ;
237+ if ( data && ! error ) {
245238 console . log (
246239 "📋 [POLLING] Response data:" ,
247240 JSON . stringify ( data , null , 2 ) ,
@@ -262,7 +255,7 @@ export default function OnboardingPage() {
262255 setPollTimeLeft ( 0 ) ;
263256 setDemoOutput (
264257 ( prev ) =>
265- `${ prev } \n\n🎉 Reply received!\n\nIt looks like you like the ${ data . reply . body } mail client! \n\n` ,
258+ `${ prev } \n\n🎉 Reply received!\n\nIt looks like you like the ${ data . reply ? .body } mail client! \n\n` ,
266259 ) ;
267260 console . log (
268261 "✅ [POLLING] Stopping polling - reply received and processed" ,
@@ -272,11 +265,7 @@ export default function OnboardingPage() {
272265 console . log ( "📭 [POLLING] No reply yet, will continue polling..." ) ;
273266 }
274267 } else {
275- console . error (
276- "❌ [POLLING] API error:" ,
277- response . status ,
278- response . statusText ,
279- ) ;
268+ console . error ( "❌ [POLLING] API error:" , getEdenErrorMessage ( error ) ) ;
280269 }
281270 } catch ( error ) {
282271 console . error ( "❌ [POLLING] Network error checking for reply:" , error ) ;
@@ -308,15 +297,11 @@ export default function OnboardingPage() {
308297 setIsManualChecking ( true ) ;
309298
310299 try {
311- const response = await fetch ( "/api/v2/onboarding/check-reply" ) ;
312- console . log (
313- "📡 [MANUAL] Response status:" ,
314- response . status ,
315- response . statusText ,
316- ) ;
300+ const { data, error } =
301+ await client . api . e2 . onboarding [ "check-reply" ] . get ( ) ;
302+ console . log ( "📡 [MANUAL] Response:" , error ? "error" : "success" ) ;
317303
318- if ( response . ok ) {
319- const data = await response . json ( ) ;
304+ if ( data && ! error ) {
320305 console . log (
321306 "📋 [MANUAL] Response data:" ,
322307 JSON . stringify ( data , null , 2 ) ,
@@ -328,7 +313,7 @@ export default function OnboardingPage() {
328313 setShowManualCheck ( false ) ;
329314 setDemoOutput (
330315 ( prev ) =>
331- `${ prev } \n\n🎉 Reply received!\nFrom: ${ data . reply . from } \nSubject: ${ data . reply . subject } ` ,
316+ `${ prev } \n\n🎉 Reply received!\nFrom: ${ data . reply ? .from } \nSubject: ${ data . reply ? .subject } ` ,
332317 ) ;
333318 } else {
334319 console . log ( "📭 [MANUAL] No reply found yet" ) ;
@@ -338,11 +323,7 @@ export default function OnboardingPage() {
338323 ) ;
339324 }
340325 } else {
341- console . error (
342- "❌ [MANUAL] API error:" ,
343- response . status ,
344- response . statusText ,
345- ) ;
326+ console . error ( "❌ [MANUAL] API error:" , getEdenErrorMessage ( error ) ) ;
346327 }
347328 } catch ( error ) {
348329 console . error ( "❌ [MANUAL] Error checking for reply:" , error ) ;
0 commit comments