Skip to content

Commit

Permalink
Merge pull request #466 from mahajanmahesh935/newbugs
Browse files Browse the repository at this point in the history
TASK : #0000 Integrate Feedback API
  • Loading branch information
ManojNathIC authored Aug 10, 2024
2 parents a56870f + 2a3c2ea commit 86771b6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
44 changes: 37 additions & 7 deletions packages/nulp_elite/src/components/FeedbackPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import StarIcon from "@mui/icons-material/Star";
import { styled } from "@mui/material/styles";
import IconButton from "@mui/material/IconButton";
import CloseIcon from "@mui/icons-material/Close";
import * as util from "../../src/services/utilService";
import axios from "axios";
const urlConfig = require("../configs/urlConfig.json");

const FeedbackPopup = ({ open, onClose }) => {


const FeedbackPopup = ({ open, onClose,contentId }) => {
const [rating, setRating] = useState(0);
const [feedback, setFeedback] = useState("");
const [additionalFeedback, setAdditionalFeedback] = useState("");
const [showTextBox, setShowTextBox] = useState(false);
const [checkboxes, setCheckboxes] = useState({});
const _userId = util.userId();


const BootstrapDialog = styled(Dialog)(({ theme }) => ({
"& .MuiDialogContent-root": {
Expand Down Expand Up @@ -84,17 +91,40 @@ const FeedbackPopup = ({ open, onClose }) => {
setAdditionalFeedback(event.target.value);
};

const handleSubmit = () => {
console.log("Rating:", rating);
console.log("Selected Checkboxes:");
const handleSubmit = async () => {
try {
let selectedCheckboxes = [];

Object.keys(checkboxes).forEach((key) => {
if (checkboxes[key]) {
console.log(checkboxLabels[key]);
if (checkboxes[key] && checkboxLabels[key] !== 'Other') {
selectedCheckboxes.push(checkboxLabels[key]);
}
});

const url = `${urlConfig.URLS.FEEDBACK.CREATE}`;
const request = {
content_id: contentId,
user_id: _userId,
rating: rating,
default_feedback: selectedCheckboxes,
other_feedback: additionalFeedback,
};

const response = await axios.post(url, request);
console.log("response.data", response.data);

console.log("Rating:", rating);
console.log("Selected Checkboxes:", selectedCheckboxes);
console.log("Additional Feedback:", additionalFeedback);

onClose();
};
} catch (error) {
console.error("Error submitting feedback:", error);
}
};



const handleClose = () => {
setOpen(false);
};
Expand Down
4 changes: 4 additions & 0 deletions packages/nulp_elite/src/configs/urlConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@
"GET_USER_POLL": "/polls/user/get_user_poll",
"USER_CREATE": "/polls/user/create",
"USER_UPDATE": "/polls/user/update"
},
"FEEDBACK": {
"CREATE" : "/custom_feedback/create",
"LIST" : "/custom_feedback/list"
}
}
}
29 changes: 27 additions & 2 deletions packages/nulp_elite/src/pages/content/Player.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Player = () => {

const handleTrackData = useCallback(
({ score, trackData, attempts, ...props }, playerType = "quml") => {
setOpenFeedBack(true);
CheckfeedBackSubmitted();
if (
playerType === "pdf-video" &&
props.currentPage === props.totalPages
Expand All @@ -76,6 +76,30 @@ const Player = () => {
[]
);

const CheckfeedBackSubmitted =async()=>{
try{
const url = `${urlConfig.URLS.FEEDBACK.LIST}`;
const RequestBody={
request:{
filters:{
content_id:contentId,
user_id:_userId,
}

}
}
const response=await axios.post(url,RequestBody);
console.log(response.data);
if(response.data?.result?.totalCount===0){
setOpenFeedBack(true);
}else{
setOpenFeedBack(false);
}
}catch(error){
console.error("Error fetching course data:", error);
}
}

const updateContentState = useCallback(
async (status) => {
if (isEnrolled) {
Expand All @@ -96,7 +120,7 @@ const Player = () => {

const fetchData = async () => {
try {
const response = await fetch(`/api/content/v1/read/${contentId}`, {
const response = await fetch(`${urlConfig.URLS.PUBLIC_PREFIX}${urlConfig.URLS.CONTENT.GET}/${contentId}`, {
headers: { "Content-Type": "application/json" },
});
if (!response.ok) throw new Error("Failed to fetch course data");
Expand Down Expand Up @@ -300,6 +324,7 @@ const Player = () => {
open={openFeedBack}
onClose={handleClose}
className="feedback-popup"
contentId={contentId}
/>
)}
<FloatingChatIcon />
Expand Down
2 changes: 1 addition & 1 deletion packages/nulp_elite/src/pages/events/eventDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ const EventDetails = () => {
const getEventRecording = async () => {
try {
const url = "/custom_event/fetch_recordings?event_id=" + eventId;
const response = await axios.get(url); // Use axios.get instead of axios.fetch
const response = await axios.get(url);
console.log("---------------Recording Link", response.data);
console.log("Recording Hardcoded Data",recording);
} catch (error) {
Expand Down

0 comments on commit 86771b6

Please sign in to comment.