next-learn
next-learn copied to clipboard
Fix invoices pagination ordering by adding time to the dates.
When multiple invoices share the same date, the list becomes unstable and starts repeating invoices from other pages. This PR adds the time to the invoice dates, allowing for better sorting of invoices created on the same day.
If this is accepted, the action in Chapter 7: Mutating Data will also need to be updated to include the time when creating a new invoice.
export async function createInvoice(formData: FormData) {
const { customerId, amount, status } = CreateInvoice.parse({
customerId: formData.get('customerId'),
amount: formData.get('amount'),
status: formData.get('status'),
});
const amountInCents = amount * 100;
- const date = new Date().toISOString().split('T')[0];
+ const date = new Date().toISOString().replace('T', ' ').slice(0, 19);
}
This problem was referenced in #531, but I don't know how to contribute to an already opened pull request 😅.
@RomanFausek gave great code suggestion in the other PR, thank you!