Skip to content

Commit

Permalink
Merge pull request #63 from Rushikesh-Sonawane99/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1256 feat: Edit Facilitator profile and learner's profile based on new form API
  • Loading branch information
itsvick authored Jul 31, 2024
2 parents 6e5de60 + 2c34e04 commit 428ba59
Show file tree
Hide file tree
Showing 9 changed files with 489 additions and 1,528 deletions.
5 changes: 3 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
"NEW_LEARNER": "New Learner",
"NEW_FACILITATOR": "New Facilitator",
"SUBMIT": "Submit",
"LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!"
"LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!",
"LEARNER_UPDATED_SUCCESSFULLY": "Learner has been Updated Created!"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -393,7 +394,7 @@
"DESIGNATION": "Designation",
"NUMBER_OF_CLUSTERS_I_TEACH": "Number of Clusters I Teach",
"YEAR_OF_JOINING_SCP": "Year of joining SCP",
"MAIN_SUBJECT": "My Main Subjects",
"MY_MAIN_SUBJECTS": "My Main Subjects",
"SUBJECTS_I_TEACH": "Subjects I Teach",
"GENDER": "Gender",
"UNIT_NAME": "Unit Name",
Expand Down
110 changes: 82 additions & 28 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,22 @@ import { Field, FormData } from '@/utils/Interfaces';
import { IChangeEvent } from '@rjsf/core';
import { RJSFSchema } from '@rjsf/utils';
import { useTranslation } from 'next-i18next';
import { showToastMessage } from './Toastify';
import { editEditUser } from '@/services/ProfileService';

interface AddFacilitatorModalprops {
open: boolean;
onClose: () => void;
formData?: object;
isEditModal?: boolean;
userId?: string;
}
const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
open,
onClose,
formData,
isEditModal = false,
userId,
}) => {
const [schema, setSchema] = React.useState<any>();
const [openModal, setOpenModal] = React.useState(false);
Expand Down Expand Up @@ -68,8 +76,10 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
coreField: 0,
maxSelections: null,
};
response?.fields.push(assignCentersField);
console.log(response);
if (!isEditModal){
response?.fields.push(assignCentersField);
console.log(response);
}

if (response) {
const { schema, uiSchema } = GenerateSchemaAndUiSchema(response, t);
Expand Down Expand Up @@ -134,19 +144,21 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
if (typeof fieldValue !== 'object') {
apiBody[fieldKey] = fieldValue;
}
} else if (
Object.hasOwn(fieldSchema, 'isDropdown') ||
Object.hasOwn(fieldSchema, 'isCheckbox')
) {
apiBody.customFields.push({
fieldId: fieldId,
value: [String(fieldValue)],
});
} else {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
if (
fieldSchema?.hasOwnProperty('isDropdown') ||
fieldSchema.hasOwnProperty('isCheckbox')
) {
apiBody.customFields.push({
fieldId: fieldId,
value: [String(fieldValue)],
});
} else {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
}
}
});

Expand All @@ -170,10 +182,32 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
// });
console.log(apiBody);

try {
if (isEditModal && userId) {
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 editEditUser(userId, object);
showToastMessage(t('COMMON.LEARNER_UPDATED_SUCCESSFULLY'), 'success');
} else {
const response = await createUser(apiBody);
console.log(response);
};

showToastMessage(t('LEARNERS.LEARNER_CREATED_SUCCESSFULLY'), 'success');
}
onClose();
}catch (error) {
onClose();
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
};
const handleChange = (event: IChangeEvent<any>) => {
console.log('Form data changed:', event.formData);
};
Expand All @@ -195,18 +229,38 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
showFooter={false}
modalTitle={t('COMMON.NEW_FACILITATOR')}
>
{schema && uiSchema && (
<DynamicForm
schema={schema}
uiSchema={uiSchema}
onSubmit={handleSubmit}
onChange={handleChange}
onError={handleError}
widgets={{}}
showErrorList={true}
customFields={customFields}
/>
)}
{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>
)
: 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 428ba59

Please sign in to comment.