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

feat: default id for connector label #84

Merged
merged 17 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
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
8 changes: 8 additions & 0 deletions public/hyperswitch/icons/solid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/tooltip/ToolTip.res
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ let make = (
~descriptionComponent=React.null,
~tooltipPositioning: tooltipPositioning=#fixed,
~toolTipFor=?,
~tooltipWidthClass="w-64",
~tooltipWidthClass="w-fit",
~tooltipForWidthClass="",
~toolTipPosition: option<toolTipPosition>=?,
~customStyle="",
Expand Down
23 changes: 20 additions & 3 deletions src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ module BusinessProfileRender = {
let hyperswitchMixPanel = HSMixPanel.useSendEvent()
let {setDashboardPageState} = React.useContext(GlobalProvider.defaultContext)
let businessProfiles = Recoil.useRecoilValueFromAtom(HyperswitchAtom.businessProfilesAtom)

let arrayOfBusinessProfile = businessProfiles->MerchantAccountUtils.getArrayOfBusinessProfile
let defaultBusinessProfile = businessProfiles->MerchantAccountUtils.getValueFromBusinessProfile
let connectorLabelOnChange = ReactFinalForm.useField(`connector_label`).input.onChange

let (showModalFromOtherScreen, setShowModalFromOtherScreen) = React.useState(_ => false)

Expand Down Expand Up @@ -64,6 +65,16 @@ module BusinessProfileRender = {
...input,
onChange: {
ev => {
let profileName = (
arrayOfBusinessProfile
->Js.Array2.find((ele: HSwitchSettingTypes.profileEntity) =>
ele.profile_id === ev->Identity.formReactEventToString
)
->Belt.Option.getWithDefault(defaultBusinessProfile)
).profile_name
connectorLabelOnChange(
`${selectedConnector}_${profileName}`->Identity.stringToFormReactEvent,
)
input.onChange(ev)
mixpanelEventWrapper(
~url,
Expand All @@ -89,7 +100,7 @@ module BusinessProfileRender = {
/>
<UIUtils.RenderIf condition={!isUpdateFlow}>
<div className="text-gray-400 text-sm mt-3">
<span> {"Manage your list of business units"->React.string} </span>
<span> {"Manage your list of profiles."->React.string} </span>
<span
className={`ml-1 ${hereTextStyle}`}
onClick={_ => {
Expand Down Expand Up @@ -272,12 +283,18 @@ let make = (
let (showModal, setShowModal) = React.useState(_ => false)

let updatedInitialVal = React.useMemo1(() => {
let initialValuesToDict = initialValues->LogicUtils.getDictFromJsonObject
if !isUpdateFlow {
initialValuesToDict->Js.Dict.set(
"connector_label",
`${connector}_${activeBusinessProfile.profile_name}`->Js.Json.string,
)
}
if (
connector
->getConnectorNameTypeFromString
->checkIsDummyConnector(featureFlagDetails.testProcessors) && !isUpdateFlow
) {
let initialValuesToDict = initialValues->LogicUtils.getDictFromJsonObject
let apiKeyDict = [("api_key", "test_key"->Js.Json.string)]->Js.Dict.fromArray
initialValuesToDict->Js.Dict.set("connector_account_details", apiKeyDict->Js.Json.object_)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
external formEventToStr: ReactEvent.Form.t => string = "%identity"
external strToFormEvent: Js.String.t => ReactEvent.Form.t = "%identity"
let metaDataInputKeysToIgnore = ["google_pay", "apple_pay", "zen_apple_pay"]

let getCurrencyOption: CurrencyUtils.currencyCode => SelectBox.dropdownOption = currencyType => {
Expand Down Expand Up @@ -56,6 +58,46 @@ let inputField = (
(),
)

let inputFieldForConnectorLabel = (
~name,
~field,
~label,
~connector: ConnectorTypes.connectorName,
~getPlaceholder,
~checkRequiredFields,
~disabled,
) => {
FormRenderer.makeFieldInfo(
~label,
~isRequired=switch checkRequiredFields {
| Some(fun) => fun(connector, field)
| None => true
},
~name,
~description="This is an unique label you can generate and pass in order to identify this connector account on your Hyperswitch dashboard and reports. Eg: if your profile label is 'default', connector label can be 'stripe_default'",
~toolTipPosition=Right,
~customInput=(~input, ~placeholder as _) =>
InputFields.textInput(
~input={
...input,
value: input.value,
onChange: {
ev => {
input.onChange(ev)
}
},
},
~isDisabled=disabled,
~placeholder=switch getPlaceholder {
| Some(fun) => fun(connector, field, label)
| None => `Enter ${label->LogicUtils.snakeToTitle}`
},
(),
),
(),
)
}

module ErrorValidation = {
@react.component
let make = (~fieldName, ~validate) => {
Expand Down Expand Up @@ -100,11 +142,11 @@ module RenderConnectorInputFields = {
let keys =
details->Js.Dict.keys->Js.Array2.filter(ele => !Js.Array2.includes(keysToIgnore, ele))
keys
->Array.mapWithIndex((field, index) => {
->Array.map(field => {
let label = details->getString(field, "")
let formName = isLabelNested ? `${name}.${field}` : name
<UIUtils.RenderIf condition={label->Js.String2.length > 0}>
<div key={index->string_of_int}>
<div key={label}>
<FormRenderer.FieldRenderer
labelClass="font-semibold !text-hyperswitch_black"
field={switch (connector, field) {
Expand Down Expand Up @@ -138,6 +180,59 @@ module RenderConnectorInputFields = {
}
}

module RenderConnectorLabel = {
open ConnectorTypes
@react.component
let make = (
~connector: connectorName,
~selectedConnector,
~details,
~name,
~keysToIgnore: array<string>=[],
~checkRequiredFields=?,
~getPlaceholder=?,
~isLabelNested=true,
~disabled=false,
) => {
open ConnectorUtils
open LogicUtils
let featureFlagDetails = HyperswitchAtom.featureFlagAtom->Recoil.useRecoilValueFromAtom
let keys =
details->Js.Dict.keys->Js.Array2.filter(ele => !Js.Array2.includes(keysToIgnore, ele))
keys
->Array.map(field => {
let label = details->getString(field, "")
let formName = isLabelNested ? `${name}.${field}` : name
<UIUtils.RenderIf condition={label->Js.String2.length > 0}>
<div key={label}>
<FormRenderer.FieldRenderer
labelClass="font-semibold !text-hyperswitch_black"
field={inputFieldForConnectorLabel(
~name=formName,
~field,
~label,
~connector,
~checkRequiredFields,
~getPlaceholder,
~disabled,
)}
/>
<ErrorValidation
fieldName=formName
validate={validate(
~selectedConnector,
~dict=details,
~fieldName=formName,
~isLiveMode={featureFlagDetails.isLiveMode},
)}
/>
</div>
</UIUtils.RenderIf>
})
->React.array
}
}

module CurrencyAuthKey = {
@react.component
let make = (~dict, ~connector, ~selectedConnector: ConnectorTypes.integrationFields) => {
Expand Down Expand Up @@ -201,7 +296,7 @@ module ConnectorConfigurationFields = {
selectedConnector
/>
}}
<RenderConnectorInputFields
<RenderConnectorLabel
jainlokesh318 marked this conversation as resolved.
Show resolved Hide resolved
details={connectorLabelDetailField}
name={"connector_label"}
keysToIgnore=metaDataInputKeysToIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ let getHeading = colType => {
| ProfileName =>
Table.makeHeaderInfo(~key="profile_name", ~title="Profile Name", ~showSort=false, ())
| ConnectorLabel =>
Table.makeHeaderInfo(~key="connector_label", ~title="Label", ~showSort=false, ())
Table.makeHeaderInfo(~key="connector_label", ~title="Connector Label", ~showSort=false, ())
| PaymentMethods =>
Table.makeHeaderInfo(~key="payment_methods", ~title="Payment Methods", ~showSort=false, ())
}
Expand Down