Skip to content

Commit

Permalink
feat: global search customer email search support (#964)
Browse files Browse the repository at this point in the history
Co-authored-by: Riddhiagrawal001 <[email protected]>
  • Loading branch information
sagarnaikjuspay and Riddhiagrawal001 authored Jul 11, 2024
1 parent 088f0d1 commit ba411d1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/screens/Analytics/GlobalSearch/GlobalSearchBar.res
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ module SearchResultsComponent = {
open UIUtils
@react.component
let make = (~searchResults, ~searchText, ~redirectOnSelect, ~setShowModal) => {
React.useEffect0(() => {
let onKeyPress = event => {
let keyPressed = event->ReactEvent.Keyboard.key

if keyPressed == "Enter" {
let redirectLink = `/search?query=${searchText}`
if redirectLink->isNonEmptyString {
setShowModal(_ => false)
GlobalVars.appendDashboardPath(~url=redirectLink)->RescriptReactRouter.push
}
}
}
Window.addEventListener("keydown", onKeyPress)
Some(() => Window.removeEventListener("keydown", onKeyPress))
})

<OptionsWrapper>
{searchResults
->Array.mapWithIndex((section: resultType, index) => {
Expand Down Expand Up @@ -216,7 +232,14 @@ let make = () => {
let getSearchResults = async results => {
try {
let url = getURL(~entityName=GLOBAL_SEARCH, ~methodType=Post, ())
let body = [("query", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson

let body = if !(searchText->CommonAuthUtils.isValidEmail) {
let filters = [("email", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson
[("query", ""->JSON.Encode.string), ("filters", filters)]->LogicUtils.getJsonFromArrayOfJson
} else {
[("query", searchText->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson
}

let response = await fetchDetails(url, body, Post, ())

let local_results = []
Expand Down

0 comments on commit ba411d1

Please sign in to comment.