Skip to content

Commit

Permalink
Issue #PS-000 feat: Form create using rjsf
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Jul 18, 2024
1 parent 6f3450b commit 2a3c452
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/components/GeneratedSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -36,7 +36,7 @@ formData?.fields?.forEach((field: Field) => {
} = field;

const fieldSchema: any = {
title: label,
title: t(`FORM.${label}`),
};

const fieldUiSchema: any = {};
Expand Down
14 changes: 11 additions & 3 deletions src/pages/add-learner.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -10,20 +13,25 @@ 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<any>();
const [uiSchema, setUiSchema] = React.useState<any>();

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);
}
Expand Down

0 comments on commit 2a3c452

Please sign in to comment.