-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refunds failure reasons (#1938)
- Loading branch information
1 parent
939457d
commit 971ecca
Showing
5 changed files
with
298 additions
and
3 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
src/screens/NewAnalytics/NewRefundsAnalytics/FailureReasonsRefunds/FailureReasonsRefunds.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
open NewAnalyticsTypes | ||
open FailureReasonsRefundsTypes | ||
open NewRefundsAnalyticsEntity | ||
open FailureReasonsRefundsUtils | ||
open NewAnalyticsHelper | ||
|
||
module TableModule = { | ||
@react.component | ||
let make = (~data, ~className="") => { | ||
let (offset, setOffset) = React.useState(_ => 0) | ||
|
||
let defaultSort: Table.sortedObject = { | ||
key: "", | ||
order: Table.INC, | ||
} | ||
|
||
let visibleColumns = [ | ||
Refund_Error_Message, | ||
Refund_Error_Message_Count, | ||
Refund_Error_Message_Count_Ratio, | ||
Connector, | ||
] | ||
|
||
let tableData = getTableData(data) | ||
|
||
<div className> | ||
<LoadedTable | ||
visibleColumns | ||
title=" " | ||
hideTitle=true | ||
actualData={tableData} | ||
entity=failureReasonsTableEntity | ||
resultsPerPage=10 | ||
totalResults={tableData->Array.length} | ||
offset | ||
setOffset | ||
defaultSort | ||
currrentFetchCount={tableData->Array.length} | ||
tableLocalFilter=false | ||
tableheadingClass=tableBorderClass | ||
tableBorderClass | ||
ignoreHeaderBg=true | ||
tableDataBorderClass=tableBorderClass | ||
isAnalyticsModule=true | ||
/> | ||
</div> | ||
} | ||
} | ||
|
||
@react.component | ||
let make = (~entity: moduleEntity) => { | ||
open LogicUtils | ||
open APIUtils | ||
let getURL = useGetURL() | ||
let updateDetails = useUpdateMethod() | ||
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading) | ||
let {filterValueJson} = React.useContext(FilterContext.filterContext) | ||
let (tableData, setTableData) = React.useState(_ => JSON.Encode.array([])) | ||
let startTimeVal = filterValueJson->getString("startTime", "") | ||
let endTimeVal = filterValueJson->getString("endTime", "") | ||
|
||
let getRefundsProcessed = async () => { | ||
setScreenState(_ => PageLoaderWrapper.Loading) | ||
try { | ||
let url = getURL( | ||
~entityName=ANALYTICS_REFUNDS, | ||
~methodType=Post, | ||
~id=Some((entity.domain: domain :> string)), | ||
) | ||
|
||
let groupByNames = switch entity.requestBodyConfig.groupBy { | ||
| Some(dimentions) => | ||
dimentions | ||
->Array.map(item => (item: dimension :> string)) | ||
->Some | ||
| _ => None | ||
} | ||
|
||
let body = NewAnalyticsUtils.requestBody( | ||
~startTime=startTimeVal, | ||
~endTime=endTimeVal, | ||
~delta=entity.requestBodyConfig.delta, | ||
~metrics=entity.requestBodyConfig.metrics, | ||
~groupByNames, | ||
) | ||
|
||
let response = await updateDetails(url, body, Post) | ||
|
||
let metaData = response->getDictFromJsonObject->getArrayFromDict("metaData", []) | ||
|
||
let data = | ||
response | ||
->getDictFromJsonObject | ||
->getArrayFromDict("queryData", []) | ||
->modifyQuery(metaData) | ||
|
||
if data->Array.length > 0 { | ||
setTableData(_ => data->JSON.Encode.array) | ||
setScreenState(_ => PageLoaderWrapper.Success) | ||
} else { | ||
setScreenState(_ => PageLoaderWrapper.Custom) | ||
} | ||
} catch { | ||
| _ => setScreenState(_ => PageLoaderWrapper.Custom) | ||
} | ||
} | ||
|
||
React.useEffect(() => { | ||
if startTimeVal->isNonEmptyString && endTimeVal->isNonEmptyString { | ||
getRefundsProcessed()->ignore | ||
} | ||
None | ||
}, [startTimeVal, endTimeVal]) | ||
|
||
<div> | ||
<ModuleHeader title={entity.title} /> | ||
<Card> | ||
<PageLoaderWrapper | ||
screenState customLoader={<Shimmer layoutId=entity.title />} customUI={<NoData />}> | ||
<TableModule data={tableData} className="ml-6 mr-5 mt-6 mb-5" /> | ||
</PageLoaderWrapper> | ||
</Card> | ||
</div> | ||
} |
14 changes: 14 additions & 0 deletions
14
...ens/NewAnalytics/NewRefundsAnalytics/FailureReasonsRefunds/FailureReasonsRefundsTypes.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
type failreResonsColsTypes = | ||
| Refund_Error_Message | ||
| Refund_Error_Message_Count | ||
| Total_Refund_Error_Message_Count | ||
| Refund_Error_Message_Count_Ratio | ||
| Connector | ||
|
||
type failreResonsObjectType = { | ||
connector: string, | ||
refund_error_message: string, | ||
refund_error_message_count: int, | ||
total_refund_error_message_count: int, | ||
refund_error_message_count_ratio: float, | ||
} |
131 changes: 131 additions & 0 deletions
131
...ens/NewAnalytics/NewRefundsAnalytics/FailureReasonsRefunds/FailureReasonsRefundsUtils.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
open NewAnalyticsTypes | ||
open FailureReasonsRefundsTypes | ||
open LogicUtils | ||
|
||
let getStringFromVariant = value => { | ||
switch value { | ||
| Refund_Error_Message => "refund_error_message" | ||
| Refund_Error_Message_Count => "refund_error_message_count" | ||
| Total_Refund_Error_Message_Count => "total_refund_error_message_count" | ||
| Refund_Error_Message_Count_Ratio => "refund_error_message_count_ratio" | ||
| Connector => "connector" | ||
} | ||
} | ||
|
||
let tableItemToObjMapper: Dict.t<JSON.t> => failreResonsObjectType = dict => { | ||
{ | ||
refund_error_message: dict->getString(Refund_Error_Message->getStringFromVariant, ""), | ||
refund_error_message_count: dict->getInt(Refund_Error_Message_Count->getStringFromVariant, 0), | ||
total_refund_error_message_count: dict->getInt( | ||
Total_Refund_Error_Message_Count->getStringFromVariant, | ||
0, | ||
), | ||
refund_error_message_count_ratio: dict->getFloat( | ||
Refund_Error_Message_Count_Ratio->getStringFromVariant, | ||
0.0, | ||
), | ||
connector: dict->getString(Connector->getStringFromVariant, ""), | ||
} | ||
} | ||
|
||
let getObjects: JSON.t => array<failreResonsObjectType> = json => { | ||
json | ||
->LogicUtils.getArrayFromJson([]) | ||
->Array.map(item => { | ||
tableItemToObjMapper(item->getDictFromJsonObject) | ||
}) | ||
} | ||
|
||
let getHeading = colType => { | ||
switch colType { | ||
| Refund_Error_Message => | ||
Table.makeHeaderInfo( | ||
~key=Refund_Error_Message->getStringFromVariant, | ||
~title="Error Reason", | ||
~dataType=TextType, | ||
) | ||
| Refund_Error_Message_Count => | ||
Table.makeHeaderInfo( | ||
~key=Refund_Error_Message_Count->getStringFromVariant, | ||
~title="Count", | ||
~dataType=TextType, | ||
) | ||
| Total_Refund_Error_Message_Count => | ||
Table.makeHeaderInfo( | ||
~key=Total_Refund_Error_Message_Count->getStringFromVariant, | ||
~title="", | ||
~dataType=TextType, | ||
) | ||
| Refund_Error_Message_Count_Ratio => | ||
Table.makeHeaderInfo( | ||
~key=Refund_Error_Message_Count_Ratio->getStringFromVariant, | ||
~title="Ratio", | ||
~dataType=TextType, | ||
) | ||
| Connector => | ||
Table.makeHeaderInfo( | ||
~key=Connector->getStringFromVariant, | ||
~title="Connector", | ||
~dataType=TextType, | ||
) | ||
} | ||
} | ||
|
||
let getCell = (obj, colType): Table.cell => { | ||
open NewAnalyticsUtils | ||
switch colType { | ||
| Refund_Error_Message => Text(obj.refund_error_message) | ||
| Refund_Error_Message_Count => Text(obj.refund_error_message_count->Int.toString) | ||
| Total_Refund_Error_Message_Count => Text(obj.total_refund_error_message_count->Int.toString) | ||
| Refund_Error_Message_Count_Ratio => | ||
Text(obj.refund_error_message_count_ratio->valueFormatter(Rate)) | ||
| Connector => Text(obj.connector) | ||
} | ||
} | ||
|
||
let getTableData = json => { | ||
json->getArrayDataFromJson(tableItemToObjMapper)->Array.map(Nullable.make) | ||
} | ||
|
||
let modifyQuery = (queryData, metaData) => { | ||
let totalCount = switch metaData->Array.get(0) { | ||
| Some(val) => { | ||
let valueDict = val->getDictFromJsonObject | ||
let failure_reason_count = | ||
valueDict->getInt(Total_Refund_Error_Message_Count->getStringFromVariant, 0) | ||
failure_reason_count | ||
} | ||
| _ => 0 | ||
} | ||
|
||
let modifiedQuery = if totalCount > 0 { | ||
queryData->Array.map(query => { | ||
let valueDict = query->getDictFromJsonObject | ||
let failure_reason_count = | ||
valueDict->getInt(Refund_Error_Message_Count->getStringFromVariant, 0) | ||
let ratio = failure_reason_count->Int.toFloat /. totalCount->Int.toFloat *. 100.0 | ||
|
||
valueDict->Dict.set( | ||
Refund_Error_Message_Count_Ratio->getStringFromVariant, | ||
ratio->JSON.Encode.float, | ||
) | ||
valueDict->JSON.Encode.object | ||
}) | ||
} else { | ||
queryData | ||
} | ||
|
||
modifiedQuery->Array.sort((queryA, queryB) => { | ||
let valueDictA = queryA->getDictFromJsonObject | ||
let valueDictB = queryB->getDictFromJsonObject | ||
|
||
let failure_reason_countA = | ||
valueDictA->getInt(Refund_Error_Message_Count->getStringFromVariant, 0) | ||
let failure_reason_countB = | ||
valueDictB->getInt(Refund_Error_Message_Count->getStringFromVariant, 0) | ||
|
||
compareLogic(failure_reason_countA, failure_reason_countB) | ||
}) | ||
|
||
modifiedQuery | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters