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: make auto retry value field mandatory #1632

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/screens/Developer/APIKeys/DeveloperUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ let maxAutoRetries = FormRenderer.makeFieldInfo(
~label="Max Auto Retries",
~name="max_auto_retries_enabled",
~placeholder="Enter number of max auto retries",
~customInput=InputFields.textInput(~autoComplete="off"),
~isRequired=false,
~customInput=InputFields.numericTextInput(),
~isRequired=true,
)

module ErrorUI = {
Expand Down
15 changes: 10 additions & 5 deletions src/screens/Developer/PaymentSettings/PaymentSettings.res
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ module CollectDetails = {

module AutoRetries = {
@react.component
let make = () => {
let make = (~setCheckMaxAutoRetry) => {
open FormRenderer
open DeveloperUtils
open LogicUtils
Expand All @@ -307,6 +307,9 @@ module AutoRetries = {

if !isAutoRetryEnabled {
form.change("max_auto_retries_enabled", JSON.Encode.null->Identity.genericTypeToJson)
setCheckMaxAutoRetry(_ => false)
} else {
setCheckMaxAutoRetry(_ => true)
}

<>
Expand Down Expand Up @@ -352,6 +355,7 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {
let (busiProfieDetails, setBusiProfie) = React.useState(_ => businessProfileDetails)

let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Loading)
let (checkMaxAutoRetry, setCheckMaxAutoRetry) = React.useState(_ => true)
let (enableCustomHttpHeaders, setCustomHttpHeaders) = React.useState(_ => false)
let bgClass = webhookOnly ? "" : "bg-white dark:bg-jp-gray-lightgray_background"
let fetchBusinessProfiles = BusinessProfileHook.useFetchBusinessProfiles()
Expand All @@ -376,9 +380,10 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {

let fieldsToValidate = () => {
let defaultFieldsToValidate =
[WebhookUrl, ReturnUrl, MaxAutoRetries]->Array.filter(urlField =>
urlField === WebhookUrl || !webhookOnly
)
[WebhookUrl, ReturnUrl]->Array.filter(urlField => urlField === WebhookUrl || !webhookOnly)
if checkMaxAutoRetry {
defaultFieldsToValidate->Array.push(MaxAutoRetries)
}
defaultFieldsToValidate
}

Expand Down Expand Up @@ -521,7 +526,7 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {
/>
</DesktopRow>
</RenderIf>
<AutoRetries />
<AutoRetries setCheckMaxAutoRetry />
<ReturnUrl />
<WebHook enableCustomHttpHeaders setCustomHttpHeaders />
<DesktopRow>
Expand Down
22 changes: 9 additions & 13 deletions src/screens/Settings/MerchantAccountUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,6 @@ let checkValueChange = (~initialDict, ~valuesDict) => {
key->Option.isSome || updatedKeys > initialKeys
}

let validateEmptyValue = (key, errors) => {
switch key {
| ReturnUrl =>
Dict.set(errors, key->validationFieldsMapper, "Please enter a return url"->JSON.Encode.string)
| _ => ()
}
}

let validateEmptyArray = (key, errors, arrayValue) => {
switch key {
| AuthetnticationConnectors(_) =>
Expand Down Expand Up @@ -412,14 +404,13 @@ let validateCustom = (key, errors, value, isLiveMode) => {
}
}
| MaxAutoRetries =>
if !RegExp.test(%re("/^[1-5]$/"), value) {
if !RegExp.test(%re("/^(?:[1-5])$/"), value) {
Dict.set(
errors,
key->validationFieldsMapper,
"Please enter integer value from 1 to 5"->JSON.Encode.string,
)
}

| _ => ()
}
}
Expand All @@ -435,9 +426,14 @@ let validateMerchantAccountForm = (

let valuesDict = values->getDictFromJsonObject
fieldsToValidate->Array.forEach(key => {
let value = getString(valuesDict, key->validationFieldsMapper, "")->getNonEmptyString
switch value {
| Some(str) => key->validateCustom(errors, str, isLiveMode)
let val = valuesDict->getJsonObjectFromDict(key->validationFieldsMapper)

switch val->JSON.Classify.classify {
| String(str) => switch str->getNonEmptyString {
| Some(str) => key->validateCustom(errors, str, isLiveMode)
| _ => ()
}
| Number(num) => key->validateCustom(errors, num->Float.toString, isLiveMode)
| _ => ()
}
})
Expand Down
Loading