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

TASK : #0000 Event crtificate functionality #762

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
86 changes: 85 additions & 1 deletion packages/nulp_elite/src/pages/events/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const EventDetails = () => {
const [recording, setRecording] = useState();
const [isAllreadyFilledRegistation,setIsAlreadyFilledRegistration] = useState(true)
const [isExpired , setIsExpired] = useState(false)
const [batchCertData,setBatchCertData] = useState();
const [isCertificateIssued , setIsCertificateIssued] = useState(true)
const handleClickOpen = () => {
setOpen(true);
};
Expand Down Expand Up @@ -286,6 +288,8 @@ const formatTimeWithTimezone = (date) => {
getUserData(_userId, "loggedIn");
fetchMyEvents();
getEventRecording();
fetchData();
checkCertificateAlreadyIssued();
// checkEnrolledCourse();
}, [_userId, eventId]);

Expand All @@ -308,7 +312,7 @@ const formatTimeWithTimezone = (date) => {

const { result } = response.data;
const { response: batchResponse } = result;

setBatchCertData(response.data.result)
if (batchResponse && batchResponse.count === 0) {
showErrorMessage(t("This course has no active Batches"));
} else if (batchResponse?.content?.length > 0) {
Expand Down Expand Up @@ -455,6 +459,82 @@ const formatTimeWithTimezone = (date) => {
});
};

const fetchData = async () => {
try {
const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.USER.GET_PROFILE}${_userId}?fields=${urlConfig.params.userReadParam.fields}`;

const header = "application/json";
const response = await fetch(url, {
// headers: {
// "Content-Type": "application/json",
// },
});
const data = await response.json();
setUserData(data);
} catch (error) {
console.error("Error fetching user data:", error);
showErrorMessage(t("FAILED_TO_FETCH_DATA"));
}
};

const checkCertificateAlreadyIssued = async () => {
try{
const url = `${urlConfig.URLS.LEARNER_PREFIX}${urlConfig.URLS.CERTIFICATE.CERTIF_SEARCH}`;
const requestBody = {
filters: {
recipient: {
id: {
eq: _userId
}
}
}
}
const resopnse = await axios.post(url, requestBody);
setIsCertificateIssued(resopnse.data.some((item) => item.training?.id === eventId));

}catch(error){
console.log("error While calling API ");
}

}

const generateCertificate = async () => {
const templateId = Object.keys(batchCertData?.response?.content[0]["certTemplates"])[0];
const certificateDetails = batchCertData?.response?.content[0]["certTemplates"][templateId];
try {
const url = `${urlConfig.URLS.CERTIFICATE.CUSTOM_CERTIFICATE_CREATE}`;
const requestBody = {
recipient: {
id: _userId,
name: userData?.result?.response?.firstName + " " + userData?.result?.response?.lastName,
type: "user",
},
issuer: certificateDetails?.issuer,
training: {
id: detailData?.identifier,
name: detailData?.name,
type: "Event",
batchId: batchData?.batchId,
},
templateUrl:
certificateDetails?.url,
status: "ACTIVE",
signatoryList:
certificateDetails?.signatoryList,
certificateLabel: "test",
issuedOn: new Date().toISOString(),
};
if(!isCertificateIssued){
const response = await axios.post(url, requestBody);
if(response.data.responseCode === "OK"){
setIsCertificateIssued(true)
}
}
} catch (error) {
console.error("Error creating certificate:", error);
}
};

const managePublicPrivateEvent = (button) => {
if (eventVisibility && eventVisibility === "Public" && button === "reg") {
handleOpenConsentModal();
Expand Down Expand Up @@ -865,6 +945,10 @@ const formatTimeWithTimezone = (date) => {
type="button"
onClick={() => {
managePublicPrivateEvent("join");
// generateCertificate();
if(detailData.issueCerificate === "Yes"){
generateCertificate();
}
}}
// onClick={attendWebinar}
style={{
Expand Down
Loading