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: profile name validations on edit profile #1633

Merged
merged 3 commits into from
Oct 21, 2024
Merged
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
25 changes: 24 additions & 1 deletion src/screens/Settings/BusinessMapping/BusinessMappingEntity.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,29 @@ module ProfileActions = {
)
let initialValues = [("profile_name", defaultProfileName->JSON.Encode.string)]->Dict.fromArray

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 onSubmit = async (values, _) => {
try {
let url = getURL(~entityName=BUSINESS_PROFILE, ~methodType=Post, ~id=Some(profileId))
Expand Down Expand Up @@ -72,7 +95,7 @@ module ProfileActions = {
showModal
setShowModal
modalClass="w-1/4 m-auto">
<Form initialValues={initialValues->JSON.Encode.object} onSubmit>
<Form initialValues={initialValues->JSON.Encode.object} onSubmit validate={validateForm}>
<div className="flex flex-col gap-12 h-full w-full">
<FormRenderer.DesktopRow>
<FormRenderer.FieldRenderer
Expand Down
Loading