diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 93d98fcb..77d016be 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -70,8 +70,8 @@ "SEARCHBAR_PLACEHOLDER": "Search Learners..", "NEW_LEARNER": "New Learner", "FIRST_SELECT_REQUIRED_FIELDS": "First select required fields", - "LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!", - "LEARNER_UPDATED_SUCCESSFULLY": "Leaner has been Successfully Updated!" + "LEARNER_CREATED_SUCCESSFULLY": "Learner has been Successfully Created!", + "LEARNER_UPDATED_SUCCESSFULLY": "Learner has been Successfully Updated!" }, "TEAM_LEADERS": { "SEARCHBAR_PLACEHOLDER": "Search Team leaders.." @@ -188,7 +188,10 @@ "YEAR_OF_JOINING_SCP": "Year of joining SCP", "ASSIGN_CENTERS": "Assign Centers", "TYPE_OF_COHORT": "Type Of Cohort List", - "UNIT_NAME": "Unit Name" + "UNIT_NAME": "Unit Name", + "DESIGNATION":"Designation", + "SUBJECTS_I_TEACH":"Subject Teach", + "MY_MAIN_SUBJECTS":"Main subjects" }, "FORM_ERROR_MESSAGES": { "INVALID_INPUT": "Invalid Input.", @@ -200,8 +203,12 @@ "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", + "CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED": "Characters and special characters are not allowed", "NAME_CANNOT_INCLUDE_DIGITS": "Name can not include digits", - "INVALID_EMAIL_FORMAT": "Invalid email format" + "INVALID_EMAIL_FORMAT": "Invalid email format", + "ENTER_VALID_EMAIL": "Enter a valid email address", + "ENTER_VALID_MOBILE_NUMBER": "Enter a valid Mobile Number" + }, "TABLE_TITLE": { "NAME": "Name", @@ -212,4 +219,4 @@ "UPDATED_BY": "Updated By", "ACTIONS": "Actions" } -} +} \ No newline at end of file diff --git a/src/components/ActionIcon.tsx b/src/components/ActionIcon.tsx index 6fc02883..e8a3e4d2 100644 --- a/src/components/ActionIcon.tsx +++ b/src/components/ActionIcon.tsx @@ -44,10 +44,8 @@ const ActionIcon: React.FC = ({ // pointerEvents: "none", }} > - - - {t("COMMON.EDIT")} - + + {t("COMMON.EDIT")} @@ -63,7 +61,7 @@ const ActionIcon: React.FC = ({ }} > - {t("COMMON.DELETE")} + {t("COMMON.DELETE")} diff --git a/src/components/AddFacilitator.tsx b/src/components/AddFacilitator.tsx index 32b56388..9e5a5c65 100644 --- a/src/components/AddFacilitator.tsx +++ b/src/components/AddFacilitator.tsx @@ -11,27 +11,31 @@ import { FormContext, FormContextType, Role } from "@/utils/app.constant"; import DynamicForm from "@/components/DynamicForm"; import SendCredentialModal from "@/components/SendCredentialModal"; import SimpleModal from "@/components/SimpleModal"; -import { createUser, getFormRead, updateUser } from "@/services/CreateUserService"; +import { + createUser, + getFormRead, + updateUser, +} from "@/services/CreateUserService"; import { generateUsernameAndPassword } from "@/utils/Helper"; import { FormData } from "@/utils/Interfaces"; import { RoleId } from "@/utils/app.constant"; import AreaSelection from "./AreaSelection"; import { showToastMessage } from "./Toastify"; import { transformArray } from "../utils/Helper"; -import { useLocationState } from "@/utils/useLocationState"; +import { useLocationState } from "@/utils/useLocationState"; interface AddFacilitatorModalprops { open: boolean; onClose: () => void; - formData?:object; - isEditModal?:boolean; - userId?:string + formData?: object; + isEditModal?: boolean; + userId?: string; } const AddFacilitatorModal: React.FC = ({ open, formData, - isEditModal=false, + isEditModal = false, userId, onClose, }) => { @@ -41,10 +45,25 @@ const AddFacilitatorModal: React.FC = ({ const [uiSchema, setUiSchema] = useState(); const { - states, districts, blocks, allCenters, isMobile, isMediumScreen, - selectedState, selectedStateCode, selectedDistrict, selectedDistrictCode, - selectedCenter, dynamicForm, selectedBlock, selectedBlockCode, selectedCenterCode, - handleStateChangeWrapper, handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper + states, + districts, + blocks, + allCenters, + isMobile, + isMediumScreen, + selectedState, + selectedStateCode, + selectedDistrict, + selectedDistrictCode, + selectedCenter, + dynamicForm, + selectedBlock, + selectedBlockCode, + selectedCenterCode, + handleStateChangeWrapper, + handleDistrictChangeWrapper, + handleBlockChangeWrapper, + handleCenterChangeWrapper, } = useLocationState(open, onClose); useEffect(() => { @@ -66,7 +85,7 @@ const AddFacilitatorModal: React.FC = ({ ); console.log(centerOptionsList); } - + if (response) { const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t); setSchema(schema); @@ -83,7 +102,7 @@ const AddFacilitatorModal: React.FC = ({ data: IChangeEvent, event: React.FormEvent ) => { - // setOpenModal(true); + // setOpenModal(true); const target = event.target as HTMLFormElement; const elementsArray = Array.from(target.elements); @@ -104,7 +123,10 @@ const AddFacilitatorModal: React.FC = ({ console.log("Form data submitted:", formData); const schemaProperties = schema.properties; - const { username, password } = generateUsernameAndPassword(selectedStateCode,Role.TEACHER); + const { username, password } = generateUsernameAndPassword( + selectedStateCode, + Role.TEACHER + ); let apiBody: any = { username: username, @@ -121,11 +143,11 @@ const AddFacilitatorModal: React.FC = ({ Object.entries(formData).forEach(([fieldKey, fieldValue]) => { const fieldSchema = schemaProperties[fieldKey]; + console.log(fieldSchema) const fieldId = fieldSchema?.fieldId; console.log( `FieldID: ${fieldId}, FieldValue: ${fieldValue}, type: ${typeof fieldValue}` ); - if (fieldId === null || fieldId === "null") { if (typeof fieldValue !== "object") { apiBody[fieldKey] = fieldValue; @@ -140,59 +162,69 @@ const AddFacilitatorModal: React.FC = ({ value: [String(fieldValue)], }); } else { + if(fieldSchema.checkbox &&fieldSchema.type==="array") + { + apiBody.customFields.push({ + fieldId: fieldId, + value: String(fieldValue).split(',') + }); + } + else{ apiBody.customFields.push({ fieldId: fieldId, value: String(fieldValue), }); } + } } }); - console.log(apiBody); - if(!isEditModal) - { - apiBody.customFields.push({ - fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736", - value: [selectedBlockCode], - }); - apiBody.customFields.push({ - fieldId: "61b5909a-0b45-4282-8721-e614fd36d7bd", - value: [selectedStateCode], - }); - apiBody.customFields.push({ - fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300", - value: [selectedDistrictCode], - }); + if (!isEditModal) { + apiBody.customFields.push({ + fieldId: "549d3575-bf01-48a9-9fff-59220fede174", + value: [selectedBlockCode], + }); + apiBody.customFields.push({ + fieldId: "b61edfc6-3787-4079-86d3-37262bf23a9e", + value: [selectedStateCode], + }); + apiBody.customFields.push({ + fieldId: "f2d731dd-2298-40d3-80bb-9ae6c5b38fb8", + value: [selectedDistrictCode], + }); + } + try { + if (isEditModal && userId) { + console.log(userId); + const userData = { + name: apiBody.name, + mobile: apiBody.mobile, + }; + const customFields = apiBody.customFields; + console.log(customFields); + const object = { + userData: userData, + customFields: customFields, + }; + // const response = await updateUser(userId, object); + showToastMessage(t("LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"), "success"); + } else { + try{ + const response = await createUser(apiBody); + showToastMessage( + t("FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY"), + "success" + ); + } + catch (error) { + console.log(error); + } + + } + onClose(); + } catch (error) { + console.log(error); } -try{ - if(isEditModal && userId) - { - const userData={ - "name":apiBody.name, - "mobile": apiBody.mobile, - - }; - const customFields=apiBody.customFields; - console.log(customFields) - const object= - { - "userData":userData, - "customFields":customFields - } - const response = await updateUser(userId,object) - showToastMessage(t("LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"), "success"); - }else{ - const response = await createUser(apiBody); - showToastMessage(t('FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY'), 'success'); - } - onClose(); - - -} -catch(error) -{ - console.log(error); -} }; const handleChange = (event: IChangeEvent) => { @@ -217,9 +249,7 @@ catch(error) modalTitle={t("FACILITATORS.NEW_FACILITATOR")} > {!dynamicForm && ( - - {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")}{" "} - + {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")} )} - -{formData ? ( schema && uiSchema && ( - - {/* */} - - )) :( dynamicForm && schema && uiSchema && ( - - {/* */} - - ))} + {formData + ? schema && + uiSchema && ( + + {/* */} + + ) + : dynamicForm && + schema && + uiSchema && ( + + {/* */} + + )} diff --git a/src/components/AddLeanerModal.tsx b/src/components/AddLeanerModal.tsx index 6c6f8e03..e823b2b8 100644 --- a/src/components/AddLeanerModal.tsx +++ b/src/components/AddLeanerModal.tsx @@ -4,7 +4,11 @@ import { customFields, } from "@/components/GeneratedSchemas"; import SimpleModal from "@/components/SimpleModal"; -import { createUser, getFormRead , updateUser} from "@/services/CreateUserService"; +import { + createUser, + getFormRead, + updateUser, +} from "@/services/CreateUserService"; import { generateUsernameAndPassword } from "@/utils/Helper"; import { FormData } from "@/utils/Interfaces"; import { @@ -14,12 +18,7 @@ import { RoleId, } from "@/utils/app.constant"; import { useLocationState } from "@/utils/useLocationState"; -import { - Box, - Button, - Typography, - useTheme -} from "@mui/material"; +import { Box, Button, Typography, useTheme } from "@mui/material"; import { IChangeEvent } from "@rjsf/core"; import { RJSFSchema } from "@rjsf/utils"; import React, { useEffect } from "react"; @@ -31,15 +30,21 @@ import { showToastMessage } from "./Toastify"; interface AddLearnerModalProps { open: boolean; onClose: () => void; - formData?:object; - isEditModal?:boolean; - userId?:string + formData?: object; + isEditModal?: boolean; + userId?: string; } interface FieldProp { value: string; label: string; } -const AddLearnerModal: React.FC = ({ open, onClose, formData , isEditModal=false, userId}) => { +const AddLearnerModal: React.FC = ({ + open, + onClose, + formData, + isEditModal = false, + userId, +}) => { const [schema, setSchema] = React.useState(); const [uiSchema, setUiSchema] = React.useState(); @@ -68,7 +73,7 @@ const AddLearnerModal: React.FC = ({ open, onClose, formDa handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper, - selectedCenterCode + selectedCenterCode, } = useLocationState(open, onClose); useEffect(() => { @@ -83,7 +88,7 @@ const AddLearnerModal: React.FC = ({ open, onClose, formDa if (response) { const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t); setSchema(schema); - console.log(schema) + console.log(schema); setUiSchema(uiSchema); } } catch (error) { @@ -147,7 +152,6 @@ const AddLearnerModal: React.FC = ({ open, onClose, formDa console.log( `FieldID: ${fieldId}, FieldValue: ${fieldValue}, type: ${typeof fieldValue}` ); - if (fieldId === null || fieldId === "null") { if (typeof fieldValue !== "object") { @@ -169,51 +173,41 @@ const AddLearnerModal: React.FC = ({ open, onClose, formDa }); } } - - - }); - if(!isEditModal) - { - apiBody.customFields.push({ - fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736", - value: [selectedBlockCode], - }); - apiBody.customFields.push({ - fieldId: "61b5909a-0b45-4282-8721-e614fd36d7bd", - value: [selectedStateCode], - }); - apiBody.customFields.push({ - fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300", - value: [selectedDistrictCode], }); - } - - try { - if(isEditModal && userId) - { - console.log(apiBody) - const userData={ - "name":apiBody.name, - "mobile": apiBody.mobile, - "father_name":apiBody.father_name + if (!isEditModal) { + apiBody.customFields.push({ + fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736", + value: [selectedBlockCode], + }); + apiBody.customFields.push({ + fieldId: "61b5909a-0b45-4282-8721-e614fd36d7bd", + value: [selectedStateCode], + }); + apiBody.customFields.push({ + fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300", + value: [selectedDistrictCode], + }); + } + try { + if (isEditModal && userId) { + console.log("apiBody", apiBody); + const userData = { + name: apiBody.name, + mobile: apiBody.mobile, + father_name: apiBody.father_name, }; - const customFields=apiBody.customFields; - console.log(customFields) - const object= - { - "userData":userData, - "customFields":customFields - } - const response = await updateUser(userId,object) + const customFields = apiBody.customFields; + console.log(customFields); + const object = { + userData: userData, + customFields: customFields, + }; + const response = await updateUser(userId, object); showToastMessage(t("LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"), "success"); - - - } - else{ + } else { const response = await createUser(apiBody); showToastMessage(t("LEARNERS.LEARNER_CREATED_SUCCESSFULLY"), "success"); - } onClose(); } catch (error) { @@ -342,36 +336,39 @@ const AddLearnerModal: React.FC = ({ open, onClose, formDa - - {formData ? ( schema && uiSchema && ( - - {/* */} - - )) :( dynamicForm && schema && uiSchema && ( - - {/* */} - - ))} - + {formData + ? schema && + uiSchema && ( + + {/* */} + + ) + : dynamicForm && + schema && + uiSchema && ( + + {/* */} + + )} ); diff --git a/src/components/DynamicForm.tsx b/src/components/DynamicForm.tsx index 717ef03d..023f7aeb 100644 --- a/src/components/DynamicForm.tsx +++ b/src/components/DynamicForm.tsx @@ -1,11 +1,11 @@ -import { IChangeEvent, withTheme } from '@rjsf/core'; -import { Theme as MaterialUITheme } from '@rjsf/mui'; -import { RJSFSchema, RegistryFieldsType, WidgetProps } from '@rjsf/utils'; -import validator from '@rjsf/validator-ajv8'; -import { useTranslation } from 'next-i18next'; -import React, { ReactNode } from 'react'; -import CustomRadioWidget from './CustomRadioWidget'; -import MultiSelectCheckboxes from './MultiSelectCheckboxes'; +import { IChangeEvent, withTheme } from "@rjsf/core"; +import { Theme as MaterialUITheme } from "@rjsf/mui"; +import { RJSFSchema, RegistryFieldsType, WidgetProps } from "@rjsf/utils"; +import validator from "@rjsf/validator-ajv8"; +import { useTranslation } from "next-i18next"; +import React, { ReactNode } from "react"; +import CustomRadioWidget from "./CustomRadioWidget"; +import MultiSelectCheckboxes from "./MultiSelectCheckboxes"; const FormWithMaterialUI = withTheme(MaterialUITheme); @@ -21,7 +21,6 @@ interface DynamicFormProps { onError: (errors: any) => void; showErrorList: boolean; - widgets: { [key: string]: React.FC>; }; @@ -50,7 +49,7 @@ const DynamicForm: React.FC = ({ const handleError = (errors: any) => { if (errors.length > 0) { - const property = errors[0].property?.replace(/^root\./, ''); + const property = errors[0].property?.replace(/^root\./, ""); const errorField = document.querySelector( `[name$="${property}"]` ) as HTMLElement; @@ -68,47 +67,89 @@ const DynamicForm: React.FC = ({ }; function transformErrors(errors: any) { - console.log('errors', errors); - console.log('schema', schema); + console.log("errors", errors); + console.log("schema", schema); return errors.map((error: any) => { switch (error.name) { - case 'required': { - error.message = t('FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD'); + case "required": { + error.message = t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD"); break; } - case 'pattern': { - const property = error.property.substring(1); - if (schema.properties?.[property]?.validation?.includes('numeric')) { - error.message = t('FORM_ERROR_MESSAGES.ENTER_ONLY_DIGITS'); - } else if ( - schema.properties?.[property]?.validation?.includes( - 'characters-with-space' - ) - ) { - error.message = t( - 'FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED' - ); + case "pattern": { + // if (schema.properties?.[property]?.validation?.includes("numeric")) { + // error.message = t("FORM_ERROR_MESSAGES.ENTER_ONLY_DIGITS"); + // } else if ( + // schema.properties?.[property]?.validation?.includes( + // "characters-with-space" + // ) + // ) { + // error.message = t( + // "FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED" + // ); + // } else if (error.params.pattern === "^[a-z A-Z]+$") { + // error.message = t( + // "FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED" + // ); + // } + + const pattern = error?.params?.pattern; + const property = error.property.substring(1); + + switch (pattern) { + case "^[a-z A-Z]+$": { + error.message = t( + "FORM_ERROR_MESSAGES.NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED" + ); + break; + } + case "^[0-9]{10}$": { + if (schema.properties?.[property]?.validation?.includes("mobile")) { + error.message = t( + "FORM_ERROR_MESSAGES.ENTER_VALID_MOBILE_NUMBER" + ); + } 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 'minLength': { + case "minLength": { const property = error.property.substring(1); - if (schema.properties?.[property]?.validation?.includes('numeric')) { - error.message = t('FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR', { + if (schema.properties?.[property]?.validation?.includes("numeric")) { + error.message = t("FORM_ERROR_MESSAGES.MIN_LENGTH_DIGITS_ERROR", { minLength: schema.properties?.[property]?.minLength, }); } break; } - case 'maxLength': { + case "maxLength": { const property = error.property.substring(1); - if (schema.properties?.[property]?.validation?.includes('numeric')) { - error.message = t('FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR', { + if (schema.properties?.[property]?.validation?.includes("numeric")) { + error.message = t("FORM_ERROR_MESSAGES.MAX_LENGTH_DIGITS_ERROR", { maxLength: schema.properties?.[property]?.maxLength, }); } break; } + case "format": { + const format = error?.params?.format; + switch (format) { + case "email": { + error.message = t("FORM_ERROR_MESSAGES.ENTER_VALID_EMAIL"); + } + } + } } return error; @@ -116,17 +157,16 @@ const DynamicForm: React.FC = ({ } function handleChange(event: any) { - console.log('Form data changed:', event.formData); + console.log("Form data changed:", event.formData); onChange(event); } - return (
= ({ onError={handleError} transformErrors={transformErrors} fields={customFields} - > {children} @@ -145,4 +184,4 @@ const DynamicForm: React.FC = ({ ); }; -export default DynamicForm; \ No newline at end of file +export default DynamicForm; diff --git a/src/components/GeneratedSchemas.ts b/src/components/GeneratedSchemas.ts index 25798a89..cdaf3d0c 100644 --- a/src/components/GeneratedSchemas.ts +++ b/src/components/GeneratedSchemas.ts @@ -22,6 +22,7 @@ export const GenerateSchemaAndUiSchema = ( }; const uiSchema: UiSchema = {}; //form ui schema + let formValues: any = {}; // console.log('FormData', formData) formData?.fields?.forEach((field: Field) => { @@ -46,12 +47,17 @@ export const GenerateSchemaAndUiSchema = ( const fieldUiSchema: any = {}; + if (field?.default) { + formValues[name] = field.default; + } + switch (type) { case 'text': fieldSchema.type = 'string'; break; case 'email': fieldSchema.type = 'string'; + fieldSchema.format = 'email'; break; case 'numeric': fieldSchema.type = 'number'; @@ -210,5 +216,5 @@ export const GenerateSchemaAndUiSchema = ( } }); - return { schema, uiSchema, customFields }; + return { schema, uiSchema, customFields, formValues }; }; \ No newline at end of file diff --git a/src/components/HeaderComponent.tsx b/src/components/HeaderComponent.tsx index daa7f7f2..5ae9d3ac 100644 --- a/src/components/HeaderComponent.tsx +++ b/src/components/HeaderComponent.tsx @@ -39,6 +39,9 @@ const HeaderComponent = ({ userType, searchPlaceHolder, selectedState, + selectedStateCode, + selectedDistrictCode, + selectedBlockCode, selectedDistrict, selectedBlock, selectedSort, @@ -53,6 +56,7 @@ const HeaderComponent = ({ showStateDropdown = true, handleSearch, handleAddUserClick, + }: any) => { const { t } = useTranslation(); const theme = useTheme(); @@ -77,7 +81,7 @@ const HeaderComponent = ({ const object= { - "controllingfieldfk": selectedState, + "controllingfieldfk": selectedStateCode, "fieldName": "districts" @@ -102,7 +106,7 @@ const HeaderComponent = ({ const object= { - "controllingfieldfk": selectedDistrict, + "controllingfieldfk": selectedDistrictCode, "fieldName": "blocks" diff --git a/src/components/UserTable.tsx b/src/components/UserTable.tsx index 6ce23a90..ecf7d342 100644 --- a/src/components/UserTable.tsx +++ b/src/components/UserTable.tsx @@ -358,68 +358,67 @@ const UserTable: React.FC = ({ setSelectedSort(event.target.value as string); }; + const mapFields = (formFields: any, response: any) => { + let initialFormData: any = {}; + formFields.fields.forEach((item: any) => { + const userData = response?.userData; + const customField = userData?.customFields?.find((field: any) => field.fieldId === item.fieldId); + + const getValue = (data: any, field: any) => { + if (item?.isMultiSelect) { + if (item?.type === 'checkbox') { + return String(field.value).split(','); + } + return [field.value]; + } else { + if (item?.type === 'numeric') { + return Number(field.value); + } else if (item?.type === 'text') { + return String(field.value); + } else { + return field.value; + } + } + }; + + if (item.coreField) { + initialFormData[item.name] = item?.isMultiSelect + ? userData[item.name] ? [userData[item.name]] : userData[item.name] || '' + : item?.type === 'numeric' ? Number(userData[item.name]) + : item?.type === 'text' ? String(userData[item.name]) + : userData[item.name]; + } else { + initialFormData[item.name] = getValue(userData, customField); + } + }); + return initialFormData; + }; const handleEdit = async (rowData: any) => { console.log("Edit row:", rowData); - + try { const userId = rowData.userId; setUserId(userId); const fieldValue = true; const response = await getUserDetails(userId, fieldValue); - if(Role.STUDENT === role) - { - const formFields = await getFormRead("USERS", "STUDENT"); - + console.log(role); + + let formFields; + if (Role.STUDENT === role) { + formFields = await getFormRead("USERS", "STUDENT"); + setFormData(mapFields(formFields, response)); + handleOpenAddLearnerModal(); + } else if (Role.TEACHER === role) { + formFields = await getFormRead("USERS", "TEACHER"); + setFormData(mapFields(formFields, response)); + handleOpenAddFacilitatorModal(); + } + console.log("response", response); console.log("formFields", formFields); - // map according to formFields - - let initialFormData: any = {}; - formFields.fields.map((item: any) => { - if (item.coreField) { - // initialFormData[item.name] = response?.userData[item.name] || ""; - - if (item?.isMultiSelect) { - initialFormData[item.name] = response?.userData[item.name] ? [response.userData[item.name]] : response.userData[item.name] || ''; - } else { - if (item?.type === 'numeric') { - initialFormData[item.name] = Number(response.userData[item.name]); - } else if (item?.type === 'text') { - initialFormData[item.name] = String(response.userData[item.name]); - } else { - initialFormData[item.name] = response?.userData[item.name]; - } - } - - } else { - const field = response?.userData?.customFields.find( (field: any) => field.fieldId === item.fieldId); - - if (item?.isMultiSelect) { - initialFormData[item.name] = [field.value]; - } else { - if (item?.type === 'numeric') { - initialFormData[item.name] = Number(field.value); - } else if (item?.type === 'text') { - initialFormData[item.name] = String(field.value); - } else { - initialFormData[item.name] = field.value; - } - } - } - }); - - setFormData(initialFormData); - handleOpenAddLearnerModal(); - - console.log("initialFormData", initialFormData); - } - - } catch (error) { console.log(error); } - // console.log("responce",responce) - // Handle edit action here }; const handleDelete = (rowData: any) => { @@ -588,6 +587,10 @@ const UserTable: React.FC = ({ handleFilterChange: handleFilterChange, handleSearch: handleSearch, handleAddUserClick: handleAddUserClick, + selectedBlockCode:selectedBlockCode, + selectedDistrictCode:selectedDistrictCode, + selectedStateCode:selectedStateCode + }; return ( diff --git a/src/data/cardData.js b/src/data/cardData.js deleted file mode 100644 index 296fe78d..00000000 --- a/src/data/cardData.js +++ /dev/null @@ -1,51 +0,0 @@ -const cardData = [ - { - id: "1", - state: "Andhra Pradesh", - boardsUploaded: 1, - totalBoards: 3, - details: - "Andhra Pradesh is a state in the southeastern coastal region of India.", - boards: ["AP Board", "NIOS", "ICSE"], - subjects: ["Telugu", "English", "Maths"], - }, - { - id: "2", - state: "Maharashtra", - boardsUploaded: 2, - totalBoards: 3, - details: - "Maharashtra is a state in the western peninsular region of India.", - boards: ["Maharashtra Board", "CBSE", "ICSE"], - subjects: ["Marathi", "English", "Science"], - }, - { - id: "3", - state: "Karnataka", - boardsUploaded: 2, - totalBoards: 3, - details: "Karnataka is a state in the southwestern region of India.", - boards: ["Karnataka Board", "ICSE", "NIOS"], - subjects: ["Kannada", "Maths", "Science"], - }, - { - id: "4", - state: "Tamil Nadu", - boardsUploaded: 1, - totalBoards: 3, - details: "Tamil Nadu is a state in the southern part of India.", - boards: ["Tamil Nadu Board", "NIOS", "CBSE"], - subjects: ["Tamil", "English", "Social Studies"], - }, - { - id: "5", - state: "Kerala", - boardsUploaded: 2, - totalBoards: 2, - details: "Kerala is a state on the southwestern Malabar Coast of India.", - boards: ["Kerala Board", "ICSE", "CBSE"], - subjects: ["Malayalam", "Science", "Maths"], - }, -]; - -export default cardData; diff --git a/src/data/stateData.tsx b/src/data/stateData.tsx deleted file mode 100644 index b0dc5622..00000000 --- a/src/data/stateData.tsx +++ /dev/null @@ -1,888 +0,0 @@ -type StateDetails = { - state: string; - districts: string[]; -}; -const StateData: StateDetails[] = [ - { - state: "Andaman and Nicobar Islands", - districts: ["Nicobar", "North and Middle Andaman", "South Andaman"], - }, - { - state: "Andhra Pradesh", - districts: [ - "Anantapur", - "Chittoor", - "East Godavari", - "Guntur", - "Krishna", - "Kurnool", - "Nellore", - "Prakasam", - "Srikakulam", - "Visakhapatnam", - "Vizianagaram", - "West Godavari", - "YSR Kadapa", - ], - }, - { - state: "Arunachal Pradesh", - districts: [ - "Tawang", - "West Kameng", - "East Kameng", - "Papum Pare", - "Kurung Kumey", - "Kra Daadi", - "Lower Subansiri", - "Upper Subansiri", - "West Siang", - "East Siang", - "Siang", - "Upper Siang", - "Lower Siang", - "Lower Dibang Valley", - "Dibang Valley", - "Anjaw", - "Lohit", - "Namsai", - "Changlang", - "Tirap", - "Longding", - ], - }, - { - state: "Assam", - districts: [ - "Baksa", - "Barpeta", - "Biswanath", - "Bongaigaon", - "Cachar", - "Charaideo", - "Chirang", - "Darrang", - "Dhemaji", - "Dhubri", - "Dibrugarh", - "Goalpara", - "Golaghat", - "Hailakandi", - "Hojai", - "Jorhat", - "Kamrup Metropolitan", - "Kamrup", - "Karbi Anglong", - "Karimganj", - "Kokrajhar", - "Lakhimpur", - "Majuli", - "Morigaon", - "Nagaon", - "Nalbari", - "Dima Hasao", - "Sivasagar", - "Sonitpur", - "South Salmara-Mankachar", - "Tinsukia", - "Udalguri", - "West Karbi Anglong", - ], - }, - { - state: "Bihar", - districts: [ - "Araria", - "Arwal", - "Aurangabad", - "Banka", - "Begusarai", - "Bhagalpur", - "Bhojpur", - "Buxar", - "Darbhanga", - "East Champaran (Motihari)", - "Gaya", - "Gopalganj", - "Jamui", - "Jehanabad", - "Kaimur (Bhabua)", - "Katihar", - "Khagaria", - "Kishanganj", - "Lakhisarai", - "Madhepura", - "Madhubani", - "Munger (Monghyr)", - "Muzaffarpur", - "Nalanda", - "Nawada", - "Patna", - "Purnia (Purnea)", - "Rohtas", - "Saharsa", - "Samastipur", - "Saran", - "Sheikhpura", - "Sheohar", - "Sitamarhi", - "Siwan", - "Supaul", - "Vaishali", - "West Champaran", - ], - }, - { - state: "Chandigarh", - districts: ["Chandigarh"], - }, - { - state: "Chhattisgarh", - districts: [ - "Balod", - "Baloda Bazar", - "Balrampur", - "Bastar", - "Bemetara", - "Bijapur", - "Bilaspur", - "Dantewada", - "Dhamtari", - "Durg", - "Gariaband", - "Janjgir-Champa", - "Jashpur", - "Kabirdham (Kawardha)", - "Kanker (North Bastar)", - "Kondagaon", - "Korba", - "Korea (Koriya)", - "Mahasamund", - "Mungeli", - "Narayanpur", - "Raigarh", - "Raipur", - "Rajnandgaon", - "Sukma", - "Surajpur", - "Surguja", - ], - }, - { - state: "Dadra and Nagar Haveli and Daman and Diu", - districts: ["Dadra and Nagar Haveli", "Daman", "Diu"], - }, - { - state: "Delhi", - districts: [ - "Central Delhi", - "East Delhi", - "New Delhi", - "North Delhi", - "North East Delhi", - "North West Delhi", - "Shahdara", - "South Delhi", - "South East Delhi", - "South West Delhi", - "West Delhi", - ], - }, - { - state: "Goa", - districts: ["North Goa", "South Goa"], - }, - { - state: "Gujarat", - districts: [ - "Ahmedabad", - "Amreli", - "Anand", - "Aravalli", - "Banaskantha (Palanpur)", - "Bharuch", - "Bhavnagar", - "Botad", - "Chhota Udepur", - "Dahod", - "Dang", - "Devbhoomi Dwarka", - "Gandhinagar", - "Gir Somnath", - "Jamnagar", - "Junagadh", - "Kachchh", - "Kheda (Nadiad)", - "Mahisagar", - "Mehsana", - "Morbi", - "Narmada (Rajpipla)", - "Navsari", - "Panchmahal (Godhra)", - "Patan", - "Porbandar", - "Rajkot", - "Sabarkantha (Himmatnagar)", - "Surat", - "Surendranagar", - "Tapi (Vyara)", - "Vadodara", - "Valsad", - ], - }, - { - state: "Haryana", - districts: [ - "Ambala", - "Bhiwani", - "Charkhi Dadri", - "Faridabad", - "Fatehabad", - "Gurugram (Gurgaon)", - "Hisar", - "Jhajjar", - "Jind", - "Kaithal", - "Karnal", - "Kurukshetra", - "Mahendragarh", - "Nuh", - "Palwal", - "Panchkula", - "Panipat", - "Rewari", - "Rohtak", - "Sirsa", - "Sonipat", - "Yamunanagar", - ], - }, - { - state: "Himachal Pradesh", - districts: [ - "Bilaspur", - "Chamba", - "Hamirpur", - "Kangra", - "Kinnaur", - "Kullu", - "Lahaul and Spiti", - "Mandi", - "Shimla", - "Sirmaur (Sirmour)", - "Solan", - "Una", - ], - }, - { - state: "Jammu and Kashmir", - districts: [ - "Anantnag", - "Bandipore", - "Baramulla", - "Budgam", - "Doda", - "Ganderbal", - "Jammu", - "Kathua", - "Kishtwar", - "Kulgam", - "Kupwara", - "Poonch", - "Pulwama", - "Rajouri", - "Ramban", - "Reasi", - "Samba", - "Shopian", - "Srinagar", - "Udhampur", - ], - }, - { - state: "Jharkhand", - districts: [ - "Bokaro", - "Chatra", - "Deoghar", - "Dhanbad", - "Dumka", - "East Singhbhum", - "Garhwa", - "Giridih", - "Godda", - "Gumla", - "Hazaribag", - "Jamtara", - "Khunti", - "Koderma", - "Latehar", - "Lohardaga", - "Pakur", - "Palamu", - "Ramgarh", - "Ranchi", - "Sahibganj", - "Seraikela-Kharsawan", - "Simdega", - "West Singhbhum", - ], - }, - { - state: "Karnataka", - districts: [ - "Bagalkot", - "Ballari (Bellary)", - "Belagavi (Belgaum)", - "Bengaluru Rural", - "Bengaluru Urban", - "Bidar", - "Chamarajanagar", - "Chikballapur", - "Chikkamagaluru (Chikmagalur)", - "Chitradurga", - "Dakshina Kannada", - "Davanagere", - "Dharwad", - "Gadag", - "Hassan", - "Haveri", - "Kalaburagi (Gulbarga)", - "Kodagu", - "Kolar", - "Koppal", - "Mandya", - "Mysuru (Mysore)", - "Raichur", - "Ramanagara", - "Shivamogga (Shimoga)", - "Tumakuru (Tumkur)", - "Udupi", - "Uttara Kannada (Karwar)", - "Vijayapura (Bijapur)", - "Yadgir", - ], - }, - { - state: "Kerala", - districts: [ - "Alappuzha", - "Ernakulam", - "Idukki", - "Kannur", - "Kasaragod", - "Kollam", - "Kottayam", - "Kozhikode", - "Malappuram", - "Palakkad", - "Pathanamthitta", - "Thiruvananthapuram", - "Thrissur", - "Wayanad", - ], - }, - { - state: "Ladakh", - districts: ["Kargil", "Leh"], - }, - { - state: "Lakshadweep", - districts: ["Lakshadweep"], - }, - { - state: "Madhya Pradesh", - districts: [ - "Agar Malwa", - "Alirajpur", - "Anuppur", - "Ashoknagar", - "Balaghat", - "Barwani", - "Betul", - "Bhind", - "Bhopal", - "Burhanpur", - "Chhatarpur", - "Chhindwara", - "Damoh", - "Datia", - "Dewas", - "Dhar", - "Dindori", - "Guna", - "Gwalior", - "Harda", - "Hoshangabad", - "Indore", - "Jabalpur", - "Jhabua", - "Katni", - "Khandwa", - "Khargone", - "Mandla", - "Mandsaur", - "Morena", - "Narsinghpur", - "Neemuch", - "Panna", - "Raisen", - "Rajgarh", - "Ratlam", - "Rewa", - "Sagar", - "Satna", - "Sehore", - "Seoni", - "Shahdol", - "Shajapur", - "Sheopur", - "Shivpuri", - "Sidhi", - "Singrauli", - "Tikamgarh", - "Ujjain", - "Umaria", - "Vidisha", - ], - }, - { - state: "Maharashtra", - districts: [ - "Ahmednagar", - "Akola", - "Amravati", - "Aurangabad", - "Beed", - "Bhandara", - "Buldhana", - "Chandrapur", - "Dhule", - "Gadchiroli", - "Gondia", - "Hingoli", - "Jalgaon", - "Jalna", - "Kolhapur", - "Latur", - "Mumbai City", - "Mumbai Suburban", - "Nagpur", - "Nanded", - "Nandurbar", - "Nashik", - "Osmanabad", - "Palghar", - "Parbhani", - "Pune", - "Raigad", - "Ratnagiri", - "Sangli", - "Satara", - "Sindhudurg", - "Solapur", - "Thane", - "Wardha", - "Washim", - "Yavatmal", - ], - }, - { - state: "Manipur", - districts: [ - "Bishnupur", - "Chandel", - "Churachandpur", - "Imphal East", - "Imphal West", - "Jiribam", - "Kakching", - "Kamjong", - "Kangpokpi", - "Noney", - "Pherzawl", - "Senapati", - "Tamenglong", - "Tengnoupal", - "Thoubal", - "Ukhrul", - ], - }, - { - state: "Meghalaya", - districts: [ - "East Garo Hills", - "East Jaintia Hills", - "East Khasi Hills", - "North Garo Hills", - "Ri Bhoi", - "South Garo Hills", - "South West Garo Hills", - "South West Khasi Hills", - "West Garo Hills", - "West Jaintia Hills", - "West Khasi Hills", - ], - }, - { - state: "Mizoram", - districts: [ - "Aizawl", - "Champhai", - "Hnahthial", - "Khawzawl", - "Kolasib", - "Lawngtlai", - "Lunglei", - "Mamit", - "Saiha", - "Saitual", - "Serchhip", - ], - }, - { - state: "Nagaland", - districts: [ - "Dimapur", - "Kiphire", - "Kohima", - "Longleng", - "Mokokchung", - "Mon", - "Peren", - "Phek", - "Tuensang", - "Wokha", - "Zunheboto", - ], - }, - { - state: "Odisha", - districts: [ - "Angul", - "Balangir", - "Balasore", - "Bargarh", - "Bhadrak", - "Boudh", - "Cuttack", - "Deogarh", - "Dhenkanal", - "Gajapati", - "Ganjam", - "Jagatsinghpur", - "Jajpur", - "Jharsuguda", - "Kalahandi", - "Kandhamal", - "Kendrapara", - "Kendujhar (Keonjhar)", - "Khordha", - "Koraput", - "Malkangiri", - "Mayurbhanj", - "Nabarangpur", - "Nayagarh", - "Nuapada", - "Puri", - "Rayagada", - "Sambalpur", - "Subarnapur (Sonepur)", - "Sundargarh", - ], - }, - { - state: "Puducherry", - districts: ["Karaikal", "Mahe", "Puducherry", "Yanam"], - }, - { - state: "Punjab", - districts: [ - "Amritsar", - "Barnala", - "Bathinda", - "Faridkot", - "Fatehgarh Sahib", - "Fazilka", - "Ferozepur", - "Gurdaspur", - "Hoshiarpur", - "Jalandhar", - "Kapurthala", - "Ludhiana", - "Mansa", - "Moga", - "Muktsar", - "Pathankot", - "Patiala", - "Rupnagar", - "Sangrur", - "Shaheed Bhagat Singh Nagar (Nawanshahr)", - "Sri Muktsar Sahib", - "Tarn Taran", - ], - }, - { - state: "Rajasthan", - districts: [ - "Ajmer", - "Alwar", - "Banswara", - "Baran", - "Barmer", - "Bharatpur", - "Bhilwara", - "Bikaner", - "Bundi", - "Chittorgarh", - "Churu", - "Dausa", - "Dholpur", - "Dungarpur", - "Hanumangarh", - "Jaipur", - "Jaisalmer", - "Jalore", - "Jhalawar", - "Jhunjhunu", - "Jodhpur", - "Karauli", - "Kota", - "Nagaur", - "Pali", - "Pratapgarh", - "Rajsamand", - "Sawai Madhopur", - "Sikar", - "Sirohi", - "Sri Ganganagar", - "Tonk", - "Udaipur", - ], - }, - { - state: "Sikkim", - districts: ["East Sikkim", "North Sikkim", "South Sikkim", "West Sikkim"], - }, - { - state: "Tamil Nadu", - districts: [ - "Ariyalur", - "Chengalpattu", - "Chennai", - "Coimbatore", - "Cuddalore", - "Dharmapuri", - "Dindigul", - "Erode", - "Kallakurichi", - "Kanchipuram", - "Kanyakumari", - "Karur", - "Krishnagiri", - "Madurai", - "Mayiladuthurai", - "Nagapattinam", - "Namakkal", - "Nilgiris", - "Perambalur", - "Pudukkottai", - "Ramanathapuram", - "Ranipet", - "Salem", - "Sivaganga", - "Tenkasi", - "Thanjavur", - "Theni", - "Thoothukudi", - "Tiruchirappalli", - "Tirunelveli", - "Tirupathur", - "Tiruppur", - "Tiruvallur", - "Tiruvannamalai", - "Tiruvarur", - "Vellore", - "Viluppuram", - "Virudhunagar", - ], - }, - { - state: "Telangana", - districts: [ - "Adilabad", - "Bhadradri Kothagudem", - "Hyderabad", - "Jagtial", - "Jangaon", - "Jayashankar Bhupalpally", - "Jogulamba Gadwal", - "Kamareddy", - "Karimnagar", - "Khammam", - "Komaram Bheem Asifabad", - "Mahabubabad", - "Mahabubnagar", - "Mancherial", - "Medak", - "Medchal–Malkajgiri", - "Mulugu", - "Nagarkurnool", - "Nalgonda", - "Nirmal", - "Nizamabad", - "Peddapalli", - "Rajanna Sircilla", - "Rangareddy", - "Sangareddy", - "Siddipet", - "Suryapet", - "Vikarabad", - "Wanaparthy", - "Warangal Rural", - "Warangal Urban", - "Yadadri Bhuvanagiri", - ], - }, - { - state: "Tripura", - districts: [ - "Dhalai", - "Gomati", - "Khowai", - "North Tripura", - "Sepahijala", - "South Tripura", - "Unakoti", - "West Tripura", - ], - }, - { - state: "Uttar Pradesh", - districts: [ - "Agra", - "Aligarh", - "Ambedkar Nagar", - "Amethi (Chatrapati Sahuji Mahraj Nagar)", - "Amroha (J.P. Nagar)", - "Auraiya", - "Ayodhya (Faizabad)", - "Azamgarh", - "Baghpat", - "Bahraich", - "Ballia", - "Balrampur", - "Banda", - "Barabanki", - "Bareilly", - "Basti", - "Bhadohi", - "Bijnor", - "Budaun", - "Bulandshahr", - "Chandauli", - "Chitrakoot", - "Deoria", - "Etah", - "Etawah", - "Farrukhabad", - "Fatehpur", - "Firozabad", - "Gautam Buddha Nagar", - "Ghaziabad", - "Ghazipur", - "Gonda", - "Gorakhpur", - "Hamirpur", - "Hapur (Panchsheel Nagar)", - "Hardoi", - "Hathras", - "Jalaun", - "Jaunpur", - "Jhansi", - "Kannauj", - "Kanpur Dehat", - "Kanpur Nagar", - "Kasganj", - "Kaushambi", - "Kushinagar (Padrauna)", - "Lakhimpur - Kheri", - "Lalitpur", - "Lucknow", - "Maharajganj", - "Mahoba", - "Mainpuri", - "Mathura", - "Mau", - "Meerut", - "Mirzapur", - "Moradabad", - "Muzaffarnagar", - "Pilibhit", - "Pratapgarh", - "Prayagraj (Allahabad)", - "Rae Bareli", - "Rampur", - "Saharanpur", - "Sambhal (Bhim Nagar)", - "Sant Kabir Nagar", - "Shahjahanpur", - "Shamli", - "Shrawasti", - "Siddharthnagar", - "Sitapur", - "Sonbhadra", - "Sultanpur", - "Unnao", - "Varanasi", - ], - }, - { - state: "Uttarakhand", - districts: [ - "Almora", - "Bageshwar", - "Chamoli", - "Champawat", - "Dehradun", - "Haridwar", - "Nainital", - "Pauri Garhwal", - "Pithoragarh", - "Rudraprayag", - "Tehri Garhwal", - "Udham Singh Nagar", - "Uttarkashi", - ], - }, - { - state: "West Bengal", - districts: [ - "Alipurduar", - "Bankura", - "Birbhum", - "Cooch Behar", - "Dakshin Dinajpur (South Dinajpur)", - "Darjeeling", - "Hooghly", - "Howrah", - "Jalpaiguri", - "Jhargram", - "Kalimpong", - "Kolkata", - "Malda", - "Murshidabad", - "Nadia", - "North 24 Parganas", - "Paschim Medinipur (West Medinipur)", - "Paschim (West) Burdwan (Bardhaman)", - "Purba Burdwan (Bardhaman)", - "Purba Medinipur (East Medinipur)", - "Purulia", - "South 24 Parganas", - "Uttar Dinajpur (North Dinajpur)", - ], - }, -]; - -export default StateData; diff --git a/src/services/MasterDataService.ts b/src/services/MasterDataService.ts index 37423298..399ecd55 100644 --- a/src/services/MasterDataService.ts +++ b/src/services/MasterDataService.ts @@ -2,7 +2,7 @@ import { get, post } from "./RestClient"; export interface StateListParam { limit?: number; // page: number; - + controllingfieldfk?: any fieldName?: any; sort?: object; offset?: number; @@ -14,19 +14,28 @@ export interface CenterListParam { offset?: number; } export const getStateBlockDistrictList = async ({ + controllingfieldfk, fieldName, -}: StateListParam): Promise => { +}: { + controllingfieldfk?: string; + fieldName: string; +}): Promise => { const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/fields/options/read`; try { - const response = await post(apiUrl, { - fieldName, - }); + const requestBody: { fieldName: string; controllingfieldfk?: string } = { fieldName }; + + if (controllingfieldfk) { + requestBody.controllingfieldfk = controllingfieldfk; + } + + const response = await post(apiUrl, requestBody); return response?.data; } catch (error) { console.error("error in fetching user details", error); return error; } }; + export const getDistrictsForState = async ({ controllingfieldfk, fieldName, diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index e4367e92..abf82ff6 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -26,6 +26,7 @@ export interface Field { minLength?: number | null; fieldId: string; required?: boolean; + default: string | number; } export interface TenantCohortRoleMapping { tenantId: string;