Skip to content

Commit

Permalink
Merge pull request #79 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #0000 chore : facilitator flow changes
  • Loading branch information
itsvick authored Aug 2, 2024
2 parents 9073788 + 7ed9279 commit 56c893f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
4 changes: 3 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@
"MIN_LENGTH_CHARACTERS_ERROR": "Minimum {{minLength}} characters required",
"MAX_LENGTH_CHARACTERS_ERROR": "Maximum {{maxLength}} characters allowed",
"NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED": "Numbers and special characters are not allowed",
"ENTER_VALID_MOBILE_NUMBER": "Enter Valid mobile number"
"ENTER_VALID_MOBILE_NUMBER": "Enter Valid mobile number",
"ENTER_VALID_EMAIL": "Enter valid Email",
"ENTER_VALID_YEAR": "Enter valid Year"
},
"COURSE_PLANNER": {
"COURSE_PLANNER": "Course Plan",
Expand Down
24 changes: 19 additions & 5 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
value: [String(fieldValue)],
});
} else {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
if (fieldSchema.checkbox && fieldSchema.type === 'array') {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue).split(','),
});
} else {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
}
}
}
});
Expand Down Expand Up @@ -214,7 +221,14 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
} else {
const response = await createUser(apiBody);
console.log(response);
showToastMessage(t('COMMON.FACILITATOR_ADDED_SUCCESSFULLY'), 'success');
if (response) {
showToastMessage(
t('COMMON.FACILITATOR_ADDED_SUCCESSFULLY'),
'success'
);
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
}
onClose();
} catch (error) {
Expand Down
10 changes: 10 additions & 0 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import MultiSelectCheckboxes from './MultiSelectCheckboxes';
import { Button, Divider } from '@mui/material';
import { useTheme } from '@mui/material/styles';
import MultiSelectDropdown from './MultiSelectDropdown';
import { getCurrentYearPattern } from '@/utils/Helper';

const FormWithMaterialUI = withTheme(MaterialUITheme);

Expand Down Expand Up @@ -73,6 +74,8 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
function transformErrors(errors: any) {
console.log('errors', errors);
console.log('schema', schema);
const currentYearPattern = new RegExp(getCurrentYearPattern());

return errors.map((error: any) => {
switch (error.name) {
case 'required': {
Expand Down Expand Up @@ -110,6 +113,13 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
);
break;
}
default: {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t('FORM_ERROR_MESSAGES.ENTER_VALID_YEAR');
}
break;
}
}
break;
}
Expand Down
8 changes: 8 additions & 0 deletions src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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';

export const customFields = {
NumberInputField: NumberInputField,
Expand Down Expand Up @@ -216,6 +217,10 @@ export const GenerateSchemaAndUiSchema = (
fieldSchema.minLength = Number(field.minLength);
}

if (field?.default) {
fieldSchema.default = field.default;
}

if (field?.maxLength) {
fieldSchema.maxLength = Number(field.maxLength);
}
Expand All @@ -224,6 +229,9 @@ export const GenerateSchemaAndUiSchema = (
if (field?.validation?.includes('numeric')) {
// fieldUiSchema['ui:field'] = 'NumberInputField';
}
if (field?.validation?.includes('currentYear')) {
fieldSchema.pattern = getCurrentYearPattern();
}
fieldSchema.validation = field.validation;
}

Expand Down
5 changes: 5 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,8 @@ export const convertLocalToUTC = (localDateTime: any) => {
const utcDateTime = localDate.toISOString();
return utcDateTime;
};

export const getCurrentYearPattern = () => {
const currentYear = new Date().getFullYear();
return `^(19[0-9][0-9]|20[0-${Math.floor(currentYear / 10) % 10}][0-${currentYear % 10}])$`;
};
1 change: 1 addition & 0 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ export interface Field {
minLength?: number | null;
fieldId: string;
isRequired?: boolean;
default?: any;
}

export interface FormData {
Expand Down

0 comments on commit 56c893f

Please sign in to comment.