Skip to content

Commit d5ecdf3

Browse files
authored
Merge pull request #1683 from ActiveLearningStudio/msteams-release
Msteams release
2 parents 647c49a + 42692f9 commit d5ecdf3

File tree

2 files changed

+109
-5
lines changed

2 files changed

+109
-5
lines changed

src/containers/LMS/MsTeams/MsTeamsActivityContainer/index.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import MsTeamsService from 'services/msTeams.service';
88
import { useLocation } from "react-router-dom";
99
import { Alert } from 'react-bootstrap';
1010
import { app, authentication } from '@microsoft/teams-js';
11+
import logo from 'assets/images/studio_new_logo_small.png';
12+
import './style.scss';
1113

1214
function MsTeamsActivityContainer({ match, history }) {
1315
const { activityId, tenantId } = match.params;
@@ -36,20 +38,46 @@ function MsTeamsActivityContainer({ match, history }) {
3638
localStorage.setItem('msteams_token_timestamp', new Date().toString());
3739
setToken(response.access_token);
3840
setFreshToken(true);
39-
}).catch(() => {
40-
setError('Could not fetch platform token');
41+
}).catch((e) => {
42+
console.log('token error:', e);
43+
44+
// No permission grant from user or admin. Going into oauth flow
45+
if (e.errors === 'invalid_grant') {
46+
const url = new URL(`https://login.microsoftonline.com/${tenantId}/oauth2/authorize`);
47+
const params = new URLSearchParams();
48+
params.append('client_id', config.teamsClientId);
49+
params.append('response_type', 'code');
50+
params.append('scope', 'offline_access user.read mail.read');
51+
params.append('redirect_uri', `https://${window.location.hostname}/msteams/callback`);
52+
params.append('state', window.location.href);
53+
url.search = params.toString();
54+
authentication.authenticate({ url: url.href }).then((result) => {
55+
const tokenTimestamp = localStorage.getItem('msteams_token_timestamp');
56+
const tempToken = localStorage.getItem('msteams_token');
57+
setToken(tempToken);
58+
setFreshToken((tempToken && ((new Date() - new Date(tokenTimestamp)) / 1000) / 60 < 15));
59+
}).catch((e) => {
60+
console.log('failed to authenticate', e);
61+
if (e.message === 'CancelledByUser')
62+
setError('Please reload the tab and follow the instructions in the authentication popup to use this application or ask your Teams administrator Grant consent for the Curriki Application on behalf of your organization.');
63+
else if (e.message === 'FailedToOpenWindow')
64+
setError('If you have a pop-up blocker, please enable pop-ups for https://teams.microsoft.com then reload the tab and follow the instructions in the authentication pop-up. Alternatively, you can ask your Teams administrator Grant consent for the Curriki Application on behalf of your organization.');
65+
});
66+
} else {
67+
setError('There was a problem initializing the application. Please contact your Teams administrator. E003');
68+
}
4169
});
4270
},
4371
failureCallback: (response) => {
4472
console.log('failure:', response);
45-
setError('Error requesting authentication token');
73+
setError('There was a problem initializing the application. Please contact your Teams administrator. E002');
4674
},
4775
};
4876

4977
app.initialize().then(() => {
5078
authentication.getAuthToken(authRequest);
5179
}).catch(() => {
52-
setError('Failed to initialize teams sdk');
80+
setError('There was a problem initializing the application. Please contact your Teams administrator. E001');
5381
});
5482
}, []);
5583

@@ -116,7 +144,16 @@ function MsTeamsActivityContainer({ match, history }) {
116144
<div className="activity-bg left-vdo msteams-width">
117145
<div className="main-item-wrapper desktop-view">
118146
<div className="item-container">
119-
{error && <Alert variant="danger">{error}</Alert>}
147+
{error && (
148+
<div className="outcome-summary-container">
149+
<div className="loading">
150+
<div className="loading_image">
151+
<img src={logo} alt="Curriki Studio logo" />
152+
</div>
153+
<div className="loading-message">{error}</div>
154+
</div>
155+
</div>
156+
)}
120157
{!error && activityParams && <MsTeamActivityLaunchScreen activityId={activityId} paramObj={activityParams} />}
121158
</div>
122159
</div>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
.outcome-summary-container {
2+
background: black;
3+
color: ghostwhite;
4+
padding-bottom: 4em;
5+
6+
.fa-star {
7+
color: yellow;
8+
margin-right: 0.5em;
9+
}
10+
11+
.skipped-badge {
12+
margin-left: 2em;
13+
}
14+
15+
.answers-table th {
16+
width: 50%;
17+
font-weight: bolder;
18+
}
19+
20+
.answers-table .question-col {
21+
font-style: italic;
22+
}
23+
24+
a {
25+
color: gainsboro;
26+
}
27+
28+
.title-container {
29+
display:flex;
30+
margin-bottom: 1em;
31+
}
32+
33+
.title-label {
34+
width:30%;
35+
background-color: steelblue;
36+
padding: 1em;
37+
font-weight: bolder;
38+
}
39+
40+
.title-spacer {
41+
background-color: #454d55;
42+
}
43+
44+
.title-spacer div {
45+
width: 0;
46+
height: 0;
47+
border-top: 25px solid #454d55;
48+
border-bottom: 25px solid #454d55;
49+
border-left: 25px solid steelblue;
50+
}
51+
52+
.title-content {
53+
background-color: #454d55;
54+
width:70%;
55+
padding: 1em;
56+
}
57+
58+
.loading {
59+
display: flex;
60+
}
61+
62+
.loading-message {
63+
display: flex;
64+
align-items: center;
65+
font-size: large;
66+
}
67+
}

0 commit comments

Comments
 (0)