Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
#1206 - move paramters from user details event to custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rupeshparab committed Jul 23, 2020
1 parent 65b57fa commit 76cbaf6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
7 changes: 6 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import keyMap from '../constants/hotkeyConfig.json';
import { stopEvent, passEventForKeys } from '../services/events';
import { getPathTo } from '../services/dom';
import './styles.scss';
import { getFormattedUserType } from '../services/mathshare';


const mathLive = process.env.MATHLIVE_DEBUG_MODE
Expand Down Expand Up @@ -468,11 +469,15 @@ class App extends Component {
modal, problemList, problemStore, userProfile,
} = this.props;
const { email, name } = userProfile;
const { userType, role, grades } = userProfile.info;

const intercomAttributes = {
user_id: email,
email,
name,
userType: getFormattedUserType(userType),
userRole: role,
grades,
};
return (
<React.Fragment>
Expand Down Expand Up @@ -568,7 +573,7 @@ class App extends Component {
<Route render={p => <NotFound {...p} />} />
</Switch>
</div>
{['teacher', 'other'].includes(userProfile.info.userType) && <Intercom {...intercomAttributes} appID={process.env.INTERCOM_APP_ID} />}
{['teacher', 'other'].includes(userType) && <Intercom {...intercomAttributes} appID={process.env.INTERCOM_APP_ID} />}
<footer id="footer">
<h2 className="sROnly">
{' '}
Expand Down
26 changes: 2 additions & 24 deletions src/redux/userProfile/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,13 @@ import { getCookie } from '../../scripts/cookie';
import Locales from '../../strings';
import { sessionStore } from '../../scripts/storage';
import { waitForIntercomToBoot } from '../../services/intercom';
import { getFormattedUserType } from '../../services/mathshare';

const loginAlertId = 'login-alert';
const redirectAlertId = 'redirect-info';
const redirectWait = 2500;

const getFormattedUserType = (userType) => {
if (userType === 'teacher') {
return 'Teacher';
}
if (userType === 'student') {
return 'Student';
}
return 'Undefined';
};


function* checkUserLoginSaga() {
yield throttle(60000, 'CHECK_USER_LOGIN', function* workerSaga() {
Expand Down Expand Up @@ -198,37 +191,22 @@ function* saveUserInfoSaga() {
email,
redirectTo,
} = yield select(getState);
let intercomPayload = null;
try {
const {
userType,
grades,
role,
} = payload;
const userInfoResponse = yield call(saveUserInfoApi, {
...payload,
user_type: userType,
email,
});
yield put(setUserInfo(userInfoResponse.data));
if (['teacher', 'other'].includes(userType)) {
intercomPayload = {
userType: getFormattedUserType(userType),
userRole: role,
grades,
};
}
} catch (error) {
yield put({
type: 'SAVE_USER_INFO_FAILURE',
});
} finally {
yield put(replace(redirectTo));
if (intercomPayload) {
if (yield call(waitForIntercomToBoot, 5)) {
IntercomAPI('trackEvent', 'user-details', intercomPayload);
}
}
}
});
}
Expand Down
11 changes: 11 additions & 0 deletions src/services/mathshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ export const getMathshareLink = (params, currentSolution, problem) => {
return null;
};

export const getFormattedUserType = (userType) => {
if (userType === 'teacher') {
return 'Teacher';
}
if (userType === 'student') {
return 'Student';
}
return 'Undefined';
};

export default {
getFormattedUserType,
getMathshareLink,
};

0 comments on commit 76cbaf6

Please sign in to comment.