diff --git a/webclient/src/Admin.js b/webclient/src/Admin.js index 6f63577..b7af65e 100644 --- a/webclient/src/Admin.js +++ b/webclient/src/Admin.js @@ -1,8 +1,71 @@ import React, { useState, useEffect } from 'react'; import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom'; import './light.css'; -import { Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react'; +import { Button, Container, Checkbox, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react'; +import moment from 'moment'; import { BasicTable, staticUrl, requester } from './utils.js'; +import { TransactionList, TransactionEditor } from './Transactions.js'; + +export function AdminTransactions(props) { + const { token, result, refreshResult } = props; + const transactions = result.transactions; + const [open, setOpen] = useState(false); + const [input, setInput] = useState({ date: moment().format('YYYY-MM-DD'), info_source: 'Web' }); + const [error, setError] = useState(false); + const [loading, setLoading] = useState(false); + const [success, setSuccess] = useState(false); + const { id } = useParams(); + + const handleSubmit = (e) => { + setLoading(true); + setSuccess(false); + const data = { ...input, member_id: id }; + requester('/transactions/', 'POST', token, data) + .then(res => { + setSuccess(res.id); + setInput({}); + setLoading(false); + setError(false); + refreshResult(); + }) + .catch(err => { + setLoading(false); + console.log(err); + setError(err.data); + }); + }; + + return ( +
+
Edit Member Transactions
+ +
+
Add a Transaction
+ + + + {success &&

Added! View the transaction.

} + + Submit + + + +
Current Transactions
+ + {transactions.length ? + open ? + + : + + : +

None

+ } + +
+ ); +}; function AdminCardDetail(props) { const { token, result, card } = props; diff --git a/webclient/src/InstructorClasses.js b/webclient/src/InstructorClasses.js index ea3e5ec..ebd4e5d 100644 --- a/webclient/src/InstructorClasses.js +++ b/webclient/src/InstructorClasses.js @@ -245,4 +245,3 @@ export function InstructorClassList(props) { ); }; - diff --git a/webclient/src/Members.js b/webclient/src/Members.js index a5fe1a8..de5d28a 100644 --- a/webclient/src/Members.js +++ b/webclient/src/Members.js @@ -4,7 +4,7 @@ import './light.css'; import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react'; import { isAdmin, BasicTable, staticUrl, requester } from './utils.js'; import { NotFound, PleaseLogin } from './Misc.js'; -import { AdminMemberInfo, AdminMemberForm, AdminMemberCards } from './Admin.js'; +import { AdminMemberInfo, AdminMemberForm, AdminMemberCards, AdminTransactions } from './Admin.js'; export function Members(props) { const [response, setResponse] = useState(false); @@ -134,6 +134,10 @@ export function MemberDetail(props) { } + {isAdmin(user) && + + } + :

Loading...

diff --git a/webclient/src/Transactions.js b/webclient/src/Transactions.js index 7cb0b88..a95f782 100644 --- a/webclient/src/Transactions.js +++ b/webclient/src/Transactions.js @@ -5,7 +5,7 @@ import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Me import { isAdmin, BasicTable, requester } from './utils.js'; import { NotFound, PleaseLogin } from './Misc.js'; -function TransactionEditor(props) { +export function TransactionEditor(props) { const { input, setInput, error } = props; const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); @@ -178,6 +178,40 @@ function EditTransaction(props) { ); }; +export function TransactionList(props) { + const { transactions } = props; + + return ( + + + + Date + Amount + Account + Memo + + + + + {transactions.length ? + transactions.slice().sort((a, b) => a.date < b.date ? 1 : -1).map(x => + + + {x.date} + + ${x.amount} + {x.account_type} + {x.memo} + + ) + : + None + } + +
+ ); +}; + export function Transactions(props) { const { user } = props; @@ -185,33 +219,7 @@ export function Transactions(props) {
Transactions
- - - - Date - Amount - Account - Memo - - - - - {user.transactions.length ? - user.transactions.slice().reverse().map(x => - - - {x.date} - - ${x.amount} - {x.account_type} - {x.memo} - - ) - : - None - } - -
+
);