1
0
mirror of https://github.com/flarum/core.git synced 2025-08-11 10:55:47 +02:00

update: Fix Alert on modals

This commit is contained in:
Matthew Kilgore
2020-08-07 19:40:07 -04:00
committed by Franz Liedke
parent dcd14821c2
commit e10220ae47
3 changed files with 13 additions and 12 deletions

View File

@@ -346,11 +346,11 @@ export default class Application {
return m.request(options).then( return m.request(options).then(
(response) => response, (response) => response,
(error) => { (error) => {
let children; let content;
switch (error.status) { switch (error.status) {
case 422: case 422:
children = error.response.errors content = error.response.errors
.map((error) => [error.detail, <br />]) .map((error) => [error.detail, <br />])
.reduce((a, b) => a.concat(b), []) .reduce((a, b) => a.concat(b), [])
.slice(0, -1); .slice(0, -1);
@@ -358,20 +358,20 @@ export default class Application {
case 401: case 401:
case 403: case 403:
children = app.translator.trans('core.lib.error.permission_denied_message'); content = app.translator.trans('core.lib.error.permission_denied_message');
break; break;
case 404: case 404:
case 410: case 410:
children = app.translator.trans('core.lib.error.not_found_message'); content = app.translator.trans('core.lib.error.not_found_message');
break; break;
case 429: case 429:
children = app.translator.trans('core.lib.error.rate_limit_exceeded_message'); content = app.translator.trans('core.lib.error.rate_limit_exceeded_message');
break; break;
default: default:
children = app.translator.trans('core.lib.error.generic_message'); content = app.translator.trans('core.lib.error.generic_message');
} }
const isDebug = app.forum.attribute('debug'); const isDebug = app.forum.attribute('debug');
@@ -381,7 +381,7 @@ export default class Application {
error.alert = { error.alert = {
type: 'error', type: 'error',
children, content,
controls: isDebug && [ controls: isDebug && [
<Button className="Button Button--link" onclick={this.showDebug.bind(this, error, formattedError)}> <Button className="Button Button--link" onclick={this.showDebug.bind(this, error, formattedError)}>
Debug Debug

View File

@@ -18,13 +18,12 @@ import extract from '../utils/extract';
* All other props will be assigned as attributes on the alert element. * All other props will be assigned as attributes on the alert element.
*/ */
export default class Alert extends Component { export default class Alert extends Component {
view() { view(vnode) {
const attrs = Object.assign({}, this.props); const attrs = Object.assign({}, this.attrs);
const type = extract(attrs, 'type'); const type = extract(attrs, 'type');
attrs.className = 'Alert Alert--' + type + ' ' + (attrs.className || ''); attrs.className = 'Alert Alert--' + type + ' ' + (attrs.className || '');
const children = extract(attrs, 'children');
const controls = extract(attrs, 'controls') || []; const controls = extract(attrs, 'controls') || [];
// If the alert is meant to be dismissible (which is the case by default), // If the alert is meant to be dismissible (which is the case by default),
@@ -34,13 +33,15 @@ export default class Alert extends Component {
const ondismiss = extract(attrs, 'ondismiss'); const ondismiss = extract(attrs, 'ondismiss');
const dismissControl = []; const dismissControl = [];
const content = extract(attrs, 'content') || vnode.children;
if (dismissible || dismissible === undefined) { if (dismissible || dismissible === undefined) {
dismissControl.push(<Button icon="fas fa-times" className="Button Button--link Button--icon Alert-dismiss" onclick={ondismiss} />); dismissControl.push(<Button icon="fas fa-times" className="Button Button--link Button--icon Alert-dismiss" onclick={ondismiss} />);
} }
return ( return (
<div {...attrs}> <div {...attrs}>
<span className="Alert-body">{children}</span> <span className="Alert-body">{content}</span>
<ul className="Alert-controls">{listItems(controls.concat(dismissControl))}</ul> <ul className="Alert-controls">{listItems(controls.concat(dismissControl))}</ul>
</div> </div>
); );

View File

@@ -182,7 +182,7 @@ export default class LogInModal extends Modal {
onerror(error) { onerror(error) {
if (error.status === 401) { if (error.status === 401) {
error.alert.children = app.translator.trans('core.forum.log_in.invalid_login_message'); error.alert.content = app.translator.trans('core.forum.log_in.invalid_login_message');
} }
super.onerror(error); super.onerror(error);