Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/tekdi/shiksha-admin into co…
Browse files Browse the repository at this point in the history
…hort_list
  • Loading branch information
upendraTekdi committed Jul 30, 2024
2 parents 24bea6b + c58e1af commit a42d627
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 1,217 deletions.
17 changes: 12 additions & 5 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"SEARCHBAR_PLACEHOLDER": "Search Learners..",
"NEW_LEARNER": "New Learner",
"FIRST_SELECT_REQUIRED_FIELDS": "First select required fields",
"LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!",
"LEARNER_UPDATED_SUCCESSFULLY": "Leaner has been Successfully Updated!"
"LEARNER_CREATED_SUCCESSFULLY": "Learner has been Successfully Created!",
"LEARNER_UPDATED_SUCCESSFULLY": "Learner has been Successfully Updated!"
},
"TEAM_LEADERS": {
"SEARCHBAR_PLACEHOLDER": "Search Team leaders.."
Expand Down Expand Up @@ -188,7 +188,10 @@
"YEAR_OF_JOINING_SCP": "Year of joining SCP",
"ASSIGN_CENTERS": "Assign Centers",
"TYPE_OF_COHORT": "Type Of Cohort List",
"UNIT_NAME": "Unit Name"
"UNIT_NAME": "Unit Name",
"DESIGNATION":"Designation",
"SUBJECTS_I_TEACH":"Subject Teach",
"MY_MAIN_SUBJECTS":"Main subjects"
},
"FORM_ERROR_MESSAGES": {
"INVALID_INPUT": "Invalid Input.",
Expand All @@ -200,8 +203,12 @@
"MIN_LENGTH_CHARACTERS_ERROR": "Minimum {{minLength}} characters required",
"MAX_LENGTH_CHARACTERS_ERROR": "Maximum {{maxLength}} characters allowed",
"NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED": "Numbers and special characters are not allowed",
"CHARACTERS_AND_SPECIAL_CHARACTERS_NOT_ALLOWED": "Characters and special characters are not allowed",
"NAME_CANNOT_INCLUDE_DIGITS": "Name can not include digits",
"INVALID_EMAIL_FORMAT": "Invalid email format"
"INVALID_EMAIL_FORMAT": "Invalid email format",
"ENTER_VALID_EMAIL": "Enter a valid email address",
"ENTER_VALID_MOBILE_NUMBER": "Enter a valid Mobile Number"

},
"TABLE_TITLE": {
"NAME": "Name",
Expand All @@ -212,4 +219,4 @@
"UPDATED_BY": "Updated By",
"ACTIONS": "Actions"
}
}
}
8 changes: 3 additions & 5 deletions src/components/ActionIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ const ActionIcon: React.FC<ActionCellProps> = ({
// pointerEvents: "none",
}}
>
<EditIcon sx={{ color: "rgba(0, 0, 0, 0.5)" }} />
<Typography variant="body2" color={"black"}>
{t("COMMON.EDIT")}
</Typography>
<EditIcon/>
<Typography variant="body2">{t("COMMON.EDIT")}</Typography>
</Box>
</Tooltip>
<Tooltip title={t("COMMON.DELETE")}>
Expand All @@ -63,7 +61,7 @@ const ActionIcon: React.FC<ActionCellProps> = ({
}}
>
<DeleteIcon sx={{ color: "rgb(244, 67, 54)" }} />
<Typography variant="body2"> {t("COMMON.DELETE")}</Typography>
<Typography variant="body2">{t("COMMON.DELETE")}</Typography>
</Box>
</Tooltip>
</Box>
Expand Down
214 changes: 124 additions & 90 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@ import { FormContext, FormContextType, Role } from "@/utils/app.constant";
import DynamicForm from "@/components/DynamicForm";
import SendCredentialModal from "@/components/SendCredentialModal";
import SimpleModal from "@/components/SimpleModal";
import { createUser, getFormRead, updateUser } from "@/services/CreateUserService";
import {
createUser,
getFormRead,
updateUser,
} from "@/services/CreateUserService";
import { generateUsernameAndPassword } from "@/utils/Helper";
import { FormData } from "@/utils/Interfaces";
import { RoleId } from "@/utils/app.constant";
import AreaSelection from "./AreaSelection";
import { showToastMessage } from "./Toastify";
import { transformArray } from "../utils/Helper";
import { useLocationState } from "@/utils/useLocationState";
import { useLocationState } from "@/utils/useLocationState";

interface AddFacilitatorModalprops {
open: boolean;
onClose: () => void;
formData?:object;
isEditModal?:boolean;
userId?:string
formData?: object;
isEditModal?: boolean;
userId?: string;
}

