diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 8e15e4d1..cc9a64a3 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -69,9 +69,9 @@ "MAIN_COURSE": "Main Course" }, "FACILITATORS": { - "ALL_STATES": "All States", - "ALL_DISTRICTS": "All Districts", - "ALL_BLOCKS": "All Blocks", + "ALL_STATES": "States", + "ALL_DISTRICTS": "Districts", + "ALL_BLOCKS": "Blocks", "NEW_FACILITATOR": "New Facilitator", "SEARCHBAR_PLACEHOLDER": "Search Facilitators..", "FACILITATOR_CREATED_SUCCESSFULLY": "Teacher has been Successfully Created", @@ -89,7 +89,10 @@ }, "TEAM_LEADERS": { "SEARCHBAR_PLACEHOLDER": "Search Team leaders..", - "NEW_TEAM_LEADER": "New Team Leader" + "NEW_TEAM_LEADER": "New Team Leader", + "FIRST_SELECT_REQUIRED_FIELDS": "First select required fields", + "TEAM_LEADER_CREATED_SUCCESSFULLY": "Team Leader has been Successfully Created!", + "TEAM_LEADER_UPDATED_SUCCESSFULLY": "Team Leader has been Successfully Updated!" }, "COHORTS": { "SEARCHBAR_PLACEHOLDER": "Search Center.." @@ -207,7 +210,7 @@ "ASSIGN_CENTERS": "Assign Centers", "TYPE_OF_COHORT": "Type Of Center", "UNIT_NAME": "Unit Name", - "SUBJECTS_I_TEACH": "Subject Teach", + "SUBJECTS_I_TEACH": "Subject I Teach", "MY_MAIN_SUBJECTS": "Main subjects", "NUMBER_OF_CLUSTERS_I_TEACH": "Number of cluster", "DESIGNATION": "Designation", diff --git a/src/components/AddFacilitator.tsx b/src/components/AddFacilitator.tsx index e727c2ad..f3adfe15 100644 --- a/src/components/AddFacilitator.tsx +++ b/src/components/AddFacilitator.tsx @@ -87,9 +87,14 @@ const AddFacilitatorModal: React.FC = ({ ); console.log(centerOptionsList); } - + console.log(response) + if (response) { - const { schema, uiSchema, formValues } = GenerateSchemaAndUiSchema(response, t); + 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); @@ -107,20 +112,20 @@ const AddFacilitatorModal: React.FC = ({ ) => { // setOpenModal(true); const target = event.target as HTMLFormElement; - const elementsArray = Array.from(target.elements); + // 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; - } - } + // 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); @@ -252,9 +257,9 @@ const AddFacilitatorModal: React.FC = ({ showFooter={false} modalTitle={t("FACILITATORS.NEW_FACILITATOR")} > - {!dynamicForm && ( + {/* {!dynamicForm && ( {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")} - )} + )} */} = ({ 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("onsubmit", data); + // 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; @@ -311,11 +313,11 @@ const AddLearnerModal: React.FC = ({ marginTop: "10px", }} > - {!dynamicForm && ( + {/* {!dynamicForm && ( {t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")}{" "} - )} + )} */} = ({ const { t } = useTranslation(); const handleError = (errors: any) => { + console.log('handle error', errors); if (errors.length > 0) { const property = errors[0].property?.replace(/^root\./, ""); const errorField = document.querySelector( diff --git a/src/components/KaTableComponent.tsx b/src/components/KaTableComponent.tsx index 04f79ecc..a411243d 100644 --- a/src/components/KaTableComponent.tsx +++ b/src/components/KaTableComponent.tsx @@ -154,6 +154,14 @@ const KaTableComponent: React.FC = ({ /> ); } + // if (props.column.key === "selection-cell") { + // return ( + // handleCheckboxChange(props.rowData.id)} + // /> + // ); + // } return
{props.value}
; }, }, diff --git a/src/components/UserTable.tsx b/src/components/UserTable.tsx index 12d9abd4..2628d719 100644 --- a/src/components/UserTable.tsx +++ b/src/components/UserTable.tsx @@ -25,6 +25,7 @@ import AddFacilitatorModal from "./AddFacilitator"; import { Role } from "@/utils/app.constant"; import { getFormRead } from "@/services/CreateUserService"; import { showToastMessage } from "./Toastify"; +import { capitalizeFirstLetterOfEachWordInArray } from "../utils/Helper"; type UserDetails = { userId: any; @@ -66,10 +67,10 @@ const columns = [ // title: "ID", // dataType: DataType.String, // }, - { - key: "selection-cell", - width: 50, - }, + // { + // key: "selection-cell", + // width: 50, + // }, { key: "name", title: "Name", @@ -77,13 +78,7 @@ const columns = [ sortDirection: SortDirection.Ascend, width: 160, }, - { - key: "centers", - title: "Centers", - dataType: DataType.String, - sortDirection: SortDirection.Ascend, - width: 160, - }, + // { // key: "programs", // title: "Programs", @@ -124,7 +119,14 @@ const columns = [ { key: "blocks", - title: "Bocks", + title: "Blocks", + dataType: DataType.String, + sortDirection: SortDirection.Ascend, + width: 160, + }, + { + key: "centers", + title: "Centers", dataType: DataType.String, sortDirection: SortDirection.Ascend, width: 160, @@ -351,72 +353,78 @@ const UserTable: React.FC = ({ }; const handleSortChange = async (event: SelectChangeEvent) => { // let sort; - if (event.target.value === "Z-A") { + if (event.target?.value === "Z-A") { setSortBy(["name", SORT.DESCENDING]); - } else if (event.target.value === "A-Z") { + } else if (event.target?.value === "A-Z") { setSortBy(["name", SORT.ASCENDING]); } else { setSortBy(["createdAt", SORT.ASCENDING]); } - setSelectedSort(event.target.value as string); + 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( + const customFieldValue = userData?.customFields?.find( (field: any) => field.fieldId === item.fieldId ); const getValue = (data: any, field: any) => { - if(item.default) - { - return item.default; - } - if (item?.isMultiSelect) { + if (item.default) { + return item.default; + } + if (item?.isMultiSelect) { if (data[item.name] && item?.maxSelections > 1) { - return [field.value]; + return [field?.value]; } else if (item?.type === "checkbox") { - return String(field.value).split(","); + return String(field?.value).split(","); } else { - return field.value; + return field?.value; } } else { - if (item?.type === "numeric") { - return Number(field.value); + console.log(typeof field?.value); + + return parseInt(String(field?.value)); } else if (item?.type === "text") { - return String(field.value); + return String(field?.value); } else { - return field.value; + return field?.value; } } - }; if (item.coreField) { - if (item?.isMultiSelect) { + if (item?.isMultiSelect) { if (userData[item.name] && item?.maxSelections > 1) { initialFormData[item.name] = [userData[item.name]]; - } else { - initialFormData[item.name] = userData[item.name] || ""; + } + else if (item?.type === "checkbox") { + initialFormData[item.name]= String(userData[item.name]).split(","); + } + else { + initialFormData[item.name] = userData[item.name]; } } else if (item?.type === "numeric") { + console.log(item?.name); initialFormData[item.name] = Number(userData[item.name]); - } else if (item?.type === "text") { + } else if (item?.type === "text" && userData[item.name]) { initialFormData[item.name] = String(userData[item.name]); - } - // else if(item?.type === "email") - // { - // initialFormData[item.name] = String(userData[item.name]); - - // } + } else { - initialFormData[item.name] = userData[item.name]; + console.log(item.name); + if (userData[item.name]) { + initialFormData[item.name] = userData[item.name]; + } } } else { - initialFormData[item.name] = getValue(userData, customField); + const fieldValue = getValue(userData, customFieldValue); + + if (fieldValue) { + initialFormData[item.name] = fieldValue; + } } }); @@ -437,6 +445,7 @@ const UserTable: React.FC = ({ if (Role.STUDENT === role) { 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"); @@ -476,7 +485,7 @@ const UserTable: React.FC = ({ const sort = sortBy; console.log("filters", filters); const resp = await userList({ limit, filters, sort, offset, fields }); - + const result = resp?.getUserDetails; // console.log(resp?.totalCount) if (resp?.totalCount >= 15) { @@ -501,7 +510,7 @@ const UserTable: React.FC = ({ (field: any) => field.name === "age" ); const genderField = user.customFields.find( - (field: any) => field.name === "gender" + (field: any) => field.name=== "gender" ); const blockField = user.customFields.find( (field: any) => field.name === "blocks" @@ -520,13 +529,13 @@ const UserTable: React.FC = ({ user.name.charAt(0).toUpperCase() + user.name.slice(1).toLowerCase(), role: user.role, - // gender: user.gender, + // gender: user.gender, mobile: user.mobile === "NaN" ? "" : user.mobile, age: ageField ? ageField.value : null, district: districtField ? districtField.value : null, state: stateField ? stateField.value : null, blocks: blockField ? blockField.value : null, - gender:genderField?genderField.value: null, + gender: genderField ? genderField.value?.charAt(0)?.toUpperCase() + genderField.value.slice(1).toLowerCase() : null, // centers: null, // Programs: null, }; @@ -546,7 +555,7 @@ const UserTable: React.FC = ({ } }; fetchUserList(); - }, [pageOffset, pageLimit, sortBy, filters]); + }, [pageOffset, pageLimit, sortBy, filters, openAddFacilitatorModal, openAddLearnerModal]); useEffect(() => { const fetchData = async () => { @@ -560,14 +569,19 @@ const UserTable: React.FC = ({ const cohortNames = response?.result?.cohortData?.map( (cohort: Cohort) => cohort.name ); - + let finalArray; + if(cohortNames?.length>=1) + { + finalArray=capitalizeFirstLetterOfEachWordInArray(cohortNames) + } + // const finalArray=capitalizeFirstLetterOfEachWordInArray(cohortNames) + // console.log(finalArray) return { ...user, - centers: cohortNames?.join(" , "), + centers: finalArray?.join(" , "), }; }) ); - setData(newData); setCohortsFetched(true); } catch (error: any) { @@ -596,7 +610,6 @@ const UserTable: React.FC = ({ const response = await deleteUser(userId, userData); handleCloseDeleteModal(); showToastMessage(t("COMMON.USER_DELETE_SUCCSSFULLY"), "success"); - } catch (error) { console.log("error while deleting entry", error); } diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index 970ee3bd..a7e98c6e 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -88,3 +88,7 @@ export const firtstLetterInUpperCase = (label: string): string | null => { ?.map((word) => word?.charAt(0).toUpperCase() + word?.slice(1)) ?.join(" "); }; +export const capitalizeFirstLetterOfEachWordInArray = (arr: string[]): string[] => { + console.log(arr) + return arr.map(str => str.replace(/\b[a-z]/g, char => char.toUpperCase())); +} \ No newline at end of file