Skip to content

Commit

Permalink
refactor: unused routing Types and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jainlokesh318 committed Jan 15, 2024
1 parent 719ed25 commit 6786412
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
38 changes: 0 additions & 38 deletions src/screens/HyperSwitch/Routing/RoutingUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -170,44 +170,6 @@ let constructNameDescription = routingType => {

let currentTabNameRecoilAtom = Recoil.atom(. "currentTabName", "ActiveTab")

module SaveAndActivateButton = {
@react.component
let make = (
~onSubmit: (Js.Json.t, 'a) => promise<Js.Nullable.t<Js.Json.t>>,
~handleActivateConfiguration,
) => {
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values"])->Js.Nullable.return,
)

let handleSaveAndActivate = async _ev => {
try {
let onSubmitResponse = await onSubmit(formState.values, false)
let currentActivatedFromJson =
onSubmitResponse->Js.Nullable.toOption->Belt.Option.getWithDefault(Js.Json.null)
let currentActivatedId =
currentActivatedFromJson->LogicUtils.getDictFromJsonObject->LogicUtils.getString("id", "")
let _ = await handleActivateConfiguration(Some(currentActivatedId))
} catch {
| Js.Exn.Error(e) =>
let _err =
Js.Exn.message(e)->Belt.Option.getWithDefault(
"Failed to save and activate configuration!",
)
}
}
<Button
text={"Save and Activate Rule"}
buttonType={Primary}
buttonSize=Button.Small
onClick={_ => {
handleSaveAndActivate()->ignore
}}
customButtonStyle="w-1/5 rounded-sm"
/>
}
}

let validateNameAndDescription = (~dict, ~errors) => {
["name", "description"]->Array.forEach(field => {
if dict->LogicUtils.getString(field, "")->String.trim === "" {
Expand Down
4 changes: 3 additions & 1 deletion src/screens/HyperSwitch/Routing/VolumeSplitRouting.res
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ module VolumeRoutingView = {
customSumbitButtonStyle="w-1/5 rounded-lg"
tooltipWidthClass="w-48"
/>}
submitButton={<SaveAndActivateButton onSubmit handleActivateConfiguration />}
submitButton={<AdvancedRoutingUIUtils.SaveAndActivateButton
onSubmit handleActivateConfiguration
/>}
headingText="Activate Current Configuration?"
subHeadingText="Activating the current configuration will override the current active configuration. Alternatively, save this configuration to access / activate it later from the configuration history. Please confirm."
leftIcon="hswitch-warning"
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/RoutingRevamp/AdvancedRouting.res
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ let make = (~routingRuleId, ~isActive, ~setCurrentRouting) => {
customSumbitButtonStyle="w-1/5 rounded-lg"
tooltipWidthClass="w-48"
/>}
submitButton={<RoutingUtils.SaveAndActivateButton
submitButton={<AdvancedRoutingUIUtils.SaveAndActivateButton
onSubmit handleActivateConfiguration
/>}
headingText="Activate Current Configuration?"
Expand Down
38 changes: 38 additions & 0 deletions src/screens/HyperSwitch/RoutingRevamp/AdvancedRoutingUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,41 @@ module ConfigureRuleButton = {
/>
}
}

module SaveAndActivateButton = {
@react.component
let make = (
~onSubmit: (Js.Json.t, 'a) => promise<Js.Nullable.t<Js.Json.t>>,
~handleActivateConfiguration,
) => {
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values"])->Js.Nullable.return,
)

let handleSaveAndActivate = async _ev => {
try {
let onSubmitResponse = await onSubmit(formState.values, false)
let currentActivatedFromJson =
onSubmitResponse->Js.Nullable.toOption->Belt.Option.getWithDefault(Js.Json.null)
let currentActivatedId =
currentActivatedFromJson->LogicUtils.getDictFromJsonObject->LogicUtils.getString("id", "")
let _ = await handleActivateConfiguration(Some(currentActivatedId))
} catch {
| Js.Exn.Error(e) =>
let _err =
Js.Exn.message(e)->Belt.Option.getWithDefault(
"Failed to save and activate configuration!",
)
}
}
<Button
text={"Save and Activate Rule"}
buttonType={Primary}
buttonSize=Button.Small
onClick={_ => {
handleSaveAndActivate()->ignore
}}
customButtonStyle="w-1/5 rounded-sm"
/>
}
}

0 comments on commit 6786412

Please sign in to comment.