Skip to content

Comments

Feature/client side pdf generation#658

Open
speixoto12 wants to merge 2 commits intoal1abb:masterfrom
speixoto12:feature/client-side-pdf-generation
Open

Feature/client side pdf generation#658
speixoto12 wants to merge 2 commits intoal1abb:masterfrom
speixoto12:feature/client-side-pdf-generation

Conversation

@speixoto12
Copy link

@speixoto12 speixoto12 commented Mar 31, 2025

This Pull Request aims to implement #603:

  • Added a function to the Invoice Context to print the PDF immediately based on @dragonman225 suggestion
  • Replaced Generate PDF Button logic with a call to this previous function avoiding a trip to the server

Summary by CodeRabbit

  • New Features
    • Enhanced invoice PDF generation that allows users to print invoices immediately through a streamlined action.
    • Improved error notifications during printing, ensuring users receive clear feedback if an issue occurs.

@vercel
Copy link

vercel bot commented Mar 31, 2025

@speixoto12 is attempting to deploy a commit to the al1abb-team Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Mar 31, 2025

Walkthrough

The changes introduce new imports and update component logic in the invoice actions component, integrating the form submission process with PDF printing. In the invoice context, a new method for immediate and private PDF printing is added, utilizing server-side rendering for an invoice template and handling potential popup errors. Additionally, a new toast function for printing errors is included in the toast hooks, and overall, code formatting adjustments have been made for improved readability.

Changes

File(s) Change Summary
app/components/invoice/InvoiceActions.tsx Added new imports (useFormContext, InvoiceType); reformatted component structure; attached an onClick handler to the PDF generation button to invoke handleSubmit(printPdfImmediatelyAndPrivately).
contexts/InvoiceContext.tsx Introduced the printPdfImmediatelyAndPrivately method for immediate and private PDF printing; updated context defaults and provider with error handling (including timeout management and popup block detection).
hooks/useToasts.tsx Reformatted type declarations and functions for consistency; added printPdfImmediatelyAndPrivatelyError to display toast notifications for printing errors.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InvoiceActions
    participant InvoiceContext
    participant Toasts

    User->>InvoiceActions: Click "Generate PDF" button
    InvoiceActions->>InvoiceContext: Execute handleSubmit(printPdfImmediatelyAndPrivately)
    InvoiceContext->>InvoiceContext: Render invoice HTML using ReactDOMServer
    InvoiceContext->>InvoiceContext: Open new window for printing
    alt Popup blocked or error occurs
        InvoiceContext->>Toasts: Invoke printPdfImmediatelyAndPrivatelyError(error)
    end
Loading

Poem

I'm a little rabbit, code in my paw,
Hopping through changes without a flaw.
A button clicked, a PDF on the run,
Invoices now printed with a dash of fun.
If errors arise, a toast lights the night,
My code hops forward, keeping things bright!

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 0

🧹 Nitpick comments (1)
hooks/useToasts.tsx (1)

68-74: Minor grammar issue in error description.
The toast message says: "Something went importing the invoice." Consider adding "wrong" to clarify.

- description: "Something went importing the invoice. Make sure the file is a valid Invoify JSON export",
+ description: "Something went wrong importing the invoice. Make sure the file is a valid Invoify JSON export",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe9c976 and f31e186.

📒 Files selected for processing (3)
  • app/components/invoice/InvoiceActions.tsx (2 hunks)
  • contexts/InvoiceContext.tsx (8 hunks)
  • hooks/useToasts.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/components/invoice/InvoiceActions.tsx (1)
contexts/InvoiceContext.tsx (1)
  • useInvoiceContext (58-60)
🔇 Additional comments (34)
hooks/useToasts.tsx (9)

6-9: Revised type declaration looks good.
No issues found with the updated SendErrorType.


11-17: Toast for creating a new invoice is correct.
The toast message logic is consistent with other notifications.


19-26: Toast for PDF generation success is consistent.
No concerns regarding the messaging or variant.


28-34: Toast for saving an invoice is well-structured.
Everything looks fine here.


36-42: Toast for modifying an invoice is correct.
No additional feedback needed.


44-50: Toast for sending PDF succeeded.
The user-friendly message and variant usage are appropriate.


52-66: Toast for sending PDF error is well-implemented.
The retry mechanism with onClick={() => sendPdfToMail(email)} is a thoughtful addition.


76-82: New error toast for printing PDFs is a welcome addition.
Good usage of the destructive variant for error handling.


84-93: Return statement cleanly exports all toast handlers.
No objections; the structure is consistent and comprehensive.

contexts/InvoiceContext.tsx (13)

4-9: Imports for React utilities are correct.
No issues; these hooks and methods are standard.


25-29: Additional variable imports align with usage.
Everything looks consistent with the rest of the codebase.


34-34: Importing getInvoiceTemplate is consistent.
Adequate for dynamic template retrieval.


37-53: Default context object looks good.
Including printPdfImmediatelyAndPrivately ensures the method is part of the context contract.


59-59: useInvoiceContext reference is fine.
This is an expected pattern for context consumption.


63-64: Provider props definition is correct.
This minimal interface covers the children node.


68-68: InvoiceContextProvider structure is standard.
No issues with the functional component approach.


80-80: Integration of printPdfImmediatelyAndPrivatelyError from toasts.
This ensures user-facing error feedback for print failures.


97-98: Local storage retrieval of saved invoices.
No concerns; the approach is straightforward.


250-251: Invoice number comparison for existing invoices.
Logic is simple and direct; no issues detected.


270-273: Local storage update for saved invoices.
Implementation is correct and consistent with the rest of the code.


380-463: Implementation of printPdfImmediatelyAndPrivately is robust.
The window-handling logic, fallback timeouts, and error catching appear solid. Great to see multi-tiered protection against pop-up or rendering issues.


485-485: Added method to provider’s value is appropriate.
Ensures all consuming components can invoke it as needed.

app/components/invoice/InvoiceActions.tsx (12)

5-9: Card UI imports look correct.
No potential naming collisions or usage issues.


13-18: Additional component imports are consistent.
They match usage in the JSX below.


26-27: useFormContext and InvoiceType imports.
These match the subsequent usage of handleSubmit and typed form data.


30-30: Context destructuring for immediate PDF printing.
Clean approach to retrieve printPdfImmediatelyAndPrivately and invoicePdfLoading.


32-32: Destructuring handleSubmit from react-hook-form.
Ensures the button triggers the correct form submission logic.


34-34: Translation context usage is proper.
No concerns; _t usage is consistent.


36-55: Card layout is well-structured.
These lines effectively present UI content without duplications.


58-67: Export modal button is integrated correctly.
Disables itself when invoicePdfLoading is true, which is good for user feedback.


70-81: New invoice logic in the button is sound.
No concurrency or duplication issues identified.


84-95: Generate PDF button triggers form submit to immediate print.
Practical approach for seamlessly generating and printing.


96-101: PDF viewer integration is correct.
Offers a preview area that complements the new printing flow.


102-103: Overall return structure finalizes with Card layout.
Layout is logically consistent.

@vercel
Copy link

vercel bot commented Apr 1, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
invoify ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 1, 2025 5:50pm

@coderabbitai
Copy link

coderabbitai bot commented Apr 2, 2025

Warning

Docstrings generation is only available on the Pro tier.

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.

1 participant