Display backend mute errors on studio edit

This commit is contained in:
seotts 2021-06-09 10:56:56 -04:00
parent 68460611d8
commit 91d66cd20b
12 changed files with 23 additions and 12 deletions

View file

@ -21,7 +21,8 @@ const Errors = keyMirror({
THUMBNAIL_INVALID: null, THUMBNAIL_INVALID: null,
TEXT_TOO_LONG: null, TEXT_TOO_LONG: null,
REQUIRED_FIELD: null, REQUIRED_FIELD: null,
UNHANDLED: null UNHANDLED: null,
USER_MUTED: null
}); });
const MAX_IMAGE_BYTES = 524288; const MAX_IMAGE_BYTES = 524288;
@ -104,6 +105,7 @@ const selectCommentsAllowedMutationError = state => state.studioMutations.mutati
*/ */
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 403 && body.mute_status) return Errors.USER_MUTED;
if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION; if (res.statusCode === 401 || res.statusCode === 403) return Errors.PERMISSION;
if (res.statusCode !== 200) return Errors.SERVER; if (res.statusCode !== 200) return Errors.SERVER;
try { try {

View file

@ -97,10 +97,11 @@
"studio.reportThanksForLettingUsKnow": "Thanks for letting us know!", "studio.reportThanksForLettingUsKnow": "Thanks for letting us know!",
"studio.reportYourFeedback": "Your feedback will help us make Scratch better.", "studio.reportYourFeedback": "Your feedback will help us make Scratch better.",
"studios.mutedCurators": "You will be able to invite curators and add managers again {inDuration}.", "studio.mutedCurators": "You will be able to invite curators and add managers again {inDuration}.",
"studios.mutedProjects": "You will be able to add and remove projects again {inDuration}.", "studio.mutedProjects": "You will be able to add and remove projects again {inDuration}.",
"studios.mutedEdit": "You will be able to edit studios again {inDuration}.", "studio.mutedEdit": "You will be able to edit studios again {inDuration}.",
"studios.mutedPaused": "Your account has been paused from using studios until then.", "studio.mutedPaused": "Your account has been paused from using studios until then.",
"studio.mutedError": "Your account has been paused from using studios. Refresh for more information.",
"studio.alertProjectAdded": "\"{title}\" added to studio", "studio.alertProjectAdded": "\"{title}\" added to studio",
"studio.alertProjectAlreadyAdded": "That project is already in this studio", "studio.alertProjectAlreadyAdded": "That project is already in this studio",

View file

@ -10,12 +10,14 @@ const Errors = keyMirror({
SERVER: null, SERVER: null,
PERMISSION: null, PERMISSION: null,
DUPLICATE: null, DUPLICATE: null,
USER_MUTED: null,
UNKNOWN_USERNAME: null, UNKNOWN_USERNAME: null,
RATE_LIMIT: null RATE_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 === 403 && body.mute_status) return Errors.USER_MUTED;
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;

View file

@ -12,11 +12,13 @@ const Errors = keyMirror({
PERMISSION: null, PERMISSION: null,
UNKNOWN_PROJECT: null, UNKNOWN_PROJECT: null,
RATE_LIMIT: null, RATE_LIMIT: null,
DUPLICATE: null DUPLICATE: null,
USER_MUTED: null
}); });
const normalizeError = (err, body, res) => { const normalizeError = (err, body, res) => {
if (err) return Errors.NETWORK; if (err) return Errors.NETWORK;
if (res.statusCode === 403 && body.mute_status) return Errors.USER_MUTED;
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_PROJECT; if (res.statusCode === 404) return Errors.UNKNOWN_PROJECT;
if (res.statusCode === 409) return Errors.DUPLICATE; if (res.statusCode === 409) return Errors.DUPLICATE;

View file

@ -16,6 +16,7 @@ const errorToMessageId = error => {
case Errors.PERMISSION: return 'studio.curatorErrors.generic'; case Errors.PERMISSION: return 'studio.curatorErrors.generic';
case Errors.DUPLICATE: return 'studio.curatorErrors.alreadyCurator'; case Errors.DUPLICATE: return 'studio.curatorErrors.alreadyCurator';
case Errors.UNKNOWN_USERNAME: return 'studio.curatorErrors.unknownUsername'; case Errors.UNKNOWN_USERNAME: return 'studio.curatorErrors.unknownUsername';
case Errors.USER_MUTED: return 'studio.mutedError';
case Errors.RATE_LIMIT: return 'studio.curatorErrors.tooFast'; case Errors.RATE_LIMIT: return 'studio.curatorErrors.tooFast';
default: return 'studio.curatorErrors.generic'; default: return 'studio.curatorErrors.generic';
} }

View file

@ -21,6 +21,7 @@ const errorToMessageId = error => {
case Errors.INAPPROPRIATE: return 'studio.updateErrors.inappropriate'; case Errors.INAPPROPRIATE: return 'studio.updateErrors.inappropriate';
case Errors.TEXT_TOO_LONG: return 'studio.updateErrors.textTooLong'; case Errors.TEXT_TOO_LONG: return 'studio.updateErrors.textTooLong';
case Errors.REQUIRED_FIELD: return 'studio.updateErrors.requiredField'; case Errors.REQUIRED_FIELD: return 'studio.updateErrors.requiredField';
case Errors.USER_MUTED: return 'studio.mutedError';
default: return 'studio.updateErrors.generic'; default: return 'studio.updateErrors.generic';
} }
}; };

