Skip to content

Commit

Permalink
chore: some code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay committed Dec 28, 2023
1 parent 409912a commit a311bfe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
23 changes: 12 additions & 11 deletions src/context/FilterContext.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ module Provider = {
@react.component
let make = (~index: string, ~children, ~disableSessionStorage=false) => {
open FilterUtils
let temp = React.useMemo0(() => {ref("")})
let searcParamsToDict = temp.contents->parseFilterString
open HSwitchUtils
let query = React.useMemo0(() => {ref("")})
let searcParamsToDict = query.contents->parseFilterString
let (filterDict, setfilterDict) = React.useState(_ => searcParamsToDict)

let updateFilter = React.useMemo2(() => {
Expand All @@ -48,7 +49,7 @@ let make = (~index: string, ~children, ~disableSessionStorage=false) => {
let (key, value) = item
switch dict->Js.Dict.get(key) {
| Some(_) => None
| None => value !== "" ? Some(item) : None
| None => !(value->isEmptyString) ? Some(item) : None
}
},
)
Expand All @@ -58,7 +59,7 @@ let make = (~index: string, ~children, ~disableSessionStorage=false) => {
->Js.Array2.filter(
item => {
let (_, value) = item
value !== ""
!(value->isEmptyString)
},
)

Expand All @@ -68,15 +69,15 @@ let make = (~index: string, ~children, ~disableSessionStorage=false) => {
} else {
updatedDict
}
temp := dict->FilterUtils.parseFilterDict
query := dict->FilterUtils.parseFilterDict
dict
})
}

let reset = () => {
let dict = Js.Dict.empty()
setfilterDict(_ => dict)
temp := dict->FilterUtils.parseFilterDict
query := dict->FilterUtils.parseFilterDict
}

let removeKeys = (arr: array<string>) => {
Expand All @@ -88,12 +89,12 @@ let make = (~index: string, ~children, ~disableSessionStorage=false) => {
} else {
updatedDict
}
temp := dict->FilterUtils.parseFilterDict
query := dict->FilterUtils.parseFilterDict
dict
})
}
{
query: temp.contents,
query: query.contents,
filterValue: filterDict,
updateExistingKeys: updateFilter,
removeKeys,
Expand All @@ -120,11 +121,11 @@ let make = (~index: string, ~children, ~disableSessionStorage=false) => {
})

React.useEffect1(() => {
if !(temp.contents->Js.String2.length < 1) && !disableSessionStorage {
sessionStorage.setItem(. index, temp.contents)
if !(query.contents->Js.String2.length < 1) && !disableSessionStorage {
sessionStorage.setItem(. index, query.contents)
}
None
}, [temp.contents])
}, [query.contents])

<Provider value={updateFilter}> children </Provider>
}
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ let useGetFiltersData = () => {
let endTimeVal = filterValueJson->getString("end_time", "")

(url, body) => {
React.useEffect1(() => {
React.useEffect3(() => {
setFilterData(_ => None)
if startTimeVal->isStringNonEmpty && endTimeVal->isStringNonEmpty {
try {
Expand All @@ -131,7 +131,7 @@ let useGetFiltersData = () => {
}
}
None
}, [startTimeVal, endTimeVal, body->Js.Json.object_->Js.Json.stringify])
}, (startTimeVal, endTimeVal, body->Js.Json.object_->Js.Json.stringify))
filterData
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/screens/HyperSwitch/Order/Orders.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let make = (~previewOnly=false) => {

filters->Js.Dict.set("offset", offset->Belt.Int.toFloat->Js.Json.number)
if !(searchText->isEmptyString) {
filters->Js.Dict.set("payment_id", searchText->Js.Json.string)
filters->Js.Dict.set("payment_id", searchText->Js.String2.trim->Js.Json.string)
}

dict
Expand Down Expand Up @@ -80,7 +80,7 @@ let make = (~previewOnly=false) => {

let customUI = <NoData isConfigureConnector paymentModal setPaymentModal />

let filtersUI = React.useMemo1(() => {
let filtersUI = React.useMemo0(() => {
<RemoteTableFilters
placeholder="Search payment id"
setSearchVal=setSearchText
Expand All @@ -93,7 +93,7 @@ let make = (~previewOnly=false) => {
initialFixedFilter
setOffset
/>
}, [])
})

<ErrorBoundary>
<div className={`flex flex-col mx-auto h-full ${widthClass} ${heightClass} min-h-[50vh]`}>
Expand Down
4 changes: 2 additions & 2 deletions src/screens/HyperSwitch/Refunds/Refund.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ let make = () => {

filters->Js.Dict.set("offset", offset->Belt.Int.toFloat->Js.Json.number)
if !(searchText->isEmptyString) {
filters->Js.Dict.set("payment_id", searchText->Js.Json.string)
filters->Js.Dict.set("refund_id", searchText->Js.Json.string)
filters->Js.Dict.set("payment_id", searchText->Js.String2.trim->Js.Json.string)
filters->Js.Dict.set("refund_id", searchText->Js.String2.trim->Js.Json.string)
}

dict
Expand Down

0 comments on commit a311bfe

Please sign in to comment.