Skip to content

Commit

Permalink
feat: add disable option for pm auth processor (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitanjli525 authored Sep 9, 2024
1 parent 646b752 commit 0a491d1
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/screens/Connectors/ConnectorTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ type paymentMethodTypes =
| ApplePay
| PayPal
| BankDebit
| OpenBankingPIS
| UnknownPaymentMethodType(string)

type advancedConfigurationList = {
Expand Down
6 changes: 6 additions & 0 deletions src/screens/Connectors/ConnectorUIUtils/PaymentMethod.res
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ module CardRenderer = {
? "PayPal Redirect"->React.string
: "PayPal SDK"->React.string}
</p>
| (OpenBankingPIS, _, _) =>
<p
className={`${p2RegularTextStyle} cursor-pointer`}
onClick={_ => removeOrAddMethods(value)}>
{"Open Banking PIS"->React.string}
</p>
| _ =>
<p
className={`${p2RegularTextStyle} cursor-pointer`}
Expand Down
1 change: 1 addition & 0 deletions src/screens/Connectors/ConnectorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ let getPaymentMethodTypeFromString = paymentMethodType => {
| "google_pay" => GooglePay
| "apple_pay" => ApplePay
| "paypal" => PayPal
| "open_banking_pis" => OpenBankingPIS
| _ => UnknownPaymentMethodType(paymentMethodType)
}
}
Expand Down
73 changes: 65 additions & 8 deletions src/screens/PMAuthenticationProcessor/PMAuthenticationHome.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
module MenuOption = {
open HeadlessUI
@react.component
let make = (~updateStepValue, ~setCurrentStep) => {
let make = (~updateStepValue, ~setCurrentStep, ~disableConnector, ~isConnectorDisabled) => {
let showPopUp = PopUpState.useShowPopUp()
let openConfirmationPopUp = _ => {
showPopUp({
popUpType: (Warning, WithIcon),
heading: "Confirm Action?",
description: `You are about to ${isConnectorDisabled
? "Enable"
: "Disable"->String.toLowerCase} this connector. This might impact your desired routing configurations. Please confirm to proceed.`->React.string,
handleConfirm: {
text: "Confirm",
onClick: _ => disableConnector(isConnectorDisabled)->ignore,
},
handleCancel: {text: "Cancel"},
})
}

let connectorStatusAvailableToSwitch = isConnectorDisabled ? "Enable" : "Disable"

<Popover \"as"="div" className="relative inline-block text-left">
{_popoverProps => <>
<Popover.Button> {_buttonProps => <Icon name="menu-option" size=28 />} </Popover.Button>
Expand All @@ -18,6 +36,13 @@ module MenuOption = {
setCurrentStep(_ => updateStepValue)
}}
/>
<Navbar.MenuOption
text={connectorStatusAvailableToSwitch}
onClick={_ => {
panelProps["close"]()
openConfirmationPopUp()
}}
/>
</>}
</div>
}}
Expand All @@ -38,6 +63,7 @@ let make = () => {
let url = RescriptReactRouter.useUrl()
let updateAPIHook = useUpdateMethod(~showErrorToast=false)
let fetchDetails = useGetMethod()
let updateDetails = useUpdateMethod()
let connectorName = UrlUtils.useGetFilterDictFromUrl("")->LogicUtils.getString("name", "")

let connectorID = HSwitchUtils.getConnectorIDFromUrl(url.path->List.toArray, "")
Expand All @@ -55,6 +81,27 @@ let make = () => {
| _ => true
}

let connectorInfo =
initialValues->LogicUtils.getDictFromJsonObject->ConnectorListMapper.getProcessorPayloadType

let isConnectorDisabled = connectorInfo.disabled

let disableConnector = async isConnectorDisabled => {
try {
let connectorID = connectorInfo.merchant_connector_id
let disableConnectorPayload = ConnectorUtils.getDisableConnectorPayload(
connectorInfo.connector_type,
isConnectorDisabled,
)
let url = getURL(~entityName=CONNECTOR, ~methodType=Post, ~id=Some(connectorID))
let _ = await updateDetails(url, disableConnectorPayload->JSON.Encode.object, Post)
showToast(~message="Successfully Saved the Changes", ~toastType=ToastSuccess)
RescriptReactRouter.push(GlobalVars.appendDashboardPath(~url="/pm-authentication-processor"))
} catch {
| Exn.Error(_) => showToast(~message="Failed to Disable connector!", ~toastType=ToastError)
}
}

let getConnectorDetails = async () => {
try {
let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Get, ~id=Some(connectorID))
Expand Down Expand Up @@ -194,8 +241,23 @@ let make = () => {
)
}

let connectorStatusStyle = connectorStatus =>
switch connectorStatus {
| true => "border bg-red-600 bg-opacity-40 border-red-400 text-red-500"
| false => "border bg-green-600 bg-opacity-40 border-green-700 text-green-700"
}

let summaryPageButton = switch currentStep {
| Preview => <MenuOption updateStepValue=ConfigurationFields setCurrentStep />
| Preview =>
<div className="flex gap-6 items-center">
<div
className={`px-4 py-2 rounded-full w-fit font-medium text-sm !text-black ${isConnectorDisabled->connectorStatusStyle}`}>
{(isConnectorDisabled ? "DISABLED" : "ENABLED")->React.string}
</div>
<MenuOption
updateStepValue=ConfigurationFields setCurrentStep disableConnector isConnectorDisabled
/>
</div>
| _ =>
<Button
text="Done"
Expand Down Expand Up @@ -271,12 +333,7 @@ let make = () => {
connectorType={PMAuthenticationProcessor}
headerButton={summaryPageButton}>
<ConnectorPreview.ConnectorSummaryGrid
connectorInfo={initialValues
->LogicUtils.getDictFromJsonObject
->ConnectorListMapper.getProcessorPayloadType}
connector=connectorName
setScreenState={_ => ()}
isPayoutFlow=false
connectorInfo connector=connectorName setScreenState={_ => ()} isPayoutFlow=false
/>
</ConnectorAccountDetailsHelper.ConnectorHeaderWrapper>
}}
Expand Down

0 comments on commit 0a491d1

Please sign in to comment.