diff --git a/packages/twenty-front/src/modules/action-menu/actions/record-actions/constants/WorkflowActionsConfig.tsx b/packages/twenty-front/src/modules/action-menu/actions/record-actions/constants/WorkflowActionsConfig.tsx index 3d3b77bb3..10144c61a 100644 --- a/packages/twenty-front/src/modules/action-menu/actions/record-actions/constants/WorkflowActionsConfig.tsx +++ b/packages/twenty-front/src/modules/action-menu/actions/record-actions/constants/WorkflowActionsConfig.tsx @@ -17,6 +17,11 @@ import { ActionType } from '@/action-menu/actions/types/ActionType'; import { ActionViewType } from '@/action-menu/actions/types/ActionViewType'; import { CoreObjectNamePlural } from '@/object-metadata/types/CoreObjectNamePlural'; import { AppPath } from '@/types/AppPath'; +import { + WorkflowStep, + WorkflowTrigger, + WorkflowWithCurrentVersion, +} from '@/workflow/types/Workflow'; import { msg } from '@lingui/core/macro'; import { isDefined } from 'twenty-shared/utils'; import { @@ -28,6 +33,21 @@ import { IconVersions, } from 'twenty-ui/display'; +const areWorkflowTriggerAndStepsDefined = ( + workflowWithCurrentVersion: WorkflowWithCurrentVersion | undefined, +): workflowWithCurrentVersion is WorkflowWithCurrentVersion & { + currentVersion: { + trigger: WorkflowTrigger; + steps: Array; + }; +} => { + return ( + isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) && + isDefined(workflowWithCurrentVersion.currentVersion?.steps) && + workflowWithCurrentVersion.currentVersion.steps.length > 0 + ); +}; + export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({ config: { [WorkflowSingleRecordActionKeys.ACTIVATE]: { @@ -40,9 +60,7 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({ type: ActionType.Standard, scope: ActionScope.RecordSelection, shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) => - isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) && - isDefined(workflowWithCurrentVersion.currentVersion?.steps) && - workflowWithCurrentVersion.currentVersion.steps.length > 0 && + areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) && (workflowWithCurrentVersion.currentVersion.status === 'DRAFT' || !workflowWithCurrentVersion.versions?.some( (version) => version.status === 'ACTIVE', @@ -158,14 +176,15 @@ export const WORKFLOW_ACTIONS_CONFIG = inheritActionsFromDefaultConfig({ type: ActionType.Standard, scope: ActionScope.RecordSelection, shouldBeRegistered: ({ selectedRecord, workflowWithCurrentVersion }) => - isDefined(workflowWithCurrentVersion?.currentVersion?.trigger) && + areWorkflowTriggerAndStepsDefined(workflowWithCurrentVersion) && ((workflowWithCurrentVersion.currentVersion.trigger.type === 'MANUAL' && !isDefined( workflowWithCurrentVersion.currentVersion.trigger.settings .objectType, )) || workflowWithCurrentVersion.currentVersion.trigger.type === - 'WEBHOOK') && + 'WEBHOOK' || + workflowWithCurrentVersion.currentVersion.trigger.type === 'CRON') && !isDefined(selectedRecord?.deletedAt), availableOn: [ ActionViewType.SHOW_PAGE,