Skip to content

Commit 6e93fad

Browse files
authored
ui: add cross in the undo email toast, decrease time from 30s to 15s (#1979)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Added a close (cross) button to the undo email toast and reduced the undo window from 30 seconds to 15 seconds. - **UI Improvements** - The undo toast now shows a close button for quick dismissal. - The undo option is available for 15 seconds instead of 30. <!-- End of auto-generated description by cubic. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved Undo experience: separate flows for scheduled vs. immediate sends with clearer toasts. Undoing a scheduled send cancels scheduling; undoing an immediate send restores the draft (including attachments) and reopens the composer. Toasts now last 15 seconds and include a close button. * Default delay before processing a send/schedule reduced from 30 seconds to 15 seconds. * **Bug Fixes** * Prevented negative time remaining, ensuring Undo is reliably available and consistent with the 5-second gating. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 722fef4 commit 6e93fad

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

apps/mail/hooks/use-undo-send.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,31 @@ export const useUndoSend = () => {
6868
if (isSendResult(result) && settings?.settings?.undoSendEnabled) {
6969
const { messageId, sendAt } = result;
7070

71-
const timeRemaining = sendAt ? sendAt - Date.now() : 15_000;
71+
const timeRemaining = sendAt ? Math.max(0, sendAt - Date.now()) : 15_000;
72+
const wasUserScheduled = Boolean(emailData?.scheduleAt);
7273

7374
if (timeRemaining > 5_000) {
74-
toast.success('Email scheduled', {
75-
action: {
76-
label: 'Undo',
77-
onClick: async () => {
75+
if (wasUserScheduled) {
76+
toast.success('Email scheduled', {
77+
action: {
78+
label: 'Undo',
79+
onClick: async () => {
80+
try {
81+
await unsendEmail({ messageId });
82+
toast.info('Schedule cancelled');
83+
} catch {
84+
toast.error('Failed to cancel');
85+
}
86+
},
87+
},
88+
duration: 15_000,
89+
closeButton: true,
90+
});
91+
} else {
92+
toast.success('Email sent', {
93+
action: {
94+
label: 'Undo',
95+
onClick: async () => {
7896
try {
7997
await unsendEmail({ messageId });
8098

@@ -98,10 +116,12 @@ export const useUndoSend = () => {
98116
} catch {
99117
toast.error('Failed to cancel');
100118
}
119+
},
101120
},
102-
},
103-
duration: 15_000,
104-
});
121+
duration: 15_000,
122+
closeButton: true,
123+
});
124+
}
105125
}
106126
}
107127
};

apps/server/src/trpc/routes/mail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export const mailRouter = router({
515515

516516
targetTime = parsedTime;
517517
} else {
518-
targetTime = Date.now() + 30_000;
518+
targetTime = Date.now() + 15_000;
519519
}
520520

521521
const rawDelaySeconds = Math.floor((targetTime - Date.now()) / 1000);

0 commit comments

Comments
 (0)