diff --git a/src/components/AddFacilitator.tsx b/src/components/AddFacilitator.tsx deleted file mode 100644 index 486b0900..00000000 --- a/src/components/AddFacilitator.tsx +++ /dev/null @@ -1,324 +0,0 @@ -import React, { useState, useEffect } from "react"; -import { useTranslation } from "next-i18next"; -import { IChangeEvent } from "@rjsf/core"; -import { RJSFSchema } from "@rjsf/utils"; -import { Typography, useMediaQuery } from "@mui/material"; -import { - GenerateSchemaAndUiSchema, - customFields, -} from "@/components/GeneratedSchemas"; -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 { 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 { tenantId } from "../../app.config"; - -interface AddFacilitatorModalprops { - open: boolean; - onClose: () => void; - formData?: object; - isEditModal?: boolean; - userId?: string; -} - -const AddFacilitatorModal: React.FC = ({ - open, - formData, - isEditModal = false, - userId, - onClose, -}) => { - const { t } = useTranslation(); - const [schema, setSchema] = useState(); - const [openModal, setOpenModal] = useState(false); - const [uiSchema, setUiSchema] = useState(); - const [formvalue, setFormvalue] = useState(); - - - const { - states, - districts, - blocks, - allCenters, - isMobile, - isMediumScreen, - selectedState, - selectedStateCode, - selectedDistrict, - selectedDistrictCode, - selectedCenter, - dynamicForm, - selectedBlock, - selectedBlockCode, - selectedCenterCode, - handleStateChangeWrapper, - handleDistrictChangeWrapper, - handleBlockChangeWrapper, - handleCenterChangeWrapper, - BlockFieldId, DistrctFieldId, StateFieldId - - } = useLocationState(open, onClose); - - useEffect(() => { - const getAddLearnerFormData = async () => { - try { - const response: FormData = await getFormRead( - FormContext.USERS, - FormContextType.TEACHER - ); - console.log("sortedFields", response); - if (typeof window !== "undefined" && window.localStorage) { - const CenterList = localStorage.getItem("CenterList"); - const centerOptions = CenterList ? JSON.parse(CenterList) : []; - var centerOptionsList = centerOptions?.map( - (center: { cohortId: string; cohortName: string }) => ({ - value: center.cohortId, - label: center.cohortName, - }) - ); - console.log(centerOptionsList); - } - console.log(response) - - if (response) { - const newResponse={ - ...response, - fields: response.fields.filter(field => field.name !== 'no_of_clusters') - } - const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(newResponse, t); - setFormvalue(formValues) - setSchema(schema); - setUiSchema(uiSchema); - } - } catch (error) { - console.error("Error fetching form data:", error); - } - }; - getAddLearnerFormData(); - }, []); - - const handleSubmit = async ( - data: IChangeEvent, - event: React.FormEvent - ) => { - // setOpenModal(true); - const target = event.target as HTMLFormElement; - // const elementsArray = Array.from(target.elements); - - // for (const element of elementsArray) { - // if ( - // (element instanceof HTMLInputElement || - // element instanceof HTMLSelectElement || - // element instanceof HTMLTextAreaElement) && - // (element.value === "" || - // (Array.isArray(element.value) && element.value.length === 0)) - // ) { - // element.focus(); - // return; - // } - // } - - const formData = data.formData; - console.log("Form data submitted:", formData); - const schemaProperties = schema.properties; - - const { username, password } = generateUsernameAndPassword( - selectedStateCode, - Role.TEACHER - ); - - let apiBody: any = { - username: username, - password: password, - tenantCohortRoleMapping: [ - { - tenantId: tenantId, - roleId: RoleId.TEACHER, - cohortId: [selectedCenterCode], - }, - ], - customFields: [], - }; - - 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; - } - } else { - if ( - fieldSchema?.hasOwnProperty("isDropdown") || - fieldSchema.hasOwnProperty("isCheckbox") - ) { - apiBody.customFields.push({ - fieldId: fieldId, - 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), - }); - } - } - } - }); - - if (!isEditModal) { - apiBody.customFields.push({ - fieldId: BlockFieldId, - value: [selectedBlockCode], - }); - apiBody.customFields.push({ - fieldId: StateFieldId, - value: [selectedStateCode] - }); - apiBody.customFields.push({ - fieldId: DistrctFieldId, - value: [selectedDistrictCode] - }); - } - try { - if (isEditModal && userId) { - console.log(userId); - const userData = { - name: apiBody.name, - mobile: apiBody.mobile, - email:apiBody.email - }; - const customFields = apiBody.customFields; - console.log(customFields); - const object = { - userData: userData, - customFields: customFields, - }; - const response = await updateUser(userId, object); - showToastMessage(t("FACILITATORS.FACILITATOR_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); - } - }; - - const handleChange = (event: IChangeEvent) => { - console.log("Form data changed:", event.formData); - }; - - const handleError = (errors: any) => { - console.log("Form errors:", errors); - }; - - const onCloseModal = () => { - setOpenModal(false); - onClose(); - }; - - return ( - <> - - {/* {!dynamicForm && ( - {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")} - )} */} - - - {formData - ? schema && - uiSchema && ( - - {/* */} - - ) - : dynamicForm && - schema && - uiSchema && ( - - {/* */} - - )} - - - - ); -}; - -export default AddFacilitatorModal; diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx index cd375197..9423c363 100644 --- a/src/components/AddNewCenters.tsx +++ b/src/components/AddNewCenters.tsx @@ -66,7 +66,7 @@ const AddNewCenters: React.FC = ({ handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper, - selectedBlockFieldId, + selectedBlockCohortId, dynamicFormForBlock, } = useLocationState(open, onClose); @@ -96,8 +96,8 @@ const AddNewCenters: React.FC = ({ ) => { const formData = data?.formData; - if (selectedBlockFieldId) { - const parentId = selectedBlockFieldId; + if (selectedBlockCohortId) { + const parentId = selectedBlockCohortId; const cohortDetails: CohortDetails = { name: formData.name, type: CohortTypes.COHORT, diff --git a/src/components/AddTeamLeaderModal.tsx b/src/components/AddTeamLeaderModal.tsx deleted file mode 100644 index 99bd624f..00000000 --- a/src/components/AddTeamLeaderModal.tsx +++ /dev/null @@ -1,389 +0,0 @@ -import DynamicForm from "@/components/DynamicForm"; -import { - GenerateSchemaAndUiSchema, - customFields, -} from "@/components/GeneratedSchemas"; -import SimpleModal from "@/components/SimpleModal"; -import { - createUser, - getFormRead, - updateUser, -} from "@/services/CreateUserService"; -import { tenantId } from "../../app.config"; -import { - - getCohortList - -} from "@/services/CohortService/cohortService"; -import { generateUsernameAndPassword } from "@/utils/Helper"; -import { FormData } from "@/utils/Interfaces"; -import { - FormContext, - FormContextType, - Role, - RoleId, -} from "@/utils/app.constant"; -import { useLocationState } from "@/utils/useLocationState"; -import { Box, Button, Typography, useTheme } from "@mui/material"; -import { IChangeEvent } from "@rjsf/core"; -import { RJSFSchema } from "@rjsf/utils"; -import React, { useEffect } from "react"; -import { useTranslation } from "react-i18next"; -import { transformArray } from "../utils/Helper"; -import AreaSelection from "./AreaSelection"; -import { showToastMessage } from "./Toastify"; - -interface AddLearnerModalProps { - open: boolean; - onClose: () => void; - formData?: object; - isEditModal?: boolean; - userId?: string; -} -interface FieldProp { - value: string; - label: string; -} -const AddTeamLeaderModal: React.FC = ({ - open, - onClose, - formData, - isEditModal = false, - userId, -}) => { - const [schema, setSchema] = React.useState(); - const [uiSchema, setUiSchema] = React.useState(); - const [formValue, setFormValue] = React.useState(); - - - const [credentials, setCredentials] = React.useState({ - username: "", - password: "", - }); - const { t } = useTranslation(); - const theme = useTheme(); - const { - states, - districts, - blocks, - allCenters, - isMobile, - isMediumScreen, - selectedState, - selectedStateCode, - selectedDistrict, - selectedDistrictCode, - selectedCenter, - dynamicForm, - selectedBlock, - selectedBlockCode, - handleStateChangeWrapper, - handleDistrictChangeWrapper, - handleBlockChangeWrapper, - handleCenterChangeWrapper, - selectedCenterCode, - selectedBlockFieldId, - dynamicFormForBlock, - BlockFieldId, DistrctFieldId, StateFieldId - - } = useLocationState(open, onClose); - - useEffect(() => { - const getAddLearnerFormData = async () => { - try { - let userType="TEAM LEADER" - const response: FormData = await getFormRead( - FormContext.USERS, - userType - ); - console.log("sortedFields", response); - - if (response) { - const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(response, t); - setFormValue(formValues) - setSchema(schema); - console.log(schema); - setUiSchema(uiSchema); - } - } catch (error) { - console.error("Error fetching form data:", error); - } - }; - getAddLearnerFormData(); - }, []); - - const handleSubmit = async ( - data: IChangeEvent, - event: React.FormEvent - ) => { - // setOpenModal(true); - const target = event.target as HTMLFormElement; - // const elementsArray = Array.from(target.elements); - - // for (const element of elementsArray) { - // if ( - // (element instanceof HTMLInputElement || - // element instanceof HTMLSelectElement || - // element instanceof HTMLTextAreaElement) && - // (element.value === "" || - // (Array.isArray(element.value) && element.value.length === 0)) - // ) { - // element.focus(); - // return; - // } - // } - console.log("Form data submitted:", data.formData); - - const formData = data.formData; - console.log("Form data submitted:", formData); - const schemaProperties = schema.properties; - - const { username, password } = generateUsernameAndPassword( - selectedStateCode, - Role.TEAM_LEADER - ); - - let apiBody: any = { - username: username, - password: password, - tenantCohortRoleMapping: [ - { - tenantId: tenantId, - roleId: RoleId.TEAM_LEADER, - cohortId: [selectedBlockFieldId], - }, - ], - customFields: [], - }; - - Object.entries(formData).forEach(([fieldKey, fieldValue]) => { - const fieldSchema = schemaProperties[fieldKey]; - 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; - } - } else { - if ( - fieldSchema?.hasOwnProperty("isDropdown") || - fieldSchema.hasOwnProperty("isCheckbox") - ) { - apiBody.customFields.push({ - fieldId: fieldId, - value: [String(fieldValue)], - }); - } else { - apiBody.customFields.push({ - fieldId: fieldId, - value: String(fieldValue), - }); - } - } - }); - if (!isEditModal) { - apiBody.customFields.push({ - fieldId: BlockFieldId, - value: [selectedBlockCode], - }); - apiBody.customFields.push({ - fieldId: StateFieldId, - value: [selectedStateCode], - }); - apiBody.customFields.push({ - fieldId: DistrctFieldId, - 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); - showToastMessage(t("TEAM_LEADERS.TEAM_LEADER_UPDATED_SUCCESSFULLY"), "success"); - } else { - const response = await createUser(apiBody); - showToastMessage(t("TEAM_LEADERS.TEAM_LEADER_CREATED_SUCCESSFULLY"), "success"); - } - onClose(); - } catch (error) { - onClose(); - console.log(error); - } - }; - - const handleChange = (event: IChangeEvent) => { - console.log("Form data changed:", event.formData); - // setFormData({ - // ...formData, - // [event.target.name]: event.target.value - // }); - }; - - const handleError = (errors: any) => { - console.log("Form errors:", errors); - }; - - const CustomSubmitButton: React.FC<{ onClose: () => void }> = ({ - onClose, - }) => ( -
- <> - - - -
- ); - - const primaryActionHandler = () => { - onClose(); - }; - - const secondaryActionHandler = async (e: React.FormEvent) => { - // console.log('Secondary action handler clicked'); - e.preventDefault(); - // handleGenerateCredentials(); - // try { - // const response = await createUser(learnerFormData); - // console.log('User created successfully', response); - // } catch (error) { - // console.error('Error creating user', error); - // } - }; - - return ( - <> - - <> - - {/* {!dynamicForm && ( - - {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")}{" "} - - )} */} - - - - - {formData - ? schema && - uiSchema && ( - - {/* */} - - ) - : dynamicFormForBlock && - schema && - uiSchema && ( - - {/* */} - - )} - - - ); -}; - -export default AddTeamLeaderModal; diff --git a/src/components/AddLeanerModal.tsx b/src/components/CommonUserModal.tsx similarity index 66% rename from src/components/AddLeanerModal.tsx rename to src/components/CommonUserModal.tsx index cc95f379..4764cc39 100644 --- a/src/components/AddLeanerModal.tsx +++ b/src/components/CommonUserModal.tsx @@ -1,8 +1,15 @@ -import DynamicForm from "@/components/DynamicForm"; +import React, { useState, useEffect } from "react"; +import { useTranslation } from "next-i18next"; +import { IChangeEvent } from "@rjsf/core"; +import { RJSFSchema } from "@rjsf/utils"; +import { Typography, useMediaQuery , Box, Button, useTheme} from "@mui/material"; import { GenerateSchemaAndUiSchema, customFields, } from "@/components/GeneratedSchemas"; +import { FormContext, FormContextType } from "@/utils/app.constant"; +import DynamicForm from "@/components/DynamicForm"; +import SendCredentialModal from "@/components/SendCredentialModal"; import SimpleModal from "@/components/SimpleModal"; import { createUser, @@ -11,54 +18,44 @@ import { } from "@/services/CreateUserService"; import { generateUsernameAndPassword } from "@/utils/Helper"; import { FormData } from "@/utils/Interfaces"; -import { - FormContext, - FormContextType, - Role, - RoleId, -} from "@/utils/app.constant"; -import { useLocationState } from "@/utils/useLocationState"; -import { Box, Button, Typography, useTheme } from "@mui/material"; -import { IChangeEvent } from "@rjsf/core"; -import { RJSFSchema } from "@rjsf/utils"; -import React, { useEffect } from "react"; -import { useTranslation } from "react-i18next"; -import { transformArray } from "../utils/Helper"; +import { RoleId ,Role} from "@/utils/app.constant"; import AreaSelection from "./AreaSelection"; import { showToastMessage } from "./Toastify"; +import { transformArray } from "../utils/Helper"; +import { useLocationState } from "@/utils/useLocationState"; import { tenantId } from "../../app.config"; -interface AddLearnerModalProps { + + + + +interface UserModalProps { open: boolean; onClose: () => void; formData?: object; isEditModal?: boolean; userId?: string; onSubmit: (submitValue: boolean) => void; + userType:string } -interface FieldProp { - value: string; - label: string; -} -const AddLearnerModal: React.FC = ({ + +const CommonUserModal: React.FC = ({ open, onClose, formData, isEditModal = false, userId, - onSubmit + onSubmit, + userType }) => { + console.log(userType) const [schema, setSchema] = React.useState(); const [uiSchema, setUiSchema] = React.useState(); - - - const [credentials, setCredentials] = React.useState({ - username: "", - password: "", - }); const { t } = useTranslation(); + const [formValue, setFormValue] = useState(); + const modalTitle=!isEditModal? userType === FormContextType.STUDENT?t("LEARNERS.NEW_LEARNER"):userType === FormContextType.TEACHER?t("FACILITATORS.NEW_FACILITATOR"):t("TEAM_LEADERS.NEW_TEAM_LEADER"): userType === FormContextType.STUDENT?t("LEARNERS.EDIT_LEARNER"):userType === FormContextType.TEACHER?t("FACILITATORS.EDIT_FACILITATOR"):t("TEAM_LEADERS.EDIT_TEAM_LEADER") const theme = useTheme(); - const { + const { states, districts, blocks, @@ -77,30 +74,54 @@ const AddLearnerModal: React.FC = ({ handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper, - selectedCenterCode, BlockFieldId, DistrctFieldId, StateFieldId + selectedCenterCode, selectedBlockCohortId, blockFieldId, distrctFieldId, stateFieldId, dynamicFormForBlock } = useLocationState(open, onClose); useEffect(() => { - const getAddLearnerFormData = async () => { + const getAddUserFormData = async () => { try { + const response: FormData = await getFormRead( FormContext.USERS, - FormContextType.STUDENT - ); + userType ); + console.log("sortedFields", response); if (response) { + if(userType=== FormContextType.TEACHER ) + { + const newResponse={ + ...response, + fields: response.fields.filter(field => field.name !== 'no_of_clusters') + } + const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(newResponse, t); + setFormValue(formValues) + setSchema(schema); + setUiSchema(uiSchema); + } + else if(userType=== FormContextType.TEAM_LEADER) + { + const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(response, t); + setFormValue(formValues) + setSchema(schema); + console.log(schema); + setUiSchema(uiSchema); + } + else { + console.log("true") const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t); setSchema(schema); console.log(schema); setUiSchema(uiSchema); + } } + } catch (error) { console.error("Error fetching form data:", error); } }; - getAddLearnerFormData(); + getAddUserFormData(); }, []); const handleSubmit = async ( @@ -109,7 +130,7 @@ const AddLearnerModal: React.FC = ({ ) => { // setOpenModal(true); const target = event.target as HTMLFormElement; - const elementsArray = Array.from(target.elements); + // const elementsArray = Array.from(target.elements); console.log("onsubmit", data); // for (const element of elementsArray) { @@ -129,14 +150,10 @@ const AddLearnerModal: React.FC = ({ const formData = data.formData; console.log("Form data submitted:", formData); const schemaProperties = schema.properties; - let cohortId; - if (typeof window !== "undefined" && window.localStorage) { - var teacherData = JSON.parse(localStorage.getItem("teacherApp") || ""); - cohortId = "3f6825ab-9c94-4ee4-93e8-ef21e27dcc67"; - } + const { username, password } = generateUsernameAndPassword( selectedStateCode, - Role.STUDENT + userType ); let apiBody: any = { @@ -145,8 +162,8 @@ const AddLearnerModal: React.FC = ({ tenantCohortRoleMapping: [ { tenantId: tenantId, - roleId: RoleId.STUDENT, - cohortId: [selectedCenterCode], + roleId:userType===FormContextType.STUDENT? RoleId.STUDENT: userType===FormContextType.TEACHER?RoleId.TEACHER:RoleId.TEAM_LEADER, + cohortId:userType===FormContextType.TEAM_LEADER ?[selectedBlockCohortId] :[selectedCenterCode], }, ], customFields: [], @@ -156,7 +173,7 @@ const AddLearnerModal: React.FC = ({ const fieldSchema = schemaProperties[fieldKey]; const fieldId = fieldSchema?.fieldId; console.log( - `FieldID: ${fieldId}, FieldValue: ${fieldValue}, type: ${typeof fieldValue}` + `FieldID: ${fieldId}, FieldValue: ${fieldSchema}, type: ${typeof fieldValue}` ); if (fieldId === null || fieldId === "null") { @@ -164,33 +181,45 @@ const AddLearnerModal: React.FC = ({ apiBody[fieldKey] = fieldValue; } } else { + if ( fieldSchema?.hasOwnProperty("isDropdown") || - fieldSchema.hasOwnProperty("isCheckbox") + fieldSchema?.hasOwnProperty("isCheckbox") ) { apiBody.customFields.push({ fieldId: fieldId, value: [String(fieldValue)], }); } else { - apiBody.customFields.push({ + if(fieldSchema.checkbox &&fieldSchema.type==="array") + { + apiBody.customFields.push({ + fieldId: fieldId, + value: String(fieldValue).split(',') + }); + } + + else{ apiBody.customFields.push({ fieldId: fieldId, value: String(fieldValue), }); } + + + } } }); if (!isEditModal) { apiBody.customFields.push({ - fieldId: BlockFieldId, + fieldId: blockFieldId, value: [selectedBlockCode], }); apiBody.customFields.push({ - fieldId: StateFieldId, + fieldId: stateFieldId, value: [selectedStateCode], }); apiBody.customFields.push({ - fieldId: DistrctFieldId, + fieldId: distrctFieldId, value: [selectedDistrictCode], }); } @@ -199,21 +228,33 @@ const AddLearnerModal: React.FC = ({ if (isEditModal && userId) { console.log("apiBody", apiBody); const userData = { - name: apiBody.name, - mobile: apiBody.mobile, - father_name: apiBody.father_name, + name: apiBody?.name, + mobile: apiBody?.mobile, + father_name: apiBody?.father_name, }; - const customFields = apiBody.customFields; + 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"); + const messageKey = userType === FormContextType.STUDENT + ? "LEARNERS.LEARNER_UPDATED_SUCCESSFULLY" + : userType === FormContextType.TEACHER + ? "FACILITATORS.FACILITATOR_UPDATED_SUCCESSFULLY" + : "TEAM_LEADERS.TEAM_LEADER_UPDATED_SUCCESSFULLY"; + + showToastMessage(t(messageKey), "success"); } else { const response = await createUser(apiBody); - showToastMessage(t("LEARNERS.LEARNER_CREATED_SUCCESSFULLY"), "success"); + const messageKey = userType === FormContextType.STUDENT + ? "LEARNERS.LEARNER_CREATED_SUCCESSFULLY" + : userType === FormContextType.TEACHER + ? "FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY" + : "TEAM_LEADERS.TEAM_LEADER_CREATED_SUCCESSFULLY"; + +showToastMessage(t(messageKey), "success"); } onSubmit(true); onClose(); @@ -307,7 +348,7 @@ const AddLearnerModal: React.FC = ({ open={open} onClose={onClose} showFooter={false} - modalTitle={!isEditModal?t("LEARNERS.NEW_LEARNER"): t("LEARNERS.EDIT_LEARNER")} + modalTitle={modalTitle} > <> = ({ handleBlockChangeWrapper={handleBlockChangeWrapper} isMobile={isMobile} isMediumScreen={isMediumScreen} - isCenterSelection={true} + isCenterSelection={userType!=="TEAM LEADER"?true: false} allCenters={allCenters} selectedCenter={selectedCenter} handleCenterChangeWrapper={handleCenterChangeWrapper} @@ -360,7 +401,8 @@ const AddLearnerModal: React.FC = ({ {/* */} ) - : dynamicForm && + :userType==="TEAM LEADER"? + dynamicFormForBlock && schema && uiSchema && ( = ({ widgets={{}} showErrorList={true} customFields={customFields} + formData={formValue} + + > + {/* */} + ) + + + : (dynamicForm && + schema && + uiSchema && ( + {/* */} - )} + ))} ); }; -AddLearnerModal.defaultProps = { +CommonUserModal.defaultProps = { onSubmit: () => {}, // Default to a no-op function }; -export default AddLearnerModal; +export default CommonUserModal; diff --git a/src/components/UserTable.tsx b/src/components/UserTable.tsx index d06f9e7d..2fb17bb3 100644 --- a/src/components/UserTable.tsx +++ b/src/components/UserTable.tsx @@ -19,9 +19,6 @@ import { deleteUser } from "../services/DeleteUser"; import { getCohortList } from "../services/GetCohortList"; import { userList, getUserDetails } from "../services/UserList"; import PersonSearchIcon from "@mui/icons-material/PersonSearch"; -import AddLearnerModal from "@/components/AddLeanerModal"; -import AddFacilitatorModal from "./AddFacilitator"; -import AddTeamLeaderModal from "./AddTeamLeaderModal"; import { Role } from "@/utils/app.constant"; import { getFormRead } from "@/services/CreateUserService"; import { showToastMessage } from "./Toastify"; @@ -29,7 +26,7 @@ import { capitalizeFirstLetterOfEachWordInArray } from "../utils/Helper"; import { getUserTableColumns,getTLTableColumns } from "@/data/tableColumns"; import { useMediaQuery } from '@mui/material'; import { Theme } from '@mui/system'; - +import CommonUserModal from "./CommonUserModal"; type UserDetails = { userId: any; username: any; @@ -75,6 +72,7 @@ const UserTable: React.FC = ({ handleAddUserClick, parentState }) => { + console.log(userType) const [selectedState, setSelectedState] = React.useState([]); const [selectedStateCode, setSelectedStateCode] = useState(""); const [selectedDistrict, setSelectedDistrict] = React.useState([]); @@ -340,8 +338,7 @@ const handleCloseAddTeamLeaderModal = () => { } else { - console.log("asakas",field?.value) - if(field.value ==='FEMALE' || field.value ==='MALE') + if(field?.value ==='FEMALE' || field?.value ==='MALE') { console.log(true) return field?.value?.toLowerCase(); @@ -402,17 +399,17 @@ const handleCloseAddTeamLeaderModal = () => { formFields = await getFormRead("USERS", "STUDENT"); setFormData(mapFields(formFields, response)); console.log("mapped formdata", formdata); - handleOpenAddLearnerModal(); } else if (Role.TEACHER === role) { formFields = await getFormRead("USERS", "TEACHER"); setFormData(mapFields(formFields, response)); - handleOpenAddFacilitatorModal(); + // handleOpenAddFacilitatorModal(); } else if (Role.TEAM_LEADER === role) { formFields = await getFormRead("USERS", "TEAM LEADER"); setFormData(mapFields(formFields, response)); - handleOpenAddTeamLeaderModal(); + // handleOpenAddTeamLeaderModal(); } + handleOpenAddLearnerModal(); console.log("response", response); console.log("formFields", formFields); @@ -659,38 +656,21 @@ const handleCloseAddTeamLeaderModal = () => { confirmButtonDisable={confirmButtonDisable} setConfirmButtonDisable={setConfirmButtonDisable} /> - - - + ); }; -// export async function getStaticProps({ locale }: any) { -// return { -// props: { -// ...(await serverSideTranslations(locale, ["common"])), -// }, -// }; -// } export default UserTable; diff --git a/src/pages/faciliator.tsx b/src/pages/faciliator.tsx index c0f59656..c4e24197 100644 --- a/src/pages/faciliator.tsx +++ b/src/pages/faciliator.tsx @@ -2,15 +2,20 @@ import React from "react"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import UserTable from "@/components/UserTable"; import { useTranslation } from "next-i18next"; -import { Role } from "@/utils/app.constant"; -import AddFacilitatorModal from "@/components/AddFacilitator"; +import { Role, FormContextType } from "@/utils/app.constant"; +import CommonUserModal from "@/components/CommonUserModal"; const Faciliator: React.FC = () => { const { t } = useTranslation(); const [openAddFacilitatorModal, setOpenAddFacilitatorModal] = React.useState(false); + const [submitValue, setSubmitValue] = React.useState(false); + const handleOpenAddFacilitatorModal = () => { setOpenAddFacilitatorModal(true); }; +const handleModalSubmit = (value: boolean) => { + setSubmitValue(true); +}; const handleCloseAddFacilitatorModal = () => { setOpenAddFacilitatorModal(false); }; @@ -20,10 +25,14 @@ const handleCloseAddFacilitatorModal = () => { }; return ( <> - - + ); diff --git a/src/pages/learners.tsx b/src/pages/learners.tsx index 45cccb2f..ef251390 100644 --- a/src/pages/learners.tsx +++ b/src/pages/learners.tsx @@ -2,9 +2,8 @@ import React from "react"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import UserTable from "@/components/UserTable"; import { useTranslation } from "next-i18next"; -import { Role } from "@/utils/app.constant"; -import AddLearnerModal from '@/components/AddLeanerModal'; - +import { Role, FormContextType } from "@/utils/app.constant"; +import CommonUserModal from "@/components/CommonUserModal"; const Learners: React.FC = () => { const { t } = useTranslation(); const [openAddLearnerModal, setOpenAddLearnerModal] = React.useState(false); @@ -25,12 +24,18 @@ const handleCloseAddLearnerModal = () => { }; return ( <> - - + {/* */} + diff --git a/src/pages/teamLeader.tsx b/src/pages/teamLeader.tsx index 954e494c..3cccbf47 100644 --- a/src/pages/teamLeader.tsx +++ b/src/pages/teamLeader.tsx @@ -2,29 +2,37 @@ import React from "react"; import { serverSideTranslations } from "next-i18next/serverSideTranslations"; import UserTable from "@/components/UserTable"; import { useTranslation } from "next-i18next"; -import { Role } from "@/utils/app.constant"; -import AddTeamLeaderModal from "@/components/AddTeamLeaderModal"; +import { Role, FormContextType } from "@/utils/app.constant"; +import CommonUserModal from "@/components/CommonUserModal"; const TeamLeader: React.FC = () => { const { t } = useTranslation(); const handleAddTeamLeaderClick = () => { - handleOpenAddLearnerModal(); + handleOpenAddTeamLeaderModal(); }; - const [openAddLearnerModal, setOpenAddLearnerModal] = React.useState(false); - const handleOpenAddLearnerModal = () => { - setOpenAddLearnerModal(true); + const [submitValue, setSubmitValue] = React.useState(false); + + const [openAddTeamLeaderModal, setOpenAddTeamLeaderModal] = React.useState(false); + const handleOpenAddTeamLeaderModal = () => { + setOpenAddTeamLeaderModal(true); }; +const handleModalSubmit = (value: boolean) => { + setSubmitValue(true); -const handleCloseAddLearnerModal = () => { - setOpenAddLearnerModal(false); +}; +const handleCloseAddTeamLeaderModal = () => { + setOpenAddTeamLeaderModal(false); }; return ( <> - - + + ); diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index 3480f830..4b61b7fc 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -1,6 +1,6 @@ import FingerprintJS from "fingerprintjs2"; import { getUserDetails } from "../services/UserList"; -import { Role } from "./app.constant"; +import { Role, FormContextType } from "./app.constant"; import { State } from "./Interfaces"; export const generateUUID = () => { @@ -53,9 +53,9 @@ export const generateUsernameAndPassword = ( const randomNum = Math.floor(10000 + Math.random() * 90000).toString(); // 5 digit random number const rolePrefixes: Record = { - [Role.TEACHER]: 'FSC', - [Role.STUDENT]: 'SC', - [Role.TEAM_LEADER]: 'TL' + [FormContextType.TEACHER]: 'FSC', + [FormContextType.STUDENT]: 'SC', + [FormContextType.TEAM_LEADER]: 'TL' }; if (!(role in rolePrefixes)) { diff --git a/src/utils/app.constant.ts b/src/utils/app.constant.ts index e479d974..0db05f7c 100644 --- a/src/utils/app.constant.ts +++ b/src/utils/app.constant.ts @@ -28,7 +28,7 @@ export enum FormContext { export enum FormContextType { STUDENT = "STUDENT", TEACHER = "TEACHER", - TEAM_LEADER = "TEAMLEADER", + TEAM_LEADER = "TEAM LEADER", } export enum RoleId { diff --git a/src/utils/useLocationState.tsx b/src/utils/useLocationState.tsx index 58367d9b..976d43e8 100644 --- a/src/utils/useLocationState.tsx +++ b/src/utils/useLocationState.tsx @@ -32,10 +32,10 @@ export const useLocationState = (open: boolean, onClose: () => void) => { const [selectedBlock, setSelectedBlock] = useState([]); const [selectedBlockCode, setSelectedBlockCode] = useState(""); const [selectedCenterCode, setSelectedCenterCode] = useState(""); - const [selectedBlockFieldId, setSelectedBlockFieldId] = useState(""); - const [BlockFieldId, setBlockFieldId] = useState(""); - const [StateFieldId, setStateFieldId] = useState(""); - const [DistrctFieldId, setDistrictFieldId] = useState(""); + const [selectedBlockCohortId, setSelectedBlockCohortId] = useState(""); + const [blockFieldId, setBlockFieldId] = useState(""); + const [stateFieldId, setStateFieldId] = useState(""); + const [distrctFieldId, setDistrictFieldId] = useState(""); const handleStateChangeWrapper = useCallback( async (selectedNames: string[], selectedCodes: string[]) => { @@ -120,7 +120,7 @@ export const useLocationState = (open: boolean, onClose: () => void) => { }, } const response = await getCenterList(getBlockIdObject); - setSelectedBlockFieldId( + setSelectedBlockCohortId( response?.result?.results?.cohortDetails[0].cohortId ); console.log(response?.result?.results?.cohortDetails[0].cohortId); @@ -246,14 +246,14 @@ export const useLocationState = (open: boolean, onClose: () => void) => { selectedBlock, selectedBlockCode, dynamicFormForBlock, - BlockFieldId, - DistrctFieldId, - StateFieldId, + blockFieldId, + distrctFieldId, + stateFieldId, handleStateChangeWrapper, handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper, selectedCenterCode, - selectedBlockFieldId, + selectedBlockCohortId, }; };