Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: UI connector preview #1538

Merged
merged 28 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
70079f1
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 18, 2024
780a799
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 19, 2024
24ac760
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 24, 2024
2883deb
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 25, 2024
047c6c5
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 25, 2024
0365e91
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 25, 2024
5eeb7af
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 26, 2024
7ff97cf
Merge branch 'main' of github.com:juspay/hyperswitch-control-center
JeevaRamu0104 Sep 27, 2024
c3c5401
chore: remove error state
JeevaRamu0104 Sep 27, 2024
05d4d85
chore: update
JeevaRamu0104 Sep 27, 2024
071cdad
chore: update
JeevaRamu0104 Sep 30, 2024
1417473
chore: update
JeevaRamu0104 Sep 30, 2024
3057f7b
chore: update
JeevaRamu0104 Oct 1, 2024
11969e5
Merge branch 'main' of github.com:juspay/hyperswitch-control-center i…
JeevaRamu0104 Oct 3, 2024
6da0d24
chore: update connector preview page ui
JeevaRamu0104 Oct 3, 2024
55b010c
chore: update connector preview page ui
JeevaRamu0104 Oct 3, 2024
54e292c
chore: resolve conflict
JeevaRamu0104 Oct 3, 2024
048e515
chore: resolve conflict
JeevaRamu0104 Oct 3, 2024
cd15b30
Merge branch 'main' into update-ui-connector-preview
JeevaRamu0104 Oct 4, 2024
a7ae6bf
Merge branch 'update-ui-connector-preview' of github.com:juspay/hyper…
JeevaRamu0104 Oct 4, 2024
3927af1
chore: update connector preview
JeevaRamu0104 Oct 4, 2024
47b0462
Merge branch 'main' into update-ui-connector-preview
JeevaRamu0104 Oct 4, 2024
3347f5d
Merge branch 'update-ui-connector-preview' of github.com:juspay/hyper…
JeevaRamu0104 Oct 4, 2024
d43f30e
chore: update connector preview
JeevaRamu0104 Oct 4, 2024
b6d8375
Merge branch 'main' into update-ui-connector-preview
JeevaRamu0104 Oct 4, 2024
97e232d
chore: update
JeevaRamu0104 Oct 4, 2024
2db9137
Merge branch 'update-ui-connector-preview' of github.com:juspay/hyper…
JeevaRamu0104 Oct 4, 2024
b2d0d0e
Merge branch 'main' into update-ui-connector-preview
JeevaRamu0104 Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/screens/Connectors/ConnectPayPalFlow/MenuOptionForPayPal.res
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ let make = (
handleCancel: {text: "Cancel"},
})
}

