-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
4 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
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,89 @@ | ||
import { | ||
Container, | ||
Stack, | ||
Typography, | ||
Card, | ||
CardContent, | ||
Button, | ||
} from "@mui/material"; | ||
import { useNavigate } from "react-router-dom"; | ||
import Header from "../components/header"; | ||
import { useContext, useEffect, useState } from "react"; | ||
import { UserType } from "../types/user"; | ||
import Decimal from "decimal.js"; | ||
import { UserContext } from "../UserProvider"; | ||
import { TransactionHistoryDetails } from "../types/transaction"; | ||
import { getTransactionHistoryBooth } from "../api"; | ||
|
||
export default function BoothTransactionHistoryPage() { | ||
const navigate = useNavigate(); | ||
const { user } = useContext(UserContext); | ||
const [transactionDetails, setTransactionDetails] = useState< | ||
TransactionHistoryDetails[] | null | ||
>(null); | ||
|
||
useEffect(() => { | ||
if (user === undefined) { | ||
return; | ||
} else if (user === null) { | ||
return navigate("/"); | ||
} else if (user.type === UserType.STUDENT) { | ||
navigate("/student"); | ||
} else if (user.type === UserType.ADMIN) { | ||
navigate("/admin"); | ||
} else if (user.type === UserType.BOOTH) { | ||
getTransactionHistoryBooth().then(setTransactionDetails); | ||
return; | ||
} | ||
}, [user]); | ||
|
||
if (!user || !transactionDetails) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<Container maxWidth="sm"> | ||
<Header /> | ||
<Stack | ||
direction="column" | ||
spacing={3} | ||
sx={{ | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Button | ||
variant="outlined" | ||
color="white" | ||
onClick={() => { | ||
navigate("/booth"); | ||
}} | ||
> | ||
Back | ||
</Button> | ||
<Typography variant="body1">Transaction History</Typography> | ||
{transactionDetails.length > 0 ? ( | ||
transactionDetails.map((transaction, idx) => ( | ||
<Card | ||
variant="outlined" | ||
key={idx} | ||
sx={{ width: "100%", borderColor: "#ffffff" }} | ||
> | ||
<CardContent> | ||
<Typography variant="h5"> | ||
${new Decimal(transaction.amount).toFixed(2)} | ||
</Typography> | ||
<Typography variant="body1">From {transaction.name}</Typography> | ||
<Typography variant="body1"> | ||
{transaction.completed_timestamp.toLocaleString()} | ||
</Typography> | ||
</CardContent> | ||
</Card> | ||
)) | ||
) : ( | ||
<Typography variant="italic1">No transactions yet</Typography> | ||
)} | ||
</Stack> | ||
</Container> | ||
); | ||
} |
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