diff --git a/apps/mail/components/context/thread-context.tsx b/apps/mail/components/context/thread-context.tsx index e304a60e05..06b28c9ea1 100644 --- a/apps/mail/components/context/thread-context.tsx +++ b/apps/mail/components/context/thread-context.tsx @@ -78,12 +78,17 @@ const LabelsList = ({ threadId }: { threadId: string }) => { const handleToggleLabel = async (labelId: string) => { if (!labelId) return; const hasLabel = thread.labels?.map((label) => label.id).includes(labelId); - await modifyLabels({ + const promise = modifyLabels({ threadId: [threadId], addLabels: hasLabel ? [] : [labelId], removeLabels: hasLabel ? [labelId] : [], }); - refetch(); + toast.promise(promise, { + error: hasLabel ? "Failed to remove label" : "Failed to add label", + finally: async () => { + await refetch(); + }, + }); }; return ( @@ -209,14 +214,14 @@ export function ThreadContextMenu({ const handleFavorites = async () => { const targets = mail.bulkSelected.length ? mail.bulkSelected : [threadId]; - if (!isStarred) { - toast.success(t('common.actions.addedToFavorites')); - } else { - toast.success(t('common.actions.removedFromFavorites')); - } - await toggleStar({ ids: targets }); - setMail((prev) => ({ ...prev, bulkSelected: [] })); - return await Promise.allSettled([refetchThread(), refetch()]); + const promise = toggleStar({ ids: targets }); + toast.promise(promise, { + error: isStarred ? t('common.actions.failedToRemoveFromFavorites') : t('common.actions.failedToAddToFavorites'), + finally: async () => { + setMail((prev) => ({ ...prev, bulkSelected: [] })); + await Promise.allSettled([refetchThread(), refetch()]); + }, + }); }; const handleToggleImportant = async () => {