fix: sort table

This commit is contained in:
Ephraim Atta-Duncan
2024-09-19 14:07:13 +00:00
parent 894e857826
commit 087d8bf150
6 changed files with 94 additions and 30 deletions

View File

@ -12,12 +12,16 @@ export type GetSigningVolumeOptions = {
search?: string;
page?: number;
perPage?: number;
sortBy?: 'name' | 'createdAt' | 'signingVolume';
sortOrder?: 'asc' | 'desc';
};
export async function getSigningVolume({
search = '',
page = 1,
perPage = 10,
sortBy = 'signingVolume',
sortOrder = 'desc',
}: GetSigningVolumeOptions) {
const whereClause = Prisma.validator<Prisma.SubscriptionWhereInput>()({
status: 'ACTIVE',
@ -38,6 +42,8 @@ export async function getSigningVolume({
],
});
const orderBy = getOrderByClause({ sortBy, sortOrder });
const [subscriptions, totalCount] = await Promise.all([
prisma.subscription.findMany({
where: whereClause,
@ -76,15 +82,7 @@ export async function getSigningVolume({
},
},
},
orderBy: [
{
User: {
Document: {
_count: 'desc',
},
},
},
],
orderBy,
skip: Math.max(page - 1, 0) * perPage,
take: perPage,
}),
@ -112,3 +110,34 @@ export async function getSigningVolume({
totalPages: Math.ceil(totalCount / perPage),
};
}
type GetOrderByClauseOptions = {
sortBy: string;
sortOrder: 'asc' | 'desc';
};
const getOrderByClause = ({ sortBy, sortOrder }: GetOrderByClauseOptions) => {
switch (sortBy) {
case 'name':
return [{ User: { name: sortOrder } }, { team: { name: sortOrder } }];
case 'createdAt':
return { createdAt: sortOrder };
default:
return [
{
User: {
Document: {
_count: sortOrder,
},
},
},
{
team: {
document: {
_count: sortOrder,
},
},
},
];
}
};

View File

@ -961,7 +961,7 @@ msgid "Create your account and start using state-of-the-art document signing. Op
msgstr ""
#: apps/web/src/app/(dashboard)/admin/documents/document-results.tsx:62
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:85
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:89
#: apps/web/src/app/(dashboard)/documents/[id]/document-page-view-information.tsx:35
#: apps/web/src/app/(dashboard)/documents/data-table.tsx:54
#: apps/web/src/app/(dashboard)/settings/security/passkeys/user-passkeys-data-table.tsx:65
@ -1989,7 +1989,7 @@ msgid "My templates"
msgstr ""
#: apps/web/src/app/(dashboard)/admin/documents/[id]/recipient-item.tsx:148
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:57
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:61
#: apps/web/src/app/(dashboard)/admin/users/[id]/page.tsx:99
#: apps/web/src/app/(dashboard)/admin/users/data-table-users.tsx:66
#: apps/web/src/app/(dashboard)/settings/security/passkeys/user-passkeys-data-table-actions.tsx:144
@ -2594,7 +2594,7 @@ msgstr ""
msgid "Search by document title"
msgstr ""
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:125
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:141
#: apps/web/src/app/(dashboard)/admin/users/data-table-users.tsx:144
msgid "Search by name or email"
msgstr ""
@ -2816,8 +2816,8 @@ msgstr ""
msgid "Signing up..."
msgstr ""
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:71
#: apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx:37
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:75
#: apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx:46
msgid "Signing Volume"
msgstr ""

View File

@ -956,7 +956,7 @@ msgid "Create your account and start using state-of-the-art document signing. Op
msgstr "Create your account and start using state-of-the-art document signing. Open and beautiful signing is within your grasp."
#: apps/web/src/app/(dashboard)/admin/documents/document-results.tsx:62
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:85
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:89
#: apps/web/src/app/(dashboard)/documents/[id]/document-page-view-information.tsx:35
#: apps/web/src/app/(dashboard)/documents/data-table.tsx:54
#: apps/web/src/app/(dashboard)/settings/security/passkeys/user-passkeys-data-table.tsx:65
@ -2007,7 +2007,7 @@ msgid "My templates"
msgstr "My templates"
#: apps/web/src/app/(dashboard)/admin/documents/[id]/recipient-item.tsx:148
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:57
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:61
#: apps/web/src/app/(dashboard)/admin/users/[id]/page.tsx:99
#: apps/web/src/app/(dashboard)/admin/users/data-table-users.tsx:66
#: apps/web/src/app/(dashboard)/settings/security/passkeys/user-passkeys-data-table-actions.tsx:144
@ -2612,7 +2612,7 @@ msgstr "Search"
msgid "Search by document title"
msgstr "Search by document title"
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:125
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:141
#: apps/web/src/app/(dashboard)/admin/users/data-table-users.tsx:144
msgid "Search by name or email"
msgstr "Search by name or email"
@ -2838,8 +2838,8 @@ msgstr "Signing in..."
msgid "Signing up..."
msgstr "Signing up..."
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:71
#: apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx:37
#: apps/web/src/app/(dashboard)/admin/leaderboard/data-table-leaderboard.tsx:75
#: apps/web/src/app/(dashboard)/admin/leaderboard/page.tsx:46
msgid "Signing Volume"
msgstr "Signing Volume"