Skip to content

Commit

Permalink
Merge pull request #63 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat: Integrate update learner API
  • Loading branch information
itsvick authored Jul 29, 2024
2 parents 2408d9b + f648ce3 commit 9524276
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 78 deletions.
8 changes: 6 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@
"ALL_BLOCKS": "All Blocks",
"NEW_FACILITATOR": "New Facilitator",
"SEARCHBAR_PLACEHOLDER": "Search Facilitators..",
"FACILITATOR_CREATED_SUCCESSFULLY": "Teacher has been Successfully Created"
"FACILITATOR_CREATED_SUCCESSFULLY": "Teacher has been Successfully Created",
"FACILITATOR_UPDATED_SUCCESSFULLY": "Teacher has been Successfully Updated!"

},
"NAVBAR": {
"SEARCHBAR_PLACEHOLDER": "Search course, topic, student, pdf etc.."
Expand All @@ -67,7 +69,9 @@
"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_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!",
"LEARNER_UPDATED_SUCCESSFULLY": "Leaner has been Successfully Updated!"

},
"TEAM_LEADERS": {
"SEARCHBAR_PLACEHOLDER": "Search Team leaders.."
Expand Down
6 changes: 3 additions & 3 deletions src/components/ActionIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from "react";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import { useTranslation } from "next-i18next";
import { Box, Typography, Tooltip } from "@mui/material";
import EditIcon from "@mui/icons-material/Edit";
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from "@mui/icons-material/Delete";

interface ActionCellProps {
Expand Down Expand Up @@ -41,11 +41,11 @@ const ActionIcon: React.FC<ActionCellProps> = ({
flexDirection: "column",
alignItems: "center",
cursor: "pointer",
opacity: 0.5, // Reduced opacity to make it appear disabled
// opacity: 0.5, // Reduced opacity to make it appear disabled
pointerEvents: "auto", // Enable pointer events to allow click
}}
>
<EditIcon sx={{ color: "rgba(0, 0, 0, 0.5)" }} />
<EditIcon/>
<Typography variant="body2">Edit</Typography>
</Box>
</Tooltip>
Expand Down
75 changes: 67 additions & 8 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
GenerateSchemaAndUiSchema,
customFields,
} from "@/components/GeneratedSchemas";
import { FormContext, FormContextType } from "@/utils/app.constant";
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 } 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";
Expand All @@ -23,10 +23,16 @@ import { useLocationState } from "@/utils/useLocationState";
interface AddFacilitatorModalprops {
open: boolean;
onClose: () => void;
formData?:object;
isEditModal?:boolean;
userId?:string
}

const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
open,
formData,
isEditModal=false,
userId,
onClose,
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -98,7 +104,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
console.log("Form data submitted:", formData);
const schemaProperties = schema.properties;

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

let apiBody: any = {
username: username,
Expand Down Expand Up @@ -143,10 +149,45 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
});

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],
});
}
try{
const response = await createUser(apiBody);
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();
showToastMessage(t('FACILITATORS.FACILITATOR_CREATED_SUCCESSFULLY'), 'success');


}
catch(error)
{
Expand Down Expand Up @@ -197,7 +238,9 @@ catch(error)
selectedCenter={selectedCenter}
handleCenterChangeWrapper={handleCenterChangeWrapper}
/>
{dynamicForm && schema && uiSchema && (


{formData ? ( schema && uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
Expand All @@ -207,8 +250,24 @@ catch(error)
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
65 changes: 58 additions & 7 deletions src/components/AddLeanerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
customFields,
} from "@/components/GeneratedSchemas";
import SimpleModal from "@/components/SimpleModal";
import { createUser, getFormRead } from "@/services/CreateUserService";
import { createUser, getFormRead , updateUser} from "@/services/CreateUserService";
import { generateUsernameAndPassword } from "@/utils/Helper";
import { FormData } from "@/utils/Interfaces";
import {
Expand All @@ -31,12 +31,15 @@ import { showToastMessage } from "./Toastify";
interface AddLearnerModalProps {
open: boolean;
onClose: () => void;
formData?:object;
isEditModal?:boolean;
userId?:string
}
interface FieldProp {
value: string;
label: string;
}
const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose, formData , isEditModal=false, userId}) => {
const [schema, setSchema] = React.useState<any>();
const [uiSchema, setUiSchema] = React.useState<any>();

Expand Down Expand Up @@ -80,6 +83,7 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
if (response) {
const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
setSchema(schema);
console.log(schema)
setUiSchema(uiSchema);
}
} catch (error) {
Expand Down Expand Up @@ -143,6 +147,7 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
console.log(
`FieldID: ${fieldId}, FieldValue: ${fieldValue}, type: ${typeof fieldValue}`
);


if (fieldId === null || fieldId === "null") {
if (typeof fieldValue !== "object") {
Expand All @@ -164,8 +169,11 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
});
}
}
});


});
if(!isEditModal)
{
apiBody.customFields.push({
fieldId: "a717bb68-5c8a-45cb-b6dd-376caa605736",
value: [selectedBlockCode],
Expand All @@ -178,10 +186,36 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
fieldId: "aecb84c9-fe4c-4960-817f-3d228c0c7300",
value: [selectedDistrictCode],
});
}

