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

Bug #235333 [Admin Portal] Error Displayed When Updating User with Empty Mobile and Email Fields. PFA #58

Open
wants to merge 1 commit into
base: all-saas-0.2
Choose a base branch
from
Open
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
247 changes: 132 additions & 115 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,152 +132,169 @@ const DynamicForm: React.FC<DynamicFormProps> = ({

let updatedUiSchema: UiSchema = { ...uiSchema };

return errors?.map((error: any) => {
const property = error.property ? error.property.substring(1) : ""; // Check if error.property exists
return errors
?.map((error: any) => {
const property = error.property ? error.property : "";

if (!property) {
return error;
}
if (!property) {
return error;
}

if (updatedUiSchema[property] && updatedUiSchema[property]["ui:help"]) {
delete updatedUiSchema[property]["ui:help"];
}
const isFieldRequired = schema.required?.includes(property);

if (property === "mail") {
if (error.name === "required") {
error.message = submittedButtonStatus
? t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD")
: "";
} else if (error.name === "format" || error.name === "pattern") {
error.message = !submittedButtonStatus
? t("FORM_ERROR_MESSAGES.ENTER_VALID_EMAIL_ADDRESS")
: "";
if (!isFieldRequired) {
error.message = "";
return null;
}
return error;
}
switch (error.name) {
case "required": {
error.message = submittedButtonStatus
? t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD")
: "";
break;

if (updatedUiSchema[property] && updatedUiSchema[property]["ui:help"]) {
delete updatedUiSchema[property]["ui:help"];
}
case "maximum": {
if (schema.properties?.[property]?.validation?.includes("numeric")) {
if (property === "age") {
error.message = t(
"FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR_AGE",
{
maxLength: schema.properties?.[property]?.maxLength,
}
);
}

if (property === "mail") {
if (error.name === "required") {
error.message = submittedButtonStatus
? t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD")
: "";
} else if (error.name === "format" || error.name === "pattern") {
error.message = !submittedButtonStatus
? t("FORM_ERROR_MESSAGES.ENTER_VALID_EMAIL_ADDRESS")
: "";
}
break;
return error;
}
case "minimum": {
if (schema.properties?.[property]?.validation?.includes("numeric")) {
error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", {
minLength: schema.properties?.[property]?.minLength,
});
if (property === "age") {
error.message = t(
"FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR_AGE",
{
minLength: schema.properties?.[property]?.minLength,
}
);

switch (error.name) {
case "required": {
error.message = submittedButtonStatus
? t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD")
: "";
break;
}
case "maximum": {
if (
schema.properties?.[property]?.validation?.includes("numeric")
) {
if (property === "age") {
error.message = t(
"FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR_AGE",
{
maxLength: schema.properties?.[property]?.maxLength,
}
);
}
}
break;
}
break;
}
case "pattern": {
const pattern = error?.params?.pattern;

const shouldSkipDefaultValidation =
schema.properties?.[property]?.skipDefaultValidation;
if (shouldSkipDefaultValidation) {
error.message = "";
case "minimum": {
if (
schema.properties?.[property]?.validation?.includes("numeric")
) {
error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", {
minLength: schema.properties?.[property]?.minLength,
});
if (property === "age") {
error.message = t(
"FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR_AGE",
{
minLength: schema.properties?.[property]?.minLength,
}
);
}
}
break;
}
case "pattern": {
const pattern = error?.params?.pattern;

switch (pattern) {
case "^[a-zA-Z][a-zA-Z ]*[a-zA-Z]$": {
error.message = t(
"FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
const shouldSkipDefaultValidation =
schema.properties?.[property]?.skipDefaultValidation;
if (shouldSkipDefaultValidation) {
error.message = "";
break;
}
case "^[6-9]\\d{9}$": {
const validations = schema.properties?.[property]?.validation;
if (
validations?.includes("mobile") ||
validations?.includes("mobileNo")
) {

switch (pattern) {
case "^[a-zA-Z][a-zA-Z ]*[a-zA-Z]$": {
error.message = t(
"FORM_ERROR_MESSAGES.ENTER_VALID_MOBILE_NUMBER"
"FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
} else if (validations?.includes(".age")) {
error.message = t("age must be valid");
} else {
break;
}
case "^[6-9]\\d{9}$": {
const validations = schema.properties?.[property]?.validation;
if (
validations?.includes("mobile") ||
validations?.includes("mobileNo")
) {
error.message = t(
"FORM_ERROR_MESSAGES.ENTER_VALID_MOBILE_NUMBER"
);
} else if (validations?.includes(".age")) {
error.message = t("age must be valid");
} else {
error.message = t(
"FORM_ERROR_MESSAGES.CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
}
break;
}

case "^d{10}$": {
error.message = t(
"FORM_ERROR_MESSAGES.CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
break;
}
break;
}

case "^d{10}$": {
error.message = t(
"FORM_ERROR_MESSAGES.CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED"
);
break;
}
default: {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t("FORM_ERROR_MESSAGES.ENTER_VALID_DATA");
default: {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t("FORM_ERROR_MESSAGES.ENTER_VALID_DATA");
}
break;
}
break;
}
break;
}
break;
}
case "minLength": {
if (schema.properties?.[property]?.validation?.includes("numeric")) {
error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", {
minLength: schema.properties?.[property]?.minLength,
});
case "minLength": {
if (
schema.properties?.[property]?.validation?.includes("numeric")
) {
error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", {
minLength: schema.properties?.[property]?.minLength,
});
}
break;
}
break;
}
case "maxLength": {
if (schema.properties?.[property]?.validation?.includes("numeric")) {
error.message = t("FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR", {
maxLength: schema.properties?.[property]?.maxLength,
});
case "maxLength": {
if (
schema.properties?.[property]?.validation?.includes("numeric")
) {
error.message = t("FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR", {
maxLength: schema.properties?.[property]?.maxLength,
});
}
break;
}
break;
}
case "format": {
const format = error?.params?.format;
switch (format) {
case "email": {
error.message = t("");
break;
case "format": {
const format = error?.params?.format;
switch (format) {
case "email": {
error.message = t("");
break;
}
}
}
}
}

if (!error.message && updatedUiSchema[property]) {
error.message = updatedUiSchema[property]["ui:help"];
}
if (!error.message && updatedUiSchema[property]) {
error.message = updatedUiSchema[property]["ui:help"];
}

return error;
});
return error;
})
.filter(Boolean);
};

useEffect(() => {
setSubmittedButtonStatus(false);
}, []);
Expand Down