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 1 commit
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
14 changes: 9 additions & 5 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,15 @@ let handleLogout = async (
) => Promise.t<Fetch.Response.t>,
~setAuthStatus,
) => {
let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ())
let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ())
setAuthStatus(HyperSwitchAuthTypes.LoggedOut)
LocalStorage.clear()
RescriptReactRouter.push("/register")
try {
let logoutUrl = getURL(~entityName=USERS, ~methodType=Post, ~userType=#SIGNOUT, ())
let _ = await fetchApi(logoutUrl, ~method_=Fetch.Post, ())
setAuthStatus(HyperSwitchAuthTypes.LoggedOut)
LocalStorage.clear()
RescriptReactRouter.push("/register")
} catch {
| _ => ()
}
}

let responseHandler = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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
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,63 @@ let inputField = (
(),
)

let inputFieldForConnectorLabel = (
~name,
~field,
~label,
~connector: ConnectorTypes.connectorName,
~getPlaceholder,
~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(() => {
jainlokesh318 marked this conversation as resolved.
Show resolved Hide resolved
connectorLabelOnChange(`${connectorName}_${profileName}`->strToFormEvent)
None
}, [profileName])

FormRenderer.makeFieldInfo(
~label,
~isRequired=switch checkRequiredFields {
| Some(fun) => fun(connector, field)
| None => true
},
~name,
~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 @@ -142,6 +201,63 @@ 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
->LogicUtils.safeParse
->FeatureFlagUtils.featureFlagType
let keys =
details->Js.Dict.keys->Js.Array2.filter(ele => !Js.Array2.includes(keysToIgnore, ele))
keys
->Array.mapWithIndex((field, index) => {
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}>
jainlokesh318 marked this conversation as resolved.
Show resolved Hide resolved
<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 @@ -205,7 +321,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