Skip to content

Commit

Permalink
Merge branch 'release-1.0.0' of github.com:tekdi/teachers-app into ce…
Browse files Browse the repository at this point in the history
…nterSession
  • Loading branch information
shreyas143shinde committed Jul 25, 2024
2 parents a31895d + a56e4dc commit 5aed789
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 8 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"TYPE_OF_PHONE_AVAILABLE": "Type of Phone Available",
"REASON_FOR_DROP_OUT_FROM_SCHOOL": "Reason for drop out from School",
"EMAIL": "Email",
"YEAR_OF_ JOINING_SCP": "Year of joining SCP",
"YEAR_OF_JOINING_SCP": "Year of joining SCP",
"ASSIGN_CENTERS": "Assign Centers"
},
"FORM_ERROR_MESSAGES": {
Expand Down
93 changes: 86 additions & 7 deletions src/components/AddFacilitator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import { IChangeEvent } from '@rjsf/core';
import ISubmitEvent from '@rjsf/core';
import { RJSFSchema } from '@rjsf/utils';
import SendCredentialModal from '@/components/SendCredentialModal';
import SimpleModal from '@/components/SimpleModal';
import { getFormRead } from '@/services/CreateUserService';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { useTranslation } from 'react-i18next';
import { createUser, getFormRead } from '@/services/CreateUserService';
import { RoleId } from '@/utils/app.constant';
import SimpleModal from '@/components/SimpleModal';
import { generateUsernameAndPassword } from '@/utils/Helper';
import { useTranslation } from 'next-i18next';

interface AddFacilitatorModalprops {
open: boolean;
Expand All @@ -27,6 +29,7 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
onClose,
}) => {
const [schema, setSchema] = React.useState<any>();
const [openModal, setOpenModal] = React.useState(false);
const [uiSchema, setUiSchema] = React.useState<any>();
const { t } = useTranslation();

Expand Down Expand Up @@ -84,11 +87,11 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
getAddLearnerFormData();
}, []);

const handleSubmit = (
const handleSubmit = async (
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 +107,77 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
return;
}
}
console.log('Form data submitted:', data.formData);

const formData = data.formData;
console.log('Form data submitted:', formData);
const schemaProperties = schema.properties;

const { username, password } = generateUsernameAndPassword('MH', 'F');

let apiBody: any = {
username: username,
password: password,
tenantCohortRoleMapping: [
{
tenantId: 'ef99949b-7f3a-4a5f-806a-e67e683e38f3',
roleId: RoleId.TEACHER,
cohortId: formData?.assignCenters,
},
],
customFields: [],
};

Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
const fieldSchema = schemaProperties[fieldKey];
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;
}
} else {
if (
fieldSchema?.hasOwnProperty('isDropdown') ||
fieldSchema.hasOwnProperty('isCheckbox')
) {
apiBody.customFields.push({
fieldId: fieldId,
value: [String(fieldValue)],
});
} else {
apiBody.customFields.push({
fieldId: fieldId,
value: String(fieldValue),
});
}
}
});

if (typeof window !== 'undefined' && window.localStorage) {
var teamLeaderData = JSON.parse(
localStorage.getItem('teamLeadApp') || ''
);
console.log(teamLeaderData);
}
// apiBody.customFields.push({
// fieldId: teamLeaderData?.state?.blockId,
// value: [teamLeaderData?.state?.blockCode],
// });
// apiBody.customFields.push({
// fieldId: teamLeaderData?.state?.stateId,
// value: [teamLeaderData?.state?.stateCode],
// });
// apiBody.customFields.push({
// fieldId: teamLeaderData?.state?.districtId,
// value: [teamLeaderData?.state?.districtCode],
// });
console.log(apiBody);

const response = await createUser(apiBody);
console.log(response);
};

const handleChange = (event: IChangeEvent<any>) => {
Expand All @@ -115,6 +188,11 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
console.log('Form errors:', errors);
};

const onCloseModal = () => {
setOpenModal(false);
onClose();
};

