summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/admin/broadcast_messages/edit.js
blob: 70a270f7a566c51179e1ef9caa856f9e461877f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import Vue from 'vue';
import MessageForm from './components/message_form.vue';

export default () => {
  const el = document.querySelector('#js-broadcast-message');
  const {
    id,
    message,
    broadcastType,
    theme,
    dismissable,
    targetAccessLevels,
    targetAccessLevelOptions,
    targetPath,
    startsAt,
    endsAt,
  } = el.dataset;

  return new Vue({
    el,
    name: 'EditBroadcastMessage',
    provide: {
      targetAccessLevelOptions: JSON.parse(targetAccessLevelOptions),
    },
    render(createElement) {
      return createElement(MessageForm, {
        props: {
          broadcastMessage: {
            id: parseInt(id, 10),
            message,
            broadcastType,
            theme,
            dismissable: dismissable === 'true',
            targetAccessLevels: JSON.parse(targetAccessLevels),
            targetPath,
            startsAt: new Date(startsAt),
            endsAt: new Date(endsAt),
          },
        },
      });
    },
  });
};