@@ -47,6 +47,7 @@ import Link from "next/link";
4747import { CaseSensitiveIcon , RegexIcon , Wand2Icon } from "lucide-react" ;
4848import { SearchAssistBox } from "./searchAssistBox" ;
4949import useCaptureEvent from "@/hooks/useCaptureEvent" ;
50+ import { LoginDialog } from "@/app/components/loginDialog" ;
5051
5152const LANGUAGE_MODEL_DOCS_URL = "https://docs.sourcebot.dev/docs/configuration/language-model-providers" ;
5253
@@ -60,6 +61,7 @@ interface SearchBarProps {
6061 }
6162 autoFocus ?: boolean ;
6263 isSearchAssistSupported : boolean ;
64+ showLoginWall : boolean ;
6365}
6466
6567const searchBarKeymap : readonly KeyBinding [ ] = ( [
@@ -107,6 +109,7 @@ export const SearchBar = ({
107109 query : defaultQuery = "" ,
108110 } = { } ,
109111 isSearchAssistSupported,
112+ showLoginWall,
110113} : SearchBarProps ) => {
111114 const router = useRouter ( ) ;
112115 const captureEvent = useCaptureEvent ( ) ;
@@ -120,6 +123,7 @@ export const SearchBar = ({
120123 const [ isHistorySearchEnabled , setIsHistorySearchEnabled ] = useState ( false ) ;
121124 const [ isRegexEnabled , setIsRegexEnabled ] = useState ( defaultIsRegexEnabled ) ;
122125 const [ isCaseSensitivityEnabled , setIsCaseSensitivityEnabled ] = useState ( defaultIsCaseSensitivityEnabled ) ;
126+ const [ loginCallbackUrl , setLoginCallbackUrl ] = useState < string > ( ) ;
123127
124128 const focusEditor = useCallback ( ( ) => editorRef . current ?. view ?. focus ( ) , [ ] ) ;
125129 const focusSuggestionsBox = useCallback ( ( ) => suggestionBoxRef . current ?. focus ( ) , [ ] ) ;
@@ -230,8 +234,24 @@ export const SearchBar = ({
230234 [ SearchQueryParams . isRegexEnabled , isRegexEnabled ? "true" : null ] ,
231235 [ SearchQueryParams . isCaseSensitivityEnabled , isCaseSensitivityEnabled ? "true" : null ] ,
232236 ) ;
237+
238+ if ( showLoginWall ) {
239+ if ( query . trim ( ) . length === 0 ) {
240+ return ;
241+ }
242+ captureEvent ( 'wa_publicsaas_cs_login_wall_prompted' , { } ) ;
243+ setLoginCallbackUrl ( url ) ;
244+ return ;
245+ }
246+
233247 router . push ( url ) ;
234- } , [ router , isRegexEnabled , isCaseSensitivityEnabled ] ) ;
248+ } , [
249+ captureEvent ,
250+ isCaseSensitivityEnabled ,
251+ isRegexEnabled ,
252+ router ,
253+ showLoginWall ,
254+ ] ) ;
235255
236256 return (
237257 < div
@@ -401,6 +421,15 @@ export const SearchBar = ({
401421 cursorPosition = { cursorPosition }
402422 { ...suggestionData }
403423 />
424+ < LoginDialog
425+ isOpen = { loginCallbackUrl !== undefined }
426+ onOpenChange = { ( open ) => {
427+ if ( ! open ) {
428+ setLoginCallbackUrl ( undefined ) ;
429+ }
430+ } }
431+ callbackUrl = { loginCallbackUrl }
432+ />
404433 </ div >
405434 )
406435}
0 commit comments