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

chore: Remove redundant OMP switch code [DRAFT PR] #2196

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
32 changes: 4 additions & 28 deletions src/screens/OMPSwitch/MerchantSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,15 @@ let make = () => {
let getURL = useGetURL()
let fetchDetails = useGetMethod()
let showToast = ToastState.useShowToast()
let internalSwitch = OMPSwitchHooks.useInternalSwitch()
let url = RescriptReactRouter.useUrl()

let {userInfo: {merchantId}} = React.useContext(UserInfoProvider.defaultContext)
let (showModal, setShowModal) = React.useState(_ => false)
let (merchantList, setMerchantList) = Recoil.useRecoilState(HyperswitchAtom.merchantListAtom)
let merchantDetailsTypedValue = Recoil.useRecoilValueFromAtom(
HyperswitchAtom.merchantDetailsValueAtom,
)
let (showSwitchingMerch, setShowSwitchingMerch) = React.useState(_ => false)
let (arrow, setArrow) = React.useState(_ => false)

let {
globalUIConfig: {sidebarColor: {backgroundColor, primaryTextColor, borderColor}},
} = React.useContext(ThemeProvider.themeContext)
Expand All @@ -153,28 +152,10 @@ let make = () => {
}
}
}

let switchMerch = async value => {
try {
setShowSwitchingMerch(_ => true)
let _ = await internalSwitch(~expectedMerchantId=Some(value))
RescriptReactRouter.replace(GlobalVars.extractModulePath(url))
setShowSwitchingMerch(_ => false)
} catch {
| _ => {
showToast(~message="Failed to switch merchant", ~toastType=ToastError)
setShowSwitchingMerch(_ => false)
}
}
}

let input: ReactFinalForm.fieldRenderPropsInput = {
name: "name",
onBlur: _ => (),
onChange: ev => {
let value = ev->Identity.formReactEventToString
switchMerch(value)->ignore
},
onChange: _ => (),
onFocus: _ => (),
value: merchantId->JSON.Encode.string,
checked: true,
Expand Down Expand Up @@ -213,9 +194,9 @@ let make = () => {
})
<div className="w-fit">
<SelectBox.BaseDropdown
input
allowMultiSelect=false
buttonText=""
input
deselectDisable=true
options={updatedMerchantList->generateDropdownOptionsCustomComponent}
marginTop={`mt-8 ${borderColor} shadow-generic_shadow`}
Expand All @@ -240,10 +221,5 @@ let make = () => {
<RenderIf condition={showModal}>
<NewMerchantCreationModal setShowModal showModal getMerchantList />
</RenderIf>
<LoaderModal
showModal={showSwitchingMerch}
setShowModal={setShowSwitchingMerch}
text="Switching merchant..."
/>
</div>
}
80 changes: 0 additions & 80 deletions src/screens/OMPSwitch/OMPSwitchHelper.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module ListBaseComp = {
~heading="",
~subHeading,
~arrow,
~showEditIcon=false,
~onEditClick=_ => (),
~isDarkBg=false,
~showDropdownArrow=true,
Expand Down Expand Up @@ -517,82 +516,3 @@ let generateDropdownOptionsCustomComponent: array<OMPSwitchTypes.ompListTypesCus
})
options
}
module EditOrgName = {
@react.component
let make = (~showModal, ~setShowModal, ~orgList, ~orgId, ~getOrgList) => {
open LogicUtils
open APIUtils
let getURL = useGetURL()
let updateDetails = useUpdateMethod()
let showToast = ToastState.useShowToast()
let initialValues =
[
("organization_name", OMPSwitchUtils.currentOMPName(orgList, orgId)->JSON.Encode.string),
]->Dict.fromArray

let validateForm = (values: JSON.t) => {
let errors = Dict.make()
let organizationName =
values->getDictFromJsonObject->getString("organization_name", "")->String.trim
let regexForOrganizationName = "^([a-z]|[A-Z]|[0-9]|_|\\s)+$"

let errorMessage = if organizationName->isEmptyString {
"Organization name cannot be empty"
} else if organizationName->String.length > 64 {
"Organization name cannot exceed 64 characters"
} else if !RegExp.test(RegExp.fromString(regexForOrganizationName), organizationName) {
"Organization name should not contain special characters"
} else {
""
}

if errorMessage->isNonEmptyString {
Dict.set(errors, "organization_name", errorMessage->JSON.Encode.string)
}

errors->JSON.Encode.object
}

let orgName = FormRenderer.makeFieldInfo(
~label="Org Name",
~name="organization_name",
~placeholder=`Eg: Hyperswitch`,
~customInput=InputFields.textInput(),
~isRequired=true,
)

let onSubmit = async (values, _) => {
try {
let url = getURL(~entityName=UPDATE_ORGANIZATION, ~methodType=Put, ~id=Some(orgId))
let _ = await updateDetails(url, values, Put)
let _ = await getOrgList()
showToast(~message="Updated organization name!", ~toastType=ToastSuccess)
} catch {
| _ => showToast(~message="Failed to update organization name!", ~toastType=ToastError)
}
setShowModal(_ => false)
Nullable.null
}

<>
<Modal modalHeading="Edit Org name" showModal setShowModal modalClass="w-1/4 m-auto">
<Form initialValues={initialValues->JSON.Encode.object} onSubmit validate={validateForm}>
<div className="flex flex-col gap-12 h-full w-full">
<FormRenderer.DesktopRow>
<FormRenderer.FieldRenderer
fieldWrapperClass="w-full"
field={orgName}
labelClass="!text-black font-medium !-ml-[0.5px]"
/>
</FormRenderer.DesktopRow>
<div className="flex justify-end w-full pr-5 pb-3">
<FormRenderer.SubmitButton
text="Submit changes" buttonSize={Small} loadingText="Processing..."
/>
</div>
</div>
</Form>
</Modal>
</>
}
}
Loading
Loading