Move admin components to different files, add backup info

This commit is contained in:
Tanner Collin 2020-02-16 04:57:55 +00:00
parent 6954a1a137
commit dcfc16d20d
5 changed files with 630 additions and 554 deletions

View File

@ -3,577 +3,53 @@ import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } f
import './light.css'; import './light.css';
import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react'; import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment'; import moment from 'moment';
import { statusColor, BasicTable, staticUrl, requester } from './utils.js'; import { apiUrl, statusColor, BasicTable, staticUrl, requester } from './utils.js';
import { TransactionList, TransactionEditor } from './Transactions.js';
import { NotFound } from './Misc.js'; import { NotFound } from './Misc.js';
export function AdminReportedTransactions(props) { export function Admin(props) {
const { token, user } = props; const { token, user } = props;
const [transactions, setTransactions] = useState(false); const [backup, setBackup] = useState(false);
const [error, setError] = useState(false); const [error, setError] = useState(false);
useEffect(() => { useEffect(() => {
requester('/transactions/', 'GET', token) requester('/backup/', 'GET', token)
.then(res => { .then(res => {
setTransactions(res.results); setBackup(res.url);
setError(false);
}) })
.catch(err => { .catch(err => {
console.log(err); console.log(err);
setError(true);
}); });
}, []); }, []);
return ( return (
<Container> <Container>
<Header size='large'>Reported Transactions</Header> <Header size='large'>Portal Admin</Header>
{!error ? <Header size='medium'>Backup</Header>
transactions ? <p>Spaceport backups are created daily. 14 days are kept on the server.</p>
{backup ?
<div> <div>
<TransactionList transactions={transactions} /> <p>
Download link:<br />
<a href={backup} target='_blank' rel='noopener noreferrer' aria-label='link to a backup'>
{backup}
</a>
</p>
<p>
Automate with wget (keep secret, that's <b>your</b> login token):
<pre>
wget \
<br /> --header="Authorization: Token {token}" \
<br /> {apiUrl}/backup/
</pre>
</p>
</div> </div>
: :
<p>Loading...</p> <p>Loading...</p>
:
<NotFound />
} }
</Container> </Container>
); );
}; };
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) => {
if (loading) return;
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 (
<div>
<Header size='medium'>Edit Member Transactions</Header>
<Form onSubmit={handleSubmit}>
<Header size='small'>Add a Transaction</Header>
<TransactionEditor noMemberSearch 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>
<Header size='small'>Current Transactions</Header>
{transactions.length ?
open ?
<TransactionList transactions={transactions} />
:
<Button onClick={() => setOpen(true)}>
View / Edit Transactions
</Button>
:
<p>None</p>
}
</div>
);
};
function AdminCardDetail(props) {
const { token, result, card } = props;
const [input, setInput] = useState({ ...card });
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const id = card.id;
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, member_id: result.member.id };
requester('/cards/'+id+'/', 'PUT', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
setInput(res);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const handleDelete = (e) => {
e.preventDefault();
requester('/cards/'+id+'/', 'DELETE', token)
.then(res => {
setInput(false);
})
.catch(err => {
console.log(err);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
const statusOptions = [
{ key: '0', text: 'Card Active', value: 'card_active' },
{ key: '1', text: 'Card Blocked', value: 'card_blocked' },
{ key: '2', text: 'Card Inactive', value: 'card_inactive' },
{ key: '3', text: 'Card Member Blocked', value: 'card_member_blocked' },
];
return (
input ?
<Segment raised color={input.active_status === 'card_active' ? 'green' : 'red'}>
<Form onSubmit={handleSubmit}>
<Form.Group widths='equal'>
<Form.Input
fluid
{...makeProps('card_number')}
/>
<Form.Select
fluid
options={statusOptions}
{...makeProps('active_status')}
onChange={handleValues}
/>
<Form.Group widths='equal'>
<Form.Button
loading={loading}
error={error.non_field_errors}
>
{success ? 'Saved.' : 'Save'}
</Form.Button>
<Form.Button
color='red'
onClick={handleDelete}
>
Delete
</Form.Button>
</Form.Group>
</Form.Group>
Notes: {input.notes || 'None'}
</Form>
</Segment>
:
<Segment raised color='black'>
Deleted card: {card.card_number}
</Segment>
);
};
export function AdminMemberCards(props) {
const { token, result, refreshResult } = props;
const cards = result.cards;
const startDimmed = Boolean(result.member.paused_date && cards.length);
const [dimmed, setDimmed] = useState(startDimmed);
const [input, setInput] = useState({ active_status: 'card_active' });
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const { id } = useParams();
useEffect(() => {
const startDimmed = Boolean(result.member.paused_date && cards.length);
setDimmed(startDimmed);
}, [result.member]);
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, member_id: result.member.id };
requester('/cards/', 'POST', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
const statusOptions = [
{ key: '0', text: 'Card Active', value: 'card_active' },
{ key: '1', text: 'Card Blocked', value: 'card_blocked' },
{ key: '2', text: 'Card Inactive', value: 'card_inactive' },
{ key: '3', text: 'Card Member Blocked', value: 'card_member_blocked' },
];
return (
<div>
<Header size='medium'>Edit Member Cards</Header>
<Form onSubmit={handleSubmit}>
<Header size='small'>Add a Card</Header>
<Form.Group widths='equal'>
<Form.Input
label='Card Number'
fluid
{...makeProps('card_number')}
/>
<Form.Select
label='Card Status'
options={statusOptions}
fluid
{...makeProps('active_status')}
onChange={handleValues}
/>
<Form.Input
label='Optional Note'
fluid
{...makeProps('notes')}
/>
</Form.Group>
<Form.Button loading={loading} error={error.non_field_errors}>
Submit
</Form.Button>
{success && <div>Success!</div>}
</Form>
<Header size='small'>Current Cards</Header>
<Dimmer.Dimmable dimmed={dimmed}>
{cards.length ?
cards.map(x =>
<AdminCardDetail key={x.id} card={x} {...props} />
)
:
<p>None</p>
}
<Dimmer active={dimmed}>
<p>
Member paused, {cards.length} card{cards.length === 1 ? '' : 's'} ignored anyway.
</p>
<p>
<Button size='tiny' onClick={() => setDimmed(false)}>Close</Button>
</p>
</Dimmer>
</Dimmer.Dimmable>
</div>
);
};
export function AdminMemberPause(props) {
const { token, result, refreshResult } = props;
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [yousure, setYousure] = useState(false);
const { id } = useParams();
useEffect(() => {
setLoading(false);
}, [result.member]);
const handlePause = (e) => {
if (yousure) {
if (loading) return;
setLoading(true);
setSuccess(false);
requester('/members/' + id + '/pause/', 'POST', token, {})
.then(res => {
setYousure(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(true);
});
} else {
setYousure(true);
}
};
const handleUnpause = (e) => {
if (loading) return;
setLoading(true);
setSuccess(false);
requester('/members/' + id + '/unpause/', 'POST', token, {})
.then(res => {
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(true);
});
};
return (
<div>
<Header size='medium'>Pause / Unpause Membership</Header>
<p>Pause members who are inactive, former, or on vacation.</p>
<p>
{result.member.paused_date ?
<Button onClick={handleUnpause} loading={loading}>
Unpause
</Button>
:
<Button onClick={handlePause} loading={loading}>
{yousure ? 'You Sure?' : 'Pause'}
</Button>
}
</p>
{success && <div>Success!</div>}
{error && <p>Error, something went wrong.</p>}
</div>
);
};
export function AdminMemberForm(props) {
const { token, result, refreshResult } = props;
const [input, setInput] = useState(result.member);
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const { id } = useParams();
useEffect(() => {
setInput(result.member);
}, [result.member]);
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, email: input.email.toLowerCase() };
requester('/members/' + id + '/', 'PATCH', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
<div>
<Form onSubmit={handleSubmit}>
<Header size='medium'>Edit Member Details</Header>
<Form.Group widths='equal'>
<Form.Input
label='First Name'
fluid
{...makeProps('first_name')}
/>
<Form.Input
label='Last Name'
fluid
{...makeProps('last_name')}
/>
</Form.Group>
<Form.Input
label='Email'
{...makeProps('email')}
/>
<Form.Input
label='Application Date'
{...makeProps('application_date')}
/>
<Form.Input
label='Current Start Date'
{...makeProps('current_start_date')}
/>
<Form.Input
label='Vetted Date'
{...makeProps('vetted_date')}
/>
<Form.Input
label='Membership Fee'
{...makeProps('monthly_fees')}
/>
<Form.Field>
<label>Is the member an instructor?</label>
<Checkbox
label='Yes'
name='is_instructor'
onChange={handleCheck}
checked={input.is_instructor}
/>
</Form.Field>
<Form.Button loading={loading} error={error.non_field_errors}>
Submit
</Form.Button>
{success && <div>Success!</div>}
</Form>
</div>
);
};
export function AdminMemberInfo(props) {
const member = props.result.member;
return (
<div>
<Header size='medium'>Admin Details</Header>
<BasicTable>
<Table.Body>
<Table.Row>
<Table.Cell>Name:</Table.Cell>
<Table.Cell>{member.first_name} {member.last_name}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Status:</Table.Cell>
<Table.Cell>
<Icon name='circle' color={statusColor[member.status]} />
{member.status || 'Unknown'}
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Expire Date:</Table.Cell>
<Table.Cell>{member.expire_date}</Table.Cell>
</Table.Row>
{member.paused_date && <Table.Row>
<Table.Cell>Paused Date:</Table.Cell>
<Table.Cell>{member.paused_date}</Table.Cell>
</Table.Row>}
<Table.Row>
<Table.Cell>Phone:</Table.Cell>
<Table.Cell>{member.phone}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Address:</Table.Cell>
<Table.Cell>{member.street_address}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>City:</Table.Cell>
<Table.Cell>{member.city}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Postal:</Table.Cell>
<Table.Cell>{member.postal_code}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Minor:</Table.Cell>
<Table.Cell>{member.is_minor ? 'Yes' : 'No'}</Table.Cell>
</Table.Row>
{member.is_minor && <Table.Row>
<Table.Cell>Birthdate:</Table.Cell>
<Table.Cell>{member.birthdate}</Table.Cell>
</Table.Row>}
{member.is_minor && <Table.Row>
<Table.Cell>Guardian:</Table.Cell>
<Table.Cell>{member.guardian_name}</Table.Cell>
</Table.Row>}
<Table.Row>
<Table.Cell>Emergency Contact Name:</Table.Cell>
<Table.Cell>{member.emergency_contact_name || 'None'}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Emergency Contact Phone:</Table.Cell>
<Table.Cell>{member.emergency_contact_phone || 'None'}</Table.Cell>
</Table.Row>
</Table.Body>
</BasicTable>
{member.member_forms && <p>
<a href={staticUrl + '/' + member.member_forms} target='_blank'>
View application forms
</a>
</p>}
</div>
);
};

View File

@ -0,0 +1,480 @@
import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import './light.css';
import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment';
import { statusColor, BasicTable, staticUrl, requester } from './utils.js';
import { NotFound } from './Misc.js';
function AdminCardDetail(props) {
const { token, result, card } = props;
const [input, setInput] = useState({ ...card });
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const id = card.id;
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, member_id: result.member.id };
requester('/cards/'+id+'/', 'PUT', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
setInput(res);
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const handleDelete = (e) => {
e.preventDefault();
requester('/cards/'+id+'/', 'DELETE', token)
.then(res => {
setInput(false);
})
.catch(err => {
console.log(err);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
const statusOptions = [
{ key: '0', text: 'Card Active', value: 'card_active' },
{ key: '1', text: 'Card Blocked', value: 'card_blocked' },
{ key: '2', text: 'Card Inactive', value: 'card_inactive' },
{ key: '3', text: 'Card Member Blocked', value: 'card_member_blocked' },
];
return (
input ?
<Segment raised color={input.active_status === 'card_active' ? 'green' : 'red'}>
<Form onSubmit={handleSubmit}>
<Form.Group widths='equal'>
<Form.Input
fluid
{...makeProps('card_number')}
/>
<Form.Select
fluid
options={statusOptions}
{...makeProps('active_status')}
onChange={handleValues}
/>
<Form.Group widths='equal'>
<Form.Button
loading={loading}
error={error.non_field_errors}
>
{success ? 'Saved.' : 'Save'}
</Form.Button>
<Form.Button
color='red'
onClick={handleDelete}
>
Delete
</Form.Button>
</Form.Group>
</Form.Group>
Notes: {input.notes || 'None'}
</Form>
</Segment>
:
<Segment raised color='black'>
Deleted card: {card.card_number}
</Segment>
);
};
export function AdminMemberCards(props) {
const { token, result, refreshResult } = props;
const cards = result.cards;
const startDimmed = Boolean(result.member.paused_date && cards.length);
const [dimmed, setDimmed] = useState(startDimmed);
const [input, setInput] = useState({ active_status: 'card_active' });
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const { id } = useParams();
useEffect(() => {
const startDimmed = Boolean(result.member.paused_date && cards.length);
setDimmed(startDimmed);
}, [result.member]);
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, member_id: result.member.id };
requester('/cards/', 'POST', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
const statusOptions = [
{ key: '0', text: 'Card Active', value: 'card_active' },
{ key: '1', text: 'Card Blocked', value: 'card_blocked' },
{ key: '2', text: 'Card Inactive', value: 'card_inactive' },
{ key: '3', text: 'Card Member Blocked', value: 'card_member_blocked' },
];
return (
<div>
<Header size='medium'>Edit Member Cards</Header>
<Form onSubmit={handleSubmit}>
<Header size='small'>Add a Card</Header>
<Form.Group widths='equal'>
<Form.Input
label='Card Number'
fluid
{...makeProps('card_number')}
/>
<Form.Select
label='Card Status'
options={statusOptions}
fluid
{...makeProps('active_status')}
onChange={handleValues}
/>
<Form.Input
label='Optional Note'
fluid
{...makeProps('notes')}
/>
</Form.Group>
<Form.Button loading={loading} error={error.non_field_errors}>
Submit
</Form.Button>
{success && <div>Success!</div>}
</Form>
<Header size='small'>Current Cards</Header>
<Dimmer.Dimmable dimmed={dimmed}>
{cards.length ?
cards.map(x =>
<AdminCardDetail key={x.id} card={x} {...props} />
)
:
<p>None</p>
}
<Dimmer active={dimmed}>
<p>
Member paused, {cards.length} card{cards.length === 1 ? '' : 's'} ignored anyway.
</p>
<p>
<Button size='tiny' onClick={() => setDimmed(false)}>Close</Button>
</p>
</Dimmer>
</Dimmer.Dimmable>
</div>
);
};
export function AdminMemberPause(props) {
const { token, result, refreshResult } = props;
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const [yousure, setYousure] = useState(false);
const { id } = useParams();
useEffect(() => {
setLoading(false);
}, [result.member]);
const handlePause = (e) => {
if (yousure) {
if (loading) return;
setLoading(true);
setSuccess(false);
requester('/members/' + id + '/pause/', 'POST', token, {})
.then(res => {
setYousure(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(true);
});
} else {
setYousure(true);
}
};
const handleUnpause = (e) => {
if (loading) return;
setLoading(true);
setSuccess(false);
requester('/members/' + id + '/unpause/', 'POST', token, {})
.then(res => {
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(true);
});
};
return (
<div>
<Header size='medium'>Pause / Unpause Membership</Header>
<p>Pause members who are inactive, former, or on vacation.</p>
<p>
{result.member.paused_date ?
<Button onClick={handleUnpause} loading={loading}>
Unpause
</Button>
:
<Button onClick={handlePause} loading={loading}>
{yousure ? 'You Sure?' : 'Pause'}
</Button>
}
</p>
{success && <div>Success!</div>}
{error && <p>Error, something went wrong.</p>}
</div>
);
};
export function AdminMemberForm(props) {
const { token, result, refreshResult } = props;
const [input, setInput] = useState(result.member);
const [error, setError] = useState(false);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const { id } = useParams();
useEffect(() => {
setInput(result.member);
}, [result.member]);
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) => {
if (loading) return;
setLoading(true);
setSuccess(false);
const data = { ...input, email: input.email.toLowerCase() };
requester('/members/' + id + '/', 'PATCH', token, data)
.then(res => {
setLoading(false);
setSuccess(true);
setError(false);
refreshResult();
})
.catch(err => {
setLoading(false);
console.log(err);
setError(err.data);
});
};
const makeProps = (name) => ({
name: name,
onChange: handleChange,
value: input[name] || '',
error: error[name],
});
return (
<div>
<Form onSubmit={handleSubmit}>
<Header size='medium'>Edit Member Details</Header>
<Form.Group widths='equal'>
<Form.Input
label='First Name'
fluid
{...makeProps('first_name')}
/>
<Form.Input
label='Last Name'
fluid
{...makeProps('last_name')}
/>
</Form.Group>
<Form.Input
label='Email'
{...makeProps('email')}
/>
<Form.Input
label='Application Date'
{...makeProps('application_date')}
/>
<Form.Input
label='Current Start Date'
{...makeProps('current_start_date')}
/>
<Form.Input
label='Vetted Date'
{...makeProps('vetted_date')}
/>
<Form.Input
label='Membership Fee'
{...makeProps('monthly_fees')}
/>
<Form.Field>
<label>Is the member an instructor?</label>
<Checkbox
label='Yes'
name='is_instructor'
onChange={handleCheck}
checked={input.is_instructor}
/>
</Form.Field>
<Form.Button loading={loading} error={error.non_field_errors}>
Submit
</Form.Button>
{success && <div>Success!</div>}
</Form>
</div>
);
};
export function AdminMemberInfo(props) {
const member = props.result.member;
return (
<div>
<Header size='medium'>Admin Details</Header>
<BasicTable>
<Table.Body>
<Table.Row>
<Table.Cell>Name:</Table.Cell>
<Table.Cell>{member.first_name} {member.last_name}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Status:</Table.Cell>
<Table.Cell>
<Icon name='circle' color={statusColor[member.status]} />
{member.status || 'Unknown'}
</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Expire Date:</Table.Cell>
<Table.Cell>{member.expire_date}</Table.Cell>
</Table.Row>
{member.paused_date && <Table.Row>
<Table.Cell>Paused Date:</Table.Cell>
<Table.Cell>{member.paused_date}</Table.Cell>
</Table.Row>}
<Table.Row>
<Table.Cell>Phone:</Table.Cell>
<Table.Cell>{member.phone}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Address:</Table.Cell>
<Table.Cell>{member.street_address}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>City:</Table.Cell>
<Table.Cell>{member.city}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Postal:</Table.Cell>
<Table.Cell>{member.postal_code}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Minor:</Table.Cell>
<Table.Cell>{member.is_minor ? 'Yes' : 'No'}</Table.Cell>
</Table.Row>
{member.is_minor && <Table.Row>
<Table.Cell>Birthdate:</Table.Cell>
<Table.Cell>{member.birthdate}</Table.Cell>
</Table.Row>}
{member.is_minor && <Table.Row>
<Table.Cell>Guardian:</Table.Cell>
<Table.Cell>{member.guardian_name}</Table.Cell>
</Table.Row>}
<Table.Row>
<Table.Cell>Emergency Contact Name:</Table.Cell>
<Table.Cell>{member.emergency_contact_name || 'None'}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Emergency Contact Phone:</Table.Cell>
<Table.Cell>{member.emergency_contact_phone || 'None'}</Table.Cell>
</Table.Row>
</Table.Body>
</BasicTable>
{member.member_forms && <p>
<a href={staticUrl + '/' + member.member_forms} target='_blank'>
View application forms
</a>
</p>}
</div>
);
};

View File

@ -0,0 +1,106 @@
import React, { useState, useEffect } from 'react';
import { BrowserRouter as Router, Switch, Route, Link, useParams, useHistory } from 'react-router-dom';
import './light.css';
import { Button, Container, Checkbox, Dimmer, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Segment, Table } from 'semantic-ui-react';
import moment from 'moment';
import { statusColor, BasicTable, staticUrl, requester } from './utils.js';
import { TransactionList, TransactionEditor } from './Transactions.js';
import { NotFound } from './Misc.js';
export function AdminReportedTransactions(props) {
const { token, user } = props;
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 (
<Container>
<Header size='large'>Reported Transactions</Header>
{!error ?
transactions ?
<div>
<TransactionList transactions={transactions} />
</div>
:
<p>Loading...</p>
:
<NotFound />
}
</Container>
);
};
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) => {
if (loading) return;
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 (
<div>
<Header size='medium'>Edit Member Transactions</Header>
<Form onSubmit={handleSubmit}>
<Header size='small'>Add a Transaction</Header>
<TransactionEditor noMemberSearch 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>
<Header size='small'>Current Transactions</Header>
{transactions.length ?
open ?
<TransactionList transactions={transactions} />
:
<Button onClick={() => setOpen(true)}>
View / Edit Transactions
</Button>
:
<p>None</p>
}
</div>
);
};

View File

@ -9,7 +9,8 @@ import { Account } from './Account.js';
import { Transactions, TransactionDetail } from './Transactions.js'; import { Transactions, TransactionDetail } from './Transactions.js';
import { Cards } from './Cards.js'; import { Cards } from './Cards.js';
import { Training } from './Training.js'; import { Training } from './Training.js';
import { AdminReportedTransactions } from './Admin.js'; import { AdminReportedTransactions } from './AdminTransactions.js';
import { Admin } from './Admin.js';
import { Courses, CourseDetail } from './Courses.js'; import { Courses, CourseDetail } from './Courses.js';
import { Classes, ClassDetail } from './Classes.js'; import { Classes, ClassDetail } from './Classes.js';
import { Members, MemberDetail } from './Members.js'; import { Members, MemberDetail } from './Members.js';
@ -132,6 +133,12 @@ function App() {
to='/classes' to='/classes'
/> />
{user && isAdmin(user) && <Dropdown.Item
content='Admin'
as={Link}
to='/admin'
/>}
{user && isAdmin(user) && <Dropdown.Item {user && isAdmin(user) && <Dropdown.Item
content='Admin Trans.' content='Admin Trans.'
as={Link} as={Link}
@ -198,6 +205,12 @@ function App() {
<Members token={token} /> <Members token={token} />
</Route> </Route>
{user && isAdmin(user) &&
<Route path='/admin'>
<Admin token={token} user={user} />
</Route>
}
{user && isAdmin(user) && {user && isAdmin(user) &&
<Route path='/admintrans'> <Route path='/admintrans'>
<AdminReportedTransactions token={token} user={user} /> <AdminReportedTransactions token={token} user={user} />

View File

@ -4,7 +4,8 @@ import './light.css';
import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react'; import { Button, Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Input, Item, Menu, Message, Segment, Table } from 'semantic-ui-react';
import { statusColor, isAdmin, BasicTable, staticUrl, requester } from './utils.js'; import { statusColor, isAdmin, BasicTable, staticUrl, requester } from './utils.js';
import { NotFound, PleaseLogin } from './Misc.js'; import { NotFound, PleaseLogin } from './Misc.js';
import { AdminMemberInfo, AdminMemberPause, AdminMemberForm, AdminMemberCards, AdminTransactions } from './Admin.js'; import { AdminMemberInfo, AdminMemberPause, AdminMemberForm, AdminMemberCards } from './AdminMembers.js';
import { AdminTransactions } from './AdminTransactions.js';
export function MembersDropdown(props) { export function MembersDropdown(props) {
const { token, name, onChange, value, initial } = props; const { token, name, onChange, value, initial } = props;