Skip to content

feat: implement reorder functionality for invoice items#72

Open
buddhsen-tripathi wants to merge 1 commit into
legions-developer:mainfrom
buddhsen-tripathi:feat/reorder-items
Open

feat: implement reorder functionality for invoice items#72
buddhsen-tripathi wants to merge 1 commit into
legions-developer:mainfrom
buddhsen-tripathi:feat/reorder-items

Conversation

@buddhsen-tripathi
Copy link
Copy Markdown

@buddhsen-tripathi buddhsen-tripathi commented May 20, 2026

This pull request adds drag-and-drop reordering functionality to the invoice items section, allowing users to rearrange invoice items interactively. It uses the motion library's Reorder components and updates the UI to include a drag handle icon. The code also introduces a helper function to efficiently determine the moved item during a reorder operation.

Invoice item reordering functionality:

  • Integrated Reorder.Group and Reorder.Item from the motion library to enable drag-and-drop reordering of invoice items in the UI (invoice-items-section.tsx). [1] [2] [3]
  • Added a drag handle (GripVerticalIcon) to each invoice item for improved user experience during reordering (invoice-items-section.tsx). [1] [2]
  • Implemented the onReorder handler and a helper function getSingleMove to compute and apply the correct item movement in the form state (invoice-items-section.tsx). [1] [2]
image

Closes #71

Copilot AI review requested due to automatic review settings May 20, 2026 08:40
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@buddhsen-tripathi is attempting to deploy a commit to the Invoicely OSS Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

InvoiceItemsSection now renders invoice items with drag-and-drop reordering using motion/react Reorder components. The component pulls move from useFieldArray, applies reordering via an onReorder handler with a helper function that calculates move indices from ID arrays, and displays a grip icon as a visual drag handle.

Changes

Invoice Items Drag-and-Drop Reordering

Layer / File(s) Summary
Drag-and-drop imports and UI dependencies
apps/web/src/app/(dashboard)/create/invoice/invoiceHelpers/invoice-items-section.tsx (19–26)
Updated imports to add Reorder and GripVerticalIcon for drag-and-drop support, while removing PencilIcon which is no longer used.
Invoice items reordering with Reorder.Group/Item
apps/web/src/app/(dashboard)/create/invoice/invoiceHelpers/invoice-items-section.tsx (35–112)
Replaced static container with Reorder.Group/Reorder.Item structure tied to field-array item IDs, added onReorder handler that computes and applies item moves, and integrated GripVerticalIcon as a visual drag handle for each item row.
Move index calculation utility
apps/web/src/app/(dashboard)/create/invoice/invoiceHelpers/invoice-items-section.tsx (127–140)
Added getSingleMove helper function that compares old and new ID arrays, strips unchanged leading/trailing segments, and returns a {from, to} move object for the single displaced item or null if no move occurred.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: implementing reorder functionality for invoice items, which matches the core purpose of the changeset.
Linked Issues check ✅ Passed The PR implements drag-and-drop reordering for invoice items [#71] via motion library's Reorder components and includes a drag handle icon, addressing the primary feature request.
Out of Scope Changes check ✅ Passed All changes are focused on implementing drag-and-drop reordering for invoice items in the invoice-items-section.tsx file, directly aligned with the PR objective and linked issue #71.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly explains the drag-and-drop reordering functionality added to invoice items, including the use of motion library components, the drag handle icon, and the reorder logic implementation.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/web/src/app/(dashboard)/create/invoice/invoiceHelpers/invoice-items-section.tsx (1)

127-139: ⚡ Quick win

Move getSingleMove into the helper section and declare it with function.

This is a pure helper, so it should follow the repo convention instead of being a const arrow placed between InvoiceItemsSection and HandleItemModal.

As per coding guidelines, **/*.{ts,tsx,js,jsx}: Structure files: exported component, subcomponents, helpers, static content, typesandUse the 'function' keyword for pure functions`.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e723c01-8f22-4a7c-9a0a-b38af880f268

📥 Commits

Reviewing files that changed from the base of the PR and between c4fc5d4 and dd5add0.

📒 Files selected for processing (1)
  • apps/web/src/app/(dashboard)/create/invoice/invoiceHelpers/invoice-items-section.tsx

Comment on lines +50 to +65
<Reorder.Group
axis="y"
values={fields.map((field) => field.id)}
onReorder={onReorder}
className="flex flex-col gap-2"
>
{fields.map((field, index) => (
<div className="bg-muted/50 flex w-full flex-row justify-between gap-2 rounded-md p-3" key={field.id}>
<Reorder.Item
value={field.id}
key={field.id}
className="bg-muted/50 flex w-full cursor-grab flex-row justify-between gap-2 rounded-md p-3 active:cursor-grabbing"
>
<div className="flex w-full flex-row gap-2">
<div className="text-muted-foreground grid h-full place-items-center">
<GripVerticalIcon className="size-4" />
</div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add a keyboard-accessible reorder path.

This makes reordering pointer-only: the rows are not focusable reorder controls, the grip is only visual, and there are no move buttons. Keyboard users can't complete the reorder task from this UI.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds drag-and-drop reordering for invoice line items in the invoice creation flow (closes #71) by integrating motion/react’s Reorder components into the invoice items list UI.

Changes:

  • Wrapped the invoice items list in Reorder.Group and each row in Reorder.Item to enable drag-and-drop ordering.
  • Added a visual drag handle icon (GripVerticalIcon) per item.
  • Introduced getSingleMove to translate motion’s reordered id list into a single react-hook-form useFieldArray.move() operation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +57 to +65
<Reorder.Item
value={field.id}
key={field.id}
className="bg-muted/50 flex w-full cursor-grab flex-row justify-between gap-2 rounded-md p-3 active:cursor-grabbing"
>
<div className="flex w-full flex-row gap-2">
<div className="text-muted-foreground grid h-full place-items-center">
<GripVerticalIcon className="size-4" />
</div>
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.

[Feature Request] Reorder Invoice Items

2 participants