Skip to content

Commit

Permalink
Merge pull request #2845 from glific/correction-in-error-message
Browse files Browse the repository at this point in the history
Updated the error message in HSM templates
  • Loading branch information
mdshamoon authored Apr 18, 2024
2 parents 10d4fb9 + f93a6a3 commit 4629b92
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/components/UI/Form/Input/Input.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
.Input {
width: 100%;
}
}
}
2 changes: 1 addition & 1 deletion src/containers/Template/Form/HSM/HSM.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('Add mode', () => {
// expect an error
expect(
screen.getByText(
'Message and sample look different. Please check for any characters, extra spaces or new lines.'
'Message and sample look different. You have to replace variables eg. {{1}} with actual values enclosed in [ ] eg. Replace {{1}} with [Monica].'
)
).toBeInTheDocument();
});
Expand Down
49 changes: 25 additions & 24 deletions src/containers/Template/Form/Template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,6 @@ import styles from './Template.module.css';

const regexForShortcode = /^[a-z0-9_]+$/g;

const HSMValidation = {
example: Yup.string()
.max(1024, 'Maximum 1024 characters are allowed')
.when('body', ([body], schema: any) =>
schema.test({
test: (exampleValue: any) => {
const finalmessageValue = body && body.replace(/\{\{([1-9]|1[0-9])\}\}/g, '[]');
const finalExampleValue = exampleValue && exampleValue.replace(/\[[^\]]*\]/g, '[]');
return finalExampleValue === finalmessageValue;
},
message:
'Message and sample look different. Please check for any characters, extra spaces or new lines.',
})
)
.required('Example is required.'),
category: Yup.object().nullable().required('Category is required.'),
shortcode: Yup.string()
.required('Element name is required.')
.matches(
regexForShortcode,
'Only lowercase alphanumeric characters and underscores are allowed.'
),
};

const dialogMessage = ' It will stop showing when you are drafting a customized message.';

const queries = {
Expand Down Expand Up @@ -398,6 +374,31 @@ const Template = ({
}
};

const HSMValidation = {
example: Yup.string()
.max(1024, t('Maximum 1024 characters are allowed'))
.when('body', ([body], schema: any) =>
schema.test({
test: (exampleValue: any) => {
const finalmessageValue = body && body.replace(/\{\{([1-9]|1[0-9])\}\}/g, '[]');
const finalExampleValue = exampleValue && exampleValue.replace(/\[[^\]]*\]/g, '[]');
return finalExampleValue === finalmessageValue;
},
message: t(
'Message and sample look different. You have to replace variables eg. {{1}} with actual values enclosed in [ ] eg. Replace {{1}} with [Monica].'
),
})
)
.required('Example is required.'),
category: Yup.object().nullable().required(t('Category is required.')),
shortcode: Yup.string()
.required(t('Element name is required.'))
.matches(
regexForShortcode,
'Only lowercase alphanumeric characters and underscores are allowed.'
),
};

const validateURL = (value: string) => {
if (value && type) {
setValidatingURL(true);
Expand Down
6 changes: 5 additions & 1 deletion src/i18n/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,9 @@
"No conversations found!": "No conversations found!",
"Add group to collection": "Add group to collection",
"Contact": "Contact",
"Remove Contact": "Remove Contact"
"Remove Contact": "Remove Contact",
"Message and sample look different. You have to replace variables eg. {{1}} with actual values enclosed in [ ] eg. Replace {{1}} with [Monica].": "Message and sample look different. You have to replace variables eg. {{1}} with actual values enclosed in [ ] eg. Replace {{1}} with [Monica].",
"Maximum 1024 characters are allowed": "Maximum 1024 characters are allowed",
"Element name is required.": "Element name is required.",
"Category is required.": "Category is required."
}
6 changes: 5 additions & 1 deletion src/i18n/hi/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,5 +444,9 @@
"Your personal WhatsApp number": "आपका निजी WhatsApp नंबर",
"Register with ": "Register with ",
"Validating URL": "URL मान्य करना",
"Enter name, label, keyword": "नाम, लेबल, कीवर्ड दर्ज करें"
"Enter name, label, keyword": "नाम, लेबल, कीवर्ड दर्ज करें",
"Message and sample look different. You have to replace variables eg. {{1}} with actual values enclosed in [ ] eg. Replace {{1}} with [Monica].": "संदेश और नमूना अलग दिखते हैं. आपको वेरिएबल्स को बदलना होगा जैसे। {{1}} उदाहरण के लिए [ ] में संलग्न वास्तविक मानों के साथ। {{1}} को [मोनिका] से बदलें।",
"Maximum 1024 characters are allowed": "अधिकतम 1024 वर्णों की अनुमति है",
"Element name is required.": "तत्व का नाम आवश्यक है.",
"Category is required.": "श्रेणी आवश्यक है."
}

0 comments on commit 4629b92

Please sign in to comment.