Skip to content

Commit

Permalink
chore: Enhance transaction views (juspay#1562)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitanjli525 authored Oct 18, 2024
1 parent f40413c commit 4bca186
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
3 changes: 2 additions & 1 deletion src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ let useGetURL = () => {
}
| _ => ""
}
| DISPUTES_AGGREGATE => switch methodType {
| DISPUTES_AGGREGATE =>
switch methodType {
| Get =>
switch queryParamerters {
| Some(queryParams) =>
Expand Down
28 changes: 15 additions & 13 deletions src/screens/TransactionViews/TransactionView.res
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@ let make = (~entity=TransactionViewTypes.Orders) => {
let customFilter = `[${view->getViewsString(countRes, entity)}]`
updateExistingKeys(Dict.fromArray([(customFilterKey, customFilter)]))

switch view {
| All => {
let updateFilterKeys = filterKeys->Array.filter(item => item != customFilterKey)
setfilterKeys(_ => updateFilterKeys)
}
| _ => {
if !(filterKeys->Array.includes(customFilterKey)) {
filterKeys->Array.push(customFilterKey)
}
setfilterKeys(_ => filterKeys)
}
if !(filterKeys->Array.includes(customFilterKey)) {
filterKeys->Array.push(customFilterKey)
setfilterKeys(_ => filterKeys)
}
}

Expand Down Expand Up @@ -96,21 +88,31 @@ let make = (~entity=TransactionViewTypes.Orders) => {
let settingActiveView = () => {
let appliedStatusFilter = filterValueJson->getArrayFromDict(customFilterKey, [])

let setViewToAll =
appliedStatusFilter->getStrArrayFromJsonArray->Array.toSorted(compareLogic) ==
countRes
->getDictFromJsonObject
->getDictfromDict("status_with_count")
->Dict.keysToArray
->Array.toSorted(compareLogic)

if appliedStatusFilter->Array.length == 1 {
let statusValue =
appliedStatusFilter->getValueFromArray(0, ""->JSON.Encode.string)->JSON.Decode.string

let status = statusValue->Option.getOr("")
setActiveView(_ => status->getViewTypeFromString(entity))
} else {
} else if setViewToAll {
setActiveView(_ => All)
} else {
setActiveView(_ => None)
}
}

React.useEffect(() => {
settingActiveView()
None
}, [filterValueJson])
}, (filterValueJson, countRes))

React.useEffect(() => {
getAggregate()->ignore
Expand Down
2 changes: 1 addition & 1 deletion src/screens/TransactionViews/TransactionViewTypes.res
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
type operationsTypes = Orders | Refunds | Disputes

type viewTypes = All | Succeeded | Failed | Dropoffs | Cancelled | Pending
type viewTypes = All | Succeeded | Failed | Dropoffs | Cancelled | Pending | None
2 changes: 2 additions & 0 deletions src/screens/TransactionViews/TransactionViewUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ let getViewsDisplayName = (view: viewTypes) => {
| Dropoffs => "Dropoffs"
| Cancelled => "Cancelled"
| Pending => "Pending"
| _ => ""
}
}

Expand Down Expand Up @@ -71,6 +72,7 @@ let getViewsString = (view, obj, entity) => {
| Dropoffs => "requires_payment_method"
| Cancelled => "cancelled"
| Pending => "pending"
| _ => ""
}
| Refunds =>
switch view {
Expand Down

0 comments on commit 4bca186

Please sign in to comment.