Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions apps/mail/actions/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ export const toggleStar = async ({ ids }: { ids: string[] }) => {
throw error;
}
};

export const deleteThread = async ({ id }: { id: string }) => {
console.log("Deleting thread:", id);
try {
const driver = await getActiveDriver();
await driver.delete(id);
return { success: true };
} catch (error) {
if (FatalErrors.includes((error as Error).message)) await deleteActiveConnection();
console.error('Error deleting thread:', error);
throw error;
}
}
23 changes: 22 additions & 1 deletion apps/mail/components/context/thread-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { useMail } from '../mail/use-mail';
import { useTranslations } from 'use-intl';
import { type ReactNode } from 'react';
import { toast } from 'sonner';
import { modifyLabels } from '@/actions/mail';
import { deleteThread, modifyLabels } from '@/actions/mail';
import { markAsRead, markAsUnread, toggleStar } from '@/actions/mail';
import { useMemo } from 'react';

Expand Down Expand Up @@ -186,6 +186,20 @@ export function ThreadContextMenu({
});
};

const handleDelete = async () => {
try {
const promise = deleteThread({ id: threadId }).then(() => mutate());
toast.promise(promise, {
loading: t('common.actions.deletingMail'),
success: t('common.actions.deletedMail'),
error: t('common.actions.failedToDeleteMail'),
});

}catch (error) {
console.error(`Error deleting ${threadId? 'email' : 'thread'}:`, error);
}
};

const primaryActions: EmailAction[] = [
{
id: 'reply',
Expand Down Expand Up @@ -242,6 +256,13 @@ export function ThreadContextMenu({
action: handleMove(LABELS.TRASH, LABELS.INBOX),
disabled: false,
},
{
id: 'delete-from-bin',
label: t('common.mail.deleteFromBin'),
icon: <Trash className="mr-2.5 h-4 w-4" />,
action: handleDelete,
disabled: false,
}
];
}

Expand Down
2 changes: 1 addition & 1 deletion apps/mail/lib/auth-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const authProviders: ProviderConfig[] = [
// TODO: Remove this before going to prod, it's to force to get `refresh_token` from google, some users don't have it yet.
prompt: "consent",
accessType: "offline",
scope: ["https://www.googleapis.com/auth/gmail.modify"],
scope: ["https://www.googleapis.com/auth/gmail.modify", 'https://mail.google.com'],
clientId: process.env.GOOGLE_CLIENT_ID!,
clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
},
Expand Down
4 changes: 4 additions & 0 deletions apps/mail/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"movingToInbox": "Moving to inbox...",
"movedToSpam": "Moved to spam",
"movingToSpam": "Moving to spam...",
"deletingMail": "Deleting mail...",
"failedToDeleteMail": "Failed to delete mail",
"deletedMail": "Mail deleted",
"archiving": "Archiving...",
"archived": "Archived",
"failedToMove": "Failed to move message",
Expand Down Expand Up @@ -245,6 +248,7 @@
"mute": "Mute",
"moveToSpam": "Move to Spam",
"moveToInbox": "Move to Inbox",
"deleteFromBin": "Delete from Bin",
"unarchive": "Unarchive",
"archive": "Archive",
"moveToBin": "Move to Bin",
Expand Down