Commit ce8e2703 authored by Karishma Chadha's avatar Karishma Chadha

Set up state, tracking the number of managers the limits used to display info...

Set up state, tracking the number of managers the limits used to display info to the user. Handle new error response when trying to promote a curator.
parent f495fbc0
...@@ -12,6 +12,9 @@ const Status = keyMirror({ ...@@ -12,6 +12,9 @@ const Status = keyMirror({
ERROR: null ERROR: null
}); });
const STUDIO_MANAGER_LIMIT = 40;
const STUDIO_MANAGER_THRESHOLD = 30;
const getInitialState = () => ({ const getInitialState = () => ({
infoStatus: Status.FETCHING, infoStatus: Status.FETCHING,
title: '', title: '',
...@@ -20,6 +23,7 @@ const getInitialState = () => ({ ...@@ -20,6 +23,7 @@ const getInitialState = () => ({
commentsAllowed: false, commentsAllowed: false,
image: '', image: '',
followers: 0, followers: 0,
managers: 0,
owner: null, owner: null,
// BEWARE: classroomId is only loaded if the user is an educator // BEWARE: classroomId is only loaded if the user is an educator
...@@ -98,6 +102,9 @@ const selectStudioLastUpdated = state => state.studio.updated; ...@@ -98,6 +102,9 @@ const selectStudioLastUpdated = state => state.studio.updated;
const selectStudioLoadFailed = state => state.studio.infoStatus === Status.ERROR; const selectStudioLoadFailed = state => state.studio.infoStatus === Status.ERROR;
const selectStudioCommentCount = state => state.studio.commentCount; const selectStudioCommentCount = state => state.studio.commentCount;
const selectStudioFollowerCount = state => state.studio.followers; const selectStudioFollowerCount = state => state.studio.followers;
const selectStudioManagerCount = state => state.studio.managers;
const selectStudioHasReachedManagerThreshold = state => state.studio.managers >= STUDIO_MANAGER_THRESHOLD;
const selectStudioHasReachedManagerLimit = state => state.studio.managers >= STUDIO_MANAGER_LIMIT;
const selectStudioProjectCount = state => state.studio.projectCount; const selectStudioProjectCount = state => state.studio.projectCount;
const selectIsFetchingInfo = state => state.studio.infoStatus === Status.FETCHING; const selectIsFetchingInfo = state => state.studio.infoStatus === Status.FETCHING;
const selectIsFollowing = state => state.studio.following; const selectIsFollowing = state => state.studio.following;
...@@ -121,6 +128,7 @@ const getInfo = () => ((dispatch, getState) => { ...@@ -121,6 +128,7 @@ const getInfo = () => ((dispatch, getState) => {
updated: new Date(body.history.modified), updated: new Date(body.history.modified),
commentCount: body.stats.comments, commentCount: body.stats.comments,
followers: body.stats.followers, followers: body.stats.followers,
managers: body.stats.managers,
projectCount: body.stats.projects, projectCount: body.stats.projects,
owner: body.owner owner: body.owner
})); }));
...@@ -169,6 +177,10 @@ module.exports = { ...@@ -169,6 +177,10 @@ module.exports = {
setInfo, setInfo,
setRoles, setRoles,
// Constants
STUDIO_MANAGER_LIMIT,
STUDIO_MANAGER_THRESHOLD,
// Selectors // Selectors
selectStudioId, selectStudioId,
selectStudioTitle, selectStudioTitle,
...@@ -180,6 +192,9 @@ module.exports = { ...@@ -180,6 +192,9 @@ module.exports = {
selectStudioLoadFailed, selectStudioLoadFailed,
selectStudioCommentCount, selectStudioCommentCount,
selectStudioFollowerCount, selectStudioFollowerCount,
selectStudioManagerCount,
selectStudioHasReachedManagerThreshold,
selectStudioHasReachedManagerLimit,
selectStudioProjectCount, selectStudioProjectCount,
selectIsFetchingInfo, selectIsFetchingInfo,
selectIsFetchingRoles, selectIsFetchingRoles,
......
...@@ -11,11 +11,15 @@ const Errors = keyMirror({ ...@@ -11,11 +11,15 @@ const Errors = keyMirror({
PERMISSION: null, PERMISSION: null,
DUPLICATE: null, DUPLICATE: null,
UNKNOWN_USERNAME: null, UNKNOWN_USERNAME: null,
RATE_LIMIT: null RATE_LIMIT: null,
MANAGER_LIMIT: null
}); });
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 400 && body.message === 'too many owners') {
return Errors.MANAGER_LIMIT;
}
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME; if (res.statusCode === 404) return Errors.UNKNOWN_USERNAME;
if (res.statusCode === 429) return Errors.RATE_LIMIT; if (res.statusCode === 429) return Errors.RATE_LIMIT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment