From 1281d8023f70ee78f3b383bfbce891349515886d Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Wed, 3 Jan 2024 16:34:56 +0800 Subject: [PATCH] Support very long strings being displayed in remarks for transactions --- .../EditTransactionModal.tsx | 195 +++++++++++------- .../TransactionEntry/TransactionEntry.tsx | 7 +- .../TransactionsListPage.tsx | 29 ++- 3 files changed, 154 insertions(+), 77 deletions(-) diff --git a/src/Components/EditTransactionModal/EditTransactionModal.tsx b/src/Components/EditTransactionModal/EditTransactionModal.tsx index 30bbcf2..d2d93c7 100644 --- a/src/Components/EditTransactionModal/EditTransactionModal.tsx +++ b/src/Components/EditTransactionModal/EditTransactionModal.tsx @@ -11,6 +11,7 @@ import FormControl from "@mui/material/FormControl"; import FormLabel from "@mui/material/FormLabel"; import Radio from "@mui/material/Radio"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import TextField from "@mui/material/TextField"; import { CircularProgress } from "@mui/material"; import React from "react"; @@ -19,7 +20,10 @@ export default function EditTransactionModal(props: { setOpen: React.Dispatch>; }) { const queryClient = useQueryClient(); - const [status, setStatus] = useState(""); + const [current_transaction, setCurrentTransaction] = useState({ + transaction_status: "", + remarks: "", + }); const [error, setError] = useState(""); const transaction = useQuery({ queryKey: ["transaction", props.id], @@ -27,10 +31,7 @@ export default function EditTransactionModal(props: { }); const update_mutation = useMutation({ mutationFn: async () => { - const data = await TransactionUpdateAPI( - { transaction_status: status }, - props.id - ); + const data = await TransactionUpdateAPI(current_transaction, props.id); if (data[0] != true) { setError(JSON.stringify(data[1])); return Promise.reject(new Error(JSON.stringify(data[1]))); @@ -60,15 +61,21 @@ export default function EditTransactionModal(props: { theme: "light", } ); - if (typeof data[1] == "object") { - setStatus(data[1].transaction_status); + if (typeof data[1] == "object" && transaction.data) { + setCurrentTransaction({ + transaction_status: transaction.data.transaction_status, + remarks: transaction.data.remarks, + }); } }, }); useEffect(() => { if (transaction.data) { - setStatus(transaction.data.transaction_status); + setCurrentTransaction({ + transaction_status: transaction.data.transaction_status, + remarks: transaction.data.remarks, + }); } }, [transaction.data]); if (transaction.isLoading) { @@ -123,75 +130,117 @@ export default function EditTransactionModal(props: {
- - Item Status - - ) => { - setStatus(e.target.value); - setError(""); - }} - > -
- + + Item Status + + ) => { + setCurrentTransaction({ + ...current_transaction, + transaction_status: e.target.value, + }); + setError(""); + }} + > +
+ {/*} label="Pending Approval" style={styles.text_dark} - /> - } - label="Approved" - style={styles.text_dark} - /> - } - label="Rejected" - style={styles.text_dark} - /> - } - label="Cancelled" - style={styles.text_dark} - /> - } - label="Borrowed" - style={styles.text_dark} - /> - } - label="Returned: Pending Checking" - style={styles.text_dark} - /> - } - label="With Breakages: Pending Resolution" - style={styles.text_dark} - /> - } - label="Finalized" - style={styles.text_dark} - /> -
-
+ />*/} + {transaction.data?.transaction_status == + "Pending Approval" ? ( + <> + } + label="Approved" + style={styles.text_dark} + /> + } + label="Rejected" + style={styles.text_dark} + /> + + ) : null} + {transaction.data?.transaction_status == "Approved" ? ( + <> + } + label="Cancelled" + style={styles.text_dark} + /> + } + label="Borrowed" + style={styles.text_dark} + /> + + ) : null} + {transaction.data?.transaction_status == "Borrowed" ? ( + <> + } + label="Returned: Pending Checking" + style={styles.text_dark} + /> + + ) : null} + {transaction.data?.transaction_status == "Borrowed" ? ( + <> + } + label="With Breakages: Pending Resolution" + style={styles.text_dark} + /> + } + label="Finalized" + style={styles.text_dark} + /> + + ) : null} +
+
+ + ) : null} + ) => { + setCurrentTransaction({ + ...current_transaction, + remarks: e.target.value, + }); + setError(""); + }} + value={current_transaction.remarks} + placeholder={ + "Optionally add a brief description of the transaction" + } + />

{error}

diff --git a/src/Components/TransactionEntry/TransactionEntry.tsx b/src/Components/TransactionEntry/TransactionEntry.tsx index 455f4bd..c3544fd 100644 --- a/src/Components/TransactionEntry/TransactionEntry.tsx +++ b/src/Components/TransactionEntry/TransactionEntry.tsx @@ -47,7 +47,7 @@ export default function TransactionEntry(props: props) { style={{ ...styles.text_dark, ...styles.text_S, - ...{ textAlign: "left", margin: 0 }, + ...{ textAlign: "left", margin: 0, wordWrap: "break-word" }, }} > Borrower: {props.transaction.borrower.name}{" "} @@ -57,7 +57,7 @@ export default function TransactionEntry(props: props) { style={{ ...styles.text_dark, ...styles.text_S, - ...{ textAlign: "left", margin: 0 }, + ...{ textAlign: "left", margin: 0, wordWrap: "break-word" }, }} > {`(${props.transaction.borrower.course})`} @@ -92,6 +92,8 @@ export default function TransactionEntry(props: props) { marginTop: "8px", flexWrap: "wrap", overflowY: "scroll", + maxWidth: "192px", + wordWrap: "break-word", }, }} > @@ -121,6 +123,7 @@ export default function TransactionEntry(props: props) { ...styles.text_S, ...{ textAlign: "right", + wordWrap: "break-word", margin: 0, }, }} diff --git a/src/Pages/TransactionsListPage/TransactionsListPage.tsx b/src/Pages/TransactionsListPage/TransactionsListPage.tsx index f5f480e..a6db7d1 100644 --- a/src/Pages/TransactionsListPage/TransactionsListPage.tsx +++ b/src/Pages/TransactionsListPage/TransactionsListPage.tsx @@ -85,6 +85,9 @@ export default function TransactionsListPage() { Status + + Remarks + Equipments @@ -141,6 +144,23 @@ export default function TransactionsListPage() { > {transaction.transaction_status} + { + SetSelectedTransaction(transaction.id); + SetEditTransactionOpen(true); + }} + > + {transaction.remarks} + @@ -172,8 +192,13 @@ export default function TransactionsListPage() { }, }} onClick={() => { - SetEditTransactionOpen(false); - SetEditEquipmentsOpen(true); + if ( + transaction.transaction_status == + "With Breakages: Pending Resolution" + ) { + SetEditTransactionOpen(false); + SetEditEquipmentsOpen(true); + } }} >