Skip to content

Conversation

@aimensahnoun
Copy link
Member

@aimensahnoun aimensahnoun commented Aug 28, 2025

Problem

If a user is logged in and trying to create an invoice in InvoiceMe link they have to fill in the name and email manually

Solution:

Autofill the information automatically

CleanShot 2025-08-28 at 13 05 21

Summary by CodeRabbit

  • Improvements

    • Creator name and email now auto-fill from your profile across all invoice creation flows, reducing manual entry.
  • Bug Fixes

    • Invoices created via “Invoice Me” now correctly associate with your logged-in account when available, while still targeting the chosen recipient.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Walkthrough

Front end now always pre-fills creatorName and creatorEmail from currentUser when available. Backend createFromInvoiceMe mutation uses session.userId when present, falling back to input.invoicedTo for the invoice userId. No API signatures changed; other flows remain the same.

Changes

Cohort / File(s) Summary of changes
Invoice creator defaults
src/components/invoice-creator.tsx
Default form values for creatorName and creatorEmail now unconditionally use currentUser?.name and currentUser?.email (fallback to empty string), instead of only when !isInvoiceMe. No other logic altered.
Invoice creation routing
src/server/routers/invoice.ts
In createFromInvoiceMe, destructures session from ctx and passes `session?.userId

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant C as InvoiceCreator (UI)
  participant R as invoice router (server)
  participant DB as Database

  U->>C: Open invoice form
  Note right of C: Prefill creatorName/email from currentUser if available
  U->>C: Submit "Create From Invoice Me"
  C->>R: createFromInvoiceMe(input with invoicedTo,...)
  alt Session available
    R->>R: userId = session.userId
  else No session
    R->>R: userId = input.invoicedTo
  end
  R->>DB: createInvoice(userId, invoicedTo, ...)
  DB-->>R: Invoice record
  R-->>C: Result
  C-->>U: Show creation result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • fix: bugs #126 — Also touches src/components/invoice-creator.tsx, adjusting mutation handling and onSuccess logic; interacts with how currentUser is supplied/used.

Suggested reviewers

  • MantisClone
  • bassgeta
  • rodrigopavezi

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/auto-fill-invoice-me

🪧 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.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit 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:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/components/invoice-creator.tsx (1)

84-86: Autofill won’t update if currentUser arrives after mount

react-hook-form only applies defaultValues on first render. If currentUser is fetched async, creator fields stay empty. Set them when currentUser changes (and avoid clobbering user edits).

Apply:

+import { useEffect } from "react";
...
   const form = useForm<InvoiceFormValues>({
     resolver: zodResolver(invoiceFormSchema),
     defaultValues: {
       invoiceNumber: generateInvoiceNumber(invoiceCount),
       dueDate: "",
       creatorName: currentUser?.name ?? "",
       creatorEmail: currentUser?.email ?? "",
       clientName: recipientDetails?.clientName ?? "",
...
     },
   });
+
+  useEffect(() => {
+    if (!currentUser) return;
+    const cn = form.getValues("creatorName");
+    const ce = form.getValues("creatorEmail");
+    if (!cn) form.setValue("creatorName", currentUser.name ?? "");
+    if (!ce) form.setValue("creatorEmail", currentUser.email ?? "");
+  }, [currentUser, form]);

Also verify invoiceFormSchema: if creatorName/creatorEmail are required non-empty, empty-string defaults will fail for anonymous InvoiceMe. Confirm UX is acceptable or make these conditionally optional in that flow.

src/server/routers/invoice.ts (2)

151-151: Context consistency: use user across procedures or type session on public context

Public ctx now destructures session. Elsewhere you use user. Ensure session is part of ctx typing for publicProcedure and consider normalizing to user for consistency.

Would you like a follow-up PR to align ctx shape and update typings?


174-181: Outdated comment + unnecessary type assertion; rely on prior guard

The comment says userId == invoicedTo, but you now prefer session user. Also (input?.invoicedTo as string) isn’t needed after the non-empty guard above.

Apply:

-          // For invoice-me, the userId is the same as invoicedTo
+          // For invoice-me, prefer the logged-in user as owner; fall back to invoicedTo for anonymous creators
           return createInvoiceHelper(
             tx,
             {
               ...input,
             },
-            session?.userId || (input?.invoicedTo as string),
+            session?.userId ?? input.invoicedTo,
           );

Add tests for both paths (with/without session) to assert invoice.userId ownership and that invoicedTo remains the recipient.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2a06d48 and 0c23ce1.

📒 Files selected for processing (2)
  • src/components/invoice-creator.tsx (1 hunks)
  • src/server/routers/invoice.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-19T13:00:48.790Z
Learnt from: rodrigopavezi
PR: RequestNetwork/easy-invoice#45
File: src/components/invoice-form.tsx:316-319
Timestamp: 2025-05-19T13:00:48.790Z
Learning: The handleFormSubmit function in src/components/invoice-form.tsx correctly uses data.clientEmail from the form submission data to find matching payers, which is the proper implementation.

Applied to files:

  • src/components/invoice-creator.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build

@aimensahnoun aimensahnoun enabled auto-merge (squash) August 28, 2025 09:14
Copy link
Contributor

@bassgeta bassgeta left a comment

Choose a reason for hiding this comment

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

Nice and simple 👌
image
Prefilled my email as intended, 🚢

@aimensahnoun aimensahnoun merged commit eed7085 into main Sep 1, 2025
9 checks passed
@aimensahnoun aimensahnoun deleted the fix/auto-fill-invoice-me branch September 1, 2025 08:52
@github-project-automation github-project-automation bot moved this from 👀 In Review to ✅ Done in Request Network Tech Backlog Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants