-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a26c78
commit 7b05196
Showing
6 changed files
with
199 additions
and
184 deletions.
There are no files selected for viewing
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
144 changes: 144 additions & 0 deletions
144
src/screens/HyperSwitch/Connectors/ConnectPayPalFlow/MenuOptionForPayPal.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,144 @@ | ||
@react.component | ||
let make = ( | ||
~updateStepValue=ConnectorTypes.IntegFields, | ||
~setCurrentStep, | ||
~disableConnector, | ||
~isConnectorDisabled, | ||
~pageName="connector", | ||
~connectorInfoDict, | ||
~setScreenState, | ||
~isUpdateFlow, | ||
~setInitialValues, | ||
) => { | ||
open HeadlessUI | ||
let showPopUp = PopUpState.useShowPopUp() | ||
let showToast = ToastState.useShowToast() | ||
let deleteTrackingDetails = PayPalFlowUtils.useDeleteTrackingDetails() | ||
let updateConnectorAccountDetails = PayPalFlowUtils.useDeleteConnectorAccountDetails() | ||
let setSetupAccountStatus = Recoil.useSetRecoilState(HyperswitchAtom.paypalAccountStatusAtom) | ||
let connectorInfo = connectorInfoDict->ConnectorTableUtils.getProcessorPayloadType | ||
|
||
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" | ||
|
||
let updateConnectorAuthType = async values => { | ||
try { | ||
setScreenState(_ => PageLoaderWrapper.Loading) | ||
let res = await updateConnectorAccountDetails( | ||
values, | ||
connectorInfo.merchant_connector_id, | ||
connectorInfo.connector_name, | ||
isUpdateFlow, | ||
true, | ||
"inactive", | ||
) | ||
setInitialValues(_ => res) | ||
setScreenState(_ => Success) | ||
} catch { | ||
| Js.Exn.Error(e) => { | ||
let err = Js.Exn.message(e)->Option.getWithDefault("Something went wrong!") | ||
Js.Exn.raiseError(err) | ||
} | ||
} | ||
} | ||
|
||
let handleNewPayPalAccount = async () => { | ||
try { | ||
await deleteTrackingDetails(connectorInfo.merchant_connector_id, connectorInfo.connector_name) | ||
await updateConnectorAuthType(connectorInfoDict->Js.Json.object_) | ||
} catch { | ||
| Js.Exn.Error(e) => { | ||
let err = Js.Exn.message(e)->Option.getWithDefault("Something went wrong!") | ||
showToast(~message=err, ~toastType=ToastError, ()) | ||
} | ||
} | ||
} | ||
|
||
let popupForNewPayPalAccount = _ => { | ||
showPopUp({ | ||
popUpType: (Warning, WithIcon), | ||
heading: "Confirm Action ?", | ||
description: `By changing this the old account details will be lost `->React.string, | ||
handleConfirm: { | ||
text: "Confirm", | ||
onClick: _ => { | ||
handleNewPayPalAccount()->ignore | ||
setCurrentStep(_ => ConnectorTypes.AutomaticFlow) | ||
setSetupAccountStatus(._ => PayPalFlowTypes.Redirecting_to_paypal) | ||
}, | ||
}, | ||
handleCancel: {text: "Cancel"}, | ||
}) | ||
} | ||
|
||
<Popover \"as"="div" className="relative inline-block text-left"> | ||
{popoverProps => <> | ||
<Popover.Button> {buttonProps => <Icon name="menu-option" size=28 />} </Popover.Button> | ||
<Popover.Panel className="absolute z-20 right-0 top-10"> | ||
{panelProps => { | ||
<div | ||
id="neglectTopbarTheme" | ||
className="relative flex flex-col bg-white py-3 overflow-hidden rounded ring-1 ring-black ring-opacity-5 w-max"> | ||
{<> | ||
<UIUtils.RenderIf | ||
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType === | ||
#SignatureKey}> | ||
<Navbar.MenuOption | ||
text="Create new PayPal account" onClick={_ => popupForNewPayPalAccount()} | ||
/> | ||
</UIUtils.RenderIf> | ||
<Navbar.MenuOption | ||
text="Change configurations" | ||
onClick={_ => { | ||
setCurrentStep(_ => ConnectorTypes.AutomaticFlow) | ||
setSetupAccountStatus(._ => PayPalFlowTypes.Connect_paypal_landing) | ||
}} | ||
/> | ||
<UIUtils.RenderIf | ||
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType === | ||
#BodyKey}> | ||
<Navbar.MenuOption | ||
text="Update" | ||
onClick={_ => { | ||
setCurrentStep(_ => ConnectorTypes.IntegFields) | ||
setSetupAccountStatus(._ => PayPalFlowTypes.Manual_setup_flow) | ||
}} | ||
/> | ||
</UIUtils.RenderIf> | ||
<UIUtils.RenderIf | ||
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType === | ||
#SignatureKey}> | ||
<Navbar.MenuOption | ||
text="Update Payment Methods" | ||
onClick={_ => { | ||
setCurrentStep(_ => updateStepValue) | ||
}} | ||
/> | ||
</UIUtils.RenderIf> | ||
<Navbar.MenuOption | ||
text={connectorStatusAvailableToSwitch} | ||
onClick={_ => { | ||
openConfirmationPopUp() | ||
}} | ||
/> | ||
</>} | ||
</div> | ||
}} | ||
</Popover.Panel> | ||
</>} | ||
</Popover> | ||
} |
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
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
Oops, something went wrong.