Files
twenty/packages/twenty-front/src/modules/workflow/components/OverrideWorkflowDraftConfirmationModal.tsx
T
Thomas Trompette dfd28f5b4a Separate create draft cases op (#18613)
Bug: When creating a draft from an activated workflow version, the draft
row was inserted into the database without steps and trigger, then
updated with them in a separate operation. The SSE create-one event
fired on the INSERT, causing the frontend to refetch the draft before
the UPDATE — resulting in steps: null and trigger: null, which crashed
the step editor.

Fix: Reorder the operations so steps are duplicated first, then either
insert a new draft or update an existing one with steps and trigger
already populated. The row never exists in the database without complete
data.
2026-03-13 10:43:20 +00:00

68 lines
2.1 KiB
TypeScript

import {
ConfirmationModal,
StyledCenteredButton,
} from '@/ui/layout/modal/components/ConfirmationModal';
import { useModal } from '@/ui/layout/modal/hooks/useModal';
import { OVERRIDE_WORKFLOW_DRAFT_CONFIRMATION_MODAL_ID } from '@/workflow/constants/OverrideWorkflowDraftConfirmationModalId';
import { useCreateDraftFromWorkflowVersion } from '@/workflow/hooks/useCreateDraftFromWorkflowVersion';
import { useLingui } from '@lingui/react/macro';
import { AppPath, CoreObjectNameSingular } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
import { useNavigateApp } from '~/hooks/useNavigateApp';
export const OverrideWorkflowDraftConfirmationModal = ({
workflowId,
workflowVersionIdToCopy,
}: {
workflowId: string;
workflowVersionIdToCopy: string;
}) => {
const { closeModal } = useModal();
const { createDraftFromWorkflowVersion } =
useCreateDraftFromWorkflowVersion();
const navigate = useNavigateApp();
const handleOverrideDraft = async () => {
await createDraftFromWorkflowVersion({
workflowId,
workflowVersionIdToCopy,
});
navigate(AppPath.RecordShowPage, {
objectNameSingular: CoreObjectNameSingular.Workflow,
objectRecordId: workflowId,
});
};
const { t } = useLingui();
return (
<>
<ConfirmationModal
modalInstanceId={OVERRIDE_WORKFLOW_DRAFT_CONFIRMATION_MODAL_ID}
title={t`A draft already exists`}
subtitle={t`A draft already exists for this workflow. Are you sure you want to erase it?`}
onConfirmClick={handleOverrideDraft}
confirmButtonText={t`Override Draft`}
AdditionalButtons={
<StyledCenteredButton
to={getAppPath(AppPath.RecordShowPage, {
objectNameSingular: CoreObjectNameSingular.Workflow,
objectRecordId: workflowId,
})}
onClick={() => {
closeModal(OVERRIDE_WORKFLOW_DRAFT_CONFIRMATION_MODAL_ID);
}}
variant="secondary"
title={t`Go to Draft`}
fullWidth
justify="center"
/>
}
/>
</>
);
};