diff --git a/hooks/use-mailbox-drop.ts b/hooks/use-mailbox-drop.ts index 6a9dc0e9..d123db54 100644 --- a/hooks/use-mailbox-drop.ts +++ b/hooks/use-mailbox-drop.ts @@ -6,6 +6,7 @@ import { useEmailStore } from "@/stores/email-store"; import { useAuthStore } from "@/stores/auth-store"; import { useDragDropContext } from "@/contexts/drag-drop-context"; import { toast } from "@/stores/toast-store"; +import { getMailboxPath } from "@/lib/utils"; interface UseMailboxDropOptions { mailbox: Mailbox; @@ -30,7 +31,7 @@ interface UseMailboxDropReturn { export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: UseMailboxDropOptions): UseMailboxDropReturn { const [isOver, setIsOver] = useState(false); const { client } = useAuthStore(); - const { moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox } = useEmailStore(); + const { moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, mailboxes } = useEmailStore(); const { isDragging, sourceMailboxId, draggedEmails, endDrag } = useDragDropContext(); // Determine if this is a valid drop target @@ -117,15 +118,15 @@ export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: // Refresh the current mailbox view await fetchEmails(client, selectedMailbox); - // Call success callback if provided, otherwise use fallback + const mailboxPath = getMailboxPath(mailbox, mailboxes); + if (onSuccess) { - onSuccess(emailIds.length, mailbox.name); + onSuccess(emailIds.length, mailboxPath); } else { - // Fallback for backward compatibility if (emailIds.length === 1) { - toast.success("Email moved", `Moved to ${mailbox.name}`); + toast.success("Email moved", `Moved to ${mailboxPath}`); } else { - toast.success("Emails moved", `${emailIds.length} emails moved to ${mailbox.name}`); + toast.success("Emails moved", `${emailIds.length} emails moved to ${mailboxPath}`); } } @@ -143,7 +144,7 @@ export function useMailboxDrop({ mailbox, onDropComplete, onSuccess, onError }: } finally { endDrag(); } - }, [client, mailbox, isValidTarget, moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, endDrag, onDropComplete, onSuccess, onError]); + }, [client, mailbox, mailboxes, isValidTarget, moveEmailsToMailbox, selectedEmailIds, clearSelection, fetchEmails, selectedMailbox, endDrag, onDropComplete, onSuccess, onError]); const valid = isValidTarget(); diff --git a/lib/utils.ts b/lib/utils.ts index 7547fd1d..4c9624ad 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -429,4 +429,23 @@ export function flattenMailboxTree(nodes: MailboxNode[]): MailboxNode[] { traverse(nodes); return result; +} + +export function getMailboxPath( + mailbox: Pick, + allMailboxes: Array>, + separator = ' › ', +): string { + const byId = new Map(allMailboxes.map(m => [m.id, m])); + const names: string[] = [mailbox.name]; + const visited = new Set([mailbox.id]); + let parentId = mailbox.parentId; + while (parentId && !visited.has(parentId)) { + visited.add(parentId); + const parent = byId.get(parentId); + if (!parent) break; + names.unshift(parent.name); + parentId = parent.parentId; + } + return names.join(separator); } \ No newline at end of file