Skip to content

Commit

Permalink
fix: onChange move from ConnectorLabel to
Browse files Browse the repository at this point in the history
ProfileId change
  • Loading branch information
Pritish Budhiraja committed Dec 11, 2023
1 parent a1b26b1 commit 1e14e92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
22 changes: 17 additions & 5 deletions src/screens/HyperSwitch/Connectors/ConnectorAccountDetails.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
external formEventToBool: ReactEvent.Form.t => bool = "%identity"
external formEventToStr: ReactEvent.Form.t => string = "%identity"
external strToFormEvent: Js.String.t => ReactEvent.Form.t = "%identity"

let connectorsWithIntegrationSteps: array<ConnectorTypes.connectorName> = [
ADYEN,
Expand Down Expand Up @@ -33,8 +34,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 @@ -67,6 +69,14 @@ module BusinessProfileRender = {
...input,
onChange: {
ev => {
let profileName = (
arrayOfBusinessProfile
->Js.Array2.find((ele: HSwitchSettingTypes.profileEntity) =>
ele.profile_id === ev->formEventToStr
)
->Belt.Option.getWithDefault(defaultBusinessProfile)
).profile_name
connectorLabelOnChange(`${selectedConnector}_${profileName}`->strToFormEvent)
input.onChange(ev)
mixpanelEventWrapper(
~url,
Expand Down Expand Up @@ -280,10 +290,12 @@ let make = (

let updatedInitialVal = React.useMemo1(() => {
let initialValuesToDict = initialValues->LogicUtils.getDictFromJsonObject
initialValuesToDict->Js.Dict.set(
"connector_label",
`${connector}_${activeBusinessProfile.profile_name}`->Js.Json.string,
)
if !isUpdateFlow {
initialValuesToDict->Js.Dict.set(
"connector_label",
`${connector}_${activeBusinessProfile.profile_name}`->Js.Json.string,
)
}
if (
connector
->getConnectorNameTypeFromString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ let inputFieldForConnectorLabel = (
~checkRequiredFields,
~disabled,
) => {
open MerchantAccountUtils
let businessProfiles = HyperswitchAtom.businessProfilesAtom->Recoil.useRecoilValueFromAtom
let defaultBusinessProfile = businessProfiles->getValueFromBusinessProfile
let arrayOfBusinessProfile = businessProfiles->getArrayOfBusinessProfile
let connectorName = connector->ConnectorUtils.getConnectorNameString
let profileId =
ReactFinalForm.useField(`profile_id`).input.value->LogicUtils.getStringFromJson("")
let profileName = (
arrayOfBusinessProfile
->Js.Array2.find((ele: HSwitchSettingTypes.profileEntity) => ele.profile_id === profileId)
->Belt.Option.getWithDefault(defaultBusinessProfile)
).profile_name
let connectorLabelOnChange = ReactFinalForm.useField(`connector_label`).input.onChange

React.useEffect1(() => {
connectorLabelOnChange(`${connectorName}_${profileName}`->strToFormEvent)
None
}, [profileId])

FormRenderer.makeFieldInfo(
~label,
~isRequired=switch checkRequiredFields {
Expand Down

0 comments on commit 1e14e92

Please sign in to comment.