Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix[task-composer]: better handling for task creation failure (#1697)
Peter Chinman745258057410
diff --git a/js/app/packages/block-md/component/ComposeTask.tsx b/js/app/packages/block-md/component/ComposeTask.tsxindex b2655627ef..6bf9c982f3 100644--- a/js/app/packages/block-md/component/ComposeTask.tsx+++ b/js/app/packages/block-md/component/ComposeTask.tsx@@ -1,4 +1,6 @@+import { useSplitLayout } from '@app/component/split-layout/layout';import { useSplitPanelOrThrow } from '@app/component/split-layout/layoutUtils';+import { CircleSpinner } from '@core/component/CircleSpinner';import { DeprecatedIconButton } from '@core/component/DeprecatedIconButton';import { EntityIcon } from '@core/component/EntityIcon';import { MiniToggleSwitch } from '@core/component/FormControls/MiniToggleSwitch';@@ -215,6 +217,7 @@ export interface ComposeTaskProps {export function ComposeTask(props: ComposeTaskProps) {const splitPanel = useSplitPanelOrThrow();+ const { popoverSplit } = useSplitLayout();const currentUserId = useUserId();const getDefaultPropertyValues = (): Record<string, PropertyApiValues> => {@@ -266,6 +269,7 @@ export function ComposeTask(props: ComposeTaskProps) {);const [createMore, setCreateMore] = createSignal(false);const [errorMessage, setErrorMessage] = createSignal<string>('');+ const [isCreating, setIsCreating] = createSignal(false);const [propertyValues, setPropertyValues] = createStore<Record<string, PropertyApiValues>@@ -372,6 +376,8 @@ export function ComposeTask(props: ComposeTaskProps) {};const handleCreateTask = async () => {+ if (isCreating()) return;+const taskTitle = title().trim();const taskContent = content().trim();@@ -381,8 +387,44 @@ export function ComposeTask(props: ComposeTaskProps) {}setErrorMessage('');+ setIsCreating(true);+const properties = structuredClone(Object.entries(unwrap(propertyValues)));+ if (!createMore()) {+ // Snapshot the draft locally, then clear localStorage so a new dialog+ // opened while this creation is in flight starts blank.+ const draftSnapshot = {+ title: taskTitle,+ content: taskContent,+ propertyValues: structuredClone(unwrap(propertyValues)),+ };+ clearTaskComposerDraft();+ // Close the dialog immediately+ splitPanel.handle.close();+ props.onClose?.();++ const documentId = await createTaskWithProperties(+ taskTitle,+ taskContent,+ properties,+ definitions(),+ (params) => upsertToHistoryMutation.mutate(params)+ );++ setIsCreating(false);++ if (!documentId) {+ // Restore the draft and re-open so the user can retry+ saveTaskComposerDraft(draftSnapshot);+ popoverSplit({ type: 'component', id: 'task-compose' });+ return;+ }++ props.onCreateTask?.(taskTitle, taskContent);+ return;+ }+const documentId = await createTaskWithProperties(taskTitle,taskContent,@@ -391,27 +433,24 @@ export function ComposeTask(props: ComposeTaskProps) {(params) => upsertToHistoryMutation.mutate(params));+ setIsCreating(false);+if (!documentId) {- // Task creation failed — keep the draft so the user can retryreturn;}- // Clear draft and reset form only on success+ // Success: clear draft and notifyclearTaskComposerDraft();- setTitle('');- setContent('');- setPropertyValues(reconcile(getDefaultPropertyValues()));- setIsDraftLoaded(false);-- const ed = bodyEditor();- ed && initializeEditorEmpty(ed);-- if (!createMore()) {- splitPanel.handle.close();- props.onCreateTask?.(taskTitle, taskContent);- props.onClose?.();- } else {- props.onCreateTask?.(taskTitle, taskContent);+ props.onCreateTask?.(taskTitle, taskContent);++ if (createMore()) {+ // Reset form for next task+ setTitle('');+ setContent('');+ setPropertyValues(reconcile(getDefaultPropertyValues()));+ setIsDraftLoaded(false);+ const ed = bodyEditor();+ ed && initializeEditorEmpty(ed);}};@@ -515,7 +554,8 @@ export function ComposeTask(props: ComposeTaskProps) {setErrorMessage('');}}}- class="w-full py-2 text-xl font-medium placeholder-ink-placeholder/50"+ disabled={isCreating()}+ class="w-full py-2 text-xl font-medium placeholder-ink-placeholder/50 disabled:opacity-50"on:keydown={(e) => {if (e.key === 'Escape') {const container = containerRef();@@ -538,7 +578,7 @@ export function ComposeTask(props: ComposeTaskProps) {</div><MarkdownTextarea- editable={() => true}+ editable={() => !isCreating()}onChange={(value) => setContent(value)}initialValue={content()}placeholder={props.placeholder ?? 'Add description...'}@@ -593,9 +633,14 @@ export function ComposeTask(props: ComposeTaskProps) {<ButtononClick={handleCreateTask}class="border border-edge-muted pr-1"- disabled={title().trim().length === 0}+ disabled={title().trim().length === 0 || isCreating()}>- <EntityIcon targetType="task" theme="monochrome" />+ <Show+ when={isCreating()}+ fallback={<EntityIcon targetType="task" theme="monochrome" />}+ >+ <CircleSpinner width={16} height={16} />+ </Show>Create Task<div class="text-[0.625rem] text-ink-extra-muted ml-auto border border-edge-muted/50 px-1.5 py-1 font-sans rounded-xs"><Hotkey shortcut="cmd+enter" />diff --git a/js/app/packages/ui/components/Button.tsx b/js/app/packages/ui/components/Button.tsxindex 4d4761fec1..359a4e3256 100644--- a/js/app/packages/ui/components/Button.tsx+++ b/js/app/packages/ui/components/Button.tsx@@ -61,14 +61,14 @@ export const Button: ParentComponent<ButtonProps> = (props) => {'relative flex items-center justify-center gap-[1ch] px-[1ch] py-[0.25lh] border border-transparent','font-mono font-medium uppercase leading-none',!local.suppressInteractionStyling &&- 'hover:bg-surface-4 focus:[--focus-border-inset:-4px] active:border-accent active:bg-accent active:text-panel disabled:opacity-50 disabled:cursor-not-allowed',+ 'enabled:hover:bg-surface-4 focus:[--focus-border-inset:-4px] active:border-accent active:bg-accent active:text-panel disabled:opacity-50 disabled:hover:','touch:min-h-11 touch:min-w-11 touch:[&_svg]:size-6',{- 'bg-ink border-ink text-panel hover:bg-accent hover:opacity-80 active:opacity-100':+ 'bg-ink border-ink text-panel enabled:hover:bg-accent enabled:hover:opacity-80 active:opacity-100':'primary' === local.variant,'border-ink': 'secondary' === local.variant,- 'border-failure text-failure active:bg-failure hover:bg-failure-bg':+ 'border-failure text-failure active:bg-failure enabled:hover:bg-failure-bg':'destructive' === local.variant,'p-0 gap-0 items-stretch': local.showChevron,},