diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 525d97d1..fbc4327c 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -63,7 +63,8 @@ "USERS_EMAIL": "Users Email", "STATE_NAME_REQUIRED": "State Name is Required", "DISTRICT_NAME_REQUIRED": "District Name is Required", - "SELECT_STATE": "Select State" + "SELECT_STATE": "Select State" , + "SOMETHING_WENT_WRONG":"Something went wrong" }, "LOGIN_PAGE": { "USERNAME": "Username", diff --git a/src/components/CommonUserModal.tsx b/src/components/CommonUserModal.tsx index 50d9f29f..6e18a9c1 100644 --- a/src/components/CommonUserModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -216,12 +216,15 @@ const CommonUserModal: React.FC = ({ fieldSchema?.hasOwnProperty("isDropdown") || fieldSchema?.hasOwnProperty("isCheckbox") ) { - apiBody.customFields.push({ + + apiBody.customFields.push({ fieldId: fieldId, value: [String(fieldValue)], }); + + } else { - if (fieldSchema.checkbox && fieldSchema.type === "array") { + if (fieldSchema.checkbox && fieldSchema.type === "array" && isEditModal) { apiBody.customFields.push({ fieldId: fieldId, value: String(fieldValue).split(","), @@ -275,6 +278,8 @@ const CommonUserModal: React.FC = ({ showToastMessage(t(messageKey), "success"); } else { const response = await createUser(apiBody); + if (response) { + const messageKey = userType === FormContextType.STUDENT ? "LEARNERS.LEARNER_CREATED_SUCCESSFULLY" @@ -283,10 +288,13 @@ const CommonUserModal: React.FC = ({ : "TEAM_LEADERS.TEAM_LEADER_CREATED_SUCCESSFULLY"; showToastMessage(t(messageKey), "success"); + } } onSubmit(true); onClose(); } catch (error) { + showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); + onClose(); console.log(error); } diff --git a/src/components/DynamicForm.tsx b/src/components/DynamicForm.tsx index 2faae2a5..2cdbf727 100644 --- a/src/components/DynamicForm.tsx +++ b/src/components/DynamicForm.tsx @@ -115,7 +115,7 @@ const DynamicForm: React.FC = ({ const property = error.property.substring(1); switch (pattern) { - case "^[a-z A-Z]+$": { + case '^[a-zA-Z][a-zA-Z ]*[a-zA-Z]$':{ error.message = t( "FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED", ); diff --git a/src/components/GeneratedSchemas.ts b/src/components/GeneratedSchemas.ts index 3216973e..2d098653 100644 --- a/src/components/GeneratedSchemas.ts +++ b/src/components/GeneratedSchemas.ts @@ -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, }; @@ -34,6 +35,7 @@ export const GenerateSchemaAndUiSchema = ( dependsOn, pattern, required, + isRequired } = field; const fieldSchema: any = { title: t(`FORM.${label}`), @@ -191,7 +193,7 @@ export const GenerateSchemaAndUiSchema = ( fieldSchema.pattern = pattern; // fieldUiSchema["ui:help"]= "Only alphabetic characters are allowed."; } - if (required) { + if (isRequired) { schema.required?.push(name); } if (field?.minLength) { @@ -201,9 +203,12 @@ export const GenerateSchemaAndUiSchema = ( fieldSchema.maxLength = Number(field.maxLength); } if (field?.validation) { - if (field?.validation?.includes("numeric")) { + if (field?.validation?.includes('numeric')) { // fieldUiSchema['ui:field'] = 'NumberInputField'; } + if (field?.validation?.includes('currentYear')) { + fieldSchema.pattern = getCurrentYearPattern(); + } fieldSchema.validation = field.validation; } if (schema !== undefined && schema.properties) { diff --git a/src/data/tableColumns.ts b/src/data/tableColumns.ts index e1c44e34..8acf77ad 100644 --- a/src/data/tableColumns.ts +++ b/src/data/tableColumns.ts @@ -6,14 +6,14 @@ export const getUserTableColumns = (t: any, isMobile: any) => { key: "name", title: t("FORM.NAME"), dataType: DataType.String, - sortDirection: SortDirection.Ascend, + // sortDirection: SortDirection.Ascend, width: isMobile ? 160 : null, }, { key: "status", title: t("FORM.STATUS"), dataType: DataType.String, - sortDirection: SortDirection.Ascend, + /// sortDirection: SortDirection.Ascend, width: isMobile ? 160 : null, }, @@ -79,14 +79,14 @@ export const getTLTableColumns = (t: any, isMobile: any) => { key: "name", title: t("FORM.NAME"), dataType: DataType.String, - sortDirection: SortDirection.Ascend, + //sortDirection: SortDirection.Ascend, // width: isMobile?160:null, }, { key: "status", title: t("FORM.STATUS"), dataType: DataType.String, - sortDirection: SortDirection.Ascend, + // sortDirection: SortDirection.Ascend, // width: isMobile?160:null, }, @@ -122,7 +122,7 @@ export const getTLTableColumns = (t: any, isMobile: any) => { key: "blocks", title: t("FORM.BLOCK"), dataType: DataType.String, - sortDirection: SortDirection.Ascend, + // sortDirection: SortDirection.Ascend, // width: isMobile?160:null, }, diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index d0be6159..9373077a 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -117,3 +117,7 @@ export const fieldTextValidation = (text: string) => { const regex = /^[A-Za-z\s]+$/; return regex.test(text); }; +export const getCurrentYearPattern = () => { + const currentYear = new Date().getFullYear(); + return `^(19[0-9][0-9]|20[0-${Math.floor(currentYear / 10) % 10}][0-${currentYear % 10}])$`; +}; \ No newline at end of file diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 9dd4d27b..08777be9 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -30,6 +30,8 @@ export interface Field { fieldId: string; required?: boolean; default: string | number; + isRequired?: boolean; + } export interface TenantCohortRoleMapping { tenantId: string; @@ -39,6 +41,8 @@ export interface TenantCohortRoleMapping { export interface CustomField { fieldId: string; value: string; + isRequired?: boolean; + } export interface FormData { formid: string;