11"use client" ;
22
3- import { useState } from "react" ;
3+ import { useEffect , useRef , useState } from "react" ;
44
5- import { Button } from "@/lib/components/button" ;
6- import {
7- Card ,
8- CardContent ,
9- CardHeader ,
10- CardTitle ,
11- } from "@/lib/components/card" ;
5+ import { Card , CardContent } from "@/lib/components/card" ;
126import { Input } from "@/lib/components/input" ;
137import { Label } from "@/lib/components/label" ;
148import { RadioGroup , RadioGroupItem } from "@/lib/components/radio-group" ;
@@ -20,6 +14,12 @@ interface ReferralStepProps {
2014export function ReferralStep ( { onComplete } : ReferralStepProps ) {
2115 const [ selectedSource , setSelectedSource ] = useState < string > ( "" ) ;
2216 const [ otherDetails , setOtherDetails ] = useState < string > ( "" ) ;
17+ const onCompleteRef = useRef ( onComplete ) ;
18+
19+ // Keep the ref updated with the latest onComplete function
20+ useEffect ( ( ) => {
21+ onCompleteRef . current = onComplete ;
22+ } , [ onComplete ] ) ;
2323
2424 const referralSources = [
2525 { value : "twitter" , label : "X (Formerly Twitter)" } ,
@@ -30,33 +30,45 @@ export function ReferralStep({ onComplete }: ReferralStepProps) {
3030 { value : "other" , label : "Other (Specify)" } ,
3131 ] ;
3232
33- const handleContinue = ( ) => {
34- if ( selectedSource ) {
35- const details = selectedSource === "other" ? otherDetails : undefined ;
36- onComplete ?.( selectedSource , details ) ;
33+ // Handle completion when a source is selected or manually triggered
34+ useEffect ( ( ) => {
35+ if ( selectedSource && selectedSource !== "other" ) {
36+ // Auto-complete for non-"other" selections after a brief delay
37+ const timer = setTimeout ( ( ) => {
38+ onCompleteRef . current ?.( selectedSource ) ;
39+ } , 1000 ) ; // Increased delay to give users time to change their mind
40+ return ( ) => clearTimeout ( timer ) ;
3741 }
38- } ;
42+ // Return empty cleanup function if condition is not met
43+ return ( ) => { } ;
44+ } , [ selectedSource ] ) ;
3945
40- const handleSkip = ( ) => {
41- onComplete ?.( "" ) ;
42- } ;
46+ // Handle "other" completion when details are provided
47+ useEffect ( ( ) => {
48+ if ( selectedSource === "other" && otherDetails . trim ( ) ) {
49+ const timer = setTimeout ( ( ) => {
50+ onCompleteRef . current ?.( selectedSource , otherDetails ) ;
51+ } , 1500 ) ; // Longer delay for typing
52+ return ( ) => clearTimeout ( timer ) ;
53+ }
54+ // Return empty cleanup function if condition is not met
55+ return ( ) => { } ;
56+ } , [ selectedSource , otherDetails ] ) ;
4357
4458 return (
4559 < div className = "space-y-6" >
4660 < div className = "text-center space-y-2" >
47- < h2 className = "text-2xl font-semibold tracking-tight" >
48- How did you hear about us?
61+ < h2 className = "text-3xl font-semibold tracking-tight" >
62+ How did you find us?
4963 </ h2 >
5064 < p className = "text-muted-foreground" >
51- Help us understand how people discover LLM Gateway (Optional)
65+ Help us improve by letting us know how you found us. No pressure - you
66+ can skip this step.
5267 </ p >
5368 </ div >
5469
5570 < Card >
56- < CardHeader >
57- < CardTitle className = "text-lg" > Referral Source</ CardTitle >
58- </ CardHeader >
59- < CardContent className = "space-y-4" >
71+ < CardContent className = "pt-6 space-y-4" >
6072 < RadioGroup
6173 value = { selectedSource }
6274 onValueChange = { setSelectedSource }
@@ -82,31 +94,24 @@ export function ReferralStep({ onComplete }: ReferralStepProps) {
8294 </ Label >
8395 < Input
8496 id = "other-details"
85- placeholder = "Where did you hear about us?"
97+ placeholder = "Blog, conference, friend, etc..."
98+ autoFocus
8699 value = { otherDetails }
87100 onChange = { ( e ) => setOtherDetails ( e . target . value ) }
88101 className = "w-full"
89102 />
90103 </ div >
91104 ) }
105+
106+ { selectedSource && (
107+ < div className = "text-sm text-muted-foreground text-center mt-4" >
108+ { selectedSource === "other" && ! otherDetails . trim ( )
109+ ? "Please provide details above, or use the Next button to continue."
110+ : "Thanks! Moving to the next step automatically..." }
111+ </ div >
112+ ) }
92113 </ CardContent >
93114 </ Card >
94-
95- < div className = "flex gap-3 pt-4" >
96- < Button variant = "outline" onClick = { handleSkip } className = "flex-1" >
97- Skip
98- </ Button >
99- < Button
100- onClick = { handleContinue }
101- disabled = {
102- ! selectedSource ||
103- ( selectedSource === "other" && ! otherDetails . trim ( ) )
104- }
105- className = "flex-1"
106- >
107- Continue
108- </ Button >
109- </ div >
110115 </ div >
111116 ) ;
112117}
0 commit comments