Skip to content

fix drop files in ticket upload#3554

Merged
steven-tey merged 1 commit intomainfrom
fix-support-chat-drag-n-drop
Mar 9, 2026
Merged

fix drop files in ticket upload#3554
steven-tey merged 1 commit intomainfrom
fix-support-chat-drag-n-drop

Conversation

@pepeladeira
Copy link
Collaborator

@pepeladeira pepeladeira commented Mar 9, 2026

Summary by CodeRabbit

  • Style

    • Chat bubble panel updated with a subtler inset border and adjusted internal container to isolate the chat area.
    • Embedded chat shadow removed for a cleaner appearance.
  • Bug Fixes

    • Support ticket file uploads now append entries and handle per-file completion with explicit success/error status updates and MAX_FILES enforcement.

@vercel
Copy link
Contributor

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Mar 9, 2026 0:06am

Request Review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

Chat UI styling was adjusted (chat-bubble now wraps ChatInterface in a white container and uses an inset 1px border), embedded-chat had its outer shadow removed, and ticket-upload refactored file handling to append files directly and perform per-entry upload status updates.

Changes

Cohort / File(s) Summary
Chat UI Styling & Structure
apps/web/ui/support/chat-bubble.tsx, apps/web/ui/support/embedded-chat.tsx
Swapped heavy drop shadows for subtle inset/border styling; chat-bubble.tsx now wraps ChatInterface in a dedicated white container and adjusts sizing (removed flex-1, uses h-full/overflow handling); embedded-chat.tsx removes shadow-sm.
File Upload Flow Refactor
apps/web/ui/support/ticket-upload.tsx
Replaced precomputed allowedEntries flow with direct append-and-upload. addFiles enforces MAX_FILES on append; per-entry upload completion updates individual entry status (guards against missing ids, sets error or done with metadata) instead of bulk updating.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • pepeladeira

Poem

🐰 I nudged the bubble, softened its gleam,
Wrapped the chat in a neat little seam,
Files hop aboard one by one, not in bulk,
Each gets a status, no more confused hulk.
Cheers from a rabbit — light, tidy, and pluck!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix drop files in ticket upload' directly and clearly describes the main change: fixing file dropping functionality in the ticket upload component.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-support-chat-drag-n-drop

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steven-tey
Copy link
Collaborator

@coderabbitai full review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

✅ Actions performed

Full review triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/web/ui/support/ticket-upload.tsx (1)

88-121: Uploads may start for files that get discarded.

The addFiles function starts uploads for all valid entries (up to MAX_FILES from incoming files) before the state update slices the combined array.

Example scenario: If 3 files already exist and user drops 4 valid files:

  1. Line 95: valid contains all 4 (sliced to MAX_FILES from incoming only)
  2. Lines 107-119: Uploads start for all 4 entries
  3. Line 105: Combined array [...prev(3), ...entries(4)] is sliced to 5, discarding 2 entries
  4. The 2 discarded entries still complete their uploads, but the guard at line 110 correctly prevents state corruption

This wastes network requests for files that won't be kept. Consider calculating the allowed count upfront:

♻️ Proposed fix to avoid wasted uploads
  const addFiles = useCallback((incoming: File[]) => {
+   setFiles((prev) => {
+     const remaining = MAX_FILES - prev.length;
+     if (remaining <= 0) return prev;
+
-   const valid = incoming
+     const valid = incoming
-     .filter((f) => {
+       .filter((f) => {
-       if (!ACCEPTED_TYPES.includes(f.type)) return false;
+         if (!ACCEPTED_TYPES.includes(f.type)) return false;
-       if (f.size > MAX_FILE_SIZE_BYTES) return false;
+         if (f.size > MAX_FILE_SIZE_BYTES) return false;
-       return true;
+         return true;
-     })
+       })
-     .slice(0, MAX_FILES);
+       .slice(0, remaining);

-   if (valid.length === 0) return;
+     if (valid.length === 0) return prev;

-   const entries: FileEntry[] = valid.map((file) => ({
+     const entries: FileEntry[] = valid.map((file) => ({
-     id: `${file.name}-${file.size}-${Date.now()}-${Math.random()}`,
+       id: `${file.name}-${file.size}-${Date.now()}-${Math.random()}`,
-     file,
+       file,
-     status: "uploading",
+       status: "uploading",
-   }));
+     }));

-   setFiles((prev) => [...prev, ...entries].slice(0, MAX_FILES));
+     // Start uploads after we know which entries will be kept
+     entries.forEach((entry) => {
+       uploadToPlain(entry.file).then((result) => {
+         setFiles((p) => {
+           if (!p.some((f) => f.id === entry.id)) return p;
+           return p.map((f) =>
+             f.id === entry.id
+               ? "error" in result
+                 ? { ...f, status: "error", errorMessage: result.error }
+                 : { ...f, status: "done", attachmentId: result.attachmentId }
+               : f,
+           );
+         });
+       });
+     });

-   entries.forEach((entry) => {
-     uploadToPlain(entry.file).then((result) => {
-       setFiles((prev) => {
-         if (!prev.some((f) => f.id === entry.id)) return prev;
-         return prev.map((f) =>
-           f.id === entry.id
-             ? "error" in result
-               ? { ...f, status: "error", errorMessage: result.error }
-               : { ...f, status: "done", attachmentId: result.attachmentId }
-             : f,
-         );
-       });
-     });
+     return [...prev, ...entries];
   });
  }, []);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/ui/support/ticket-upload.tsx` around lines 88 - 121, The addFiles
flow currently starts uploads for all generated entries before trimming against
MAX_FILES; change it to compute allowed slots from current state and only start
uploads for the entries that will actually be added. Inside addFiles, use the
setFiles functional updater to read prev.length, compute allowed = Math.max(0,
MAX_FILES - prev.length), slice entries to keptEntries = entries.slice(0,
allowed), append only keptEntries to prev, and then call uploadToPlain only for
keptEntries (not for all entries). Update references: addFiles, entries,
setFiles, uploadToPlain, MAX_FILES so discarded files never trigger network
uploads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/web/ui/support/ticket-upload.tsx`:
- Around line 88-121: The addFiles flow currently starts uploads for all
generated entries before trimming against MAX_FILES; change it to compute
allowed slots from current state and only start uploads for the entries that
will actually be added. Inside addFiles, use the setFiles functional updater to
read prev.length, compute allowed = Math.max(0, MAX_FILES - prev.length), slice
entries to keptEntries = entries.slice(0, allowed), append only keptEntries to
prev, and then call uploadToPlain only for keptEntries (not for all entries).
Update references: addFiles, entries, setFiles, uploadToPlain, MAX_FILES so
discarded files never trigger network uploads.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 373de2c1-3ca1-433d-be00-f9bf6442c12b

📥 Commits

Reviewing files that changed from the base of the PR and between d38fd01 and 34b7e91.

📒 Files selected for processing (3)
  • apps/web/ui/support/chat-bubble.tsx
  • apps/web/ui/support/embedded-chat.tsx
  • apps/web/ui/support/ticket-upload.tsx

@steven-tey steven-tey merged commit 583ba12 into main Mar 9, 2026
11 checks passed
@steven-tey steven-tey deleted the fix-support-chat-drag-n-drop branch March 9, 2026 15:49
@coderabbitai coderabbitai bot mentioned this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants