File size: 3,702 Bytes
3206347
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import defineAction from '../../../../helpers/define-action.js';

export default defineAction({
  name: 'Create card widget',
  key: 'createCardWidget',
  description: 'Creates a new card widget on an existing board.',
  arguments: [
    {
      label: 'Board',
      key: 'boardId',
      type: 'dropdown',
      required: true,
      description: '',
      variables: true,
      source: {
        type: 'query',
        name: 'getDynamicData',
        arguments: [
          {
            name: 'key',
            value: 'listBoards',
          },
        ],
      },
    },
    {
      label: 'Frame',
      key: 'frameId',
      type: 'dropdown',
      required: true,
      dependsOn: ['parameters.boardId'],
      description:
        'You need to create a frame prior to this step. Switch frame to grid mode to avoid cards overlap.',
      variables: true,
      source: {
        type: 'query',
        name: 'getDynamicData',
        arguments: [
          {
            name: 'key',
            value: 'listFrames',
          },
          {
            name: 'parameters.boardId',
            value: '{parameters.boardId}',
          },
        ],
      },
    },
    {
      label: 'Card Title',
      key: 'cardTitle',
      type: 'string',
      required: true,
      description: '',
      variables: true,
    },
    {
      label: 'Card Title Link',
      key: 'cardTitleLink',
      type: 'string',
      required: false,
      description: '',
      variables: true,
    },
    {
      label: 'Card Description',
      key: 'cardDescription',
      type: 'string',
      required: false,
      description: '',
      variables: true,
    },
    {
      label: 'Card Due Date',
      key: 'cardDueDate',
      type: 'string',
      required: false,
      description:
        'format: date-time. Example value: 2023-10-12 22:00:55+00:00',
      variables: true,
    },
    {
      label: 'Card Border Color',
      key: 'cardBorderColor',
      type: 'dropdown',
      required: false,
      description: 'In hex format. Default is blue (#2399F3).',
      variables: true,
      options: [
        { label: 'white', value: '#FFFFFF' },
        { label: 'yellow', value: '#FEF445' },
        { label: 'orange', value: '#FAC710' },
        { label: 'red', value: '#F24726' },
        { label: 'bright red', value: '#DA0063' },
        { label: 'light gray', value: '#E6E6E6' },
        { label: 'gray', value: '#808080' },
        { label: 'black', value: '#1A1A1A' },
        { label: 'light green', value: '#CEE741' },
        { label: 'green', value: '#8FD14F' },
        { label: 'dark green', value: '#0CA789' },
        { label: 'light blue', value: '#12CDD4' },
        { label: 'blue', value: '#2D9BF0' },
        { label: 'dark blue', value: '#414BB2' },
        { label: 'purple', value: '#9510AC' },
        { label: 'dark purple', value: '#652CB3' },
      ],
    },
  ],

  async run($) {
    const {
      boardId,
      frameId,
      cardTitle,
      cardTitleLink,
      cardDescription,
      cardDueDate,
      cardBorderColor,
    } = $.step.parameters;

    let title;
    if (cardTitleLink) {
      title = `<a href='${cardTitleLink}'>${cardTitle}</a>`;
    } else {
      title = cardTitle;
    }

    const body = {
      data: {
        title: title,
        description: cardDescription,
      },
      style: {},
      parent: {
        id: frameId,
      },
    };

    if (cardBorderColor) {
      body.style.cardTheme = cardBorderColor;
    }

    if (cardDueDate) {
      body.data.dueDate = cardDueDate;
    }

    const response = await $.http.post(`/v2/boards/${boardId}/cards`, body);

    $.setActionItem({
      raw: response.data,
    });
  },
});