Skip to content

Commit

Permalink
feat: refund view changes (juspay#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitanjli525 authored Sep 27, 2024
1 parent 511ee1e commit 4ba9162
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 23 deletions.
15 changes: 15 additions & 0 deletions src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ let useGetURL = () => {
}
| _ => ""
}
| REFUNDS_AGGREGATE =>
switch methodType {
| Get =>
switch queryParamerters {
| Some(queryParams) =>
switch transactionEntity {
| #Profile => `refunds/profile/aggregate?${queryParams}`
| #Merchant
| _ =>
`refunds/aggregate?${queryParams}`
}
| None => `refunds/aggregate`
}
| _ => `refunds/aggregate`
}
| DISPUTES =>
switch methodType {
| Get =>
Expand Down
1 change: 1 addition & 0 deletions src/screens/APIUtils/APIUtilsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type entityName =
| ORDERS
| ORDER_FILTERS
| ORDERS_AGGREGATE
| REFUNDS_AGGREGATE
| DEFAULT_FALLBACK
| ANALYTICS_SYSTEM_METRICS
| SDK_EVENT_LOGS
Expand Down
29 changes: 18 additions & 11 deletions src/screens/Refunds/Refund.res
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,29 @@ let make = () => {
None
}, (offset, filters, searchText))

let {generateReport} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let {generateReport, transactionView} =
HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom

<ErrorBoundary>
<div className="min-h-[50vh]">
<div className="flex justify-between items-center">
<PageUtils.PageHeading title="Refunds" subTitle="View and manage all refunds" />
<OMPSwitchHelper.OMPViews
views={OMPSwitchUtils.transactionViewList(~checkUserEntity)}
selectedEntity={transactionEntity}
onChange={updateTransactionEntity}
/>
<PageUtils.PageHeading title="Refunds" />
<div className="flex gap-4">
<OMPSwitchHelper.OMPViews
views={OMPSwitchUtils.transactionViewList(~checkUserEntity)}
selectedEntity={transactionEntity}
onChange={updateTransactionEntity}
/>
<RenderIf condition={generateReport && refundData->Array.length > 0}>
<GenerateReport entityName={REFUND_REPORT} />
</RenderIf>
</div>
</div>
<RenderIf condition={transactionView}>
<div className="flex gap-6 justify-around">
<TransactionView entity=TransactionViewTypes.Refunds />
</div>
</RenderIf>
<div className="flex justify-between gap-3">
<div className="flex-1">
<RemoteTableFilters
Expand All @@ -92,10 +103,6 @@ let make = () => {
title="Refunds"
/>
</div>
<RenderIf condition={generateReport && refundData->Array.length > 0}>
<GenerateReport entityName={REFUND_REPORT} />
</RenderIf>
<PortalCapture key={`RefundsCustomizeColumn`} name={`RefundsCustomizeColumn`} />
</div>
<PageLoaderWrapper screenState customUI>
<LoadedTableWithCustomColumns
Expand Down
12 changes: 10 additions & 2 deletions src/screens/TransactionViews/TransactionView.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ let make = (~entity=TransactionViewTypes.Orders) => {
let updateViewsFilterValue = (view: TransactionViewTypes.viewTypes) => {
let customFilterKey = switch entity {
| Orders => "status"
| Refunds => "refund_status"
| _ => ""
}
let customFilter = `[${view->getViewsString(countRes)}]`
let customFilter = `[${view->getViewsString(countRes, entity)}]`

updateExistingKeys(Dict.fromArray([(customFilterKey, customFilter)]))

Expand Down Expand Up @@ -75,6 +76,12 @@ let make = (~entity=TransactionViewTypes.Orders) => {
~methodType=Get,
~queryParamerters=Some(`start_time=${startTime}&end_time=${endTime}`),
)
| Refunds =>
getURL(
~entityName=REFUNDS_AGGREGATE,
~methodType=Get,
~queryParamerters=Some(`start_time=${startTime}&end_time=${endTime}`),
)
| _ => ""
}

Expand Down Expand Up @@ -112,6 +119,7 @@ let make = (~entity=TransactionViewTypes.Orders) => {

let viewsArray = switch entity {
| Orders => paymentViewsArray
| Refunds => refundViewsArray
| _ => []
}

Expand All @@ -120,7 +128,7 @@ let make = (~entity=TransactionViewTypes.Orders) => {
<TransactionViewCard
key={i->Int.toString}
view={item}
count={getViewCount(item, countRes)->Int.toString}
count={getViewCount(item, countRes, entity)->Int.toString}
onViewClick
isActiveView={item == activeView}
/>
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
type viewTypes = All | Succeeded | Failed | Dropoffs | Cancelled | Pending
35 changes: 26 additions & 9 deletions src/screens/TransactionViews/TransactionViewUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ open TransactionViewTypes

let paymentViewsArray: array<viewTypes> = [All, Succeeded, Failed, Dropoffs, Cancelled]

let refundViewsArray: array<viewTypes> = [All, Succeeded, Failed, Pending]

let getViewsDisplayName = (view: viewTypes) => {
switch view {
| All => "All"
| Succeeded => "Succeeded"
| Failed => "Failed"
| Dropoffs => "Dropoffs"
| Cancelled => "Cancelled"
| Pending => "Pending"
}
}

Expand All @@ -18,6 +21,7 @@ let getViewTypeFromString = view => {
| "cancelled" => Cancelled
| "failed" => Failed
| "requires_payment_method" => Dropoffs
| "pending" => Pending
| _ => All
}
}
Expand All @@ -31,13 +35,26 @@ let getAllViewsString = obj => {
->Array.joinWith(",")
}

let getViewsString = (view, obj) => {
switch view {
| All => getAllViewsString(obj)
| Succeeded => "succeeded"
| Failed => "failed"
| Dropoffs => "requires_payment_method"
| Cancelled => "cancelled"
let getViewsString = (view, obj, entity) => {
switch entity {
| Orders =>
switch view {
| All => getAllViewsString(obj)
| Succeeded => "succeeded"
| Failed => "failed"
| Dropoffs => "requires_payment_method"
| Cancelled => "cancelled"
| Pending => "pending"
}
| Refunds =>
switch view {
| All => getAllViewsString(obj)
| Succeeded => "success"
| Failed => "failure"
| Pending => "pending"
| _ => ""
}
| _ => ""
}
}

Expand All @@ -53,14 +70,14 @@ let getAllViewCount = obj => {
)
}

let getViewCount = (view, obj) => {
let getViewCount = (view, obj, entity) => {
open LogicUtils
switch view {
| All => getAllViewCount(obj)
| _ =>
obj
->getDictFromJsonObject
->getDictfromDict("status_with_count")
->getInt(view->getViewsString(obj), 0)
->getInt(view->getViewsString(obj, entity), 0)
}
}

0 comments on commit 4ba9162

Please sign in to comment.