Skip to content

Commit

Permalink
Merge pull request #1 from deepali-chavhan/all-saas
Browse files Browse the repository at this point in the history
Task #228879 fix: Remove Virtaul Id and Adding user & pass in all api…
  • Loading branch information
gouravmore authored Oct 23, 2024
2 parents f5f0547 + 1865102 commit f4e977d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 84 deletions.
44 changes: 22 additions & 22 deletions src/components/Assesment/Assesment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useNavigate } from "../../../node_modules/react-router-dom/dist/index";
import { useEffect, useState } from "react";
import axios from "../../../node_modules/axios/index";
// import { useDispatch } from 'react-redux';
import { setVirtualId } from "../../store/slices/user.slice";
import { setUserId } from "../../store/slices/user.slice";
import { useDispatch, useSelector } from "react-redux";
import React from "react";
import desktopLevel1 from "../../assets/images/desktopLevel1.png";
Expand Down Expand Up @@ -543,8 +543,8 @@ const Assesment = ({ discoverStart }) => {
let username;
if (localStorage.getItem("token") !== null) {
let jwtToken = localStorage.getItem("token");
var userDetails = jwtDecode(jwtToken);
username = userDetails.student_name;
let userDetails = jwtDecode(jwtToken);
username = userDetails.preferred_username;
setLocalData("profileName", username);
}
// const [searchParams, setSearchParams] = useSearchParams();
Expand All @@ -561,17 +561,15 @@ const Assesment = ({ discoverStart }) => {
// const level = getLocalData('userLevel');
// setLevel(level);
setLocalData("lang", lang);
dispatch(setVirtualId(localStorage.getItem("virtualId")));
let contentSessionId = localStorage.getItem("contentSessionId");
localStorage.setItem("sessionId", contentSessionId);
if (discoverStart && username && !localStorage.getItem("virtualId")) {
dispatch(setUserId(localStorage.getItem("userId")));
if (discoverStart && username && !localStorage.getItem("userId")) {
(async () => {
setLocalData("profileName", username);
const usernameDetails = await axios.post(
`${process.env.REACT_APP_VIRTUAL_ID_HOST}/${config.URLS.GET_VIRTUAL_ID}?username=${username}`
);
// const usernameDetails = await axios.post(
// `${process.env.REACT_APP_VIRTUAL_ID_HOST}/${config.URLS.GET_VIRTUAL_ID}?username=${username}`
// );
const getMilestoneDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${usernameDetails?.data?.result?.virtualID}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${localStorage.getItem("userId")}?language=${lang}`
);

localStorage.setItem(
Expand All @@ -581,9 +579,8 @@ const Assesment = ({ discoverStart }) => {
setLevel(
getMilestoneDetails?.data.data?.milestone_level?.replace("m", "")
);
localStorage.setItem(
"virtualId",
usernameDetails?.data?.result?.virtualID
localStorage.getItem(
"userId"
);
let session_id = localStorage.getItem("sessionId");

Expand All @@ -594,18 +591,18 @@ const Assesment = ({ discoverStart }) => {

localStorage.setItem("lang", lang || "ta");
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${usernameDetails?.data?.result?.virtualID}/${session_id}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${localStorage.getItem("userId")}/${session_id}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);

dispatch(setVirtualId(usernameDetails?.data?.result?.virtualID));
dispatch(setUserId(localStorage.getItem("userId")));
})();
} else {
(async () => {
const virtualId = getLocalData("virtualId");
const userId = getLocalData("userId");
const language = lang;
const getMilestoneDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${virtualId}?language=${language}`
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${userId}?language=${language}`
);
localStorage.setItem(
"getMilestone",
Expand All @@ -623,22 +620,25 @@ const Assesment = ({ discoverStart }) => {
localStorage.setItem("sessionId", sessionId);
}

if (virtualId) {
if (userId) {
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${userId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
}
})();
}
}, [lang]);

const { virtualId } = useSelector((state) => state.user);
const { userId } = useSelector((state) => {
console.log(state);
return state.user;
});

const navigate = useNavigate();
const handleRedirect = () => {
const profileName = getLocalData("profileName");
if (!username && !profileName && !virtualId && level === 0) {
if (!username && !profileName && !userId && level === 0) {
// alert("please add username in query param");
setOpenMessageDialog({
message: "please add username in query param",
Expand Down
8 changes: 4 additions & 4 deletions src/components/AssesmentEnd/AssesmentEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ const AssesmentEnd = () => {
(async () => {
let audio = new Audio(LevelCompleteAudio);
audio.play();
const virtualId = getLocalData("virtualId");
const userId = getLocalData("userId");
const lang = getLocalData("lang");
const previous_level = getLocalData("previous_level");
setPreviousLevel(previous_level?.replace("m", ""));
const getMilestoneDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${virtualId}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${userId}?language=${lang}`
);
const { data } = getMilestoneDetails;
setLevel(data.data.milestone_level);
Expand All @@ -45,7 +45,7 @@ const AssesmentEnd = () => {
localStorage.setItem("sessionId", sessionId)
}
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${userId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
})();
Expand All @@ -67,7 +67,7 @@ const AssesmentEnd = () => {
};

const handleRedirect = () => {
navigate("/practice");
navigate(`/practice?userId=${encodeURIComponent(localStorage.getItem("userId"))}`);
};
return true ? (
<Box style={sectionStyle}>
Expand Down
6 changes: 3 additions & 3 deletions src/components/DiscoverEnd/DiscoverEnd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ const SpeakSentenceComponent = () => {
(async () => {
let audio = new Audio(LevelCompleteAudio);
audio.play();
const virtualId = getLocalData("virtualId");
const userId = getLocalData("userId");
const lang = getLocalData("lang");
const getMilestoneDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${virtualId}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_APP_HOST}/${config.URLS.GET_MILESTONE}/${userId}?language=${lang}`
);
const { data } = getMilestoneDetails;
setLevel(data.data.milestone_level);
Expand All @@ -57,7 +57,7 @@ const SpeakSentenceComponent = () => {
if (process.env.REACT_APP_IS_APP_IFRAME === 'true') {
navigate("/")
} else {
navigate("/discover-start")
navigate(`/discover-start?userId=${encodeURIComponent(localStorage.getItem("userId"))}`);
}
} catch (error) {
console.error("Error posting message:", error);
Expand Down
22 changes: 11 additions & 11 deletions src/components/DiscoverSentance/DiscoverSentance.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ const SpeakSentenceComponent = () => {
if (!(localStorage.getItem("contentSessionId") !== null)) {
(async () => {
const sessionId = getLocalData("sessionId");
const virtualId = getLocalData("virtualId");
const userId = getLocalData("userId");
const lang = getLocalData("lang");
const getPointersDetails = await axios.get(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${virtualId}/${sessionId}?language=${lang}`
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.GET_POINTER}/${userId}/${sessionId}?language=${lang}`
);
setPoints(getPointersDetails?.data?.result?.totalLanguagePoints || 0);
})();
Expand Down Expand Up @@ -119,11 +119,12 @@ const SpeakSentenceComponent = () => {
const pointsRes = await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_POINTER}`,
{
userId: localStorage.getItem("virtualId"),
userId: localStorage.getItem("userId"),
sessionId: localStorage.getItem("sessionId"),
points: 1,
language: lang,
milestone: "m0",
tenantId : localStorage.getItem("tenantId"),
}
);
setPoints(pointsRes?.data?.result?.totalLanguagePoints || 0);
Expand All @@ -135,13 +136,14 @@ const SpeakSentenceComponent = () => {
await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.ADD_LESSON}`,
{
userId: localStorage.getItem("virtualId"),
userId: localStorage.getItem("userId"),
sessionId: localStorage.getItem("sessionId"),
milestone: `discoveryList/discovery/${currentCollectionId}`,
lesson: localStorage.getItem("storyTitle"),
progress: ((currentQuestion + 1) * 100) / questions.length,
language: lang,
milestoneLevel: "m0",
tenantId : localStorage.getItem("tenantId"),
}
);

Expand All @@ -155,10 +157,12 @@ const SpeakSentenceComponent = () => {
sub_session_id: sub_session_id,
contentType: currentContentType,
session_id: localStorage.getItem("sessionId"),
user_id: localStorage.getItem("virtualId"),
user_id: localStorage.getItem("userId"),
collectionId: currentCollectionId,
totalSyllableCount: totalSyllableCount,
language: localStorage.getItem("lang"),
tenantId : localStorage.getItem("tenantId"),

}
);
setInitialAssesment(false);
Expand All @@ -169,11 +173,12 @@ const SpeakSentenceComponent = () => {
await axios.post(
`${process.env.REACT_APP_LEARNER_AI_ORCHESTRATION_HOST}/${config.URLS.CREATE_LEARNER_PROGRESS}`,
{
userId: localStorage.getItem("virtualId"),
userId: localStorage.getItem("userId"),
sessionId: localStorage.getItem("sessionId"),
subSessionId: sub_session_id,
milestoneLevel: getSetData?.data?.currentLevel,
language: localStorage.getItem("lang"),
tenantId : localStorage.getItem("tenantId"),
}
);
}
Expand Down Expand Up @@ -291,11 +296,6 @@ const SpeakSentenceComponent = () => {
const handleBack = () => {
const destination = process.env.REACT_APP_IS_APP_IFRAME === 'true' ? "/" : "/discover-start";
navigate(destination);
// if (process.env.REACT_APP_IS_APP_IFRAME === 'true') {
// navigate("/");
// } else {
// navigate("/discover-start")
// }
};
return (
<>
Expand Down
8 changes: 4 additions & 4 deletions src/store/slices/user.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const userSlice = createSlice({
id: 0,
mobile: '',
otpSent: false,
virtualId: null,
userId: null,
},
reducers: {
setUser(state, action) {
Expand All @@ -31,8 +31,8 @@ const userSlice = createSlice({
setOtpVerified(state, action) {
state.isOtpVerified = action.payload.isOtpVerified;
},
setVirtualId(state, action) {
state.virtualId = action.payload;
setUserId(state, action) {
state.userId = action.payload;
},
},
});
Expand All @@ -47,7 +47,7 @@ export const {
setOtpVerified,
verifyOtp,
isOtpVerified,
setVirtualId,
setUserId,
} = userSlice.actions;

export default userSlice.reducer;
6 changes: 4 additions & 2 deletions src/utils/VoiceAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ function VoiceAnalyser(props) {

try {
const lang = getLocalData("lang");
const virtualId = getLocalData("virtualId");
const userId = getLocalData("userId");
const sessionId = getLocalData("sessionId");
const sub_session_id = getLocalData("sub_session_id");
const tenantId = getLocalData("tenantId");
const { originalText, contentType, contentId, currentLine } = props;
const responseStartTime = new Date().getTime();
let responseText = "";
Expand All @@ -279,13 +280,14 @@ function VoiceAnalyser(props) {
{
original_text: originalText,
audio: base64Data,
user_id: virtualId,
user_id: userId,
session_id: sessionId,
language: lang,
date: new Date(),
sub_session_id,
contentId,
contentType,
tenantId,
practice_duration: parseInt(loadToMicStartDuration.toFixed(0)),
read_duration: parseInt(micDuration.toFixed(0)),
}
Expand Down
13 changes: 7 additions & 6 deletions src/views/AppContent/AppContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { Routes, Route, useNavigate } from "react-router-dom";
import CustomizedSnackbars from "../../views/Snackbar/CustomSnackbar";

const PrivateRoute = (props) => {
const virtualId = localStorage.getItem("virtualId");
const { userId } = useSelector((state) => state.user);
const navigate = useNavigate();
// useEffect(() => {
// if (!virtualId && props.requiresAuth) {
// navigate("/login");
// }
// }, [virtualId]);
useEffect(() => {
if (!userId && props.requiresAuth) {
// navigate("/");
}
}, [userId]);


return <>{props.children}</>;
};
Expand Down
Loading

0 comments on commit f4e977d

Please sign in to comment.