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';
|
2023-02-03 00:02:20 +00:00
|
|
|
|
import { Container, Checkbox, Form, Header, Segment, Table } 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';
|
2023-06-03 19:43:14 +00:00
|
|
|
|
import { requester, useIsMobile } 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;
|
2023-02-03 00:02:20 +00:00
|
|
|
|
let summaryCache = 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);
|
2023-02-03 00:02:20 +00:00
|
|
|
|
const [summary, setSummary] = useState(summaryCache);
|
2023-05-03 18:57:48 +00:00
|
|
|
|
const [excludePayPal, setExcludePayPal] = useState(false);
|
|
|
|
|
const [excludeSnacks, setExcludeSnacks] = useState(true);
|
2023-06-20 23:28:10 +00:00
|
|
|
|
const [excludeDues, setExcludeDues] = useState(false);
|
2020-02-22 05:22:39 +00:00
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
const [error, setError] = useState(false);
|
2023-06-03 19:43:14 +00:00
|
|
|
|
const isMobile = useIsMobile();
|
2020-02-22 05:22:39 +00:00
|
|
|
|
|
|
|
|
|
const handleDatetime = (v) => setInput({ ...input, month: v });
|
|
|
|
|
|
2023-05-03 18:57:48 +00:00
|
|
|
|
const makeRequest = () => {
|
2020-02-22 05:22:39 +00:00
|
|
|
|
if (loading) return;
|
|
|
|
|
setLoading(true);
|
|
|
|
|
const month = input.month.format('YYYY-MM');
|
2023-06-20 23:28:10 +00:00
|
|
|
|
requester('/transactions/?month=' + month + '&exclude_paypal=' + excludePayPal + '&exclude_snacks=' + excludeSnacks + '&exclude_dues=' + excludeDues, 'GET', token)
|
2020-02-22 05:22:39 +00:00
|
|
|
|
.then(res => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
setError(false);
|
|
|
|
|
setTransactions(res.results);
|
|
|
|
|
transactionsCache = res.results;
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
console.log(err);
|
|
|
|
|
setError(true);
|
|
|
|
|
});
|
2023-02-03 00:02:20 +00:00
|
|
|
|
|
|
|
|
|
requester('/transactions/summary/?month=' + month, 'GET', token)
|
|
|
|
|
.then(res => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
setError(false);
|
|
|
|
|
setSummary(res);
|
|
|
|
|
summaryCache = res;
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
setLoading(false);
|
|
|
|
|
console.log(err);
|
|
|
|
|
setError(true);
|
|
|
|
|
});
|
2020-02-22 05:22:39 +00:00
|
|
|
|
};
|
|
|
|
|
|
2023-05-03 18:57:48 +00:00
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
|
makeRequest();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleExcludePayPal = (e, v) => {
|
|
|
|
|
setExcludePayPal(v.checked);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleExcludeSnacks = (e, v) => {
|
|
|
|
|
setExcludeSnacks(v.checked);
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-20 23:28:10 +00:00
|
|
|
|
const handleExcludeDues = (e, v) => {
|
|
|
|
|
setExcludeDues(v.checked);
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-03 18:57:48 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
makeRequest();
|
2023-06-20 23:28:10 +00:00
|
|
|
|
}, [excludePayPal, excludeSnacks, excludeDues]);
|
2023-05-03 18:57:48 +00:00
|
|
|
|
|
2020-02-22 05:22:39 +00:00
|
|
|
|
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>
|
2023-02-03 00:02:20 +00:00
|
|
|
|
{transactions && <p>Found {transactions.length} transactions.</p>}
|
|
|
|
|
|
|
|
|
|
{!error ?
|
|
|
|
|
summary && <div>
|
|
|
|
|
<Header size='small'>Summary</Header>
|
|
|
|
|
|
|
|
|
|
<Table basic='very'>
|
2023-06-03 19:43:14 +00:00
|
|
|
|
{!isMobile && <Table.Header>
|
2023-02-03 00:02:20 +00:00
|
|
|
|
<Table.Row>
|
|
|
|
|
<Table.HeaderCell>Category</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell>Dollar</Table.HeaderCell>
|
|
|
|
|
<Table.HeaderCell>Protocoin</Table.HeaderCell>
|
|
|
|
|
</Table.Row>
|
2023-06-03 19:43:14 +00:00
|
|
|
|
</Table.Header>}
|
2023-02-03 00:02:20 +00:00
|
|
|
|
|
|
|
|
|
<Table.Body>
|
|
|
|
|
{summary.map(x =>
|
|
|
|
|
<Table.Row key={x.category}>
|
2023-06-03 19:43:14 +00:00
|
|
|
|
<Table.Cell>{isMobile && 'Category: '}{x.category}</Table.Cell>
|
|
|
|
|
<Table.Cell>{isMobile && 'Dollar: '}{'$ ' + x.dollar.toFixed(2)}</Table.Cell>
|
|
|
|
|
<Table.Cell>{isMobile && 'Protocoin: '}{'₱ ' + x.protocoin.toFixed(2)}</Table.Cell>
|
2023-02-03 00:02:20 +00:00
|
|
|
|
</Table.Row>
|
|
|
|
|
)}
|
|
|
|
|
</Table.Body>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
|
|
|
|
:
|
|
|
|
|
<p>Error loading summary.</p>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<p/>
|
2020-02-22 05:22:39 +00:00
|
|
|
|
|
|
|
|
|
{!error ?
|
|
|
|
|
transactions && <div>
|
|
|
|
|
{!!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
|
2023-05-03 18:57:48 +00:00
|
|
|
|
className='filter-option'
|
2020-02-28 01:24:16 +00:00
|
|
|
|
label='Exclude PayPal'
|
|
|
|
|
onChange={handleExcludePayPal}
|
|
|
|
|
checked={excludePayPal}
|
|
|
|
|
/>
|
|
|
|
|
|
2023-05-03 18:57:48 +00:00
|
|
|
|
<Checkbox
|
|
|
|
|
className='filter-option'
|
|
|
|
|
label='Exclude Snacks'
|
|
|
|
|
onChange={handleExcludeSnacks}
|
|
|
|
|
checked={excludeSnacks}
|
|
|
|
|
/>
|
|
|
|
|
|
2023-06-20 23:28:10 +00:00
|
|
|
|
<Checkbox
|
|
|
|
|
className='filter-option'
|
|
|
|
|
label='Exclude Dues'
|
|
|
|
|
onChange={handleExcludeDues}
|
|
|
|
|
checked={excludeDues}
|
|
|
|
|
/>
|
|
|
|
|
|
2023-05-03 18:57:48 +00:00
|
|
|
|
<TransactionList transactions={transactions} />
|
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>
|
|
|
|
|
);
|
|
|
|
|
};
|