Skip to content

Commit

Permalink
fix: profile name validations (#1564)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitanjli525 authored Oct 15, 2024
1 parent 75bb251 commit 487012e
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/screens/Connectors/ConnectorUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ let taxJarInfo = {
description: "TaxJar is reimagining how businesses manage sales tax compliance. Its cloud-based platform automates the entire sales tax life cycle across all sales channels — from calculations and nexus tracking to reporting and filing.",
}
let nexixpayInfo = {
description : "Nexi's latest generation virtual POS is designed for those who, through a website, want to sell goods or services by managing payments online."
description: "Nexi's latest generation virtual POS is designed for those who, through a website, want to sell goods or services by managing payments online.",
}
let signifydInfo = {
description: "One platform to protect the entire shopper journey end-to-end",
Expand Down
46 changes: 30 additions & 16 deletions src/screens/OMPSwitch/MerchantSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,28 @@ module NewAccountCreationModal = {
}

let onSubmit = (values, _) => {
createNewAccount(values)
open LogicUtils
let dict = values->getDictFromJsonObject
let trimmedData = dict->getString("company_name", "")->String.trim
Dict.set(dict, "company_name", trimmedData->JSON.Encode.string)
createNewAccount(dict->JSON.Encode.object)
}

let merchantName = FormRenderer.makeFieldInfo(
~label="Merchant Name",
~name="company_name",
~placeholder="Eg: My New Merchant",
~customInput=InputFields.textInput(),
~customInput=(~input, ~placeholder as _) =>
InputFields.textInput()(
~input={
...input,
onChange: event =>
ReactEvent.Form.target(event)["value"]
->String.trimStart
->Identity.stringToFormReactEvent
->input.onChange,
},
~placeholder="Eg: My New Merchant",
),
~isRequired=true,
)

Expand All @@ -44,7 +58,7 @@ module NewAccountCreationModal = {
let errorMessage = if companyName->isEmptyString {
"Merchant name cannot be empty"
} else if companyName->String.length > 64 {
"Merchant name too long"
"Merchant name cannot exceed 64 characters"
} else if !RegExp.test(RegExp.fromString(regexForCompanyName), companyName) {
"Merchant name should not contain special characters"
} else {
Expand All @@ -59,34 +73,34 @@ module NewAccountCreationModal = {
}

let modalBody = {
<div className="p-2 m-2">
<div className="py-5 px-3 flex justify-between align-top">
<div className="">
<div className="pt-3 m-3 flex justify-between">
<CardUtils.CardHeader
heading="Add a new merchant"
subHeading=""
customSubHeadingStyle="w-full !max-w-none pr-10"
/>
<div className="h-fit" onClick={_ => setShowModal(_ => false)}>
<Icon
name="close" className="border-2 p-2 rounded-2xl bg-gray-100 cursor-pointer" size=30
/>
<Icon name="modal-close-icon" className="cursor-pointer" size=30 />
</div>
</div>
<hr />
<Form key="new-account-creation" onSubmit validate={validateForm}>
<div className="flex flex-col gap-12 h-full w-full">
<FormRenderer.DesktopRow>
<div className="flex flex-col gap-5">
<div className="flex flex-col h-full w-full">
<div className="py-10">
<FormRenderer.DesktopRow>
<FormRenderer.FieldRenderer
fieldWrapperClass="w-full"
field={merchantName}
showErrorOnChange=true
errorClass={ProdVerifyModalUtils.errorClass}
labelClass="!text-black font-medium !-ml-[0.5px]"
/>
</div>
</FormRenderer.DesktopRow>
<div className="flex justify-end w-full pr-5 pb-3">
<FormRenderer.SubmitButton text="Add Merchant" buttonSize={Small} />
</FormRenderer.DesktopRow>
</div>
<hr className="mt-4" />
<div className="flex justify-end w-full p-3">
<FormRenderer.SubmitButton text="Add Merchant" buttonSize=Small />
</div>
</div>
</Form>
Expand Down
67 changes: 52 additions & 15 deletions src/screens/OMPSwitch/ProfileSwitch.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,44 +49,81 @@ module NewAccountCreationModal = {
}

let onSubmit = (values, _) => {
createNewAccount(values)
open LogicUtils
let dict = values->getDictFromJsonObject
let trimmedData = dict->getString("profile_name", "")->String.trim
Dict.set(dict, "profile_name", trimmedData->JSON.Encode.string)
createNewAccount(dict->JSON.Encode.object)
}

let profileName = FormRenderer.makeFieldInfo(
~label="Profile Name",
~name="profile_name",
~placeholder="Eg: My New Profile",
~customInput=InputFields.textInput(),
~customInput=(~input, ~placeholder as _) =>
InputFields.textInput()(
~input={
...input,
onChange: event =>
ReactEvent.Form.target(event)["value"]
->String.trimStart
->Identity.stringToFormReactEvent
->input.onChange,
},
~placeholder="Eg: My New Profile",
),
~isRequired=true,
)

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

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

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

errors->JSON.Encode.object
}

let modalBody =
<div className="p-2 m-2">
<div className="py-5 px-3 flex justify-between align-top">
<div className="">
<div className="pt-3 m-3 flex justify-between">
<CardUtils.CardHeader
heading="Add a new profile"
subHeading=""
customSubHeadingStyle="w-full !max-w-none pr-10"
/>
<div className="h-fit" onClick={_ => setShowModal(_ => false)}>
<Icon
name="close" className="border-2 p-2 rounded-2xl bg-gray-100 cursor-pointer" size=30
/>
<Icon name="modal-close-icon" className="cursor-pointer" size=30 />
</div>
</div>
<Form key="new-account-creation" onSubmit>
<div className="flex flex-col gap-12 h-full w-full">
<FormRenderer.DesktopRow>
<div className="flex flex-col gap-5">
<hr />
<Form key="new-account-creation" onSubmit validate={validateForm}>
<div className="flex flex-col h-full w-full">
<div className="py-10">
<FormRenderer.DesktopRow>
<FormRenderer.FieldRenderer
fieldWrapperClass="w-full"
field={profileName}
errorClass={ProdVerifyModalUtils.errorClass}
labelClass="!text-black font-medium !-ml-[0.5px]"
/>
</div>
</FormRenderer.DesktopRow>
<div className="flex justify-end w-full pr-5 pb-3">
</FormRenderer.DesktopRow>
</div>
<hr className="mt-4" />
<div className="flex justify-end w-full p-3">
<FormRenderer.SubmitButton text="Add Profile" buttonSize=Small />
</div>
</div>
Expand Down

0 comments on commit 487012e

Please sign in to comment.