View file

@ -21,6 +21,7 @@ const errorToMessageId = error => {
switch (error) { switch (error) {
case Errors.THUMBNAIL_INVALID: return 'studio.updateErrors.thumbnailInvalid'; case Errors.THUMBNAIL_INVALID: return 'studio.updateErrors.thumbnailInvalid';
case Errors.THUMBNAIL_TOO_LARGE: return 'studio.updateErrors.thumbnailTooLarge'; case Errors.THUMBNAIL_TOO_LARGE: return 'studio.updateErrors.thumbnailTooLarge';
case Errors.USER_MUTED: return 'studio.mutedError';
default: return 'studio.updateErrors.generic'; default: return 'studio.updateErrors.generic';
} }
}; };

View file

@ -14,7 +14,7 @@ const StudioMuteEditMessage = ({
<ValidationMessage <ValidationMessage
mode="info" mode="info"
message={<FormattedMessage message={<FormattedMessage
id="studios.mutedEdit" id="studio.mutedEdit"
values={{ values={{
inDuration: formatRelativeTime(muteExpiresAtMs, window._locale) inDuration: formatRelativeTime(muteExpiresAtMs, window._locale)
}} }}

View file

@ -18,6 +18,7 @@ const errorToMessageId = error => {
case Errors.DUPLICATE: return 'studio.projectErrors.duplicate'; case Errors.DUPLICATE: return 'studio.projectErrors.duplicate';
case Errors.RATE_LIMIT: return 'studio.projectErrors.tooFast'; case Errors.RATE_LIMIT: return 'studio.projectErrors.tooFast';
case Errors.UNKNOWN_PROJECT: return 'studio.projectErrors.checkUrl'; case Errors.UNKNOWN_PROJECT: return 'studio.projectErrors.checkUrl';
case Errors.USER_MUTED: return 'studio.mutedError';
default: return 'studio.projectErrors.generic'; default: return 'studio.projectErrors.generic';
} }
}; };

View file

@ -38,13 +38,13 @@ const StudioProjects = ({
<p> <p>
<div> <div>
<FormattedMessage <FormattedMessage
id="studios.mutedProjects" id="studio.mutedProjects"
values={{ values={{
inDuration: formatRelativeTime(muteExpiresAtMs, window._locale) inDuration: formatRelativeTime(muteExpiresAtMs, window._locale)
}} }}
/> />
</div> </div>
<div><FormattedMessage id="studios.mutedPaused" /></div> <div><FormattedMessage id="studio.mutedPaused" /></div>
</p> </p>
</CommentingStatus> </CommentingStatus>
} }

View file

@ -17,6 +17,7 @@ const errorToMessageId = error => {
case Errors.INAPPROPRIATE: return 'studio.updateErrors.inappropriate'; case Errors.INAPPROPRIATE: return 'studio.updateErrors.inappropriate';
case Errors.TEXT_TOO_LONG: return 'studio.updateErrors.textTooLong'; case Errors.TEXT_TOO_LONG: return 'studio.updateErrors.textTooLong';
case Errors.REQUIRED_FIELD: return 'studio.updateErrors.requiredField'; case Errors.REQUIRED_FIELD: return 'studio.updateErrors.requiredField';
case Errors.USER_MUTED: return 'studio.mutedError';
default: return 'studio.updateErrors.generic'; default: return 'studio.updateErrors.generic';
} }
}; };

View file

@ -48,7 +48,6 @@ import {selectShowCuratorMuteError} from '../../redux/studio-permissions.js';
const StudioShell = ({showCuratorMuteError, muteExpiresAtMs, studioLoadFailed}) => { const StudioShell = ({showCuratorMuteError, muteExpiresAtMs, studioLoadFailed}) => {
const match = useRouteMatch(); const match = useRouteMatch();
return ( return (
studioLoadFailed ? studioLoadFailed ?
<NotAvailable /> : <NotAvailable /> :
@ -68,13 +67,13 @@ const StudioShell = ({showCuratorMuteError, muteExpiresAtMs, studioLoadFailed})
<p> <p>
<div> <div>
<FormattedMessage <FormattedMessage
id="studios.mutedCurators" id="studio.mutedCurators"
values={{ values={{
inDuration: formatRelativeTime(muteExpiresAtMs, window._locale) inDuration: formatRelativeTime(muteExpiresAtMs, window._locale)
}} }}
/> />
</div> </div>
<div><FormattedMessage id="studios.mutedPaused" /></div> <div><FormattedMessage id="studio.mutedPaused" /></div>
</p> </p>
</CommentingStatus> </CommentingStatus>
} }