Skip to content

Commit

Permalink
chore: add profile level views in payment page (#1290)
Browse files Browse the repository at this point in the history
Co-authored-by: Riddhiagrawal001 <[email protected]>
  • Loading branch information
JeevaRamu0104 and Riddhiagrawal001 authored Sep 4, 2024
1 parent 968478a commit ff5d897
Show file tree
Hide file tree
Showing 17 changed files with 206 additions and 90 deletions.
61 changes: 61 additions & 0 deletions src/container/TransactionContainer.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@react.component
let make = () => {
open HSwitchUtils
open HyperswitchAtom
let url = RescriptReactRouter.useUrl()
let userPermissionJson = Recoil.useRecoilValueFromAtom(userPermissionAtom)
let {userInfo: {transactionEntity}} = React.useContext(UserInfoProvider.defaultContext)
let {payOut} = featureFlagAtom->Recoil.useRecoilValueFromAtom
<div key={(transactionEntity :> string)}>
{switch url.path->urlPath {
| list{"payments", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<FilterContext key="payments" index="payments">
<EntityScaffold
entityName="Payments"
remainingPath
access=Access
renderList={() => <Orders />}
renderShow={(id, key) => <ShowOrder id profileId={key} />}
/>
</FilterContext>
</AccessControl>
| list{"payouts", ...remainingPath} =>
<AccessControl isEnabled={payOut} permission=userPermissionJson.operationsView>
<FilterContext key="payouts" index="payouts">
<EntityScaffold
entityName="Payouts"
remainingPath
access=Access
renderList={() => <PayoutsList />}
renderShow={(id, key) => <ShowPayout id profileId={key} />}
/>
</FilterContext>
</AccessControl>
| list{"refunds", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<FilterContext key="refunds" index="refunds">
<EntityScaffold
entityName="Refunds"
remainingPath
access=Access
renderList={() => <Refund />}
renderShow={(id, key) => <ShowRefund id profileId={key} />}
/>
</FilterContext>
</AccessControl>
| list{"disputes", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<EntityScaffold
entityName="Disputes"
remainingPath
access=Access
renderList={() => <Disputes />}
renderShow={(id, key) => <ShowDisputes id profileId={key} />}
/>
</AccessControl>
| list{"unauthorized"} => <UnauthorizedPage />
| _ => <NotFoundPage />
}}
</div>
}
6 changes: 5 additions & 1 deletion src/entryPoints/AuthModule/UserInfo/UserInfoProvider.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ let make = (~children) => {
setUserInfo(_ => userData)
}

let getUserInfoData = () => {
userInfo
}

React.useEffect(() => {
getUserInfo()->ignore
None
}, [])

<Provider value={userInfo, setUserInfoData}>
<Provider value={userInfo, setUserInfoData, getUserInfoData}>
<RenderIf condition={screenState === Success}> children </RenderIf>
<RenderIf condition={screenState === Error}>
<NoDataFound message="Something went wrong" renderType=Painting />
Expand Down
1 change: 1 addition & 0 deletions src/entryPoints/AuthModule/UserInfo/UserInfoTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ type userInfo = {
type userInfoProviderTypes = {
userInfo: userInfo,
setUserInfoData: userInfo => unit,
getUserInfoData: unit => userInfo,
}
1 change: 1 addition & 0 deletions src/entryPoints/AuthModule/UserInfo/UserInfoUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ let entityMapper = entity => {
let defaultValueOfUserInfoProvider = {
userInfo: defaultValueOfUserInfo,
setUserInfoData: _ => (),
getUserInfoData: _ => defaultValueOfUserInfo,
}
open LogicUtils
let itemMapper = dict => {
Expand Down
55 changes: 5 additions & 50 deletions src/entryPoints/HyperSwitchApp.res
Original file line number Diff line number Diff line change
Expand Up @@ -207,56 +207,11 @@ let make = () => {
| list{"business-profiles", ..._}
| list{"payment-settings", ..._} =>
<BusinessProfileContainer />

| list{"payments", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<FilterContext key="payments" index="payments">
<EntityScaffold
entityName="Payments"
remainingPath
access=Access
renderList={() => <Orders />}
renderShow={(id, key) => <ShowOrder id profileId={key} />}
/>
</FilterContext>
</AccessControl>

| list{"payouts", ...remainingPath} =>
<AccessControl
isEnabled={featureFlagDetails.payOut}
permission=userPermissionJson.operationsView>
<FilterContext key="payouts" index="payouts">
<EntityScaffold
entityName="Payouts"
remainingPath
access=Access
renderList={() => <PayoutsList />}
renderShow={(id, key) => <ShowPayout id profileId={key} />}
/>
</FilterContext>
</AccessControl>
| list{"refunds", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<FilterContext key="refunds" index="refunds">
<EntityScaffold
entityName="Refunds"
remainingPath
access=Access
renderList={() => <Refund />}
renderShow={(id, key) => <ShowRefund id profileId={key} />}
/>
</FilterContext>
</AccessControl>
| list{"disputes", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<EntityScaffold
entityName="Disputes"
remainingPath
access=Access
renderList={() => <Disputes />}
renderShow={(id, key) => <ShowDisputes id profileId={key} />}
/>
</AccessControl>
| list{"payments", ..._}
| list{"refunds", ..._}
| list{"disputes", ..._}
| list{"payouts", ..._} =>
<TransactionContainer />
| list{"customers", ...remainingPath} =>
<AccessControl permission=userPermissionJson.operationsView>
<EntityScaffold
Expand Down
32 changes: 22 additions & 10 deletions src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exception JsonException(JSON.t)

let useGetURL = () => {
let {merchantId} = useCommonAuthInfo()->Option.getOr(defaultAuthInfo)
let {userInfo: {userEntity}} = React.useContext(UserInfoProvider.defaultContext)
let {getUserInfoData} = React.useContext(UserInfoProvider.defaultContext)
let {userManagementRevamp} = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let getUrl = (
~entityName: entityName,
Expand All @@ -17,6 +17,7 @@ let useGetURL = () => {
~reconType: reconType=#NONE,
~queryParamerters: option<string>=None,
) => {
let {transactionEntity, userEntity} = getUserInfoData()
let connectorBaseURL = `account/${merchantId}/connectors`

let endpoint = switch entityName {
Expand Down Expand Up @@ -73,7 +74,7 @@ let useGetURL = () => {
| REFUND_FILTERS =>
switch methodType {
| Get =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `refunds/v2/filter`
| (#Profile, true) => `refunds/v2/profile/filter`
| _ => `refunds/v2/filter`
Expand All @@ -84,12 +85,23 @@ let useGetURL = () => {
| ORDER_FILTERS =>
switch methodType {
| Get =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payments/v2/filter`
| (#Profile, true) => `payments/v2/profile/filter`
| _ => `payments/v2/filter`
}

| _ => ""
}
| PAYOUTS_FILTERS =>
switch methodType {
| Post =>
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payouts/filter`
| (#Profile, true) => `payouts/profile/filter`
| _ => `payouts/filter`
}

| _ => ""
}
| ORDERS =>
Expand All @@ -104,7 +116,7 @@ let useGetURL = () => {
| None =>
switch queryParamerters {
| Some(queryParams) =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payments/list?${queryParams}`
| (#Profile, true) => `payments/profile/list?${queryParams}`
| _ => `payments/list?limit=100`
Expand All @@ -113,7 +125,7 @@ let useGetURL = () => {
}
}
| Post =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payments/list`
| (#Profile, true) => `payments/profile/list`
| _ => `payments/list`
Expand Down Expand Up @@ -144,7 +156,7 @@ let useGetURL = () => {
| None =>
switch queryParamerters {
| Some(queryParams) =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `refunds/list?${queryParams}`
| (#Profile, true) => `refunds/profile/list?limit=100`
| _ => `refunds/list?limit=100`
Expand All @@ -155,7 +167,7 @@ let useGetURL = () => {
| Post =>
switch id {
| Some(_keyid) =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `refunds/list`
| (#Profile, true) => `refunds/profile/list`
| _ => `refunds/list`
Expand All @@ -170,7 +182,7 @@ let useGetURL = () => {
switch id {
| Some(dispute_id) => `disputes/${dispute_id}`
| None =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `disputes/list?limit=10000`
| (#Profile, true) => `disputes/profile/list?limit=10000`
| _ => `disputes/list?limit=10000`
Expand All @@ -184,14 +196,14 @@ let useGetURL = () => {
switch id {
| Some(payout_id) => `payouts/${payout_id}`
| None =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payouts/list?limit=100`
| (#Profile, true) => `payouts/profile/list?limit=10000`
| _ => `payouts/list?limit=100`
}
}
| Post =>
switch (userEntity, userManagementRevamp) {
switch (transactionEntity, userManagementRevamp) {
| (#Merchant, true) => `payouts/list`
| (#Profile, true) => `payouts/profile/list`
| _ => `payouts/list`
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 @@ -6,6 +6,7 @@ type entityName =
| REFUND_FILTERS
| DISPUTES
| PAYOUTS
| PAYOUTS_FILTERS
| ANALYTICS_FILTERS
| ANALYTICS_PAYMENTS
| ANALYTICS_DISPUTES
Expand Down
14 changes: 11 additions & 3 deletions src/screens/Disputes/Disputes.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ let make = () => {
let (offset, setOffset) = React.useState(_ => 0)
let fetchDetails = useGetMethod()

let {generateReport, userManagementRevamp} =
HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let {updateTransactionEntity} = OMPSwitchHooks.useUserInfo()
let getDisputesList = async () => {
try {
setScreenState(_ => Loading)
Expand Down Expand Up @@ -62,10 +65,15 @@ let make = () => {
/>
</>

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

<div>
<PageUtils.PageHeading title="Disputes" subTitle="View and manage all disputes" />
<div className="flex justify-between items-center">
<PageUtils.PageHeading title="Disputes" subTitle="View and manage all disputes" />
<RenderIf condition={userManagementRevamp}>
<OMPSwitchHelper.OMPViews
views={OrderUIUtils.orderViewList} onChange={updateTransactionEntity}
/>
</RenderIf>
</div>
<div className="flex w-full justify-end pb-3 gap-3">
<RenderIf condition={generateReport && disputesData->Array.length > 0}>
<GenerateReport entityName={DISPUTE_REPORT} />
Expand Down
12 changes: 8 additions & 4 deletions src/screens/HSwitchRemoteFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,22 @@ module RemoteTableFilters = {
@react.component
let make = (
~apiType: Fetch.requestMethod=Get,
~filterUrl,
~setFilters,
~endTimeFilterKey,
~startTimeFilterKey,
~initialFilters,
~initialFixedFilter,
~setOffset,
~customLeftView,
~entityName: APIUtilsTypes.entityName,
(),
) => {
open LogicUtils
open APIUtils

let getURL = useGetURL()
let {userInfo: transactionEntity} = React.useContext(UserInfoProvider.defaultContext)

let {filterValue, updateExistingKeys, filterValueJson, reset} =
FilterContext.filterContext->React.useContext
let defaultFilters = {""->JSON.Encode.string}
Expand All @@ -140,8 +145,6 @@ module RemoteTableFilters = {
None
}, [])

open APIUtils

let (filterDataJson, setFilterDataJson) = React.useState(_ => None)
let updateDetails = useUpdateMethod()
let defaultDate = getDateFilteredObject(~range=30)
Expand All @@ -151,6 +154,7 @@ module RemoteTableFilters = {

let fetchAllFilters = async () => {
try {
let filterUrl = getURL(~entityName, ~methodType=apiType)
setFilterDataJson(_ => None)
let response = switch apiType {
| Post => {
Expand All @@ -172,7 +176,7 @@ module RemoteTableFilters = {
React.useEffect(() => {
fetchAllFilters()->ignore
None
}, [])
}, [transactionEntity])

let filterData = filterDataJson->Option.getOr(Dict.make()->JSON.Encode.object)

Expand Down
12 changes: 8 additions & 4 deletions src/screens/Hooks/OMPSwitchHooks.res
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
type userInfo = {
getUserInfo: unit => promise<UserInfoTypes.userInfo>,
updateTransactionEntity: unit => unit,
updateTransactionEntity: UserInfoTypes.entity => unit,
}
let useUserInfo = () => {
open LogicUtils
let fetchApi = AuthHooks.useApiFetcher()
let {setUserInfoData} = React.useContext(UserInfoProvider.defaultContext)
let {setUserInfoData, userInfo} = React.useContext(UserInfoProvider.defaultContext)
let url = `${Window.env.apiBaseUrl}/user`

let getUserInfo = async () => {
Expand All @@ -22,8 +22,12 @@ let useUserInfo = () => {
}
}
}
let updateTransactionEntity = () => {
Js.log("")
let updateTransactionEntity = (transactionEntity: UserInfoTypes.entity) => {
let updateInfo = {
...userInfo,
transactionEntity,
}
setUserInfoData(updateInfo)
}
{getUserInfo, updateTransactionEntity}
}
Expand Down
Loading

0 comments on commit ff5d897

Please sign in to comment.