From 0ec82b9bc604b8cb4ba6fedc35e12b2e87e381cb Mon Sep 17 00:00:00 2001 From: chaitanyakole Date: Mon, 11 Nov 2024 22:49:55 +0530 Subject: [PATCH] Added some validations and changes in code --- public/locales/en/common.json | 3 +- src/components/AddNewCenters.tsx | 41 ++++++------ src/components/DynamicForm.tsx | 2 +- src/pages/cohorts.tsx | 106 +++++++++++++------------------ src/pages/tenant.tsx | 76 +++++----------------- src/pages/userSchema.json | 10 +-- 6 files changed, 86 insertions(+), 152 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index efbbf811..1d8bcb8e 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -389,7 +389,8 @@ "NAME_CANNOT_INCLUDE_DIGITS": "Name can not include digits", "INVALID_EMAIL_FORMAT": "Invalid email format", "ENTER_VALID_EMAIL": "Enter a valid email address", - "ENTER_VALID_MOBILE_NUMBER": "Enter a valid Mobile Number" + "ENTER_VALID_MOBILE_NUMBER": "Enter a valid Mobile Number", + "ENTER_VALID_DATA": "Enter a valid data" }, "TABLE_TITLE": { "NAME": "Name", diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx index 68e719bf..ae6ebf2e 100644 --- a/src/components/AddNewCenters.tsx +++ b/src/components/AddNewCenters.tsx @@ -4,7 +4,10 @@ import { customFields, } from "@/components/GeneratedSchemas"; import SimpleModal from "@/components/SimpleModal"; -import { createCohort, tenantCreate } from "@/services/CohortService/cohortService"; +import { + createCohort, + tenantCreate, +} from "@/services/CohortService/cohortService"; import { CohortTypes, FormContextType } from "@/utils/app.constant"; import { useLocationState } from "@/utils/useLocationState"; import { Box, Button, Typography } from "@mui/material"; @@ -25,7 +28,6 @@ interface CohortDetails { name?: string; domain?: any; status?: string; - } interface AddLearnerModalProps { @@ -38,7 +40,7 @@ interface AddLearnerModalProps { const uiSchema = { district: { - "ui:widget": '', + "ui:widget": "", "ui:options": {}, }, status: { @@ -47,10 +49,10 @@ const uiSchema = { }, block: { - "ui:widget": '', + "ui:widget": "", "ui:options": {}, }, -} +}; const AddNewCenters: React.FC = ({ open, @@ -62,6 +64,8 @@ const AddNewCenters: React.FC = ({ const [schema] = useState(Tenatschema); const [showForm, setShowForm] = useState(false); const { t } = useTranslation(); + const [updateBtnDisabled, setUpdateBtnDisabled] = React.useState(true); + const roleType = FormContextType.ADMIN_CENTER; const { selectedBlockCohortId, @@ -70,44 +74,44 @@ const AddNewCenters: React.FC = ({ selectedBlockCode, dynamicFormForBlock, } = useLocationState(open, onClose, roleType); - + const setSubmittedButtonStatus = useSubmittedButtonStore( (state: any) => state.setSubmittedButtonStatus ); const handleSubmit = async ( - data: IChangeEvent, + data: IChangeEvent, event: React.FormEvent - ) => { + ) => { const formData = data?.formData; - if (!formData) { + if (!formData) { showToastMessage("Form data is required", "error"); return; } - + const cohortDetails: CohortDetails = { name: formData?.name, domain: formData?.domain, // status: formData?.status, }; - - const cohortData = await tenantCreate(cohortDetails); - if (cohortData?.responseCode=== 200|| cohortData?.responseCode===201) { + + const cohortData = await tenantCreate(cohortDetails); + if (cohortData?.responseCode === 200 || cohortData?.responseCode === 201) { showToastMessage(t("TENANT.CREATE_SUCCESSFULLY"), "success"); onClose(); } else { showToastMessage("Please Input Data", "warning"); } }; - + const handleChange = (data: IChangeEvent) => { + setUpdateBtnDisabled(false); console.log("Form changed:", data.formData); }; const handleError = (errors: any) => { console.log("Form errors:", errors); - } - + }; return ( = ({ widgets={{}} showErrorList={true} customFields={customFields} - onChange={handleChange} - onError={handleError} + onChange={handleChange} + onError={handleError} id="new-center-form" > = ({