From f5cfc9a1d6aaa25e13d4c024d7a4d47fc76a1ed5 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sat, 1 Feb 2020 08:56:22 +0000 Subject: [PATCH] Add UI so users can report transactions --- webclient/src/Transactions.js | 84 ++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/webclient/src/Transactions.js b/webclient/src/Transactions.js index 2a4efec..63bda25 100644 --- a/webclient/src/Transactions.js +++ b/webclient/src/Transactions.js @@ -147,11 +147,6 @@ function EditTransaction(props) { const [success, setSuccess] = useState(false); const { id } = useParams(); - const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); - const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] }); - const handleChange = (e) => handleValues(e, e.currentTarget); - const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked }); - const handleSubmit = (e) => { setLoading(true); setSuccess(false); @@ -182,7 +177,70 @@ function EditTransaction(props) { - Save + {transaction.report_type ? 'Save & Unreport' : 'Save'} + + {success &&
Success!
} + + + ); +}; + +function ReportTransaction(props) { + const { transaction, setTransaction, token, refreshUser } = props; + const [input, setInput] = useState(transaction); + const [error, setError] = useState(false); + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + const { id } = useParams(); + + const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); + const handleUpload = (e, v) => setInput({ ...input, [v.name]: e.target.files[0] }); + const handleChange = (e) => handleValues(e, e.currentTarget); + const handleCheck = (e, v) => setInput({ ...input, [v.name]: v.checked }); + + const handleSubmit = (e) => { + setLoading(true); + setSuccess(false); + requester('/transactions/'+id+'/report/', 'POST', token, input) + .then(res => { + setLoading(false); + setSuccess(true); + setError(false); + if (refreshUser) { + refreshUser(); + } + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(err.data); + }); + }; + + const makeProps = (name) => ({ + name: name, + onChange: handleChange, + value: input[name] || '', + error: error[name], + }); + + return ( +
+
Report Transaction
+ +

If this transaction was made in error or there is anything incorrect about it, please report it using this form.

+

A staff member will review the report as soon as possible.

+

Follow up with directors@protospace.ca.

+ +
+ + + + Submit Report {success &&
Success!
} @@ -254,7 +312,7 @@ export function TransactionDetail(props) { console.log(err); setError(true); }); - }, []); + }, [ownTransaction]); return ( @@ -329,9 +387,15 @@ export function TransactionDetail(props) { - {isAdmin(user) && - - } + {isAdmin(user) ? + + + + : + + + + }