From d65d7e1d2940327b72c76f131ba9f99df5065590 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Fri, 2 Aug 2024 11:35:56 +0530 Subject: [PATCH] Issue feat: fix undefine null function for array to map --- src/components/DeleteUserModal.tsx | 2 +- src/components/DynamicForm.tsx | 2 +- src/components/FormControl.tsx | 2 +- src/components/GeneratedSchemas.ts | 14 +++++++------- src/components/HeaderComponent.tsx | 2 +- src/components/Steper.tsx | 2 +- src/components/Stepper.tsx | 2 +- src/components/UserTable.tsx | 4 ++-- src/components/layouts/sidebar/Sidebar.tsx | 2 +- src/pages/course-planner/foundation.tsx | 2 +- src/pages/stateDetails.tsx | 2 +- src/pages/subjectDetails.tsx | 2 +- src/services/CreateUserService.ts | 2 +- src/utils/Helper.ts | 2 +- 14 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/components/DeleteUserModal.tsx b/src/components/DeleteUserModal.tsx index 2b2ecd0b..b2950d3e 100644 --- a/src/components/DeleteUserModal.tsx +++ b/src/components/DeleteUserModal.tsx @@ -69,7 +69,7 @@ const DeleteUserModal: React.FC = ({ > <> - {reasons.map((option) => ( + {reasons?.map((option) => ( <> = ({ function transformErrors(errors: any) { console.log("errors", errors); console.log("schema", schema); - return errors.map((error: any) => { + return errors?.map((error: any) => { switch (error.name) { case "required": { error.message = t("FORM_ERROR_MESSAGES.THIS_IS_REQUIRED_FIELD"); diff --git a/src/components/FormControl.tsx b/src/components/FormControl.tsx index 8ebd230f..0f0ec081 100644 --- a/src/components/FormControl.tsx +++ b/src/components/FormControl.tsx @@ -45,7 +45,7 @@ const MultipleSelectCheckmarks: React.FC = ({ target: { value }, } = event; const selectedNames = typeof value === "string" ? value.split(",") : value; - const selectedCodes = selectedNames.map( + const selectedCodes = selectedNames?.map( (name) => codes[names.indexOf(name)], ); onCategoryChange(selectedNames, selectedCodes); diff --git a/src/components/GeneratedSchemas.ts b/src/components/GeneratedSchemas.ts index 134c8e5b..ab7969c5 100644 --- a/src/components/GeneratedSchemas.ts +++ b/src/components/GeneratedSchemas.ts @@ -81,7 +81,7 @@ export const GenerateSchemaAndUiSchema = ( fieldSchema.checkbox = true; fieldSchema.items = { type: "string", - oneOf: options.map((opt: FieldOption) => ({ + oneOf: options?.map((opt: FieldOption) => ({ const: opt.value, title: t(`FORM.${opt.label}`) === `FORM.${opt.label}` @@ -94,7 +94,7 @@ export const GenerateSchemaAndUiSchema = ( break; case "radio": fieldSchema.type = "string"; - fieldSchema.oneOf = options.map((opt: FieldOption) => ({ + fieldSchema.oneOf = options?.map((opt: FieldOption) => ({ const: opt.value, title: t(`FORM.${opt.label}`) === `FORM.${opt.label}` @@ -131,10 +131,10 @@ export const GenerateSchemaAndUiSchema = ( fieldSchema.type = "array"; fieldSchema.items = { type: "string", - enum: options.map((opt: FieldOption) => opt.value), + enum: options?.map((opt: FieldOption) => opt.value), }; fieldSchema.uniqueItems = true; - fieldSchema.enumNames = options.map((opt: FieldOption) => + fieldSchema.enumNames = options?.map((opt: FieldOption) => t(`FORM.${opt.label}`) === `FORM.${opt.label}` ? opt.label : t(`FORM.${opt.label}`) @@ -151,7 +151,7 @@ export const GenerateSchemaAndUiSchema = ( if (isMultiSelect && maxSelections === 1 && type === "drop_down") { fieldSchema.type = "string"; fieldSchema.isDropdown = true; - fieldSchema.oneOf = options.map((opt: FieldOption) => ({ + fieldSchema.oneOf = options?.map((opt: FieldOption) => ({ const: opt.value, title: t(`FORM.${opt.label}`) === `FORM.${opt.label}` @@ -163,7 +163,7 @@ export const GenerateSchemaAndUiSchema = ( if (!isMultiSelect && type === "drop_down") { fieldSchema.type = "string"; fieldSchema.isDropdown = true; - fieldSchema.oneOf = options.map((opt: FieldOption) => ({ + fieldSchema.oneOf = options?.map((opt: FieldOption) => ({ const: opt.value, title: t(`FORM.${opt.label}`) === `FORM.${opt.label}` @@ -176,7 +176,7 @@ export const GenerateSchemaAndUiSchema = ( fieldSchema.type = "array"; fieldSchema.items = { type: "string", - oneOf: options.map((opt: FieldOption) => ({ + oneOf: options?.map((opt: FieldOption) => ({ const: opt.value, title: t(`FORM.${opt.label}`) === `FORM.${opt.label}` diff --git a/src/components/HeaderComponent.tsx b/src/components/HeaderComponent.tsx index 4068441e..9a62256f 100644 --- a/src/components/HeaderComponent.tsx +++ b/src/components/HeaderComponent.tsx @@ -225,7 +225,7 @@ const HeaderComponent = ({ }} > {t("COMMON.SORT")} - {Sort.map((state, index) => ( + {Sort?.map((state, index) => ( {state} diff --git a/src/components/Steper.tsx b/src/components/Steper.tsx index 4926cfd6..cb5d277d 100644 --- a/src/components/Steper.tsx +++ b/src/components/Steper.tsx @@ -8,7 +8,7 @@ const CustomStepper = ({ completedSteps = 0 }) => { return ( - {[...Array(totalSteps)].map((_, index) => ( + {[...Array(totalSteps)]?.map((_, index) => ( { return ( - {[...Array(totalSteps)].map((_, index) => ( + {[...Array(totalSteps)]?.map((_, index) => ( { setPageCount(Math.ceil(resp?.totalCount / pageLimit)); console.log(result); - const finalResult = result.map((user: any) => { + const finalResult = result?.map((user: any) => { const ageField = user.customFields.find( (field: any) => field.name === "age" ); @@ -587,7 +587,7 @@ const handleCloseAddTeamLeaderModal = () => { return; } const newData = await Promise.all( - data.map(async (user) => { + data?.map(async (user) => { const response = await getCohortList(user.userId); const cohortNames = response?.result?.cohortData?.map( (cohort: Cohort) => cohort.name diff --git a/src/components/layouts/sidebar/Sidebar.tsx b/src/components/layouts/sidebar/Sidebar.tsx index a992b2a1..ae41a94f 100644 --- a/src/components/layouts/sidebar/Sidebar.tsx +++ b/src/components/layouts/sidebar/Sidebar.tsx @@ -100,7 +100,7 @@ const Sidebar = ({ {item.subOptions && ( - {item.subOptions.map((subItem) => ( + {item.subOptions?.map((subItem) => ( { {t("COURSE_PLANNER.COPY_LINK")} {!selectedCardId ? ( - cardData.map((card) => ( + cardData?.map((card) => ( { - {card.boards.map((board: string, index: number) => ( + {card.boards?.map((board: string, index: number) => ( { - {card.subjects.map((subject, index) => ( + {card.subjects?.map((subject, index) => ( { return Object.entries(params) - .map(([key, value]) => `${key}=${value}`) + ?.map(([key, value]) => `${key}=${value}`) .join('&'); }, headers: { tenantId:"ef99949b-7f3a-4a5f-806a-e67e683e38f3"} diff --git a/src/utils/Helper.ts b/src/utils/Helper.ts index b8c31f1d..2294dbd6 100644 --- a/src/utils/Helper.ts +++ b/src/utils/Helper.ts @@ -36,7 +36,7 @@ export const getUserName = async (userId: string) => { export const getDeviceId = () => { return new Promise((resolve) => { FingerprintJS.get((components: any[]) => { - const values = components.map((component) => component.value); + const values = components?.map((component) => component.value); const deviceId = FingerprintJS.x64hash128(values.join(""), 31); resolve(deviceId); });