diff --git a/app/javascript/retrospring/controllers/toast_controller.ts b/app/javascript/retrospring/controllers/toast_controller.ts new file mode 100644 index 00000000..76b91eed --- /dev/null +++ b/app/javascript/retrospring/controllers/toast_controller.ts @@ -0,0 +1,17 @@ +import { Controller } from '@hotwired/stimulus'; +import { showNotification } from "utilities/notifications"; + +export default class extends Controller { + static values = { + message: String, + success: Boolean + }; + + declare readonly messageValue: string; + declare readonly successValue: boolean; + + connect(): void { + showNotification(this.messageValue, this.successValue); + this.element.remove(); + } +} diff --git a/app/javascript/retrospring/initializers/stimulus.ts b/app/javascript/retrospring/initializers/stimulus.ts index b4c3c91b..6239a1f9 100644 --- a/app/javascript/retrospring/initializers/stimulus.ts +++ b/app/javascript/retrospring/initializers/stimulus.ts @@ -9,6 +9,7 @@ import ThemeController from "retrospring/controllers/theme_controller"; import CapabilitiesController from "retrospring/controllers/capabilities_controller"; import CropperController from "retrospring/controllers/cropper_controller"; import InboxSharingController from "retrospring/controllers/inbox_sharing_controller"; +import ToastController from "retrospring/controllers/toast_controller"; /** * This module sets up Stimulus and our controllers @@ -29,4 +30,5 @@ export default function (): void { window['Stimulus'].register('format-popup', FormatPopupController); window['Stimulus'].register('inbox-sharing', InboxSharingController); window['Stimulus'].register('theme', ThemeController); + window['Stimulus'].register('toast', ToastController); }