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 2 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
2 changes: 1 addition & 1 deletion src/screens/Developer/APIKeys/DeveloperUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ let maxAutoRetries = FormRenderer.makeFieldInfo(
~name="max_auto_retries_enabled",
~placeholder="Enter number of max auto retries",
~customInput=InputFields.textInput(~autoComplete="off"),
Riddhiagrawal001 marked this conversation as resolved.
Show resolved Hide resolved
~isRequired=false,
~isRequired=true,
)

module ErrorUI = {
Expand Down
16 changes: 11 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,11 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {

let fieldsToValidate = () => {
let defaultFieldsToValidate =
[WebhookUrl, ReturnUrl, MaxAutoRetries]->Array.filter(urlField =>
urlField === WebhookUrl || !webhookOnly
)
[
WebhookUrl,
ReturnUrl,
checkMaxAutoRetry ? MaxAutoRetries : UnknownValidateFields(""),
]->Array.filter(urlField => urlField === WebhookUrl || !webhookOnly)
Riddhiagrawal001 marked this conversation as resolved.
Show resolved Hide resolved
defaultFieldsToValidate
}

Expand Down Expand Up @@ -521,7 +527,7 @@ let make = (~webhookOnly=false, ~showFormOnly=false, ~profileId="") => {
/>
</DesktopRow>
</RenderIf>
<AutoRetries />
<AutoRetries setCheckMaxAutoRetry />
<ReturnUrl />
<WebHook enableCustomHttpHeaders setCustomHttpHeaders />
<DesktopRow>
Expand Down
32 changes: 19 additions & 13 deletions src/screens/Settings/MerchantAccountUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ let parseBussinessProfileJson = (profileRecord: profileEntity) => {
)

profileInfo->setOptionBool("is_auto_retries_enabled", is_auto_retries_enabled)
profileInfo->setOptionInt("max_auto_retries_enabled", max_auto_retries_enabled)
profileInfo->setOptionString(
"max_auto_retries_enabled",
max_auto_retries_enabled->getOptionStringFromInt,
)

profileInfo->setDictNull("webhook_url", webhook_details.webhook_url)
profileInfo->setOptionString("webhook_version", webhook_details.webhook_version)
Expand Down Expand Up @@ -362,14 +365,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 @@ -419,7 +414,17 @@ let validateCustom = (key, errors, value, isLiveMode) => {
"Please enter integer value from 1 to 5"->JSON.Encode.string,
)
}
| _ => ()
}
}

let validateEmptyValue = (key, errors) => {
switch key {
| MaxAutoRetries =>
errors->Dict.set(
key->validationFieldsMapper,
"Please enter a max auto retries value"->JSON.Encode.string,
)
Riddhiagrawal001 marked this conversation as resolved.
Show resolved Hide resolved
| _ => ()
}
}
Expand All @@ -435,10 +440,11 @@ 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 value = getString(valuesDict, key->validationFieldsMapper, "")
if value->String.length < 1 {
key->validateEmptyValue(errors)
} else {
key->validateCustom(errors, value, isLiveMode)
}
})

Expand Down
4 changes: 4 additions & 0 deletions src/utils/LogicUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ let getOptionIntFromString = str => {
str->Int.fromString
}

let getOptionStringFromInt = int => {
Some(int->Option.getOr(0)->Int.toString)
}

Riddhiagrawal001 marked this conversation as resolved.
Show resolved Hide resolved
let getOptionFloatFromString = str => {
str->Float.fromString
}
Expand Down
Loading