refactor(inquiries): Update form validation and error handling

- Change required fields in inquiries form to enforce mandatory input
- Enhance API error handler to provide user-friendly messages without exposing raw server text
- Improve test cases for API error handling to ensure accurate message mapping and validation
- Refactor error messages for clarity and consistency across the application
This commit is contained in:
AmirReza Jamali
2026-04-13 08:37:22 +03:30
parent 1ee57a4ec1
commit 8518c2c140
4 changed files with 380 additions and 115 deletions
+25 -4
View File
@@ -43,25 +43,25 @@ const InquiresForm = ({
name: "full_name",
label: "Full Name",
placeholder: "",
required: false,
required: true,
},
{
name: "company_name",
label: "Company Name",
placeholder: "",
required: false,
required: true,
},
{
name: "work_email",
label: "Work Email",
placeholder: "",
required: false,
required: true,
},
{
name: "phone_number",
label: "Phone Number",
placeholder: "",
required: false,
required: true,
},
],
[],
@@ -123,6 +123,8 @@ const InquiresForm = ({
field.name.includes("email") || field.name === "work_email";
const isPhoneField =
field.name.includes("phone") || field.name === "phone_number";
const isStrictTextField =
field.name === "full_name" || field.name === "company_name";
if (isPhoneField) {
return createFieldValidation(field.label, field.required, {
@@ -150,6 +152,25 @@ const InquiresForm = ({
});
}
if (isStrictTextField) {
return createFieldValidation(field.label, field.required, {
minLength: field.required
? {
value: 2,
message: `${field.label} must be at least 2 characters`,
}
: undefined,
maxLength: {
value: 200,
message: `${field.label} must not exceed 200 characters`,
},
pattern: {
value: /^[\p{L}\p{M}\p{N}\s'.,()&/_-]+$/u,
message: `${field.label} may only include letters, numbers, spaces, and common punctuation (no HTML or code)`,
},
});
}
return createFieldValidation(field.label, field.required, {
maxLength: {
value: 200,