2020-02-16 04:57:55 +00:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2022-07-13 04:23:52 +00:00
|
|
|
import { Link } from 'react-router-dom';
|
2020-02-16 04:57:55 +00:00
|
|
|
import './light.css';
|
2022-07-13 04:23:52 +00:00
|
|
|
import { Container, Checkbox, Form, Header, Segment } from 'semantic-ui-react';
|
2020-02-22 05:22:39 +00:00
|
|
|
import * as Datetime from 'react-datetime';
|
|
|
|
import 'react-datetime/css/react-datetime.css';
|
2020-02-16 04:57:55 +00:00
|
|
|
import moment from 'moment';
|
2022-07-13 04:23:52 +00:00
|
|
|
import { requester } from './utils.js';
|
2020-02-16 04:57:55 +00:00
|
|
|
import { TransactionList, TransactionEditor } from './Transactions.js';
|
|
|
|
|
|
|
|
export function AdminReportedTransactions(props) {
|
2022-07-13 04:23:52 +00:00
|
|
|
const { token } = props;
|
2020-02-16 04:57:55 +00:00
|
|
|
const [transactions, setTransactions] = useState(false);
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
requester('/transactions/', 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setTransactions(res.results);
|
|
|
|
setError(false);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2020-02-22 05:22:39 +00:00
|
|
|
<div>
|
2020-02-16 04:57:55 +00:00
|
|
|
{!error ?
|
|
|
|
transactions ?
|
|
|
|
<div>
|
|
|
|
<TransactionList transactions={transactions} />
|
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<p>Loading...</p>
|
|
|
|
:
|
2020-02-22 05:22:39 +00:00
|
|
|
<p>Error loading.</p>
|
2020-02-16 04:57:55 +00:00
|
|
|
}
|
2020-02-22 05:22:39 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2020-02-16 04:57:55 +00:00
|
|
|
|
2020-02-22 05:22:39 +00:00
|
|
|
let transactionsCache = false;
|
2020-02-28 01:24:16 +00:00
|
|
|
let excludePayPalCache = false;
|
2020-02-22 05:22:39 +00:00
|
|
|
|
|
|
|
export function AdminHistoricalTransactions(props) {
|
2022-07-13 04:23:52 +00:00
|
|
|
const { token } = props;
|
2020-02-22 05:22:39 +00:00
|
|
|
const [input, setInput] = useState({ month: moment() });
|
|
|
|
const [transactions, setTransactions] = useState(transactionsCache);
|
2020-02-28 01:24:16 +00:00
|
|
|
const [excludePayPal, setExcludePayPal] = useState(excludePayPalCache);
|
2020-02-22 05:22:39 +00:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [error, setError] = useState(false);
|
|
|
|
|
|
|
|
const handleDatetime = (v) => setInput({ ...input, month: v });
|
|
|
|
|
2020-02-28 01:24:16 +00:00
|
|
|
const handleExcludePayPal = (e, v) => {
|
|
|
|
setExcludePayPal(v.checked);
|
|
|
|
excludePayPalCache = v.checked;
|
|
|
|
};
|
|
|
|
|
2020-02-22 05:22:39 +00:00
|
|
|
const handleSubmit = (e) => {
|
|
|
|
if (loading) return;
|
|
|
|
setLoading(true);
|
|
|
|
const month = input.month.format('YYYY-MM');
|
|
|
|
requester('/transactions/?month=' + month, 'GET', token)
|
|
|
|
.then(res => {
|
|
|
|
setLoading(false);
|
|
|
|
setError(false);
|
|
|
|
setTransactions(res.results);
|
|
|
|
transactionsCache = res.results;
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(true);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<label>Month</label>
|
|
|
|
<Form.Group>
|
|
|
|
<Form.Field>
|
|
|
|
<Datetime
|
|
|
|
dateFormat='YYYY-MM'
|
|
|
|
timeFormat={false}
|
|
|
|
value={input.month}
|
|
|
|
onChange={handleDatetime}
|
|
|
|
/>
|
|
|
|
</Form.Field>
|
|
|
|
|
|
|
|
<Form.Button loading={loading}>
|
|
|
|
Submit
|
|
|
|
</Form.Button>
|
|
|
|
</Form.Group>
|
|
|
|
</Form>
|
|
|
|
|
|
|
|
{!error ?
|
|
|
|
transactions && <div>
|
|
|
|
<p>Found {transactions.length} transactions.</p>
|
|
|
|
{!!transactions.length &&
|
|
|
|
<Header size='small'>{moment(transactions[0].date, 'YYYY-MM-DD').format('MMMM YYYY')} Transactions</Header>
|
|
|
|
}
|
2020-02-28 01:24:16 +00:00
|
|
|
|
|
|
|
<Checkbox
|
|
|
|
label='Exclude PayPal'
|
|
|
|
onChange={handleExcludePayPal}
|
|
|
|
checked={excludePayPal}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<TransactionList transactions={transactions.filter(x => !excludePayPal || x.account_type !== 'PayPal')} />
|
2020-02-22 05:22:39 +00:00
|
|
|
</div>
|
|
|
|
:
|
|
|
|
<p>Error loading transactions.</p>
|
|
|
|
}
|
|
|
|
</div>
|
2020-02-16 04:57:55 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-03-16 03:59:16 +00:00
|
|
|
export function AdminAddTransaction(props) {
|
|
|
|
const { token } = props;
|
|
|
|
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 handleSubmit = (e) => {
|
|
|
|
if (loading) return;
|
|
|
|
setLoading(true);
|
|
|
|
setSuccess(false);
|
|
|
|
requester('/transactions/', 'POST', token, input)
|
|
|
|
.then(res => {
|
|
|
|
setSuccess(res.id);
|
|
|
|
setInput({});
|
|
|
|
setLoading(false);
|
|
|
|
setError(false);
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
setLoading(false);
|
|
|
|
console.log(err);
|
|
|
|
setError(err.data);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form onSubmit={handleSubmit}>
|
|
|
|
<TransactionEditor {...props} input={input} setInput={setInput} error={error} />
|
|
|
|
|
|
|
|
<Form.Button loading={loading} error={error.non_field_errors}>
|
|
|
|
Submit
|
|
|
|
</Form.Button>
|
|
|
|
{success && <p>Added! <Link to={'/transactions/'+success}>View the transaction.</Link></p>}
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-02-16 04:57:55 +00:00
|
|
|
export function AdminTransactions(props) {
|
2020-02-22 05:22:39 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<Header size='large'>Admin Transactions</Header>
|
|
|
|
|
2020-03-16 03:59:16 +00:00
|
|
|
<Segment padded>
|
|
|
|
<Header size='medium'>Add a Transaction</Header>
|
|
|
|
<AdminAddTransaction {...props} />
|
|
|
|
</Segment>
|
|
|
|
|
2020-02-22 05:22:39 +00:00
|
|
|
<Header size='medium'>Reported</Header>
|
|
|
|
<AdminReportedTransactions {...props} />
|
|
|
|
|
|
|
|
<Header size='medium'>Historical</Header>
|
|
|
|
<AdminHistoricalTransactions {...props} />
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function AdminMemberTransactions(props) {
|
2022-07-13 04:23:52 +00:00
|
|
|
const { result } = props;
|
2020-02-16 04:57:55 +00:00
|
|
|
const transactions = result.transactions;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2020-08-08 22:02:45 +00:00
|
|
|
<Header size='medium'>Member Transactions</Header>
|
2020-02-16 04:57:55 +00:00
|
|
|
|
2020-08-08 22:02:45 +00:00
|
|
|
<Link to='/admintrans'>Add a transaction</Link>
|
2020-02-16 04:57:55 +00:00
|
|
|
|
|
|
|
<Header size='small'>Current Transactions</Header>
|
|
|
|
|
|
|
|
{transactions.length ?
|
2020-08-08 22:02:45 +00:00
|
|
|
<TransactionList noMember transactions={transactions} />
|
2020-02-16 04:57:55 +00:00
|
|
|
:
|
|
|
|
<p>None</p>
|
|
|
|
}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|