Skip to content

Commit

Permalink
feat: Refunds amount filter and UI enhancements (#1884)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanikabansal-juspay authored Dec 9, 2024
1 parent 5b1b2e9 commit 2134cbf
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 51 deletions.
3 changes: 2 additions & 1 deletion src/screens/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,15 @@ module SearchBarFilter = {
checked: true,
}

<div className="w-64">
<div className="w-max">
{InputFields.textInput(
~customStyle="rounded-lg placeholder:opacity-90",
~customPaddingClass="px-0",
~leftIcon=<Icon size=14 name="search" />,
~iconOpacity="opacity-100",
~leftIconCustomStyle="pl-4",
~inputStyle="!placeholder:opacity-90",
~customWidth="w-72",
)(~input=inputSearch, ~placeholder)}
</div>
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Payouts/PayoutsList.res
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let make = () => {
initialFixedFilter
setOffset
customLeftView={<SearchBarFilter
placeholder="Search payout id" setSearchVal=setSearchText searchVal=searchText
placeholder="Search for payout ID" setSearchVal=setSearchText searchVal=searchText
/>}
entityName=PAYOUTS_FILTERS
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open AmountFilterTypes
open LogicUtils
let amountFilterOptions: array<FilterSelectBox.dropdownOption> = [
GreaterThanOrEqualTo,
LessThanOrEqualTo,
Expand All @@ -11,8 +12,8 @@ let amountFilterOptions: array<FilterSelectBox.dropdownOption> = [
value: label,
}
})
let encodeFloatOrDefault = val => (val->getFloatFromJson(0.0) *. 100.0)->JSON.Encode.float
let validateAmount = dict => {
open LogicUtils
let sAmntK = dict->getFloat((#start_amount: AmountFilterTypes.amountFilterChild :> string), -1.0)
let eAmtK = dict->getFloat((#end_amount: AmountFilterTypes.amountFilterChild :> string), -1.0)
let key = (#amount_option: AmountFilterTypes.amountFilterChild :> string)
Expand All @@ -27,3 +28,17 @@ let validateAmount = dict => {
}
haserror
}
let createAmountQuery = (~dict) => {
let hasAmountError = validateAmount(dict)
if !hasAmountError {
let encodeAmount = value => value->mapOptionOrDefault(JSON.Encode.null, encodeFloatOrDefault)
dict->Dict.set(
"amount_filter",
[
("start_amount", dict->getvalFromDict("start_amount")->encodeAmount),
("end_amount", dict->getvalFromDict("end_amount")->encodeAmount),
]->getJsonFromArrayOfJson,
)
}
dict
}
2 changes: 1 addition & 1 deletion src/screens/Transaction/Disputes/Disputes.res
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ let make = () => {
initialFixedFilter
setOffset
customLeftView={<SearchBarFilter
placeholder="Search for any disptue id" setSearchVal=setSearchText searchVal=searchText
placeholder="Search for dispute ID" setSearchVal=setSearchText searchVal=searchText
/>}
entityName=DISPUTE_FILTERS
title="Disputes"
Expand Down
4 changes: 0 additions & 4 deletions src/screens/Transaction/Order/OrderUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,3 @@ let orderViewList: OMPSwitchTypes.ompViews = [
entity: #Profile,
},
]

let deleteNestedKeys = (dict: Dict.t<'a>, keys: array<string>) => {
keys->Array.forEach(key => dict->Dict.delete(key))
}
32 changes: 6 additions & 26 deletions src/screens/Transaction/Order/Orders.res
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,16 @@ let make = (~previewOnly=false) => {
]->getJsonFromArrayOfJson,
)
}
let encodeFloatOrDefault = val => (val->getFloatFromJson(0.0) *. 100.0)->JSON.Encode.float
let hasAmountError = AmountFilterUtils.validateAmount(dict)
if !hasAmountError {
filters->Dict.set(
"amount_filter",
[
(
"start_amount",
getvalFromDict(dict, "start_amount")->mapOptionOrDefault(
JSON.Encode.null,
encodeFloatOrDefault,
),
),
(
"end_amount",
getvalFromDict(dict, "end_amount")->mapOptionOrDefault(
JSON.Encode.null,
encodeFloatOrDefault,
),
),
]->getJsonFromArrayOfJson,
)
}
dict
//to create amount_filter query
let newDict = AmountFilterUtils.createAmountQuery(~dict)
newDict
->Dict.toArray
->Array.forEach(item => {
let (key, value) = item
filters->Dict.set(key, value)
})
filters->OrderUIUtils.deleteNestedKeys(["start_amount", "end_amount", "amount_option"])
//to delete unused keys
filters->deleteNestedKeys(["start_amount", "end_amount", "amount_option"])
filters
->getOrdersList(
~updateDetails,
Expand Down Expand Up @@ -146,7 +126,7 @@ let make = (~previewOnly=false) => {
setOffset
submitInputOnEnter=true
customLeftView={<SearchBarFilter
placeholder="Search for any payment id" setSearchVal=setSearchText searchVal=searchText
placeholder="Search for payment ID" setSearchVal=setSearchText searchVal=searchText
/>}
entityName=ORDER_FILTERS
/>
Expand Down
10 changes: 6 additions & 4 deletions src/screens/Transaction/Refunds/Refund.res
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ let make = () => {
filters->Dict.set("payment_id", searchText->String.trim->JSON.Encode.string)
filters->Dict.set("refund_id", searchText->String.trim->JSON.Encode.string)
}

dict
//to create amount_filter query
let newdict = AmountFilterUtils.createAmountQuery(~dict)
newdict
->Dict.toArray
->Array.forEach(item => {
let (key, value) = item
filters->Dict.set(key, value)
})

//to delete unused keys
filters->deleteNestedKeys(["start_amount", "end_amount", "amount_option"])
filters
->getRefundsList(
~updateDetails,
Expand Down Expand Up @@ -95,7 +97,7 @@ let make = () => {
initialFixedFilter
setOffset
customLeftView={<SearchBarFilter
placeholder="Search for any payment id or refund id"
placeholder="Search for payment ID or refund ID"
setSearchVal=setSearchText
searchVal=searchText
/>}
Expand Down
38 changes: 25 additions & 13 deletions src/screens/Transaction/Refunds/RefundUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ type filterTypes = {
currency: array<string>,
status: array<string>,
connector_label: array<string>,
amount: array<string>,
}

type filter = [
| #connector
| #currency
| #status
| #connector_label
| #amount
| #unknown
]

Expand All @@ -19,6 +21,7 @@ let getFilterTypeFromString = filterType => {
| "currency" => #currency
| "connector_label" => #connector_label
| "refund_status" => #status
| "amount" => #amount
| _ => #unknown
}
}
Expand Down Expand Up @@ -195,6 +198,7 @@ let itemToObjMapper = dict => {
currency: dict->getArrayFromDict("currency", [])->getStrArrayFromJsonArray,
status: dict->getArrayFromDict("refund_status", [])->getStrArrayFromJsonArray,
connector_label: [],
amount: [],
}
}

Expand All @@ -210,8 +214,9 @@ let initialFilters = (json, filtervalues, _, _, _) => {
if connectorFilter->Array.length !== 0 {
filtersArray->Array.push(#connector_label->getLabelFromFilterType)
}

filtersArray->Array.map((key): EntityType.initialFilters<'t> => {
let additionalFilters = [#amount]->Array.map(getLabelFromFilterType)
let allFiltersArray = filtersArray->Array.concat(additionalFilters)
allFiltersArray->Array.map((key): EntityType.initialFilters<'t> => {
let title = `Select ${key->snakeToTitle}`

let values = switch key->getFilterTypeFromString {
Expand All @@ -226,21 +231,28 @@ let initialFilters = (json, filtervalues, _, _, _) => {
| #connector_label => getOptionsForRefundFilters(filterDict, filtervalues)
| _ => values->FilterSelectBox.makeOptions
}

let customInput = switch key->getFilterTypeFromString {
| #amount =>
(~input as _, ~placeholder as _) => {
<AmountFilter options=AmountFilterUtils.amountFilterOptions />
}
| _ =>
InputFields.filterMultiSelectInput(
~options,
~buttonText=title,
~showSelectionAsChips=false,
~searchable=true,
~showToolTip=true,
~showNameAsToolTip=true,
~customButtonStyle="bg-none",
(),
)
}
{
field: FormRenderer.makeFieldInfo(
~label=key,
~name=getValueFromFilterType(key->getFilterTypeFromString),
~customInput=InputFields.filterMultiSelectInput(
~options,
~buttonText=title,
~showSelectionAsChips=false,
~searchable=true,
~showToolTip=true,
~showNameAsToolTip=true,
~customButtonStyle="bg-none",
(),
),
~customInput,
),
localFilter: Some(filterByData),
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/LogicUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,6 @@ let getValFromNullableValue = (val, default) => {
}

let dateFormat = (timestamp, format) => (timestamp->DayJs.getDayJsForString).format(format)

let deleteNestedKeys = (dict: Dict.t<'a>, keys: array<string>) =>
keys->Array.forEach(key => dict->Dict.delete(key))

0 comments on commit 2134cbf

Please sign in to comment.