Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

3.3 KB
Raw Blame
import { HttpMethod } from '@activepieces/pieces-common';
import {
  OAuth2PropertyValue,
  Property,
  createAction,
} from '@activepieces/pieces-framework';
import { weekdoneAuth } from '../../auth';
import {
  weekdoneApiCall,
  weekdoneItemsDropdown,
  weekdoneTeamsDropdown,
  weekdoneUsersDropdown,
} from '../../common';

export const assignItemAction = createAction({
  auth: weekdoneAuth,
  name: 'assign_item',
  displayName: 'Assign Item',
  description: 'Assign an item to another user.',
  audience: 'both',
  aiMetadata: { description: 'Reassign an existing Weekdone item to a different user by item ID; the user/team/period filters only help locate the item. Requires the target item and the assignee user ID. Mutates the item, so not idempotent.', idempotent: false },
  props: {
    user_id_filter: Property.Dropdown({
      auth: weekdoneAuth,
      displayName: 'User (Filter)',
      required: false,
      refreshers: [],
      options: async ({ auth }) => {
        if (!(auth as OAuth2PropertyValue)?.access_token) {
          return {
            disabled: true,
            placeholder: 'Connect your account first',
            options: [],
          };
        }
        const state = await weekdoneUsersDropdown(auth as OAuth2PropertyValue);
        return {
          ...state,
          options: [{ label: 'Me', value: 'me' as any }, ...state.options],
        };
      },
    }),
    team_id: Property.Dropdown({
      auth: weekdoneAuth,
      displayName: 'Team (Filter)',
      required: false,
      refreshers: [],
      options: async ({ auth }) => {
        if (!(auth as OAuth2PropertyValue)?.access_token) {
          return {
            disabled: true,
            placeholder: 'Connect your account first',
            options: [],
          };
        }
        return weekdoneTeamsDropdown(auth as OAuth2PropertyValue);
      },
    }),
    period: Property.ShortText({
      displayName: 'Period (Filter)',
      required: false,
    }),
    item_id: Property.Dropdown({
      auth: weekdoneAuth,
      displayName: 'Item',
      required: true,
      refreshers: ['user_id_filter', 'team_id', 'period'],
      options: async ({ auth, user_id_filter, team_id, period }) => {
        if (!(auth as OAuth2PropertyValue)?.access_token) {
          return {
            disabled: true,
            placeholder: 'Connect your account first',
            options: [],
          };
        }
        return weekdoneItemsDropdown(auth as OAuth2PropertyValue, {
          userId: user_id_filter as any,
          teamId: team_id ? Number(team_id) : undefined,
          period: period as string | undefined,
        });
      },
    }),
    assignee_user_id: Property.Dropdown({
      auth: weekdoneAuth,
      displayName: 'Assign To',
      required: true,
      refreshers: [],
      options: async ({ auth }) => {
        if (!(auth as OAuth2PropertyValue)?.access_token) {
          return {
            disabled: true,
            placeholder: 'Connect your account first',
            options: [],
          };
        }
        return weekdoneUsersDropdown(auth as OAuth2PropertyValue);
      },
    }),
  },
  async run({ auth, propsValue }) {
    return weekdoneApiCall({
      auth: auth as OAuth2PropertyValue,
      method: HttpMethod.PATCH,
      path: `/item/${propsValue.item_id}/assign`,
      body: {
        user_id: propsValue.assignee_user_id,
      },
    });
  },
});