Skip to content

A platform for community discussion. Free, open, simple.

DEV: Error if invalid `@flashType` passed to modal (#22414)

David Taylor1122454904ea
diff --git a/app/assets/javascripts/discourse/app/components/d-modal.hbs b/app/assets/javascripts/discourse/app/components/d-modal.hbs
index 5c50992aca8..3d56cb2f19f 100644
--- a/app/assets/javascripts/discourse/app/components/d-modal.hbs
+++ b/app/assets/javascripts/discourse/app/components/d-modal.hbs
@@ -63,6 +63,7 @@
{{yield to="belowHeader"}}
+ {{this.validateFlashType @flashType}}
{{#if @flash}}
<div
id="modal-alert"
diff --git a/app/assets/javascripts/discourse/app/components/d-modal.js b/app/assets/javascripts/discourse/app/components/d-modal.js
index 74d273caf70..8afc0436043 100644
--- a/app/assets/javascripts/discourse/app/components/d-modal.js
+++ b/app/assets/javascripts/discourse/app/components/d-modal.js
@@ -8,6 +8,8 @@ export const CLOSE_INITIATED_BY_ESC = "initiatedByESC";
export const CLOSE_INITIATED_BY_CLICK_OUTSIDE = "initiatedByClickOut";
export const CLOSE_INITIATED_BY_MODAL_SHOW = "initiatedByModalShow";
+const FLASH_TYPES = ["success", "error", "warning", "info"];
+
export default class DModal extends Component {
@service modal;
@tracked wrapperElement;
@@ -161,4 +163,11 @@ export default class DModal extends Component {
handleCloseButton() {
this.args.closeModal({ initiatedBy: CLOSE_INITIATED_BY_BUTTON });
}
+
+ @action
+ validateFlashType(type) {
+ if (type && !FLASH_TYPES.includes(type)) {
+ throw `@flashType must be one of ${FLASH_TYPES.join(", ")}`;
+ }
+ }
}