import { useEffect, useState } from "react"; import styles from "../../styles"; import { colors } from "../../styles"; import TextField from "@mui/material/TextField"; import AddToQueueIcon from "@mui/icons-material/AddToQueue"; import Button from "../../Components/Button/Button"; import { toast } from "react-toastify"; import { AvailableEquipmentInstancesAPI, TransactionCreateAPI, TeachersAPI, UserAPI, } from "../../Components/API/API"; import FormControl from "@mui/material/FormControl"; import FormLabel from "@mui/material/FormLabel"; import { useQueryClient } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query"; import { Select, CircularProgress, MenuItem, OutlinedInput, } from "@mui/material"; import React from "react"; import Header from "../../Components/Header/Header"; import { useNavigate } from "react-router-dom"; export default function AddTransactionPage() { const navigate = useNavigate(); const queryClient = useQueryClient(); const [transaction, SetTransaction] = useState({ equipments: [] as number[], teacher: 0, subject: "", remarks: " ", transaction_status: "Pending Approval", consumables: " ", additional_members: " ", borrower: 0, }); /* const [selecteditems, SetSelectedItems] = useState([]); const [selectedteacher, SetSelectedTeacher] = useState(0); const [subject, SetSubject] = useState(""); const [remarks, SetRemarks] = useState(""); const [consumables, SetConsumables] = useState(""); */ const [error, setError] = useState(""); const equipments = useQuery({ queryKey: ["equipment_instances_available"], queryFn: AvailableEquipmentInstancesAPI, }); const teachers = useQuery({ queryKey: ["teachers"], queryFn: TeachersAPI, }); const user = useQuery({ queryKey: ["user"], queryFn: UserAPI, }); useEffect(() => { if (user.data) { SetTransaction({ ...transaction, borrower: user.data.id }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [user.data]); const isLoading = equipments.isLoading || teachers.isLoading || user.isLoading; if (isLoading) { return (

Loading

); } return (

New Transaction

Items Requested Assigned Teacher Subject ) => { SetTransaction({ ...transaction, subject: e.target.value }); setError(""); }} label={"Subject"} value={transaction.subject} placeholder={"The subject requiring the equipments"} /> Remarks ) => { SetTransaction({ ...transaction, remarks: e.target.value }); setError(""); }} label={"Remarks"} value={transaction.remarks} placeholder={"Optionally add a brief description of the request"} /> Consumables ) => { SetTransaction({ ...transaction, consumables: e.target.value }); setError(""); }} label={"Consumables"} value={transaction.consumables} placeholder={"Write down any consumables here"} /> Additional Members ) => { SetTransaction({ ...transaction, additional_members: e.target.value, }); setError(""); }} label={"Additional Members"} value={transaction.additional_members} placeholder={ "Write down any additional members borrowing on behalf of this transaction" } />

{error}

); }