Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enrollment custom API integration #450

Merged
merged 3 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/nulp_elite/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@
"BATCH_EXPIRED_MESSAGE": "You cannot enroll in this batch as it is closed.",
"LEAVE_COURSE_CONFIRMATION_TITLE": "Batch Unenrolment",
"LEAVE_COURSE_CONFIRMATION_MESSAGE": "Do you want to unenrol from this batch?",
"ENROLLMENT_SUCCESS_MESSAGE": "Couse enroled for this batch Successfully",
"ENROLLMENT_SUCCESS_MESSAGE": "Enroled Successfully",
"UNENROLLMENT_SUCCESS_MESSAGE": " Unenroled Successfully",
"YOUR_CHAT_REQUEST_IS_PENDING": "Your chat request is pending. Please wait for the creator to accept the chat invitation",
"CHAT_WITH_CREATOR": "Chat with creator",
"CONNECT_WITH_CREATOR": "Connect with creator",
Expand Down
4 changes: 3 additions & 1 deletion packages/nulp_elite/src/configs/urlConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@
"TOP_TRENDING_EVENT": "/custom_event/get_top_trending",
"REGISTER": "/custom_event/registration",
"REPORT": "/custom_event/reports",
"CUSTOM_ENROLL_LIST": "/custom_event/enrollment-list"
"CUSTOM_ENROLL_LIST": "/custom_event/enrollment-list",
"UNREGISTER": "custom_event/unregister",
"UPDATE_REGISTER": "custom_event/registration/update"
},
"POLL": {
"CREATE": "/polls/create",
Expand Down
79 changes: 68 additions & 11 deletions packages/nulp_elite/src/pages/events/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const EventDetails = () => {

const [isEnrolled, setIsEnrolled] = useState();
const [showEnrollmentSnackbar, setShowEnrollmentSnackbar] = useState(false);
const [showUnEnrollmentSnackbar, setUnShowEnrollmentSnackbar] =
useState(false);

const [isRegStart, setIsRegStart] = useState();
const [regEnd, setRegEnd] = useState();
const [isConsentModalOpen, setIsConsentModalOpen] = useState(false);
Expand Down Expand Up @@ -130,8 +133,13 @@ const EventDetails = () => {
return;
}

enrollEvent();
handleCloseConsentModal();
if (eventVisibility && eventVisibility === "Public") {
enrollEvent();
handleCloseConsentModal();
} else if (eventVisibility && eventVisibility === "Private") {
updateRegisterEvent();
handleCloseConsentModal();
}
};

const handleChange = (event) => {
Expand Down Expand Up @@ -261,8 +269,8 @@ const EventDetails = () => {
"Content-Type": "application/json",
};
try {
// const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.CUSTOM_EVENT.CUSTOM_ENROLL_LIST}`;
const url = `https://devnulp.niua.org/event/enrollment-list`;
// const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.EVENT.CUSTOM_ENROLL_LIST}`;
const url = `https://devnulp.niua.org/custom-event/enrollment-list`;
const response = await getAllContents(url, data, headers);
console.log("My data ---", response.data.result.event);
setUserCourseData(response.data.result.event);
Expand Down Expand Up @@ -382,6 +390,7 @@ const EventDetails = () => {
return;
}
setShowEnrollmentSnackbar(false);
setUnShowEnrollmentSnackbar(false);
};

const formatDate = (dateString) => {
Expand Down Expand Up @@ -529,12 +538,6 @@ const EventDetails = () => {

const registerEvent = async (formData) => {
const url = `${urlConfig.URLS.CUSTOM_EVENT.REGISTER}`;
console.log("------------------url", url);
console.log("------------------urlConfig.URLS.EVENT", urlConfig.URLS.CUSTOM_EVENT);
console.log(
"------------------urlConfig.URLS.CUSTOM_EVENT.REGISTER",
urlConfig.URLS.CUSTOM_EVENT.REGISTER
);

const RequestBody = {
event_id: detailData.identifier,
Expand All @@ -556,6 +559,26 @@ const EventDetails = () => {
// Handle the error if needed
}
};

const updateRegisterEvent = async (formData) => {
const url = `${urlConfig.URLS.CUSTOM_EVENT.REGISTER}?event_id=${detailData.identifier}&user_id=${_userId}`;

const RequestBody = {
email: formData.email,
designation: formData.designation,
organisation: formData.organisation,
// certificate: formData.certificate,
user_consent: "true",
consentForm: consent?.consent,
};

try {
await axios.put(url, RequestBody);
console.log("update tegister successfull");
} catch (error) {
console.error("Error updating vote", error);
}
};
const unEnroll = async (formData) => {
try {
const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.COURSE.UNENROLL_USER_COURSE}`;
Expand All @@ -571,7 +594,25 @@ const EventDetails = () => {
setIsEnrolled(false);
console.log("check unenrol API-----", isEnrolled);

setShowEnrollmentSnackbar(true);
try {
const response = await axios.delete(
`${urlConfig.URLS.CUSTOM_EVENT.UNREGISTER}?event_id=${detailData.identifier}&user_id=${_userId}`
);
if (response.status === 200) {
setToasterMessage("Poll deleted successfully");
fetchPolls();
setPoll((prevPolls) => {
const updatedPolls = prevPolls.filter(
(poll) => poll.poll_id !== pollId
);
return updatedPolls;
});
}
} catch (error) {
console.error("Error deleting poll", error);
}

setUnShowEnrollmentSnackbar(true);
registerEvent(formData, detailData);
} else {
console.log("err-----", response);
Expand Down Expand Up @@ -601,6 +642,22 @@ const EventDetails = () => {
{t("ENROLLMENT_SUCCESS_MESSAGE")}
</MuiAlert>
</Snackbar>
<Snackbar
open={showUnEnrollmentSnackbar}
autoHideDuration={6000}
onClose={handleSnackbarClose}
anchorOrigin={{ vertical: "top", horizontal: "center" }}
>
<MuiAlert
elevation={6}
variant="filled"
onClose={handleSnackbarClose}
severity="success"
sx={{ mt: 2 }}
>
{t("UNENROLLMENT_SUCCESS_MESSAGE")}
</MuiAlert>
</Snackbar>
{detailData && (
<Container
className=" xs-pb-20 mt-12 mb-38"
Expand Down
2 changes: 1 addition & 1 deletion packages/nulp_elite/src/pages/events/eventList.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ const EventList = (props) => {
};
try {
// const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.EVENT.CUSTOM_ENROLL_LIST}`;
const url = `https://devnulp.niua.org/event/enrollment-list`;
const url = `https://devnulp.niua.org/custom-event/enrollment-list`;
const response = await getAllContents(url, data, headers);
console.log("My data ---", response.data.result.event);
setMyData(response.data.result.event);
Expand Down
Loading