import { useQuery } from "@tanstack/react-query"; import Header from "../../Components/Header/Header"; import styles from "../../styles"; import { TransactionsAPI } from "../../Components/API/API"; import { Autocomplete, CircularProgress } from "@mui/material"; import Table from "@mui/material/Table"; import TableBody from "@mui/material/TableBody"; import TableCell from "@mui/material/TableCell"; import TableContainer from "@mui/material/TableContainer"; import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import Paper from "@mui/material/Paper"; import { colors } from "../../styles"; import Popup from "reactjs-popup"; import { useState } from "react"; import EditTransactionModal from "../../Components/EditTransactionModal/EditTransactionModal"; import EditItemInstanceModal from "../../Components/EditItemInstanceModal/EditItemInstanceModal"; import SearchIcon from "@mui/icons-material/Search"; import { useNavigate } from "react-router-dom"; export default function TransactionsListPage() { const navigate = useNavigate(); const [EditTransactionOpen, SetEditTransactionOpen] = useState(false); const [SelectedTransaction, SetSelectedTransaction] = useState(0); const [EditEquipmentsOpen, SetEditEquipmentsOpen] = useState(false); const [SelectedEquipment, SetSelectedEquipment] = useState(0); const [filter, setFilter] = useState(null); const transactions = useQuery({ queryKey: ["transactions"], queryFn: TransactionsAPI, }); if (transactions.isLoading) { return (

Loading

); } return (
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) => (
)} />

Results Found:{" "} { transactions?.data?.filter((transaction) => filter !== null ? // If filter is not null, we filter if it matches any criteria transaction.borrower.name .toLowerCase() .includes(filter.toLowerCase()) || transaction.teacher.name .toLowerCase() .includes(filter.toLowerCase()) || transaction.additional_members .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 ).length }

ID Borrower Teacher Status Remarks Consumables Additional Members Additional Members Actions {transactions.data ? ( transactions.data .filter((transaction) => filter !== null ? // If filter is not null, we filter if it matches any criteria transaction.borrower.name .toLowerCase() .includes(filter.toLowerCase()) || transaction.additional_members .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) => ( { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.id} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.borrower.name} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.teacher.name} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.transaction_status} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.remarks} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.consumables} { if ( transaction.transaction_status != "Finalized" && transaction.transaction_status != "Rejected" ) { SetSelectedTransaction(transaction.id); SetEditTransactionOpen(true); } }} > {transaction.additional_members}

Involved Items: {transaction.equipments.length}

ID Name Status {transaction.equipments.map((equipment) => ( { if ( transaction.transaction_status == "With Breakages: Pending Resolution" ) { SetSelectedEquipment(equipment.id); SetEditTransactionOpen(false); SetEditEquipmentsOpen(true); } }} > {equipment.id} {equipment.name} {equipment.status} ))}
)) ) : ( <> )}
SetEditTransactionOpen(false)} modal position={"top center"} contentStyle={styles.popup_center} > SetEditEquipmentsOpen(false)} modal position={"top center"} contentStyle={styles.popup_center} >
); }