mirror of
https://github.com/lemeow125/Borrowing-TrackerFrontend.git
synced 2024-11-17 06:19:27 +08:00
Change filter component in transactions list page to search bar
This commit is contained in:
parent
74976b6512
commit
28183b5424
1 changed files with 68 additions and 7 deletions
|
@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
|
||||||
import Header from "../../Components/Header/Header";
|
import Header from "../../Components/Header/Header";
|
||||||
import styles from "../../styles";
|
import styles from "../../styles";
|
||||||
import { TransactionsAPI } from "../../Components/API/API";
|
import { TransactionsAPI } from "../../Components/API/API";
|
||||||
import { CircularProgress } from "@mui/material";
|
import { Autocomplete, CircularProgress } from "@mui/material";
|
||||||
import Table from "@mui/material/Table";
|
import Table from "@mui/material/Table";
|
||||||
import TableBody from "@mui/material/TableBody";
|
import TableBody from "@mui/material/TableBody";
|
||||||
import TableCell from "@mui/material/TableCell";
|
import TableCell from "@mui/material/TableCell";
|
||||||
|
@ -14,19 +14,19 @@ import { colors } from "../../styles";
|
||||||
import Popup from "reactjs-popup";
|
import Popup from "reactjs-popup";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import EditTransactionModal from "../../Components/EditTransactionModal/EditTransactionModal";
|
import EditTransactionModal from "../../Components/EditTransactionModal/EditTransactionModal";
|
||||||
import TransactionFilterMenu from "../../Components/TransactionFilterMenu/TransactionFilterMenu";
|
|
||||||
import EditItemInstanceModal from "../../Components/EditItemInstanceModal/EditItemInstanceModal";
|
import EditItemInstanceModal from "../../Components/EditItemInstanceModal/EditItemInstanceModal";
|
||||||
|
import SearchIcon from "@mui/icons-material/Search";
|
||||||
|
|
||||||
export default function TransactionsListPage() {
|
export default function TransactionsListPage() {
|
||||||
const [EditTransactionOpen, SetEditTransactionOpen] = useState(false);
|
const [EditTransactionOpen, SetEditTransactionOpen] = useState(false);
|
||||||
const [SelectedTransaction, SetSelectedTransaction] = useState(0);
|
const [SelectedTransaction, SetSelectedTransaction] = useState(0);
|
||||||
const [EditEquipmentsOpen, SetEditEquipmentsOpen] = useState(false);
|
const [EditEquipmentsOpen, SetEditEquipmentsOpen] = useState(false);
|
||||||
const [SelectedEquipment, SetSelectedEquipment] = useState(0);
|
const [SelectedEquipment, SetSelectedEquipment] = useState(0);
|
||||||
|
const [filter, setFilter] = useState<string | null>(null);
|
||||||
const transactions = useQuery({
|
const transactions = useQuery({
|
||||||
queryKey: ["transactions"],
|
queryKey: ["transactions"],
|
||||||
queryFn: TransactionsAPI,
|
queryFn: TransactionsAPI,
|
||||||
});
|
});
|
||||||
const [filter, setFilter] = useState("");
|
|
||||||
if (transactions.isLoading) {
|
if (transactions.isLoading) {
|
||||||
return (
|
return (
|
||||||
<div style={styles.background}>
|
<div style={styles.background}>
|
||||||
|
@ -76,7 +76,56 @@ export default function TransactionsListPage() {
|
||||||
style={{ width: "90%", overflowY: "scroll", marginTop: "2rem" }}
|
style={{ width: "90%", overflowY: "scroll", marginTop: "2rem" }}
|
||||||
component={Paper}
|
component={Paper}
|
||||||
>
|
>
|
||||||
<TransactionFilterMenu filter={filter} setFilter={setFilter} />
|
<div
|
||||||
|
style={{
|
||||||
|
...styles.flex_row,
|
||||||
|
...{ alignItems: "center", justifySelf: "flex-start" },
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<SearchIcon
|
||||||
|
style={{
|
||||||
|
height: 32,
|
||||||
|
width: 32,
|
||||||
|
fill: colors.font_dark,
|
||||||
|
marginLeft: "1rem",
|
||||||
|
marginRight: "1rem",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Autocomplete
|
||||||
|
sx={{
|
||||||
|
display: "inline-block",
|
||||||
|
"& input": {
|
||||||
|
width: "256x",
|
||||||
|
bgcolor: "background.paper",
|
||||||
|
color: (theme) =>
|
||||||
|
theme.palette.getContrastText(
|
||||||
|
theme.palette.background.paper
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
value={filter}
|
||||||
|
onChange={(_event, newValue) => {
|
||||||
|
setFilter(newValue);
|
||||||
|
}}
|
||||||
|
freeSolo
|
||||||
|
id="custom-input-demo"
|
||||||
|
options={[
|
||||||
|
"Pending Approval",
|
||||||
|
"Approved",
|
||||||
|
"Rejected",
|
||||||
|
"Cancelled",
|
||||||
|
"Borrowed",
|
||||||
|
"Returned: Pending Checking",
|
||||||
|
"With Breakages: Pending Resolution",
|
||||||
|
"Finalized",
|
||||||
|
]}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<div ref={params.InputProps.ref}>
|
||||||
|
<input type="text" {...params.inputProps} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<Table sx={{ marginTop: "8px", minWidth: "32rem" }} size="medium">
|
<Table sx={{ marginTop: "8px", minWidth: "32rem" }} size="medium">
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow style={{ backgroundColor: colors.header_color }}>
|
<TableRow style={{ backgroundColor: colors.header_color }}>
|
||||||
|
@ -104,9 +153,21 @@ export default function TransactionsListPage() {
|
||||||
{transactions.data ? (
|
{transactions.data ? (
|
||||||
transactions.data
|
transactions.data
|
||||||
.filter((transaction) =>
|
.filter((transaction) =>
|
||||||
filter !== ""
|
filter !== null
|
||||||
? transaction.transaction_status == filter
|
? // If filter is not null, we filter if it matches any criteria
|
||||||
: true
|
transaction.borrower.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(filter.toLowerCase()) ||
|
||||||
|
transaction.teacher.name
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(filter.toLowerCase()) ||
|
||||||
|
transaction.remarks
|
||||||
|
.toLowerCase()
|
||||||
|
.includes(filter?.toLowerCase()) ||
|
||||||
|
transaction.transaction_status.toLowerCase() ==
|
||||||
|
filter.toLowerCase()
|
||||||
|
: // If filter keyword is null then we just pass through everything as if we did not filter at all
|
||||||
|
true
|
||||||
)
|
)
|
||||||
.map((transaction) => (
|
.map((transaction) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
|
|
Loading…
Reference in a new issue