Skip to content

Commit

Permalink
Merge pull request #6 from chaitanyakole/dev_issues_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gouravmore authored Nov 12, 2024
2 parents cd7938f + 0ec82b9 commit e737927
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 152 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 23 additions & 18 deletions src/components/AddNewCenters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -25,7 +28,6 @@ interface CohortDetails {
name?: string;
domain?: any;
status?: string;

}

interface AddLearnerModalProps {
Expand All @@ -38,7 +40,7 @@ interface AddLearnerModalProps {

const uiSchema = {
district: {
"ui:widget": '',
"ui:widget": "",
"ui:options": {},
},
status: {
Expand All @@ -47,10 +49,10 @@ const uiSchema = {
},

block: {
"ui:widget": '',
"ui:widget": "",
"ui:options": {},
},
}
};

const AddNewCenters: React.FC<AddLearnerModalProps> = ({
open,
Expand All @@ -62,6 +64,8 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
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,
Expand All @@ -70,44 +74,44 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
selectedBlockCode,
dynamicFormForBlock,
} = useLocationState(open, onClose, roleType);

const setSubmittedButtonStatus = useSubmittedButtonStore(
(state: any) => state.setSubmittedButtonStatus
);

const handleSubmit = async (
data: IChangeEvent<any, RJSFSchema, any>,
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
) => {
) => {
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<any>) => {
setUpdateBtnDisabled(false);
console.log("Form changed:", data.formData);
};

const handleError = (errors: any) => {
console.log("Form errors:", errors);
}

};

return (
<SimpleModal
Expand All @@ -125,8 +129,8 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
widgets={{}}
showErrorList={true}
customFields={customFields}
onChange={handleChange}
onError={handleError}
onChange={handleChange}
onError={handleError}
id="new-center-form"
>
<Box
Expand All @@ -151,6 +155,7 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
<Button
variant="contained"
type="submit"
disabled={updateBtnDisabled}
onClick={() => setSubmittedButtonStatus(true)}
sx={{
fontSize: "14px",
Expand Down
2 changes: 1 addition & 1 deletion src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
default: {
const validRange = currentYearPattern.test(pattern);
if (!validRange) {
error.message = t("FORM_ERROR_MESSAGES.ENTER_VALID_YEAR");
error.message = t("FORM_ERROR_MESSAGES.ENTER_VALID_DATA");
}
break;
}
Expand Down
106 changes: 44 additions & 62 deletions src/pages/cohorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ const Center: React.FC = () => {
const [statesInformation, setStatesInformation] = useState<any>([]);
const [selectedRowData, setSelectedRowData] = useState<any>("");
const [Addmodalopen, setAddmodalopen] = React.useState<any>(false);
const [updateBtnDisabled, setUpdateBtnDisabled] = React.useState(true);
const [addFormData, setAddFormData] = useState({});
const [addBtnDisabled, setAddBtnDisabled] = useState(true);

const selectedBlockStore = useSubmittedButtonStore(
(state: any) => state.selectedBlockStore
Expand Down Expand Up @@ -166,17 +169,34 @@ const Center: React.FC = () => {
);

const uiSchema = {
name: {
"ui:widget": "text",
"ui:placeholder": "Enter full name",
"ui:options": {},
},
type: {
"ui:widget": "text",
// "ui:placeholder": "Select type",
// "ui:options": {
// defaultValue: "cohort",
// },
"ui:disabled": true, // This will make the field readonly
},
district: {
"ui:widget": "",
"ui:widget": "text",
"ui:placeholder": "Enter district",
"ui:options": {},
},
status: {
"ui:widget": "CustomRadioWidget",
"ui:options": {},
"ui:options": {
defaultValue: "active",
},
// "ui:disabled": true,
},

block: {
"ui:widget": "",
"ui:widget": "text",
"ui:placeholder": "Enter block",
"ui:options": {},
},
};
Expand All @@ -202,19 +222,19 @@ const Center: React.FC = () => {
},
mobileNo: {
"ui:widget": "text",
"ui:placeholder": "Enter your 10-digit mobile number",
"ui:help": "Please enter a valid 10-digit mobile number.",
"ui:placeholder": "Mobile number",
// "ui:help": "Please enter a valid 10-digit mobile number.",
},
email: {
"ui:widget": "text",
"ui:placeholder": "Enter your email address",
"ui:options": {},
},
dob: {
"ui:widget": "date",
"ui:placeholder": "Select your date of birth",
"ui:help": "Date of birth in YYYY-MM-DD format.",
},
// dob: {
// "ui:widget": "date",
// "ui:placeholder": "Select your date of birth",
// // "ui:help": "Date of birth in YYYY-MM-DD format.",
// },
};

const [filters, setFilters] = useState<cohortFilterDetails>({
Expand All @@ -225,6 +245,7 @@ const Center: React.FC = () => {
});
const handleCloseAddLearnerModal = () => {
setOpenAddNewCohort(false);
setUpdateBtnDisabled(true);
};
const isMobile = useMediaQuery((theme: Theme) =>
theme.breakpoints.down("sm")
Expand Down Expand Up @@ -714,6 +735,7 @@ const Center: React.FC = () => {

const handleCloseModal = () => {
setConfirmationModalOpen(false);
setUpdateBtnDisabled(true);
};

const handleActionForDelete = async () => {
Expand Down Expand Up @@ -869,21 +891,25 @@ const Center: React.FC = () => {

const onCloseEditMOdel = () => {
setIsEditModalOpen(false);
setUpdateBtnDisabled(true);
};

const onCloseEditForm = () => {
setIsEditForm(false);
setUpdateBtnDisabled(true);
};
const handleInputName = (event: ChangeEvent<HTMLInputElement>) => {
const updatedName = event.target.value;
setInputName(updatedName);
};

const handleChangeForm = (event: IChangeEvent<any>) => {
setUpdateBtnDisabled(false);
setAddBtnDisabled(false);
console.log("Form data changed:", event.formData);
};
const handleError = () => {
console.log("error");
const handleError = (error: any) => {
console.log("error", error);
};

const handleUpdateAction = async (
Expand All @@ -893,53 +919,6 @@ const Center: React.FC = () => {
setLoading(true);
const formData = data?.formData;
const schemaProperties = schema.properties;

// let apiBody: any = {
// customFields: [],
// };
// Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
// const fieldSchema = schemaProperties[fieldKey];
// const fieldId = fieldSchema?.fieldId;

// console.log(
// `FieldID: ${fieldId}, FieldValue: ${JSON.stringify(fieldSchema)}, type: ${typeof fieldValue}`
// );

// if (fieldId === null || fieldId === "null") {
// if (typeof fieldValue !== "object") {
// apiBody[fieldKey] = fieldValue;
// }
// } else {
// if (
// fieldSchema?.hasOwnProperty("isDropdown") ||
// fieldSchema?.hasOwnProperty("isCheckbox") ||
// fieldSchema?.type === "radio"
// ) {
// apiBody.customFields.push({
// fieldId: fieldId,
// value: Array.isArray(fieldValue) ? fieldValue : [fieldValue],
// });
// } else {
// if (fieldSchema?.checkbox && fieldSchema.type === "array") {
// if (String(fieldValue).length != 0) {
// apiBody.customFields.push({
// fieldId: fieldId,
// value: String(fieldValue).split(","),
// });
// }
// } else {
// if (fieldId) {
// apiBody.customFields.push({
// fieldId: fieldId,
// value: String(fieldValue),
// });
// }
// }
// }
// }
// });

// const customFields = apiBody?.customFields;
try {
setLoading(true);
setConfirmButtonDisable(true);
Expand Down Expand Up @@ -1107,6 +1086,7 @@ const Center: React.FC = () => {
};
const handleAddmodal = () => {
setAddmodalopen(false);
setAddFormData({});
};

const handleAddAction = async (data: any) => {
Expand Down Expand Up @@ -1316,7 +1296,8 @@ const Center: React.FC = () => {
<Button
variant="contained"
type="submit"
form="update-center-form" // Add this line
form="update-center-form"
disabled={updateBtnDisabled}
sx={{
fontSize: "14px",
fontWeight: "500",
Expand Down Expand Up @@ -1350,7 +1331,7 @@ const Center: React.FC = () => {
widgets={{}}
showErrorList={true}
customFields={customFields}
formData={editFormData}
formData={addFormData}
id="update-center-form"
>
<Box
Expand Down Expand Up @@ -1378,6 +1359,7 @@ const Center: React.FC = () => {
<Button
variant="contained"
type="submit"
disabled={addBtnDisabled}
sx={{
fontSize: "14px",
fontWeight: "500",
Expand Down
Loading

0 comments on commit e737927

Please sign in to comment.