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
feat(reminders): mark the entity done when a reminder is set (#5723)
Evan Hutnik05db469c89fc
diff --git a/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx b/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsxindex 5a8a41723a..f3d54b5566 100644--- a/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx+++ b/apps/web/src/components/app/split-layout/components/SplitFileMenu.tsx@@ -2,8 +2,11 @@ import { openBulkEditModal } from '@app/features/entity/bulk-edit/BulkEditEntityimport {makeCreateReminderAction,makeFavoriteAction,+ makeMarkDoneAction,+ markReminderTargetDone,} from '@app/features/next-soup/actions';import { useFeatureFlag } from '@app/lib/analytics/posthog';+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';import { MobileDrawer } from '@components/app/mobile/MobileDrawer';import type { BlockTool } from '@components/app/ResponsiveBlockToolbar';import { useBlockAliasedName, useBlockName } from '@core/block';@@ -14,6 +17,7 @@ import {ENABLE_REMINDERS_OVERRIDE,} from '@core/constant/featureFlags';import { useQuickAccess } from '@core/context/quickAccess';+import { useUserId } from '@core/context/user';import { triggerFocusInput } from '@core/directive/focusInput';import { isTouchDevice } from '@core/mobile/isTouchDevice';import { useIsDocumentOwner } from '@core/signal/permissions';@@ -261,7 +265,18 @@ export function SplitFileMenu(props: {const itemOperations = useItemOperations();const quickAccess = useQuickAccess();const favoriteAction = makeFavoriteAction();- const createReminderAction = makeCreateReminderAction();+ const userId = useUserId();+ const notificationSource = useGlobalNotificationSource();+ const markDone = makeMarkDoneAction({+ userId: () => userId(),+ notificationSource: () => notificationSource,+ });+ // Same follow-up as the block's command menu and every soup list: the+ // reminder brings the entity back, so it is marked done now. No soup list is+ // behind this menu, so nothing advances.+ const createReminderAction = makeCreateReminderAction({+ onCreated: markReminderTargetDone(markDone),+ });const { replaceOrInsertSplit, resetSplit } = useSplitLayout();diff --git a/apps/web/src/features/next-soup/actions/index.ts b/apps/web/src/features/next-soup/actions/index.tsindex 26e1a3785e..bb736a5e78 100644--- a/apps/web/src/features/next-soup/actions/index.ts+++ b/apps/web/src/features/next-soup/actions/index.ts@@ -3,7 +3,10 @@ export { makeCopyAction } from './make-copy-action';export { makeCopyBranchNameAction } from './make-copy-branch-name-action';export { makeCopyEntityIdAction } from './make-copy-entity-id-action';export { makeCopyLinkAction } from './make-copy-link-action';-export { makeCreateReminderAction } from './make-create-reminder-action';+export {+ makeCreateReminderAction,+ markReminderTargetDone,+} from './make-create-reminder-action';export { makeDeleteAction } from './make-delete-action';export { makeEditReminderAction } from './make-edit-reminder-action';export { makeFavoriteAction } from './make-favorite-action';diff --git a/apps/web/src/features/next-soup/actions/make-create-reminder-action.test.ts b/apps/web/src/features/next-soup/actions/make-create-reminder-action.test.tsindex 1183b4349e..132055bc82 100644--- a/apps/web/src/features/next-soup/actions/make-create-reminder-action.test.ts+++ b/apps/web/src/features/next-soup/actions/make-create-reminder-action.test.ts@@ -18,7 +18,11 @@ vi.mock('@core/constant/featureFlags', async (importOriginal) => ({ENABLE_REMINDERS: () => mocks.remindersEnabled,}));-import { makeCreateReminderAction } from './make-create-reminder-action';+import type { SoupState } from '../create-soup-state';+import {+ makeCreateReminderAction,+ markReminderTargetDone,+} from './make-create-reminder-action';const entity = (type: EntityData['type'], id = 'e1') =>({ type, id, name: 'Thing' }) as EntityData;@@ -32,6 +36,12 @@ const threadEntity = (channelId = 'chan-1') =>content: 'ship it',}) as EntityData;+const soupState = () => ({}) as SoupState;++/** The follow-up the action handed the composer for the latest open. */+const composerOnCreated = (): (() => void | Promise<void>) | undefined =>+ mocks.openReminderComposer.mock.calls.at(-1)?.[1]?.onCreated;+describe('makeCreateReminderAction', () => {beforeEach(() => {vi.clearAllMocks();@@ -66,7 +76,10 @@ describe('makeCreateReminderAction', () => {makeCreateReminderAction().execute([target]);- expect(mocks.openReminderComposer).toHaveBeenCalledWith(target);+ expect(mocks.openReminderComposer).toHaveBeenCalledWith(+ target,+ expect.anything()+ );});it('opens the composer for the entity', () => {@@ -74,7 +87,10 @@ describe('makeCreateReminderAction', () => {makeCreateReminderAction().execute([target]);- expect(mocks.openReminderComposer).toHaveBeenCalledWith(target);+ expect(mocks.openReminderComposer).toHaveBeenCalledWith(+ target,+ expect.anything()+ );});it('does nothing for an empty selection', () => {@@ -91,7 +107,10 @@ describe('makeCreateReminderAction', () => {makeCreateReminderAction().execute([first, entity('document', 'doc-2')]);expect(mocks.openReminderComposer).toHaveBeenCalledOnce();- expect(mocks.openReminderComposer).toHaveBeenCalledWith(first);+ expect(mocks.openReminderComposer).toHaveBeenCalledWith(+ first,+ expect.anything()+ );});it('does not open the composer for an unsupported entity', () => {@@ -125,13 +144,142 @@ describe('makeCreateReminderAction', () => {it('opens the composer when driven from a soup list', async () => {const target = entity('channel', 'channel-1');- await makeCreateReminderAction().executeWithSoup(+ await makeCreateReminderAction().executeWithSoup([target], soupState(), {+ advances: true,+ });++ expect(mocks.openReminderComposer).toHaveBeenCalledWith(+ target,+ expect.anything()+ );+ });++ // The row leaves the list only once the reminder that brings it back exists,+ // so the follow-up is handed to the composer rather than run here.+ it('does not run the created handler before the reminder exists', () => {+ const onCreated = vi.fn();++ makeCreateReminderAction({ onCreated }).execute([+ entity('document', 'doc-1'),+ ]);++ expect(onCreated).not.toHaveBeenCalled();+ });++ it('hands the composer a created handler bound to the entity', async () => {+ const onCreated = vi.fn();+ const target = entity('document', 'doc-1');++ makeCreateReminderAction({ onCreated }).execute([target]);+ await composerOnCreated()?.();++ expect(onCreated).toHaveBeenCalledWith(target);+ });++ // Marking done from a list moves focus off the row, which needs the list.+ it('passes the list to the created handler when driven from one', async () => {+ const onCreated = vi.fn();+ const target = entity('email', 'thread-1');+ const soup = soupState();++ await makeCreateReminderAction({ onCreated }).executeWithSoup([target],- {} as Parameters<- ReturnType<typeof makeCreateReminderAction>['executeWithSoup']- >[1]+ soup,+ { advances: true });+ await composerOnCreated()?.();++ expect(onCreated).toHaveBeenCalledWith(target, { soup, advances: true });+ });++ // Whether the list moves on is the surface's answer, carried through to the+ // handler rather than guessed at from the list.+ it('carries a list that does not advance through to the handler', async () => {+ const onCreated = vi.fn();+ const target = entity('document', 'doc-1');+ const soup = soupState();++ await makeCreateReminderAction({ onCreated }).executeWithSoup(+ [target],+ soup,+ { advances: false }+ );+ await composerOnCreated()?.();++ expect(onCreated).toHaveBeenCalledWith(target, { soup, advances: false });+ });+});++describe('markReminderTargetDone', () => {+ const markDoneStub = () => ({+ canExecute: vi.fn(() => true),+ execute: vi.fn(async () => {}),+ executeWithSoup: vi.fn(async () => {}),+ });++ // The whole point of the follow-up on a list that triages: a reminder leaves+ // the selection on the next row exactly as Mark done does, through the same+ // soup path and the same `onNavigate`.+ it('marks the target done through soup when the list advances', async () => {+ const markDone = markDoneStub();+ const onNavigate = vi.fn();+ const target = entity('email', 'thread-1');+ const soup = soupState();++ await markReminderTargetDone(markDone, onNavigate)(target, {+ soup,+ advances: true,+ });++ expect(markDone.executeWithSoup).toHaveBeenCalledWith(+ [target],+ soup,+ onNavigate,+ { silent: true }+ );+ });++ // A Documents view or a folder does not triage, so advancing would move the+ // selection, and its preview, for no reason.+ it('does not advance a list that says it does not', async () => {+ const markDone = markDoneStub();+ const target = entity('document', 'doc-1');++ await markReminderTargetDone(markDone)(target, {+ soup: soupState(),+ advances: false,+ });++ expect(markDone.executeWithSoup).not.toHaveBeenCalled();+ expect(markDone.execute).toHaveBeenCalledWith([target], undefined, {+ silent: true,+ });+ });++ // No list behind the action (block ⋯ menu, block command menu outside+ // triage): nothing to advance, so the plain path runs. Silent either way —+ // the composer's "Reminder set for …" toast is the feedback.+ it('marks the target done without a list', async () => {+ const markDone = markDoneStub();+ const target = entity('document', 'doc-1');++ await markReminderTargetDone(markDone)(target);++ expect(markDone.execute).toHaveBeenCalledWith([target], undefined, {+ silent: true,+ });+ expect(markDone.executeWithSoup).not.toHaveBeenCalled();+ });++ // A call or a CRM row has no done state of its own, and `canExecute` is the+ // app's answer for which those are.+ it('skips entity types that cannot be marked done', async () => {+ const markDone = markDoneStub();+ markDone.canExecute.mockReturnValue(false);++ await markReminderTargetDone(markDone)(entity('call', 'call-1'));- expect(mocks.openReminderComposer).toHaveBeenCalledWith(target);+ expect(markDone.execute).not.toHaveBeenCalled();+ expect(markDone.executeWithSoup).not.toHaveBeenCalled();});});diff --git a/apps/web/src/features/next-soup/actions/make-create-reminder-action.ts b/apps/web/src/features/next-soup/actions/make-create-reminder-action.tsindex f401ae7c0b..1046f4c420 100644--- a/apps/web/src/features/next-soup/actions/make-create-reminder-action.ts+++ b/apps/web/src/features/next-soup/actions/make-create-reminder-action.ts@@ -3,6 +3,31 @@ import { ENABLE_REMINDERS } from '@core/constant/featureFlags';import type { EntityData } from '@entity';import { reminderTarget } from '@queries/reminders/reminders';import type { SoupState } from '../create-soup-state';+import type { makeMarkDoneAction } from './make-mark-done-action';++/**+ * The list the action was driven from, when it was driven from one.+ *+ * `advances` is the caller's answer to whether marking the row done should move+ * the list on to the next row — the same question its own "Mark done" answers,+ * and not one this module can work out from the list alone: a soup state is+ * per-split and its predicates say what the split is showing now, not whether+ * done is a thing this list does.+ */+export type ReminderCreatedList = {+ soup: SoupState;+ advances: boolean;+};++/** What the invoking surface does with its row once the reminder exists. */+export type ReminderCreatedHandler = (+ entity: EntityData,+ list?: ReminderCreatedList+) => void | Promise<void>;++type MakeCreateReminderOptions = {+ onCreated?: ReminderCreatedHandler;+};/*** Set a reminder about an entity.@@ -11,26 +36,89 @@ import type { SoupState } from '../create-soup-state';* and the date both come from the user, so there is nothing to do until that* modal resolves. Single-entity only — a reminder points at one thing.*+ * `onCreated` is what happens on the far side of that modal, once the reminder+ * has actually been created. Every soup surface passes+ * `markReminderTargetDone`.+ ** `canExecute` carries the `ENABLE_REMINDERS` gate, which is what every surface* (hotkeys, both soup menus, the block ⋯ menu) checks before offering the* action — so the flag reaches all of them from here. `execute` re-checks it,* since a stale command-menu entry could otherwise still fire.*/-export const makeCreateReminderAction = () => {+export const makeCreateReminderAction = (+ options?: MakeCreateReminderOptions+) => {const canExecute = (entity: EntityData): boolean =>ENABLE_REMINDERS() && reminderTarget(entity) !== undefined;const execute = (entities: EntityData[]) => {const [entity] = entities;if (!entity || !canExecute(entity)) return;- openReminderComposer(entity);+ openReminderComposer(entity, {+ onCreated: () => options?.onCreated?.(entity),+ });};- const executeWithSoup = async (entities: EntityData[], _soup: SoupState) => {+ const executeWithSoup = async (+ entities: EntityData[],+ soup: SoupState,+ /** Whether the list moves on once the row is marked done. */+ opts: { advances: boolean }+ ) => {+ const [entity] = entities;+ if (!entity || !canExecute(entity)) return;// Opening the composer doesn't change the list, so selection and focus are- // left where they are.- execute(entities);+ // left where they are until the reminder exists — `onCreated` is what moves+ // them, by way of marking the row done.+ openReminderComposer(entity, {+ onCreated: () =>+ options?.onCreated?.(entity, { soup, advances: opts.advances }),+ });};return { canExecute, execute, executeWithSoup };};++type MarkDoneAction = Pick<+ ReturnType<typeof makeMarkDoneAction>,+ 'canExecute' | 'execute' | 'executeWithSoup'+>;++/**+ * Mark the reminder's target done, which is what setting a reminder is for:+ * the reminder brings the thing back, so it leaves the list now.+ *+ * Entity types with no done state of their own — a call, a CRM company or+ * contact — are skipped rather than handled; `markDone.canExecute` is the+ * app's answer for which those are, and it is the same gate the "Mark Done"+ * menu entry uses.+ *+ * On a list that moves on — the inbox, mail, the reminders views, and the same+ * lists seen from a block being triaged out of one — this runs mark-done's own+ * soup path, so a reminder leaves the selection, and any attached split, on the+ * next row exactly as "Mark done" does. A list that has no notion of done+ * (Documents, a folder) says so, and the row is marked where it sits.+ *+ * Silent: the composer's "Reminder set for …" toast is the feedback, and a+ * second "Marked as done" on top of it says the same thing twice. The+ * mark-done still lands on the undo stack, so cmd+Z reverses it.+ */+export const markReminderTargetDone =+ (+ markDone: MarkDoneAction,+ /** Follows the list's focus in an attached split, as mark-done's own+ * entry points do. */+ onNavigate?: (entity: EntityData) => void+ ): ReminderCreatedHandler =>+ async (entity, list) => {+ if (!markDone.canExecute(entity)) return;++ if (list?.advances) {+ await markDone.executeWithSoup([entity], list.soup, onNavigate, {+ silent: true,+ });+ return;+ }++ await markDone.execute([entity], undefined, { silent: true });+ };diff --git a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts b/apps/web/src/features/next-soup/actions/use-block-entity-commands.tsindex fb27c083e0..9982e4cccc 100644--- a/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts+++ b/apps/web/src/features/next-soup/actions/use-block-entity-commands.ts@@ -30,6 +30,7 @@ import {makeMarkDoneAction,makeMoveToProjectAction,makeRenameAction,+ markReminderTargetDone,} from './index';/**@@ -69,7 +70,6 @@ export const useBlockEntityCommands = (const copyBranchNameAction = makeCopyBranchNameAction();const copyEntityIdAction = makeCopyEntityIdAction();const favoriteAction = makeFavoriteAction();- const createReminderAction = makeCreateReminderAction();const allProperties = useAllProperties();@@ -131,10 +131,51 @@ export const useBlockEntityCommands = ();};+ /** Follows the list's next row into this split, as the triage flow does. */+ const advanceSplitTo = (nextEntity: EntityData) => {+ const splitHandle = splitPanel?.handle;+ if (!splitHandle) return;+ void openEntityInSplitFromUnifiedList(nextEntity, {+ splitHandle,+ mergeHistory: true,+ referredFrom: splitHandle.referredFrom(),+ });+ };++ // Setting a reminder puts the entity down: it marks it done, so it leaves the+ // list behind this block and the reminder is what brings it back. Declared+ // after `advanceSplitTo` so the follow-up advances exactly as 'e' does.+ const createReminderAction = makeCreateReminderAction({+ onCreated: markReminderTargetDone(markDone, advanceSplitTo),+ });++ /**+ * The soup row for the entity when this block is being triaged out of a list,+ * which is what decides between advancing the split and leaving it be.+ */+ const triageRow = () => {+ const entity = getEntity();+ if (!entity || !canUseMarkDoneHotkey() || !soup) return undefined;+ return soup.items.get(entity.id);+ };+const runCreateReminder = () => {const entity = getEntity();if (!entity) return false;if (!createReminderAction.canExecute(entity)) return false;++ // Driven through soup when the block is being triaged out of a list. Having+ // a `triageRow` is the same condition 'e' advances on, so the mark-done+ // that follows moves to the next row exactly as Mark done does rather than+ // leaving the split on one the list has dropped.+ const selectedRow = triageRow();+ if (soup && selectedRow) {+ void createReminderAction.executeWithSoup([selectedRow.original], soup, {+ advances: true,+ });+ return true;+ }+createReminderAction.execute([entity]);return true;};@@ -146,22 +187,14 @@ export const useBlockEntityCommands = (// Plain mark done, no advance: the command-menu registration outside the// triage flow, or the entity is no longer in the surviving soup list.- const selectedRow = soup?.items.get(entity.id);- if (!canUseMarkDoneHotkey() || !soup || !selectedRow) {+ const selectedRow = triageRow();+ if (!soup || !selectedRow) {markDone.execute([entity]);return true;}// Triage flow: mark done and advance to the next item in the list.- markDone.executeWithSoup([selectedRow.original], soup, (nextEntity) => {- const splitHandle = splitPanel?.handle;- if (!splitHandle) return;- void openEntityInSplitFromUnifiedList(nextEntity, {- splitHandle,- mergeHistory: true,- referredFrom: splitHandle.referredFrom(),- });- });+ markDone.executeWithSoup([selectedRow.original], soup, advanceSplitTo);return true;};diff --git a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.tsindex f1b272ba46..1a88d5eac8 100644--- a/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts+++ b/apps/web/src/features/next-soup/actions/use-entity-action-hotkeys.ts@@ -36,6 +36,7 @@ import {makeRenameAction,makeSetCompanyPropertyAction,makeShareAction,+ markReminderTargetDone,} from './index';type UseEntityActionHotkeysOptions = {@@ -88,7 +89,6 @@ export const useEntityActionHotkeys = (const copyBranchNameAction = makeCopyBranchNameAction();const copyEntityIdAction = makeCopyEntityIdAction();- const createReminderAction = makeCreateReminderAction();const editReminderAction = makeEditReminderAction();const shareAction = makeShareAction();@@ -132,6 +132,26 @@ export const useEntityActionHotkeys = (});};+ /**+ * Whether this list is one that marks rows done, and so one that moves on to+ * the next row when a row is marked. It gates 'e' below, and the mark-done+ * that follows setting a reminder advances on the same answer.+ */+ const marksDoneOnThisView = (): boolean => {+ const contentId = splitHandle?.content().id;+ if (!isListViewID(contentId)) return false;+ const soupViewTab = options.activeSoupViewTab?.();+ return !soupViewTab || canExecuteMarkDoneOnView(contentId, soupViewTab);+ };++ // Declared here rather than with the other actions above because its+ // mark-done follow-up advances the list the same way 'e' does, through+ // `openNextEntity`. Setting a reminder puts the row down: it marks it done,+ // so the list drops it and the reminder is what brings it back.+ const createReminderAction = makeCreateReminderAction({+ onCreated: markReminderTargetDone(markDone, openNextEntity),+ });+// Property editor setupconst allProperties = useAllProperties();const propertyById = (propertyId: string) =>@@ -176,16 +196,7 @@ export const useEntityActionHotkeys = (},condition: () => {if (condition && !condition()) return false;-- const contentId = splitHandle?.content().id;-- const soupViewTab = options.activeSoupViewTab?.();-- if (- !isListViewID(contentId) ||- (soupViewTab && !canExecuteMarkDoneOnView(contentId, soupViewTab))- )- return false;+ if (!marksDoneOnThisView()) return false;const entities = getEntitiesForAction();return entities.length > 0 && entities.every(markDone.canExecute);@@ -518,7 +529,9 @@ export const useEntityActionHotkeys = (const entities = getEntitiesForAction();if (entities.length !== 1) return false;if (!createReminderAction.canExecute(entities[0])) return false;- createReminderAction.executeWithSoup(entities, soup);+ createReminderAction.executeWithSoup(entities, soup, {+ advances: marksDoneOnThisView(),+ });return true;},condition: () => {diff --git a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.tsindex 40b254a33e..8e59b70d51 100644--- a/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts+++ b/apps/web/src/features/next-soup/soup-view/create-soup-entity-actions.ts@@ -34,6 +34,7 @@ import {makeRenameAction,makeSetCompanyPropertyAction,makeShareAction,+ markReminderTargetDone,} from '../actions';import type { SoupState } from '../create-soup-state';import {@@ -130,7 +131,11 @@ export function createSoupEntityActions(): {const copyLinkAction = makeCopyLinkAction();const copyBranchNameAction = makeCopyBranchNameAction();const copyEntityIdAction = makeCopyEntityIdAction();- const createReminderAction = makeCreateReminderAction();+ // Setting a reminder puts the row down: it marks it done, so the list drops+ // it and the reminder is what brings it back.+ const createReminderAction = makeCreateReminderAction({+ onCreated: markReminderTargetDone(markDone),+ });const editReminderAction = makeEditReminderAction();const shareAction = makeShareAction();const blockSenderAction = makeBlockSenderAction();@@ -158,11 +163,13 @@ export function createSoupEntityActions(): {// Top group: Mark Done, Open in new splitconst topItems: SoupEntityActionItem[] = [];- if (- activeTab &&+ // Also what the reminder's own mark-done advances on, further down.+ const marksDoneOnThisView =+ !!activeTab &&isListViewID(activeListView) &&- canExecuteMarkDoneOnView(activeListView, activeTab)- ) {+ canExecuteMarkDoneOnView(activeListView, activeTab);++ if (marksDoneOnThisView) {// A fully-done selection (e.g. archived threads in mail "All") gets the// reverse action; anything else gets Mark Done.if (canExecuteAll(markNotDone.canExecute)) {@@ -341,7 +348,12 @@ export function createSoupEntityActions(): {id: 'create-reminder',label: 'Remind me',hotkeyToken: TOKENS.entity.action.createReminder,- onClick: handle(createReminderAction.executeWithSoup),+ // Not `handle`: the mark-done that follows needs this view's answer to+ // whether the list moves on, the same one Mark Done above is gated by.+ onClick: () =>+ createReminderAction.executeWithSoup(entities, soup, {+ advances: marksDoneOnThisView,+ }),});}diff --git a/apps/web/src/features/reminders/ReminderComposerModal.tsx b/apps/web/src/features/reminders/ReminderComposerModal.tsxindex 0c375f686f..a3341a911d 100644--- a/apps/web/src/features/reminders/ReminderComposerModal.tsx+++ b/apps/web/src/features/reminders/ReminderComposerModal.tsx@@ -46,6 +46,7 @@ import {type ReminderDraft,reminderComposerOpen,reminderComposerState,+ takeReminderCreatedHandler,} from './reminder-composer';import {formatReminderWhen,@@ -160,6 +161,8 @@ export function ReminderComposerModal() {const submitCreate = async (date: Date, target: EntityData) => {const resolved = resolveReminderDescription(description(), target);const attachTo = reminderTarget(target);+ // Taken before the close, which clears it.+ const onCreated = takeReminderCreatedHandler();closeReminderComposer();try {@@ -172,7 +175,13 @@ export function ReminderComposerModal() {toast.success(`Reminder set for ${formatReminderWhen(date)}`);} catch {toast.failure('Failed to create reminder');+ return;}++ // Whatever the invoking surface does with its row now that the reminder+ // will bring it back — marking it done, in every soup list. Runs only once+ // the reminder exists, so a failed create leaves the row alone.+ await onCreated?.();};const submitEdit = async (date: Date, draft: ReminderDraft) => {diff --git a/apps/web/src/features/reminders/reminder-composer.test.ts b/apps/web/src/features/reminders/reminder-composer.test.tsindex 00cf5a315b..c9d3e35dd3 100644--- a/apps/web/src/features/reminders/reminder-composer.test.ts+++ b/apps/web/src/features/reminders/reminder-composer.test.ts@@ -1,5 +1,5 @@import type { EntityData } from '@entity';-import { beforeEach, describe, expect, it } from 'vitest';+import { beforeEach, describe, expect, it, vi } from 'vitest';import {closeReminderComposer,@@ -7,6 +7,7 @@ import {openReminderEditor,reminderComposerOpen,reminderComposerState,+ takeReminderCreatedHandler,} from './reminder-composer';const doc = (id: string, name: string) =>@@ -108,3 +109,42 @@ describe('reminder composer edit mode', () => {expect(reminderComposerState.editing?.description).toBe('Send the invoice');});});++describe('reminder composer created handler', () => {+ beforeEach(() => {+ closeReminderComposer();+ });++ // The composer closes before the create request is awaited, so the follow-up+ // has to be taken out of here first rather than read after the fact.+ it('hands the created handler over once', () => {+ const onCreated = vi.fn();+ openReminderComposer(doc('doc-1', 'Q3 Contract'), { onCreated });++ expect(takeReminderCreatedHandler()).toBe(onCreated);+ expect(takeReminderCreatedHandler()).toBeUndefined();+ });++ it('drops the created handler when the composer is closed', () => {+ openReminderComposer(doc('doc-1', 'Q3 Contract'), { onCreated: vi.fn() });+ closeReminderComposer();++ expect(takeReminderCreatedHandler()).toBeUndefined();+ });++ // Editing an existing reminder is not a create, so the previous open's+ // follow-up must not survive into it.+ it('drops the created handler when opened to edit', () => {+ openReminderComposer(doc('doc-1', 'Q3 Contract'), { onCreated: vi.fn() });+ openReminderEditor(draft('rem-1', 'Chase the contract'));++ expect(takeReminderCreatedHandler()).toBeUndefined();+ });++ it('drops the previous created handler when reopened to create', () => {+ openReminderComposer(doc('doc-1', 'Q3 Contract'), { onCreated: vi.fn() });+ openReminderComposer(doc('doc-2', 'Roadmap'));++ expect(takeReminderCreatedHandler()).toBeUndefined();+ });+});diff --git a/apps/web/src/features/reminders/reminder-composer.ts b/apps/web/src/features/reminders/reminder-composer.tsindex fca4f1e41c..9bd2cb7ef2 100644--- a/apps/web/src/features/reminders/reminder-composer.ts+++ b/apps/web/src/features/reminders/reminder-composer.ts@@ -39,6 +39,29 @@ interface ReminderComposerState {editing?: ReminderDraft;}+/** What the surface that opened the composer does once the reminder exists. */+export type ReminderCreatedHandler = () => void | Promise<void>;++/**+ * Held outside the store: nothing renders it, and a function in a store is a+ * footgun — the setters read one as an updater.+ */+let createdHandler: ReminderCreatedHandler | undefined;++/**+ * Hand the pending handler to the caller and forget it.+ *+ * Taken rather than read because the composer closes — and so clears its+ * target — before the create request is awaited.+ */+export function takeReminderCreatedHandler():+ | ReminderCreatedHandler+ | undefined {+ const handler = createdHandler;+ createdHandler = undefined;+ return handler;+}+const [state, setState] = createStore<ReminderComposerState>({entity: undefined,editing: undefined,@@ -51,7 +74,11 @@ const [state, setState] = createStore<ReminderComposerState>({* was invoked on and the description is derived from it, so the composer opens* straight onto the date list.*/-export function openReminderComposer(entity: EntityData) {+export function openReminderComposer(+ entity: EntityData,+ options?: { onCreated?: ReminderCreatedHandler }+) {+ createdHandler = options?.onCreated;// Batched so the modal's open-keyed effect sees this entity rather than the// previous one.batch(() => {@@ -68,6 +95,7 @@ export function openReminderComposer(entity: EntityData) {* time so a rename does not force a new date to be picked.*/export function openReminderEditor(reminder: ReminderDraft) {+ createdHandler = undefined;batch(() => {setState(reconcile({ entity: undefined, editing: reminder }));setReminderComposerOpen(true);@@ -75,6 +103,7 @@ export function openReminderEditor(reminder: ReminderDraft) {}export function closeReminderComposer() {+ createdHandler = undefined;batch(() => {setReminderComposerOpen(false);setState(reconcile({ entity: undefined, editing: undefined }));