added join token route; handle route alongside existing student signup uri

This commit is contained in:
Ben Wheeler 2020-04-02 00:12:56 -04:00
parent 7f9ffada5f
commit 75f8c6429a
2 changed files with 38 additions and 11 deletions

View file

@ -280,6 +280,13 @@
"view": "studentregistration/studentregistration", "view": "studentregistration/studentregistration",
"title": "Class Registration" "title": "Class Registration"
}, },
{
"name": "student-registration-token-only",
"pattern": "^/join/:token",
"routeAlias": "/classes/(complete_registration|.+/register/.+)",
"view": "studentregistration/studentregistration",
"title": "Class Registration"
},
{ {
"name": "teacher-faq", "name": "teacher-faq",
"pattern": "^/educators/faq/?$", "pattern": "^/educators/faq/?$",

View file

@ -32,11 +32,22 @@ class StudentRegistration extends React.Component {
} }
componentDidMount () { componentDidMount () {
this.setState({waiting: true}); // eslint-disable-line react/no-did-mount-set-state this.setState({waiting: true}); // eslint-disable-line react/no-did-mount-set-state
api({
uri: `/classrooms/${this.props.classroomId}`, // set uri and params
params: { let uri;
token: this.props.classroomToken let params;
if (this.props.classroomId === null || typeof this.props.classroomId === 'undefined') {
// configure for token-only endpoint
uri = `/classtoken/${this.props.classroomToken}`;
} else {
// configure for endpoint expecting classroomId and token
uri = `/classrooms/${this.props.classroomId}`;
params = {token: this.props.classroomToken};
} }
api({
uri: uri,
params: params
}, (err, body, res) => { }, (err, body, res) => {
this.setState({waiting: false}); this.setState({waiting: false});
if (err) { if (err) {
@ -164,14 +175,23 @@ StudentRegistration.defaultProps = {
const IntlStudentRegistration = injectIntl(StudentRegistration); const IntlStudentRegistration = injectIntl(StudentRegistration);
const [classroomId, _, classroomToken] = document.location.pathname.split('/').filter(p => { // parse either format of student registration url:
if (p) { // "class register": http://scratch.mit.edu/classes/3/register/c0256654e1be
return p; // "join token": http://scratch.mit.edu/join/c025r54ebe
let classroomId = null;
let classroomToken = null;
const classRegisterRegexp = /^\/?classes\/(\d*)\/register\/([a-zA-Z0-9]*)\/?$/;
const classRegisterMatch = classRegisterRegexp.exec(document.location.pathname);
if (classRegisterMatch) {
classroomId = classRegisterMatch[1];
classroomToken = classRegisterMatch[2];
} else {
const joinTokenRegexp = /^\/?join\/([a-zA-Z0-9]*)\/?$/;
const joinTokenMatch = joinTokenRegexp.exec(document.location.pathname);
if (joinTokenMatch) {
classroomToken = joinTokenMatch[1];
}
} }
return null;
})
.slice(-3);
const props = {classroomId, classroomToken}; const props = {classroomId, classroomToken};
render(<IntlStudentRegistration {...props} />, document.getElementById('app')); render(<IntlStudentRegistration {...props} />, document.getElementById('app'));