From bf13e2fc120f596493720e5c29a7e48cc5fb749a Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sun, 7 Aug 2022 16:12:17 -0700 Subject: [PATCH] Add profit and balance to admin csv export --- web/pages/admin.tsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/web/pages/admin.tsx b/web/pages/admin.tsx index 81f23ba9..479faee3 100644 --- a/web/pages/admin.tsx +++ b/web/pages/admin.tsx @@ -32,12 +32,24 @@ function UsersTable() { // For each user, set their email from the PrivateUser const fullUsers = users .map((user) => { - return { email: privateUsersById[user.id]?.email, ...user } + return { + email: privateUsersById[user.id]?.email, + profit: user.profitCached.allTime, + ...user, + } }) .sort((a, b) => b.createdTime - a.createdTime) function exportCsv() { - const csv = fullUsers.map((u) => [u.email, u.name].join(', ')).join('\n') + const lines = [['Email', 'Name', 'Balance', 'Profit']].concat( + fullUsers.map((u) => [ + u.email ?? '', + u.name, + Math.round(u.balance).toString(), + Math.round(u.profitCached.allTime).toString(), + ]) + ) + const csv = lines.map((line) => line.join(', ')).join('\n') const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') @@ -90,6 +102,11 @@ function UsersTable() { name: 'Balance', formatter: (cell) => (cell as number).toFixed(0), }, + { + id: 'profit', + name: 'profit', + formatter: (cell) => (cell as number).toFixed(0), + }, { id: 'id', name: 'ID',