-
Notifications
You must be signed in to change notification settings - Fork 7
feat: autofill user name and email if they're logged in in invoiceme #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughFront 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
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 unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 mountreact-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: useuseracross procedures or typesessionon public contextPublic ctx now destructures
session. Elsewhere you useuser. Ensuresessionis part of ctx typing for publicProcedure and consider normalizing touserfor 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 guardThe 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.userIdownership and thatinvoicedToremains 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.
📒 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
bassgeta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

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
Summary by CodeRabbit
Improvements
Bug Fixes