Conversation
| } | ||
| } | ||
|
|
||
| interface InvoiceData { |
There was a problem hiding this comment.
This is being created twice, just import it
|
|
||
| const [invoiceMode, setInvoiceMode] = useState<'create' | 'edit' | 'view'>('create') | ||
|
|
||
| const onCreateInvoice = async (transaction: any): Promise<void> => { |
There was a problem hiding this comment.
I don't like this any here. We do have types for transactions.
package.json
Outdated
| "jest": "^29.7.0", | ||
| "jest-mock-extended": "^2.0.6", | ||
| "lint-staged": "^12.4.1", | ||
| "lucide-react": "^0.510.0", |
There was a problem hiding this comment.
This does not seem necessary. We already have PNGs for what you are using, check the assets/ folder.
services/invoiceService.ts
Outdated
|
|
||
| export async function createInvoice (params: CreateInvoiceParams): Promise<Invoice> { | ||
| // const invoiceNumber = await getNewInvoiceNumber(params.userId); | ||
| console.log('params', params) |
utils/validators.ts
Outdated
| return { timezone: params.timezone } | ||
| } | ||
|
|
||
| export interface CreateinvoicePOSTParameters { |
There was a problem hiding this comment.
Wrong UpperCamelCase syntax
services/invoiceService.ts
Outdated
| return | ||
| } | ||
| } | ||
| const nextNumber = (invoiceWithTheLatestInvoiceNumber != null) ? parseInt(invoiceWithTheLatestInvoiceNumber.invoiceNumber.split('-')[1]) + 1 : 1 |
There was a problem hiding this comment.
If the user has created some invoice number like "2025-2Q" it would NaN here. After checking the regex above it would be safe tho
services/invoiceService.ts
Outdated
| } | ||
|
|
||
| export async function createInvoice (params: CreateInvoiceParams): Promise<Invoice> { | ||
| // const invoiceNumber = await getNewInvoiceNumber(params.userId); |
services/invoiceService.ts
Outdated
| }) | ||
| } | ||
|
|
||
| export async function getInvoices (userId: string): Promise<Invoice[]> { |
There was a problem hiding this comment.
too generic name. getUserInvoices, for example, would be better
services/invoiceService.ts
Outdated
| const invoicesWithOurPattern = userInvoices.filter(invoice => defaultPattern.test(invoice.invoiceNumber)) | ||
|
|
||
| if (invoicesWithOurPattern === null) { | ||
| const invoicesCount = await prisma.invoice.count({ |
There was a problem hiding this comment.
invoicesCount should be userInvoices.length, no need to access the DB again if you already have that information
services/invoiceService.ts
Outdated
| userId | ||
| } | ||
| }) | ||
| if (invoicesCount > 0) { |
There was a problem hiding this comment.
The logic here is not considering the case where invoicesWithOurPattern.length < userInvoices.length, which in this case (userInvoices.length > 0) should return null.
services/invoiceService.ts
Outdated
| const invoicesWithOurPattern = userInvoices.filter(invoice => defaultPattern.test(invoice.invoiceNumber)) | ||
|
|
||
| if (invoicesWithOurPattern === null || invoicesWithOurPattern.length < userInvoices.length) { | ||
| if (userInvoices.length > 0) { |
There was a problem hiding this comment.
This is redundant. This is inside the condition of userInvoices.length being strictly greater than invoicesWithOurPattern.length, which is a non-negative number, so userInvoices.length > 0 is already given.
| export interface InvoiceData { | ||
| id?: string | ||
| invoiceNumber: string | ||
| amount: number |
There was a problem hiding this comment.
Not a good idea to use number here, can get messy with float imprecision. Best to stick to Prisma.Decimal
Remember to change this also in the other interfaces you're creating.
Related to #528
Description
added actions column to transactions table in button details page.
Test plan
Test creating a new invoice, visualize it, try to edit the invoice.