try {
const response = await createUser(apiBody);
if(isEditModal && userId)
{
console.log(apiBody)
const userData={
"name":apiBody.name,
"mobile": apiBody.mobile,
"father_name":apiBody.father_name

};
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("LEARNERS.LEARNER_CREATED_SUCCESSFULLY"), "success");

}
onClose();
showToastMessage(t("LEARNERS.LEARNER_CREATED_SUCCESSFULLY"), "success");
} catch (error) {
onClose();
console.log(error);
Expand Down Expand Up @@ -307,7 +341,23 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
/>
</Box>
</>
{dynamicForm && schema && uiSchema && (


{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}
Expand All @@ -320,7 +370,8 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({ open, onClose }) => {
>
{/* <CustomSubmitButton onClose={primaryActionHandler} /> */}
</DynamicForm>
)}
))}

</SimpleModal>
</>
);
Expand Down
7 changes: 5 additions & 2 deletions src/components/DynamicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ interface DynamicFormProps {
onChange: (event: IChangeEvent<any>) => void;
onError: (errors: any) => void;
showErrorList: boolean;


widgets: {
[key: string]: React.FC<WidgetProps<any, RJSFSchema, any>>;
};
Expand All @@ -39,6 +41,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
customFields,
children,
}) => {
console.log(formData)
const widgets = {
MultiSelectCheckboxes: MultiSelectCheckboxes,
CustomRadioWidget: CustomRadioWidget,
Expand Down Expand Up @@ -113,7 +116,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
}

function handleChange(event: any) {
console.log('Form data event:', event);
console.log('Form data changed:', event.formData);
onChange(event);
}

Expand All @@ -123,7 +126,7 @@ const DynamicForm: React.FC<DynamicFormProps> = ({
<FormWithMaterialUI
schema={schema}
uiSchema={uiSchema}
formData={formData}
formData={formData}
onChange={handleChange}
onSubmit={onSubmit}
validator={validator}
Expand Down
18 changes: 11 additions & 7 deletions src/components/KaTableComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface KaTableComponentProps {
}[];
paginationEnable?: boolean;
showIcons?: boolean;
pagination?: boolean;
}

const KaTableComponent: React.FC<KaTableComponentProps> = ({
Expand All @@ -43,6 +44,7 @@ const KaTableComponent: React.FC<KaTableComponentProps> = ({
onDelete,
showIcons,
pageSizes,
pagination = true,
}) => {
const [selectedRowIds, setSelectedRowIds] = useState<number[]>([]);

Expand All @@ -59,20 +61,22 @@ const KaTableComponent: React.FC<KaTableComponentProps> = ({
data,
rowKeyField: "id",
sortingMode: SortingMode.Single,
...(pagination && {
paging: {
enabled: paginationEnable,
pageIndex: 0,
pageSize: limit,
pageSizes: pageSizes,
position: PagingPosition.Bottom,
},
}),
};

return (
<Paper>
<div className="ka-table-wrapper">
<Table
{...tableProps}
paging={{
enabled: paginationEnable,
pageIndex: 0,
pageSize: limit,
pageSizes: pageSizes,
position: PagingPosition.Bottom,
}}
childComponents={{
pagingSizes: {
content: (props) => <PageSizeSelector {...props} />,
Expand Down
Loading

0 comments on commit 9524276

Please sign in to comment.