From 2a3c452bdabfeccebbf484fb7f440db351fa1030 Mon Sep 17 00:00:00 2001 From: vivek kasture Date: Thu, 18 Jul 2024 14:27:56 +0530 Subject: [PATCH] Issue #PS-000 feat: Form create using rjsf --- src/components/GeneratedSchemas.ts | 4 ++-- src/pages/add-learner.tsx | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/GeneratedSchemas.ts b/src/components/GeneratedSchemas.ts index 769c854f..e46d1961 100644 --- a/src/components/GeneratedSchemas.ts +++ b/src/components/GeneratedSchemas.ts @@ -7,7 +7,7 @@ export const customFields = { NumberInputField: NumberInputField }; -export const GenerateSchemaAndUiSchema = (formData: FormData) => { +export const GenerateSchemaAndUiSchema = (formData: FormData, t: (key: string) => string) => { const schema: JSONSchema7 = { //Form schema title: formData.title, description: '', @@ -36,7 +36,7 @@ formData?.fields?.forEach((field: Field) => { } = field; const fieldSchema: any = { - title: label, + title: t(`FORM.${label}`), }; const fieldUiSchema: any = {}; diff --git a/src/pages/add-learner.tsx b/src/pages/add-learner.tsx index eebb90f9..bceb2f28 100644 --- a/src/pages/add-learner.tsx +++ b/src/pages/add-learner.tsx @@ -1,6 +1,9 @@ import DynamicForm from '@/components/DynamicForm'; import React, { useEffect } from 'react'; -import { GenerateSchemaAndUiSchema, customFields } from '@/components/GeneratedSchemas'; +import { + GenerateSchemaAndUiSchema, + customFields, +} from '@/components/GeneratedSchemas'; import { IChangeEvent } from '@rjsf/core'; import ISubmitEvent from '@rjsf/core'; import { Box } from '@mui/material'; @@ -10,8 +13,10 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { getFormRead } from '@/services/CreateUserService'; import { FormData } from '@/utils/Interfaces'; import { FormContext, FormContextType } from '@/utils/app.constant'; +import { useTranslation } from 'next-i18next'; const addLearner = () => { + const { t } = useTranslation(); const [openModal, setOpenModal] = React.useState(false); const [schema, setSchema] = React.useState(); const [uiSchema, setUiSchema] = React.useState(); @@ -19,11 +24,14 @@ const addLearner = () => { useEffect(() => { const getAddLearnerFormData = async () => { try { - const response: FormData = await getFormRead(FormContext.USERS, FormContextType.STUDENT); + const response: FormData = await getFormRead( + FormContext.USERS, + FormContextType.STUDENT + ); console.log('sortedFields', response); if (response) { - const { schema, uiSchema } = GenerateSchemaAndUiSchema(response); + const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t); setSchema(schema); setUiSchema(uiSchema); }