-
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
13 changed files
with
267 additions
and
14 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
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,68 @@ | ||
import { Container, Stack, Typography, Card, CardContent } 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 { getTopupHistory } from "../api"; | ||
import { TopupHistoryDetails } from "../types/topup"; | ||
|
||
export default function StudentTopupPage() { | ||
const navigate = useNavigate(); | ||
const { user } = useContext(UserContext); | ||
const [topupDetails, setTopupDetails] = useState< | ||
TopupHistoryDetails[] | null | ||
>(null); | ||
|
||
useEffect(() => { | ||
if (user === undefined) { | ||
return; | ||
} else if (user === null) { | ||
return navigate("/"); | ||
} else if (user.type === UserType.STUDENT) { | ||
getTopupHistory().then(setTopupDetails); | ||
return; | ||
} else if (user.type === UserType.ADMIN) { | ||
navigate("/admin"); | ||
} else if (user.type === UserType.BOOTH) { | ||
navigate("/booth"); | ||
} | ||
}, [user]); | ||
|
||
if (!user || !topupDetails) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<Container maxWidth="sm"> | ||
<Header /> | ||
<Stack | ||
direction="column" | ||
spacing={3} | ||
sx={{ | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography variant="body1">Topup History</Typography> | ||
{topupDetails.length > 0 ? ( | ||
topupDetails.map((topup, idx) => ( | ||
<Card variant="outlined" key={idx}> | ||
<CardContent> | ||
<Typography variant="h6"> | ||
{new Decimal(topup.amount).toFixed(2)} | ||
</Typography> | ||
<Typography variant="body1"> | ||
Lucky draw code: {topup.lucky_draw_code} | ||
</Typography> | ||
</CardContent> | ||
</Card> | ||
)) | ||
) : ( | ||
<Typography variant="body2">No topups 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Container, Stack, Typography, Card, CardContent } 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 { getTransactionHistory } from "../api"; | ||
|
||
export default function StudentTransactionPage() { | ||
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) { | ||
getTransactionHistory().then(setTransactionDetails); | ||
return; | ||
} else if (user.type === UserType.ADMIN) { | ||
navigate("/admin"); | ||
} else if (user.type === UserType.BOOTH) { | ||
navigate("/booth"); | ||
} | ||
}, [user]); | ||
|
||
if (!user || !transactionDetails) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<Container maxWidth="sm"> | ||
<Header /> | ||
<Stack | ||
direction="column" | ||
spacing={3} | ||
sx={{ | ||
justifyContent: "center", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Typography variant="body1">Transaction History</Typography> | ||
{transactionDetails.length > 0 ? ( | ||
transactionDetails.map((transaction, idx) => ( | ||
<Card variant="outlined" key={idx}> | ||
<CardContent> | ||
<Typography variant="h6"> | ||
{new Decimal(transaction.amount).toFixed(2)} | ||
</Typography> | ||
<Typography variant="body1">To {transaction.name}</Typography> | ||
<Typography variant="body1"> | ||
Timestamp: {transaction.completed_timestamp.toLocaleString()} | ||
</Typography> | ||
</CardContent> | ||
</Card> | ||
)) | ||
) : ( | ||
<Typography variant="body2">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
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
Oops, something went wrong.