From f74cdfc70aeaaa500a894cc39b692bfb5f457e50 Mon Sep 17 00:00:00 2001 From: Sagar naik Date: Mon, 22 Jul 2024 19:46:36 +0530 Subject: [PATCH] fix: global search minor bugs (#1040) --- .../GlobalSearchTables/ResultsTableUtils.res | 19 ++++++++++++++----- src/screens/Disputes/ShowDisputes.res | 3 ++- src/screens/Order/ShowOrder.res | 4 +++- src/screens/Refunds/ShowRefund.res | 3 ++- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/screens/Analytics/GlobalSearchResults/GlobalSearchTables/ResultsTableUtils.res b/src/screens/Analytics/GlobalSearchResults/GlobalSearchTables/ResultsTableUtils.res index 4d5a57e96..48b5323db 100644 --- a/src/screens/Analytics/GlobalSearchResults/GlobalSearchTables/ResultsTableUtils.res +++ b/src/screens/Analytics/GlobalSearchResults/GlobalSearchTables/ResultsTableUtils.res @@ -2,7 +2,8 @@ let tableBorderClass = "border-collapse border border-jp-gray-940 border-solid b let useGetData = () => { open LogicUtils - let filters = Dict.make() + let body = Dict.make() + let merchantDetailsValue = HSwitchUtils.useMerchantDetailsValue() let getURL = APIUtils.useGetURL() async ( ~updateDetails: ( @@ -18,13 +19,21 @@ let useGetData = () => { ~query, ~path, ) => { - filters->Dict.set("offset", offset->Int.toFloat->JSON.Encode.float) - filters->Dict.set("count", 10->Int.toFloat->JSON.Encode.float) - filters->Dict.set("query", query->JSON.Encode.string) + body->Dict.set("offset", offset->Int.toFloat->JSON.Encode.float) + body->Dict.set("count", 10->Int.toFloat->JSON.Encode.float) + body->Dict.set("query", query->JSON.Encode.string) + + if !(query->CommonAuthUtils.isValidEmail) { + let filters = [("customer_email", [query->JSON.Encode.string]->JSON.Encode.array)] + body->Dict.set("filters", filters->getJsonFromArrayOfJson) + body->Dict.set("query", merchantDetailsValue.merchant_id->JSON.Encode.string) + } else { + body->Dict.set("query", query->JSON.Encode.string) + } try { let url = getURL(~entityName=GLOBAL_SEARCH, ~methodType=Post, ~id=Some(path), ()) - let res = await updateDetails(url, filters->JSON.Encode.object, Fetch.Post, ()) + let res = await updateDetails(url, body->JSON.Encode.object, Fetch.Post, ()) let data = res->LogicUtils.getDictFromJsonObject->LogicUtils.getArrayFromDict("hits", []) let total = res->getDictFromJsonObject->getInt("count", 0) diff --git a/src/screens/Disputes/ShowDisputes.res b/src/screens/Disputes/ShowDisputes.res index 531936b0c..8cc10e080 100644 --- a/src/screens/Disputes/ShowDisputes.res +++ b/src/screens/Disputes/ShowDisputes.res @@ -170,6 +170,7 @@ module DisputesInfo = { @react.component let make = (~id) => { open APIUtils + let url = RescriptReactRouter.useUrl() let getURL = useGetURL() let fetchDetails = useGetMethod() let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) @@ -193,7 +194,7 @@ let make = (~id) => { React.useEffect(() => { fetchDisputesData()->ignore None - }, []) + }, [url]) let data = disputeData->LogicUtils.getDictFromJsonObject let paymentId = data->LogicUtils.getString("payment_id", "") diff --git a/src/screens/Order/ShowOrder.res b/src/screens/Order/ShowOrder.res index 8c0f33c97..2c6e8c3f5 100644 --- a/src/screens/Order/ShowOrder.res +++ b/src/screens/Order/ShowOrder.res @@ -593,6 +593,7 @@ module FraudRiskBanner = { let make = (~id) => { open APIUtils open OrderUIUtils + let url = RescriptReactRouter.useUrl() let getURL = useGetURL() let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom) let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom @@ -626,6 +627,7 @@ let make = (~id) => { } } } + React.useEffect(() => { let accountUrl = getURL( ~entityName=ORDERS, @@ -636,7 +638,7 @@ let make = (~id) => { ) fetchOrderDetails(accountUrl)->ignore None - }, []) + }, [url]) let isRefundDataAvailable = orderData.refunds->Array.length !== 0 diff --git a/src/screens/Refunds/ShowRefund.res b/src/screens/Refunds/ShowRefund.res index fdcb7fd61..f8be37543 100644 --- a/src/screens/Refunds/ShowRefund.res +++ b/src/screens/Refunds/ShowRefund.res @@ -75,6 +75,7 @@ module RefundInfo = { let make = (~id) => { open LogicUtils open HSwitchOrderUtils + let url = RescriptReactRouter.useUrl() let getURL = APIUtils.useGetURL() let userPermissionJson = Recoil.useRecoilValueFromAtom(HyperswitchAtom.userPermissionAtom) let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom @@ -126,7 +127,7 @@ let make = (~id) => { React.useEffect(() => { fetchRefundData()->ignore None - }, []) + }, [url]) let showSyncButton = React.useCallback(_ => { let refundDict = refundData->getDictFromJsonObject