diff --git a/apps/mail/hooks/use-undo-send.ts b/apps/mail/hooks/use-undo-send.ts index 55182c311..4b7941cb9 100644 --- a/apps/mail/hooks/use-undo-send.ts +++ b/apps/mail/hooks/use-undo-send.ts @@ -68,13 +68,31 @@ export const useUndoSend = () => { if (isSendResult(result) && settings?.settings?.undoSendEnabled) { const { messageId, sendAt } = result; - const timeRemaining = sendAt ? sendAt - Date.now() : 15_000; + const timeRemaining = sendAt ? Math.max(0, sendAt - Date.now()) : 15_000; + const wasUserScheduled = Boolean(emailData?.scheduleAt); if (timeRemaining > 5_000) { - toast.success('Email scheduled', { - action: { - label: 'Undo', - onClick: async () => { + if (wasUserScheduled) { + toast.success('Email scheduled', { + action: { + label: 'Undo', + onClick: async () => { + try { + await unsendEmail({ messageId }); + toast.info('Schedule cancelled'); + } catch { + toast.error('Failed to cancel'); + } + }, + }, + duration: 15_000, + closeButton: true, + }); + } else { + toast.success('Email sent', { + action: { + label: 'Undo', + onClick: async () => { try { await unsendEmail({ messageId }); @@ -98,10 +116,12 @@ export const useUndoSend = () => { } catch { toast.error('Failed to cancel'); } + }, }, - }, - duration: 15_000, - }); + duration: 15_000, + closeButton: true, + }); + } } } }; diff --git a/apps/server/src/trpc/routes/mail.ts b/apps/server/src/trpc/routes/mail.ts index dd419428e..55f5205c7 100644 --- a/apps/server/src/trpc/routes/mail.ts +++ b/apps/server/src/trpc/routes/mail.ts @@ -515,7 +515,7 @@ export const mailRouter = router({ targetTime = parsedTime; } else { - targetTime = Date.now() + 30_000; + targetTime = Date.now() + 15_000; } const rawDelaySeconds = Math.floor((targetTime - Date.now()) / 1000);