return (
<>
<SimpleModal
Expand All @@ -133,10 +211,11 @@ const AddFacilitatorModal: React.FC<AddFacilitatorModalprops> = ({
widgets={{}}
showErrorList={true}
customFields={customFields}
// showTwoButtons={true}
/>
)}
</SimpleModal>

<SendCredentialModal open={openModal} onClose={onCloseModal} />
</>
);
};
Expand Down
34 changes: 34 additions & 0 deletions src/pages/centers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import useStore from '@/store/store';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { ArrowDropDown, Search } from '@mui/icons-material';
import teamLeadStore from '@/store/mangageTLStore';

const TeachingCenters = () => {
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -70,6 +71,26 @@ const TeachingCenters = () => {
setValue(newValue);
};

const TLstore = teamLeadStore();
const setDistrictCode = teamLeadStore(
(state: { setDistrictCode: any }) => state.setDistrictCode
);
const setDistrictFieldId = teamLeadStore(
(state: { setDistrictFieldId: any }) => state.setDistrictFieldId
);
const setStateCode = teamLeadStore(
(state: { setStateCode: any }) => state.setStateCode
);
const setStateFieldId = teamLeadStore(
(state: { setStateFieldId: any }) => state.setStateFieldId
);
const setBlockCode = teamLeadStore(
(state: { setBlockCode: any }) => state.setBlockCode
);
const setBlockFieldId = teamLeadStore(
(state: { blockFieldId: any }) => state.blockFieldId
);

useEffect(() => {
if (typeof window !== 'undefined' && window.localStorage) {
const role = localStorage.getItem('role');
Expand Down Expand Up @@ -107,12 +128,25 @@ const TeachingCenters = () => {
const stateField = block?.customField.find(
(field: any) => field.label === 'State'
);
setStateCode(stateField.code);
// setStateFieldId(stateField.fieldId);

const districtField = block?.customField.find(
(field: any) => field.label === 'District'
);
setDistrictCode(districtField.code);
// setDistrictFieldId(districtField.fieldId);

const blockField = block?.customField.find(
(field: any) => field.label === 'Block'
);
setBlockCode(blockField.code);
// setBlockFieldId(blockField.fieldId);

const state = stateField ? stateField.value : '';

const district = districtField ? districtField.value : '';

return { blockName, blockId, state, district };
});
console.log(blockData);
Expand Down
37 changes: 37 additions & 0 deletions src/store/mangageTLStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

const teamLeadStore = create(
persist(
(set) => ({
deleteId: '',
learnerDeleteId: '',
blockCode: '',
districtCode: '',
stateCode: '',
districtFieldId: 'aecb84c9-fe4c-4960-817f-3d228c0c7300',
blockFieldId: '02d3868e-9cd1-4088-a6c1-5623daa904a4',
stateFieldId: '61b5909a-0b45-4282-8721-e614fd36d7bd',
setCohortDeleteId: (newCohortDeleteId) =>
set((state) => ({ deleteId: newCohortDeleteId })),
setCohortLearnerDeleteId: (newCohortLearnerDeleteId) =>
set((state) => ({ learnerDeleteId: newCohortLearnerDeleteId })),
setBlockCode: (newBlockCode) => set(() => ({ blockCode: newBlockCode })),
setDistrictCode: (newDistrictCode) =>
set(() => ({ districtCode: newDistrictCode })),
setStateCode: (newStateCode) => set(() => ({ stateCode: newStateCode })),
setBlockFieldId: (newBlockId) =>
set(() => ({ blockFieldId: newBlockId })),
setDistrictFieldId: (newDistrictId) =>
set(() => ({ districtFieldId: newDistrictId })),
setStateFieldId: (newStateId) =>
set(() => ({ stateFieldId: newStateId })),
}),
{
name: 'teamLeadApp',
getStorage: () => localStorage,
}
)
);

export default teamLeadStore;

0 comments on commit 5aed789

Please sign in to comment.