* Upgrade Stimulus to 3.0 * Remove unused variable * Bump postcss from 8.3.8 to 8.3.9 (#14956) Bumps [postcss](https://github.com/postcss/postcss) from 8.3.8 to 8.3.9. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/8.3.8...8.3.9) --- updated-dependencies: - dependency-name: postcss dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
import { Controller } from '@hotwired/stimulus';
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
|
export default class AjaxController extends Controller {
|
|
// This method listens to Rails's Ajax event `ajax:success`.
|
|
// See https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers
|
|
// It is bound to Stimulus via the server side EmailsComponent's HTML
|
|
success(event) {
|
|
const [data, ,] = event.detail;
|
|
const message = data.result;
|
|
|
|
// close the panel and go back to the home view
|
|
document.dispatchEvent(new CustomEvent('user:tools'));
|
|
|
|
if (message) {
|
|
// display success info message
|
|
document.dispatchEvent(
|
|
new CustomEvent('snackbar:add', { detail: { message } }),
|
|
);
|
|
}
|
|
}
|
|
|
|
// This method listens to Rails's Ajax event `ajax:error`.
|
|
// See https://guides.rubyonrails.org/working_with_javascript_in_rails.html#rails-ujs-event-handlers
|
|
// It is bound to Stimulus via the server side EmailsComponent's HTML
|
|
error(event) {
|
|
const [data, ,] = event.detail;
|
|
const message = data.error || 'An error occurred on the server!';
|
|
|
|
document.dispatchEvent(
|
|
new CustomEvent('snackbar:add', {
|
|
detail: { message, addCloseButton: true },
|
|
}),
|
|
);
|
|
}
|
|
}
|