Skip to content

Commit

Permalink
Merge pull request #141 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1702 bug: email id exception pattern validation addded
  • Loading branch information
itsvick authored Aug 13, 2024
2 parents 9c81d41 + fd41554 commit 40f749d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
19 changes: 1 addition & 18 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,6 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
replacements,
email: sendTo,
});

if (
credentialResponse?.result[0]?.data[0]?.status ===
'success'
) {
showToastMessage(
t('COMMON.USER_CREDENTIAL_SEND_SUCCESSFULLY'),
'success'
);
} else {
showToastMessage(
t('COMMON.USER_CREDENTIALS_WILL_BE_SEND_SOON'),
'success'
);
}
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
Expand All @@ -326,7 +309,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
ReactGA.event('facilitator-creation-fail', {
error: error,
});
});
}
}
} else {
Expand Down
16 changes: 12 additions & 4 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, { Children, ReactNode, useEffect } from 'react';
import CustomRadioWidget from './CustomRadioWidget';
import MultiSelectCheckboxes from './MultiSelectCheckboxes';
import MultiSelectDropdown from './MultiSelectDropdown';
import { getCurrentYearPattern } from '@/utils/Helper';
import { getCurrentYearPattern, getEmailPattern } from '@/utils/Helper';
import useSubmittedButtonStore from '@/store/useSubmittedButtonStore';

const FormWithMaterialUI = withTheme(MaterialUITheme);
Expand Down Expand Up @@ -84,6 +84,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
console.log('errors', errors);
console.log('schema', schema);
const currentYearPattern = new RegExp(getCurrentYearPattern());
const emailPattern = new RegExp(getEmailPattern());

return errors.map((error: any) => {
switch (error.name) {
Expand Down Expand Up @@ -172,9 +173,16 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
break;
}
default: {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t('FORM_ERROR_MESSAGES.ENTER_VALID_YEAR');
if (error?.property === '.email') {
const validEmail = emailPattern.test(pattern);
if (!validEmail) {
error.message = t('FORM_ERROR_MESSAGES.ENTER_VALID_EMAIL');
}
} else {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t('FORM_ERROR_MESSAGES.ENTER_VALID_YEAR');
}
}
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UiSchema } from '@rjsf/utils';
import { JSONSchema7 } from 'json-schema';
import NumberInputField from './form/NumberInputField';
import { FormData, Field, FieldOption } from '@/utils/Interfaces';
import { getCurrentYearPattern } from '@/utils/Helper';
import { getCurrentYearPattern, getEmailPattern } from '@/utils/Helper';

export const customFields = {
NumberInputField: NumberInputField,
Expand Down Expand Up @@ -63,6 +63,7 @@ export const GenerateSchemaAndUiSchema = (
case 'email':
fieldSchema.type = 'string';
fieldSchema.format = 'email';
fieldSchema.pattern = getEmailPattern();
break;
case 'numeric':
fieldSchema.type = 'number';
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlannedSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
let isRecurringEvent = endDatetime !== endDateValue ? true : false;
setSessionBlocks(
sessionBlocks.map((block) =>
block?.id === selectedBlockId // assuming selectedId represents the current block ID
block?.id === selectedBlockId
? {
...block,
startDatetime: startDatetime,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,7 @@ export const getUserDetailsById = (data: any[], userId: any) => {

return null;
};

export const getEmailPattern = (): string => {
return '^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$';
};

0 comments on commit 40f749d

Please sign in to comment.