mirror of
https://github.com/lemeow125/Borrowing-TrackerFrontend.git
synced 2024-11-17 06:19:27 +08:00
Refactor onClick function on transaction entry
This commit is contained in:
parent
f9b4729ee7
commit
e8864bc28c
3 changed files with 24 additions and 10 deletions
|
@ -5,8 +5,10 @@ import CircularProgress from "@mui/material/CircularProgress/CircularProgress";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import TransactionEntry from "../../TransactionEntry/TransactionEntry";
|
import TransactionEntry from "../../TransactionEntry/TransactionEntry";
|
||||||
import TransactionFilterMenu from "../TransactionFilterMenu";
|
import TransactionFilterMenu from "../TransactionFilterMenu";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function StudentTransactionListView() {
|
export default function StudentTransactionListView() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const transactions = useQuery({
|
const transactions = useQuery({
|
||||||
queryKey: ["transactions_student"],
|
queryKey: ["transactions_student"],
|
||||||
queryFn: TransactionsByStudentAPI,
|
queryFn: TransactionsByStudentAPI,
|
||||||
|
@ -54,7 +56,15 @@ export default function StudentTransactionListView() {
|
||||||
)
|
)
|
||||||
.map((transaction) => (
|
.map((transaction) => (
|
||||||
<React.Fragment key={transaction.id}>
|
<React.Fragment key={transaction.id}>
|
||||||
<TransactionEntry transaction={transaction} />
|
<TransactionEntry
|
||||||
|
onClick={() =>
|
||||||
|
navigate(`/view/transaction/${transaction.id}`, {
|
||||||
|
replace: true,
|
||||||
|
state: { id: transaction.id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
transaction={transaction}
|
||||||
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -5,8 +5,10 @@ import CircularProgress from "@mui/material/CircularProgress/CircularProgress";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import TransactionEntry from "../../TransactionEntry/TransactionEntry";
|
import TransactionEntry from "../../TransactionEntry/TransactionEntry";
|
||||||
import TransactionFilterMenu from "../TransactionFilterMenu";
|
import TransactionFilterMenu from "../TransactionFilterMenu";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
export default function TeacherTransactionListView() {
|
export default function TeacherTransactionListView() {
|
||||||
|
const navigate = useNavigate();
|
||||||
const transactions = useQuery({
|
const transactions = useQuery({
|
||||||
queryKey: ["transactions_teacher"],
|
queryKey: ["transactions_teacher"],
|
||||||
queryFn: TransactionsByTeacherAPI,
|
queryFn: TransactionsByTeacherAPI,
|
||||||
|
@ -54,7 +56,15 @@ export default function TeacherTransactionListView() {
|
||||||
)
|
)
|
||||||
.map((transaction) => (
|
.map((transaction) => (
|
||||||
<React.Fragment key={transaction.id}>
|
<React.Fragment key={transaction.id}>
|
||||||
<TransactionEntry transaction={transaction} />
|
<TransactionEntry
|
||||||
|
onClick={() =>
|
||||||
|
navigate(`/view/transaction/${transaction.id}`, {
|
||||||
|
replace: true,
|
||||||
|
state: { id: transaction.id },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
transaction={transaction}
|
||||||
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { colors } from "../../styles";
|
import { colors } from "../../styles";
|
||||||
import { TransactionType } from "../Types/Types";
|
import { TransactionType } from "../Types/Types";
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import StatusTextColor from "../StatusTextColor/StatusTextColor";
|
import StatusTextColor from "../StatusTextColor/StatusTextColor";
|
||||||
export interface props {
|
export interface props {
|
||||||
transaction: TransactionType;
|
transaction: TransactionType;
|
||||||
|
onClick?: React.MouseEventHandler<HTMLButtonElement>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TransactionEntry(props: props) {
|
export default function TransactionEntry(props: props) {
|
||||||
const navigate = useNavigate();
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
@ -20,12 +19,7 @@ export default function TransactionEntry(props: props) {
|
||||||
margin: "8px",
|
margin: "8px",
|
||||||
padding: "8px",
|
padding: "8px",
|
||||||
}}
|
}}
|
||||||
onClick={() =>
|
onClick={() => props.onClick}
|
||||||
navigate(`/view/transaction/${props.transaction.id}`, {
|
|
||||||
replace: true,
|
|
||||||
state: { id: props.transaction.id },
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<div style={styles.flex_row}>
|
<div style={styles.flex_row}>
|
||||||
<p
|
<p
|
||||||
|
|
Loading…
Reference in a new issue