-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add crude transaction-overview for admins
- Loading branch information
Showing
5 changed files
with
187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { RouterOutputs } from "~/utils/api" | ||
|
||
import { localStringOptions } from "~/helper/globalTypes" | ||
|
||
type TransactionData = RouterOutputs["transaction"]["getAllInfinite"]["items"] | ||
type Props = { | ||
transactions: TransactionData | undefined | ||
} | ||
const TransactionList = (props: Props) => { | ||
const Legend = () => ( | ||
<tr> | ||
<th>Transaction</th> | ||
<td>Type</td> | ||
<td>Amount (€)</td> | ||
<td>User (auführend)</td> | ||
<td>Ziel</td> | ||
<td>Verrechnungskonto</td> | ||
</tr> | ||
) | ||
|
||
if (props.transactions === undefined) { | ||
return ( | ||
<> | ||
<span className="loading loading-spinner loading-lg m-6"></span> | ||
</> | ||
) | ||
} else { | ||
return ( | ||
<> | ||
<div className="w-dvw max-w-5xl flex-col md:px-5"> | ||
<div className="mr-2 grow flex-row items-center justify-center overflow-x-auto"> | ||
<table className="table"> | ||
{/* head */} | ||
<thead> | ||
<Legend /> | ||
</thead> | ||
<tbody> | ||
{props.transactions.map((row) => ( | ||
<tr key={row.id} className={`${row.canceled ? "line-through" : ""}`}> | ||
<td> | ||
<div className="flex flex-col"> | ||
<p>{row.createdAt.toLocaleString("de", localStringOptions)}</p> | ||
<p className="text-xs font-extralight">{row.id}</p> | ||
{row.canceledBy && ( | ||
<p className="text-red-500 no-underline"> | ||
canceled by {row.canceledBy.name} | ||
</p> | ||
)} | ||
</div> | ||
</td> | ||
<td>{row.type}</td> | ||
<td> | ||
{row.totalAmount?.toFixed(2)}{" "} | ||
{!!row.amountWithoutFees && "(" + row.amountWithoutFees?.toFixed(2) + ")"} | ||
</td> | ||
<td>{row.user.name}</td> | ||
<td>{row.moneyDestination?.name}</td> | ||
<td>{row.clearingAccount?.name}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
<tfoot> | ||
<Legend /> | ||
</tfoot> | ||
</table> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} | ||
} | ||
|
||
export default TransactionList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useEffect, useState } from "react" | ||
import CenteredPage from "~/components/Layout/CenteredPage" | ||
import TransactionList from "~/components/PageComponents/TransactionList" | ||
import { api } from "~/utils/api" | ||
|
||
const AdminTransactionPage = () => { | ||
const [page, setPage] = useState(0) | ||
const [maxPage, setMaxPage] = useState(Infinity) | ||
|
||
const { | ||
data: transactionData, | ||
fetchNextPage, | ||
hasNextPage, | ||
} = api.transaction.getAllInfinite.useInfiniteQuery( | ||
{}, | ||
{ | ||
keepPreviousData: true, | ||
getNextPageParam: (lastPage) => { | ||
if (lastPage.nextPageExists) { | ||
return lastPage.pageNumber + 1 | ||
} else { | ||
return undefined | ||
} | ||
}, | ||
}, | ||
) | ||
|
||
useEffect(() => { | ||
if (!hasNextPage) { | ||
setMaxPage(page) | ||
} else { | ||
setMaxPage(Infinity) | ||
} | ||
}, [setMaxPage, hasNextPage]) | ||
|
||
useEffect(() => { | ||
if (!hasNextPage) { | ||
setMaxPage(page) | ||
} else { | ||
setMaxPage(Infinity) | ||
} | ||
}, [setMaxPage, hasNextPage]) | ||
|
||
return ( | ||
<CenteredPage> | ||
<TransactionList transactions={transactionData?.pages[page]?.items} /> | ||
|
||
<div className="join mt-2"> | ||
<button | ||
className={`btn join-item ${page < 1 ? "btn-disabled" : ""}`} | ||
onClick={() => setPage((prev) => prev - 1)} | ||
> | ||
« | ||
</button> | ||
<button className="btn join-item pointer-events-none">Seite {page + 1}</button> | ||
<button | ||
className={`btn join-item ${page >= maxPage ? "btn-disabled" : ""}`} | ||
onClick={() => { | ||
void fetchNextPage() | ||
setPage((prev) => prev + 1) | ||
return | ||
}} | ||
> | ||
» | ||
</button> | ||
</div> | ||
</CenteredPage> | ||
) | ||
} | ||
|
||
export default AdminTransactionPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters