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