diff --git a/packages/backend/src/apps/asana/actions/create-project/index.js b/packages/backend/src/apps/asana/actions/create-project/index.js new file mode 100644 index 00000000..50a1e17d --- /dev/null +++ b/packages/backend/src/apps/asana/actions/create-project/index.js @@ -0,0 +1,216 @@ +import defineAction from '../../../../helpers/define-action.js'; +import omitBy from 'lodash/omitBy.js'; +import isEmpty from 'lodash/isEmpty.js'; + +export default defineAction({ + name: 'Create project', + key: 'createProject', + description: 'Creates a new project.', + arguments: [ + { + label: 'Workspace', + key: 'workspaceId', + type: 'dropdown', + required: true, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listWorkspaces', + }, + ], + }, + }, + { + label: 'Team', + key: 'teamId', + type: 'dropdown', + required: false, + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listTeams', + }, + { + name: 'parameters.workspaceId', + value: '{parameters.workspaceId}', + }, + ], + }, + }, + { + label: 'Due date', + key: 'dueDate', + type: 'string', + required: false, + description: 'Example due on: 2019-09-15', + variables: true, + }, + { + label: 'Name', + key: 'name', + type: 'string', + required: true, + description: '', + variables: true, + }, + { + label: 'Notes', + key: 'notes', + type: 'string', + required: true, + description: 'You can format the notes using html.', + variables: true, + }, + { + label: 'Is the notes rich text?', + key: 'richText', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { + label: 'No', + value: 'false', + }, + { + label: 'Yes', + value: 'true', + }, + ], + }, + { + label: 'Default View', + key: 'defaultView', + type: 'dropdown', + required: false, + description: '', + variables: true, + options: [ + { + label: 'List', + value: 'list', + }, + { + label: 'Board', + value: 'board', + }, + { + label: 'Calendar', + value: 'calendar', + }, + { + label: 'Timeline', + value: 'timeline', + }, + ], + }, + { + label: 'Owner', + key: 'ownerId', + type: 'dropdown', + required: false, + dependsOn: ['parameters.workspaceId'], + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listUsers', + }, + { + name: 'parameters.workspaceId', + value: '{parameters.workspaceId}', + }, + ], + }, + }, + { + label: 'Followers', + key: 'followerIds', + type: 'dynamic', + required: false, + description: '', + fields: [ + { + label: 'Follower', + key: 'followerId', + type: 'dropdown', + required: false, + dependsOn: ['parameters.workspaceId'], + description: '', + variables: true, + source: { + type: 'query', + name: 'getDynamicData', + arguments: [ + { + name: 'key', + value: 'listUsers', + }, + { + name: 'parameters.workspaceId', + value: '{parameters.workspaceId}', + }, + ], + }, + }, + ], + }, + ], + + async run($) { + const { + workspaceId, + teamId, + dueDate, + name, + notes, + richText, + defaultView, + ownerId, + followerIds, + } = $.step.parameters; + + const allFollowers = followerIds + .map((followerId) => followerId.followerId) + .filter(Boolean); + + const data = { + workspace: workspaceId, + team: teamId, + due_on: dueDate, + name, + default_view: defaultView, + owner: ownerId, + followers: allFollowers, + }; + + if (richText === 'true') { + data.html_notes = notes; + } else { + data.notes = notes; + } + + const filteredData = omitBy(data, isEmpty); + + const response = await $.http.post('/1.0/projects', { data: filteredData }); + + $.setActionItem({ + raw: response.data, + }); + }, +}); diff --git a/packages/backend/src/apps/asana/actions/index.js b/packages/backend/src/apps/asana/actions/index.js index dc3e333a..c0913479 100644 --- a/packages/backend/src/apps/asana/actions/index.js +++ b/packages/backend/src/apps/asana/actions/index.js @@ -1,3 +1,4 @@ +import createProject from './create-project/index.js'; import createTask from './create-task/index.js'; -export default [createTask]; +export default [createProject, createTask]; diff --git a/packages/docs/pages/apps/asana/actions.md b/packages/docs/pages/apps/asana/actions.md index e0c8088f..1533f915 100644 --- a/packages/docs/pages/apps/asana/actions.md +++ b/packages/docs/pages/apps/asana/actions.md @@ -1,6 +1,8 @@ --- favicon: /favicons/asana.svg items: + - name: Create project + desc: Creates a new project. - name: Create task desc: Creates a new task. ---