Skip to content

Commit

Permalink
Merge pull request #64 from Rushikesh-Sonawane99/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1269 chore: Modified services and data mapping to display TL profile
  • Loading branch information
itsvick authored Aug 1, 2024
2 parents 428ba59 + d00c91f commit 4aa59ca
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 54 deletions.
8 changes: 5 additions & 3 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"NEW_FACILITATOR": "New Facilitator",
"SUBMIT": "Submit",
"LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!",
"LEARNER_UPDATED_SUCCESSFULLY": "Learner has been Updated Created!"
"FACILITATOR_ADDED_SUCCESSFULLY": "Facilitator added successfully!",
"LEARNER_UPDATED_SUCCESSFULLY": "Learner profile updated successfully!",
"FACILITATOR_UPDATED_SUCCESSFULLY": "Facilitator profile updated successfully!"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -434,7 +436,7 @@
"COURSE_PLANNER": "Course Plan",
"FOUNDATION_COURSE": "Foundation Course",
"MAIN_COURSE": "Main Course",
"COLLAPSE_ALL":"Collapse All",
"RESOURCES":"Resources"
"COLLAPSE_ALL": "Collapse All",
"RESOURCES": "Resources"
}
}
95 changes: 50 additions & 45 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
const { t } = useTranslation();

useEffect(() => {
const getAddLearnerFormData = async () => {
const getAddFacilitatorFormData = async () => {
try {
const response: FormData = await getFormRead(
FormContext.USERS,
Expand Down Expand Up @@ -76,7 +76,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
coreField: 0,
maxSelections: null,
};
if (!isEditModal){
if (!isEditModal) {
response?.fields.push(assignCentersField);
console.log(response);
}
Expand All @@ -90,14 +90,16 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
console.error('Error fetching form data:', error);
}
};
getAddLearnerFormData();
getAddFacilitatorFormData();
}, []);

const handleSubmit = async (
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
) => {
setOpenModal(true);
if(!isEditModal){
setOpenModal(true);
}
const target = event.target as HTMLFormElement;
const elementsArray = Array.from(target.elements);

Expand Down Expand Up @@ -196,18 +198,21 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
customFields: customFields,
};
const response = await editEditUser(userId, object);
showToastMessage(t('COMMON.LEARNER_UPDATED_SUCCESSFULLY'), 'success');
showToastMessage(
t('COMMON.FACILITATOR_UPDATED_SUCCESSFULLY'),
'success'
);
} else {
const response = await createUser(apiBody);
console.log(response);
showToastMessage(t('LEARNERS.LEARNER_CREATED_SUCCESSFULLY'), 'success');
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');
}
};
} catch (error) {
onClose();
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
};
const handleChange = (event: IChangeEvent<any>) => {
console.log('Form data changed:', event.formData);
};
Expand All @@ -229,38 +234,38 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
showFooter={false}
modalTitle={t('COMMON.NEW_FACILITATOR')}
>
{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>
)}
{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
2 changes: 1 addition & 1 deletion src/pages/learner/[userId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
classesMissedAttendancePercentList,
getCohortAttendance,
} from '@/services/AttendanceService';
import { editEditUser, getUserDetails } from '@/services/ProfileService';
import { getUserDetails } from '@/services/ProfileService';
import {
formatSelectedDate,
getTodayDate,
Expand Down
8 changes: 6 additions & 2 deletions src/pages/user-profile/[userId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@mui/icons-material';
import { CustomField } from '@/utils/Interfaces';
import React, { useEffect, useRef, useState } from 'react';
import { editEditUser, getUserDetails } from '@/services/ProfileService';
import { getUserDetails } from '@/services/ProfileService';
import { useTheme } from '@mui/material/styles';
import { GetStaticPaths } from 'next';
import Button from '@mui/material/Button';
Expand Down Expand Up @@ -189,9 +189,13 @@ const TeacherProfile = () => {

const fetchFormData = async () => {
try {
const formContextType =
(userRole === Role.TEAM_LEADER && selfUserId === userId)
? FormContextType.TEAM_LEADER
: FormContextType.TEACHER;
const response: FormData = await getFormRead(
FormContext.USERS,
FormContextType.TEACHER
formContextType
);
console.log('response', response);
if (response) {
Expand Down
18 changes: 16 additions & 2 deletions src/services/CreateUserService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import axios from 'axios';
import { get, post } from './RestClient';

export const getFormRead = async (
context: string,
contextType: string
): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/form/read?context=${context}&contextType=${contextType}`;
try {
const response = await get(apiUrl);
const response = await axios.get(
`${process.env.NEXT_PUBLIC_BASE_URL}/form/read`,
{
params: {
context,
contextType,
},
paramsSerializer: (params) => {
return Object.entries(params)
.map(([key, value]) => `${key}=${value}`)
.join('&');
},
headers: { tenantId: 'ef99949b-7f3a-4a5f-806a-e67e683e38f3' },
}
);

const sortedFields = response?.data?.result.fields?.sort(
(a: { order: string }, b: { order: string }) =>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/app.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export enum FormContext {
export enum FormContextType {
STUDENT = 'STUDENT',
TEACHER = 'TEACHER',
TEAM_LEADER = 'TEAMLEADER',
TEAM_LEADER = 'TEAM LEADER',
}

export enum CenterType {
Expand Down

0 comments on commit 4aa59ca

Please sign in to comment.