const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
open,
formData,
isEditModal=false,
isEditModal = false,
userId,
onClose,
}) => {
Expand All @@ -41,10 +45,25 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
const [uiSchema, setUiSchema] = useState<any>();

const {
states, districts, blocks, allCenters, isMobile, isMediumScreen,
selectedState, selectedStateCode, selectedDistrict, selectedDistrictCode,
selectedCenter, dynamicForm, selectedBlock, selectedBlockCode, selectedCenterCode,
handleStateChangeWrapper, handleDistrictChangeWrapper, handleBlockChangeWrapper, handleCenterChangeWrapper
states,
districts,
blocks,
allCenters,
isMobile,
isMediumScreen,
selectedState,
selectedStateCode,
selectedDistrict,
selectedDistrictCode,
selectedCenter,
dynamicForm,
selectedBlock,
selectedBlockCode,
selectedCenterCode,
handleStateChangeWrapper,
handleDistrictChangeWrapper,
handleBlockChangeWrapper,
handleCenterChangeWrapper,
} = useLocationState(open, onClose);

useEffect(() => {
Expand All @@ -66,7 +85,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
);
console.log(centerOptionsList);
}

if (response) {
const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
setSchema(schema);
Expand All @@ -83,7 +102,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
) => {
// setOpenModal(true);
// setOpenModal(true);
const target = event.target as HTMLFormElement;
const elementsArray = Array.from(target.elements);

Expand All @@ -104,7 +123,10 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
console.log("Form data submitted:", formData);
const schemaProperties = schema.properties;

const { username, password } = generateUsernameAndPassword(selectedStateCode,Role.TEACHER);
const { username, password } = generateUsernameAndPassword(
selectedStateCode,
Role.TEACHER
);

let apiBody: any = {
username: username,
Expand All @@ -121,11 +143,11 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({

Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
const fieldSchema = schemaProperties[fieldKey];
console.log(fieldSchema)
const fieldId = fieldSchema?.fieldId;
console.log(
`FieldID: ${fieldId}, FieldValue: ${fieldValue}, type: ${typeof fieldValue}`
);

if (fieldId === null || fieldId === "null") {
if (typeof fieldValue !== "object") {
apiBody[fieldKey] = fieldValue;
Expand All @@ -140,59 +162,69 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
value: [String(fieldValue)],
});
} else {
if(fieldSchema.checkbox &&fieldSchema.type==="array")
{
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue).split(',')
});
}
else{
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
}
}
}
});

console.log(apiBody);
if(!isEditModal)
{
apiBody.customFields.push({
fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736",
value: [selectedBlockCode],
});
apiBody.customFields.push({
fieldId: "61b5909a-0b45-4282-8721-e614fd36d7bd",
value: [selectedStateCode],
});
apiBody.customFields.push({
fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300",
value: [selectedDistrictCode],
});
if (!isEditModal) {
apiBody.customFields.push({
fieldId: "549d3575-bf01-48a9-9fff-59220fede174",
value: [selectedBlockCode],
});
apiBody.customFields.push({
fieldId: "b61edfc6-3787-4079-86d3-37262bf23a9e",
value: [selectedStateCode],
});
apiBody.customFields.push({
fieldId: "f2d731dd-2298-40d3-80bb-9ae6c5b38fb8",
value: [selectedDistrictCode],
});
}
try {
if (isEditModal && userId) {
console.log(userId);
const userData = {
name: apiBody.name,
mobile: apiBody.mobile,
};
const customFields = apiBody.customFields;
console.log(customFields);
const object = {
userData: userData,
customFields: customFields,
};
// const response = await updateUser(userId, object);
showToastMessage(t("LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"), "success");
} else {
try{
const response = await createUser(apiBody);
showToastMessage(
t("FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY"),
"success"
);
}
catch (error) {
console.log(error);
}

}
onClose();
} catch (error) {
console.log(error);
}
try{
if(isEditModal && userId)
{
const userData={
"name":apiBody.name,
"mobile": apiBody.mobile,

};
const customFields=apiBody.customFields;
console.log(customFields)
const object=
{
"userData":userData,
"customFields":customFields
}
const response = await updateUser(userId,object)
showToastMessage(t("LEARNERS.LEARNER_UPDATED_SUCCESSFULLY"), "success");
}else{
const response = await createUser(apiBody);
showToastMessage(t('FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY'), 'success');
}
onClose();


}
catch(error)
{
console.log(error);
}
};

const handleChange = (event: IChangeEvent<any>) => {
Expand All @@ -217,9 +249,7 @@ catch(error)
modalTitle={t("FACILITATORS.NEW_FACILITATOR")}
>
{!dynamicForm && (
<Typography>
{t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")}{" "}
</Typography>
<Typography>{t("LEARNERS.FIRST_SELECT_REQUIRED_FIELDS")} </Typography>
)}
<AreaSelection
states={transformArray(states)}
Expand All @@ -238,36 +268,40 @@ catch(error)
selectedCenter={selectedCenter}
handleCenterChangeWrapper={handleCenterChangeWrapper}
/>


{formData ? ( schema && uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
onSubmit={handleSubmit}
onChange={handleChange}
onError={handleError}
widgets={{}}
showErrorList={true}
customFields={customFields}
formData={formData}
>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
)) :( dynamicForm && schema && uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
onSubmit={handleSubmit}
onChange={handleChange}
onError={handleError}
widgets={{}}
showErrorList={true}
customFields={customFields}
>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
))}
{formData
? schema &&
uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
onSubmit={handleSubmit}
onChange={handleChange}
onError={handleError}
widgets={{}}
showErrorList={true}
customFields={customFields}
formData={formData}
>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
)
: dynamicForm &&
schema &&
uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
onSubmit={handleSubmit}
onChange={handleChange}
onError={handleError}
widgets={{}}
showErrorList={true}
customFields={customFields}
>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
)}
</SimpleModal>
<SendCredentialModal open={openModal} onClose={onCloseModal} />
</>
Expand Down
Loading

0 comments on commit a42d627

Please sign in to comment.