fix: sort chronologically
This commit is contained in:
@@ -17,7 +17,13 @@ export async function GET(
|
||||
with: {
|
||||
client: true,
|
||||
business: true,
|
||||
items: { orderBy: (i, { asc }) => [asc(i.position)] },
|
||||
items: {
|
||||
orderBy: (i, { asc }) => [
|
||||
asc(i.date),
|
||||
asc(i.position),
|
||||
asc(i.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -320,6 +320,7 @@ export function InvoicesDataTable({ invoices }: InvoicesDataTableProps) {
|
||||
data={invoices}
|
||||
searchKey="invoiceNumber"
|
||||
searchPlaceholder="Search invoices..."
|
||||
initialSorting={[{ id: "issueDate", desc: true }]}
|
||||
filterableColumns={filterableColumns}
|
||||
onRowClick={(invoice) =>
|
||||
router.push(`/dashboard/invoices/${invoice.id}`)
|
||||
|
||||
@@ -86,6 +86,7 @@ interface DataTableProps<TData, TValue> {
|
||||
selectedRows: TData[],
|
||||
clearSelection: () => void,
|
||||
) => React.ReactNode;
|
||||
initialSorting?: SortingState;
|
||||
}
|
||||
|
||||
export function DataTable<TData, TValue>({
|
||||
@@ -104,8 +105,9 @@ export function DataTable<TData, TValue>({
|
||||
filterableColumns = [],
|
||||
onRowClick,
|
||||
selectionActions,
|
||||
initialSorting = [],
|
||||
}: DataTableProps<TData, TValue>) {
|
||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
||||
const [sorting, setSorting] = React.useState<SortingState>(initialSorting);
|
||||
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
||||
[],
|
||||
);
|
||||
|
||||
@@ -74,7 +74,11 @@ export const clientsRouter = createTRPCRouter({
|
||||
where: eq(clients.id, input.id),
|
||||
with: {
|
||||
invoices: {
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.createdAt)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -105,7 +105,11 @@ export const dashboardRouter = createTRPCRouter({
|
||||
// Recent Activity
|
||||
const recentInvoices = await ctx.db.query.invoices.findMany({
|
||||
where: eq(invoices.createdById, userId),
|
||||
orderBy: [desc(invoices.issueDate)],
|
||||
orderBy: [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
limit: 5,
|
||||
with: {
|
||||
client: {
|
||||
|
||||
@@ -132,9 +132,19 @@ export const invoicesRouter = createTRPCRouter({
|
||||
with: {
|
||||
business: true,
|
||||
client: true,
|
||||
items: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.issueDate)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
throw new TRPCError({
|
||||
@@ -188,10 +198,18 @@ export const invoicesRouter = createTRPCRouter({
|
||||
business: true,
|
||||
client: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [desc(invoices.createdAt)],
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
// Return null if no draft invoice exists
|
||||
@@ -219,7 +237,11 @@ export const invoicesRouter = createTRPCRouter({
|
||||
business: true,
|
||||
client: true,
|
||||
items: {
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -684,7 +706,17 @@ export const invoicesRouter = createTRPCRouter({
|
||||
.query(async ({ ctx, input }) => {
|
||||
const invoice = await ctx.db.query.invoices.findFirst({
|
||||
where: eq(invoices.publicToken, input.token),
|
||||
with: { client: true, business: true, items: { orderBy: (i, { asc }) => [asc(i.position)] } },
|
||||
with: {
|
||||
client: true,
|
||||
business: true,
|
||||
items: {
|
||||
orderBy: (i, { asc }) => [
|
||||
asc(i.date),
|
||||
asc(i.position),
|
||||
asc(i.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!invoice) throw new TRPCError({ code: "NOT_FOUND" });
|
||||
if (invoice.publicTokenExpiresAt && new Date(invoice.publicTokenExpiresAt) < new Date()) {
|
||||
|
||||
@@ -541,9 +541,18 @@ export const settingsRouter = createTRPCRouter({
|
||||
amount: true,
|
||||
position: true,
|
||||
},
|
||||
orderBy: (items, { asc }) => [asc(items.position)],
|
||||
orderBy: (items, { asc }) => [
|
||||
asc(items.date),
|
||||
asc(items.position),
|
||||
asc(items.createdAt),
|
||||
],
|
||||
},
|
||||
},
|
||||
orderBy: (invoices, { desc }) => [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
// Format the data for export
|
||||
|
||||
@@ -83,7 +83,11 @@ async function addEntryToLatestInvoice(
|
||||
or(eq(invoices.status, "draft"), eq(invoices.status, "sent")),
|
||||
),
|
||||
with: { items: true },
|
||||
orderBy: [desc(invoices.createdAt)],
|
||||
orderBy: [
|
||||
desc(invoices.issueDate),
|
||||
desc(invoices.dueDate),
|
||||
desc(invoices.invoiceNumber),
|
||||
],
|
||||
});
|
||||
|
||||
if (!invoice) return null;
|
||||
|
||||
Reference in New Issue
Block a user