Skip to content

Commit eed7085

Browse files
authored
feat: autofill user name and email if they're logged in in invoiceme (#136)
1 parent 2a06d48 commit eed7085

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/components/invoice-creator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ export function InvoiceCreator({
8181
defaultValues: {
8282
invoiceNumber: generateInvoiceNumber(invoiceCount),
8383
dueDate: "",
84-
creatorName: !isInvoiceMe ? (currentUser?.name ?? "") : "",
85-
creatorEmail: !isInvoiceMe ? (currentUser?.email ?? "") : "",
84+
creatorName: currentUser?.name ?? "",
85+
creatorEmail: currentUser?.email ?? "",
8686
clientName: recipientDetails?.clientName ?? "",
8787
clientEmail: recipientDetails?.clientEmail ?? "",
8888
invoicedTo: recipientDetails?.userId ?? "",

src/server/routers/invoice.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export const invoiceRouter = router({
148148
createFromInvoiceMe: publicProcedure
149149
.input(invoiceFormSchema)
150150
.mutation(async ({ ctx, input }) => {
151-
const { db } = ctx;
151+
const { db, session } = ctx;
152152

153153
if (!input.invoicedTo) {
154154
throw new TRPCError({
@@ -177,7 +177,7 @@ export const invoiceRouter = router({
177177
{
178178
...input,
179179
},
180-
input.invoicedTo as string,
180+
session?.userId || (input?.invoicedTo as string),
181181
);
182182
});
183183
} catch (error) {

0 commit comments

Comments
 (0)