let authType = switch connectorInfo.connector_account_details {
| HeaderKey(authKeys) => authKeys.auth_type
| BodyKey(bodyKey) => bodyKey.auth_type
| SignatureKey(signatureKey) => signatureKey.auth_type
| MultiAuthKey(multiAuthKey) => multiAuthKey.auth_type
| CertificateAuth(certificateAuth) => certificateAuth.auth_type
| CurrencyAuthKey(currencyAuthKey) => currencyAuthKey.auth_type
| UnKnownAuthType(_) => ""
}
<Popover \"as"="div" className="relative inline-block text-left">
{_popoverProps => <>
<Popover.Button> {_ => <Icon name="menu-option" size=28 />} </Popover.Button>
Expand All @@ -95,9 +103,7 @@ let make = (
id="neglectTopbarTheme"
className="relative flex flex-col bg-white py-3 overflow-hidden rounded ring-1 ring-black ring-opacity-5 w-max">
{<>
<RenderIf
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType ===
#SignatureKey}>
<RenderIf condition={authType->ConnectorUtils.mapAuthType === #SignatureKey}>
<Navbar.MenuOption
text="Create new PayPal account"
onClick={_ => {
Expand All @@ -113,9 +119,7 @@ let make = (
setSetupAccountStatus(_ => PayPalFlowTypes.Connect_paypal_landing)
}}
/>
<RenderIf
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType ===
#BodyKey}>
<RenderIf condition={authType->ConnectorUtils.mapAuthType === #BodyKey}>
<Navbar.MenuOption
text="Update"
onClick={_ => {
Expand All @@ -124,9 +128,7 @@ let make = (
}}
/>
</RenderIf>
<RenderIf
condition={connectorInfo.connector_account_details.auth_type->ConnectorUtils.mapAuthType ===
#SignatureKey}>
<RenderIf condition={authType->ConnectorUtils.mapAuthType === #SignatureKey}>
<Navbar.MenuOption
text="Update Payment Methods"
onClick={_ => {
Expand Down
1 change: 0 additions & 1 deletion src/screens/Connectors/ConnectorHome.res
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ let make = (~isPayoutFlow=false, ~showStepIndicator=true, ~showBreadCrumb=true)
currentStep
setCurrentStep
isUpdateFlow
isPayoutFlow
setInitialValues
getPayPalStatus
getConnectorDetails={Some(getConnectorDetails)}
Expand Down
64 changes: 27 additions & 37 deletions src/screens/Connectors/ConnectorPreview.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module KeyAndCopyArea = {
{copyValue->React.string}
</p>
<div
className="cursor-pointer h-20 w-20 pt-1"
className="cursor-pointer w-20 pt-1"
onClick={_ => {
Clipboard.writeText(copyValue)
showToast(~message="Copied to Clipboard!", ~toastType=ToastSuccess)
Expand Down Expand Up @@ -127,8 +127,6 @@ module ConnectorSummaryGrid = {
let make = (
~connectorInfo: ConnectorTypes.connectorPayload,
~connector,
~isPayoutFlow,
~setScreenState,
~setCurrentStep,
~updateStepValue=None,
~getConnectorDetails=None,
Expand All @@ -148,26 +146,32 @@ module ConnectorSummaryGrid = {
~connectorName={connectorInfo.merchant_connector_id},
~merchantId,
)
let (processorType, _) = connectorInfo.connector_type->ConnectorUtils.connectorTypeTuple
let {connector_name: connectorName} = connectorInfo

let connectorDetails = React.useMemo(() => {
try {
if connector->LogicUtils.isNonEmptyString {
let dict = isPayoutFlow
? Window.getPayoutConnectorConfig(connector)
: Window.getConnectorConfig(connector)

if connectorName->LogicUtils.isNonEmptyString {
let dict = switch processorType {
| PaymentProcessor => Window.getConnectorConfig(connectorName)
| PayoutProcessor => Window.getPayoutConnectorConfig(connectorName)
| AuthenticationProcessor => Window.getAuthenticationConnectorConfig(connectorName)
| PMAuthProcessor => Window.getPMAuthenticationProcessorConfig(connectorName)
| TaxProcessor => Window.getTaxProcessorConfig(connectorName)
| PaymentVas => JSON.Encode.null
}
dict
} else {
Dict.make()->JSON.Encode.object
JSON.Encode.null
}
} catch {
| Exn.Error(e) => {
Js.log2("FAILED TO LOAD CONNECTOR CONFIG", e)
let err = Exn.message(e)->Option.getOr("Something went wrong")
setScreenState(_ => PageLoaderWrapper.Error(err))
Dict.make()->JSON.Encode.object
let _ = Exn.message(e)->Option.getOr("Something went wrong")
JSON.Encode.null
}
}
}, [connector])
}, [connectorInfo.merchant_connector_id])
let (_, connectorAccountFields, _, _, _, _, _) = ConnectorUtils.getConnectorFields(
connectorDetails,
)
Expand All @@ -176,8 +180,8 @@ module ConnectorSummaryGrid = {
| _ => true
}

<div className="p-2 md:px-10">
<div className="grid grid-cols-4 my-12">
<>
<div className="grid grid-cols-4 border-b md:px-10 py-8">
<h4 className="text-lg font-semibold"> {"Integration status"->React.string} </h4>
<AddDataAttributes attributes=[("data-testid", "connector_status"->String.toLowerCase)]>
<div
Expand All @@ -186,7 +190,7 @@ module ConnectorSummaryGrid = {
</div>
</AddDataAttributes>
</div>
<div className="grid grid-cols-4 my-12">
<div className="grid grid-cols-4 border-b md:px-10 py-8">
<div className="flex items-start">
<h4 className="text-lg font-semibold"> {"Webhook Endpoint"->React.string} </h4>
<ToolTip
Expand All @@ -201,31 +205,20 @@ module ConnectorSummaryGrid = {
<KeyAndCopyArea copyValue={copyValueOfWebhookEndpoint} />
</div>
</div>
<div className="grid grid-cols-4 my-12">
<div className="grid grid-cols-4 border-b md:px-10 py-8">
<h4 className="text-lg font-semibold"> {"Profile"->React.string} </h4>
<div className="col-span-3">
{`${currentProfileName.profile_name} - ${connectorInfo.profile_id}`->React.string}
</div>
</div>
<div className="grid grid-cols-4 my-12">
<div className="grid grid-cols-4 border-b md:px-10 py-8">
<div className="flex items-start">
<h4 className="text-lg font-semibold"> {"API Keys"->React.string} </h4>
<h4 className="text-lg font-semibold"> {"Creds"->React.string} </h4>
</div>
<div className="flex flex-col gap-6 col-span-3">
<div className="flex flex-col gap-6 col-span-3">
<div className="flex gap-12">
<div className="flex flex-col gap-6 w-1/2">
{connectorAccountFields
->Dict.keysToArray
->Array.mapWithIndex((field, index) => {
open LogicUtils
let label = connectorAccountFields->getString(field, "")
<InfoField
key={index->Int.toString}
label={label}
render={connectorInfo->ConnectorUtils.getConnectorDetailsValue(field)}
/>
})
->React.array}
<ConnectorPreviewHelper.PreviewCreds connectorAccountFields connectorInfo />
</div>
<RenderIf condition={isUpdateFlow}>
<ConnectorUpdateAuthCreds connectorInfo getConnectorDetails />
Expand All @@ -236,7 +229,7 @@ module ConnectorSummaryGrid = {
</div>
{switch updateStepValue {
| Some(state) =>
<div className="grid grid-cols-4 my-12">
<div className="grid grid-cols-4 border-b md:px-10 py-8">
<div className="flex items-start">
<h4 className="text-lg font-semibold"> {"PMTs"->React.string} </h4>
</div>
Expand Down Expand Up @@ -302,7 +295,7 @@ module ConnectorSummaryGrid = {

| None => React.null
}}
</div>
</>
}
}

Expand All @@ -312,7 +305,6 @@ let make = (
~currentStep: ConnectorTypes.steps,
~setCurrentStep,
~isUpdateFlow,
~isPayoutFlow,
~showMenuOption=true,
~setInitialValues,
~getPayPalStatus,
Expand Down Expand Up @@ -432,8 +424,6 @@ let make = (
<ConnectorSummaryGrid
connectorInfo
connector
isPayoutFlow
setScreenState
setCurrentStep
updateStepValue={Some(ConnectorTypes.PaymentMethods)}
getConnectorDetails
Expand Down
69 changes: 69 additions & 0 deletions src/screens/Connectors/ConnectorPreviewHelper.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module InfoField = {
@react.component
let make = (~label, ~str) => {
<div>
<h2 className="text-lg font-semibold"> {label->React.string} </h2>
<h3 className=" break-words"> {str->React.string} </h3>
</div>
}
}

module CredsInfoField = {
@react.component
let make = (~authKeys, ~connectorAccountFields) => {
open LogicUtils
let dict = authKeys->Identity.genericTypeToDictOfJson
dict
->Dict.keysToArray
->Array.filter(ele => ele !== "auth_type")
->Array.map(field => {
let value = dict->getString(field, "")
let label = connectorAccountFields->getString(field, "")
<InfoField label str=value />
})
->React.array
}
}

module CashtoCodeCredsInfo = {
@react.component
let make = (~authKeys: ConnectorTypes.currencyAuthKey) => {
open LogicUtils
let dict = authKeys.auth_key_map->Identity.genericTypeToDictOfJson
dict
->Dict.keysToArray
->Array.map(ele => {
let data = dict->getDictfromDict(ele)
let keys = data->Dict.keysToArray

{
<>
<InfoField label="Currency" str=ele />
{keys
->Array.map(ele => {
let value = data->getString(ele, "")
<InfoField label={ele->snakeToTitle} str=value />
})
->React.array}
</>
}
})
->React.array
}
}

module PreviewCreds = {
@react.component
let make = (~connectorAccountFields, ~connectorInfo: ConnectorTypes.connectorPayload) => {
switch connectorInfo.connector_account_details {
| HeaderKey(authKeys) => <CredsInfoField authKeys connectorAccountFields />
| BodyKey(bodyKey) => <CredsInfoField authKeys=bodyKey connectorAccountFields />
| SignatureKey(signatureKey) => <CredsInfoField authKeys=signatureKey connectorAccountFields />
| MultiAuthKey(multiAuthKey) => <CredsInfoField authKeys=multiAuthKey connectorAccountFields />
| CertificateAuth(certificateAuth) =>
<CredsInfoField authKeys=certificateAuth connectorAccountFields />
| CurrencyAuthKey(currencyAuthKey) => <CashtoCodeCredsInfo authKeys=currencyAuthKey />
| UnKnownAuthType(_) => React.null
}
}
}
52 changes: 51 additions & 1 deletion src/screens/Connectors/ConnectorTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,56 @@ type wasmExtraPayload = {

// This type are used for FRM configuration which need to moved to wasm

type headerKey = {auth_type: string, api_key: string}
type bodyKey = {
auth_type: string,
api_key: string,
key1: string,
}
type signatureKey = {
auth_type: string,
api_key: string,
key1: string,
api_secret: string,
}
type multiAuthKey = {
auth_type: string,
api_key: string,
key1: string,
api_secret: string,
key2: string,
}
type currencyKey = {
auth_type: string,
merchant_id_classic: string,
password_classic: string,
username_classic: string,
}
type currencyAuthKey = {auth_key_map: Js.Dict.t<JSON.t>, auth_type: string}
type certificateAuth = {
auth_type: string,
certificate: string,
private_key: string,
}

type connectorAuthType =
| HeaderKey
| BodyKey
| SignatureKey
| MultiAuthKey
| CurrencyAuthKey
| CertificateAuth
| UnKnownAuthType

type connectorAuthTypeObj =
| HeaderKey(headerKey)
| BodyKey(bodyKey)
| SignatureKey(signatureKey)
| MultiAuthKey(multiAuthKey)
| CurrencyAuthKey(currencyAuthKey)
| CertificateAuth(certificateAuth)
| UnKnownAuthType(JSON.t)

type connectorAccountDetails = {
auth_type: string,
api_secret?: string,
Expand Down Expand Up @@ -250,7 +300,7 @@ type connectorPayload = {
connector_type: string,
connector_name: string,
connector_label: string,
connector_account_details: connectorAccountDetails,
connector_account_details: connectorAuthTypeObj,
test_mode: bool,
disabled: bool,
payment_methods_enabled: payment_methods_enabled,
Expand Down
13 changes: 11 additions & 2 deletions src/screens/Connectors/ConnectorUpdateAuthCreds.res
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let make = (~connectorInfo: ConnectorTypes.connectorPayload, ~getConnectorDetail
JSON.Encode.null
}
}
}, [connectorName])
}, [connectorInfo.merchant_connector_id])
let (
_,
connectorAccountFields,
Expand All @@ -49,11 +49,20 @@ let make = (~connectorInfo: ConnectorTypes.connectorPayload, ~getConnectorDetail
) = getConnectorFields(connectorDetails)

let initialValues = React.useMemo(() => {
let authType = switch connectorInfo.connector_account_details {
| HeaderKey(authKeys) => authKeys.auth_type
| BodyKey(bodyKey) => bodyKey.auth_type
| SignatureKey(signatureKey) => signatureKey.auth_type
| MultiAuthKey(multiAuthKey) => multiAuthKey.auth_type
| CertificateAuth(certificateAuth) => certificateAuth.auth_type
| CurrencyAuthKey(currencyAuthKey) => currencyAuthKey.auth_type
| UnKnownAuthType(_) => ""
}
[
("connector_type", connectorInfo.connector_type->JSON.Encode.string),
(
"connector_account_details",
[("auth_type", connectorInfo.connector_account_details.auth_type->JSON.Encode.string)]
[("auth_type", authType->JSON.Encode.string)]
->Dict.fromArray
->JSON.Encode.object,
),
Expand Down
10 changes: 0 additions & 10 deletions src/screens/Connectors/ConnectorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -1248,16 +1248,6 @@ let getPlaceHolder = label => {
`Enter ${label->LogicUtils.snakeToTitle}`
}

let getConnectorDetailsValue = (connectorInfo: connectorPayload, str) => {
switch str {
| "api_key" => connectorInfo.connector_account_details.api_key
| "api_secret" => connectorInfo.connector_account_details.api_secret
| "key1" => connectorInfo.connector_account_details.key1
| "key2" => connectorInfo.connector_account_details.key2
| "auth_type" => Some(connectorInfo.connector_account_details.auth_type)
| _ => Some("")
}
}
let connectorLabelDetailField = Dict.fromArray([
("connector_label", "Connector label"->JSON.Encode.string),
])
Expand Down
Loading
Loading