How to use application route actions in template/components?

:wave: In discourse/app/assets/javascripts/discourse/routes/application.js.es6 there is this action:

composePrivateMessage is the action that triggers the composer to write a private message. I am trying to access this action from a component template:

{{action "composePrivateMessage" user}}

In the js for this component I am trying something like this:

export default Ember.Component.extend({
  tagName: 'div',
  layoutName: 'components/custom-fields-data',
  classNameBindings: ['custom-fields'],
  actions: {
    composePrivateMessage(user) {

This does not work, which does not come as a surprise. :unamused: Do I need to inject the application route or something to have access to the application route’s actions?

1 Like

This was more of an Ember questions than a Discourse question. Nonetheless, I figured it out.

Firstly, send the action I wanted from discourse/app/assets/javascripts/discourse/routes/application.js.es6 to the component:

{{my-component-name myAction="composePrivateMessage" user=model}}

Next, in the component’s JS file, create the action:

actions: {
  myAction(user) {

Lastly, in the component my-component-name call the action and make the magic happen:

{{action 'myAction' user}}

:microphone: :droplet: