Update person edit route
This commit is contained in:
@@ -12,6 +12,7 @@ class AdminPeople extends React.Component {
|
|||||||
firstname: PropTypes.string,
|
firstname: PropTypes.string,
|
||||||
lastname: PropTypes.string,
|
lastname: PropTypes.string,
|
||||||
completed: PropTypes.boolean,
|
completed: PropTypes.boolean,
|
||||||
|
ceremony: PropTypes.boolean,
|
||||||
email: PropTypes.string,
|
email: PropTypes.string,
|
||||||
password: PropTypes.string,
|
password: PropTypes.string,
|
||||||
attending: PropTypes.boolean,
|
attending: PropTypes.boolean,
|
||||||
@@ -31,6 +32,8 @@ class AdminPeople extends React.Component {
|
|||||||
<td>Name</td>
|
<td>Name</td>
|
||||||
<td>Email</td>
|
<td>Email</td>
|
||||||
<td>Password</td>
|
<td>Password</td>
|
||||||
|
<td>Ceremony</td>
|
||||||
|
<td>Responded</td>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -39,6 +42,8 @@ class AdminPeople extends React.Component {
|
|||||||
<td><Link to={`/admin/person/${person.key}`}>{person.firstname} {person.lastname}</Link></td>
|
<td><Link to={`/admin/person/${person.key}`}>{person.firstname} {person.lastname}</Link></td>
|
||||||
<td>{person.email}</td>
|
<td>{person.email}</td>
|
||||||
<td><Link to={`/rsvp/${person.password}`}>{person.password}</Link></td>
|
<td><Link to={`/rsvp/${person.password}`}>{person.password}</Link></td>
|
||||||
|
<td>{person.ceremony ? 'Full day' : 'Evening only'}</td>
|
||||||
|
<td>{person.completed ? 'Yes' : 'No'}</td>
|
||||||
<td>
|
<td>
|
||||||
<form method="post" action="/admin/person/delete">
|
<form method="post" action="/admin/person/delete">
|
||||||
<input type="hidden" name="key" value={person.key} />
|
<input type="hidden" name="key" value={person.key} />
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export default {
|
|||||||
path: '/admin/people',
|
path: '/admin/people',
|
||||||
|
|
||||||
async action() {
|
async action() {
|
||||||
const resp = await fetchQL('{getAllPersons{key,firstname,lastname,email,completed,password}}');
|
const resp = await fetchQL('{getAllPersons{key,firstname,lastname,email,ceremony,completed,password}}');
|
||||||
|
|
||||||
let people = await resp.json();
|
let people = await resp.json();
|
||||||
if (people.data && people.data.getAllPersons) {
|
if (people.data && people.data.getAllPersons) {
|
||||||
|
|||||||
@@ -36,7 +36,12 @@ class AdminPerson extends React.Component {
|
|||||||
<div className={s.root}>
|
<div className={s.root}>
|
||||||
<div className={s.container}>
|
<div className={s.container}>
|
||||||
<h1>{this.state.firstname} {this.state.lastname}</h1>
|
<h1>{this.state.firstname} {this.state.lastname}</h1>
|
||||||
<form method="post" action="/admin/person_todo">
|
<form method="post" action="/admin/person">
|
||||||
|
<input
|
||||||
|
type="hidden"
|
||||||
|
name="key"
|
||||||
|
value={this.props.person.key}
|
||||||
|
/>
|
||||||
<div className={s.formGroup}>
|
<div className={s.formGroup}>
|
||||||
<label className={s.label} htmlFor="firstname">
|
<label className={s.label} htmlFor="firstname">
|
||||||
First name:
|
First name:
|
||||||
|
|||||||
@@ -242,9 +242,20 @@ app.post('/admin/person', (req, res, next) => {
|
|||||||
if (req.body.password && req.body.password !== '') {
|
if (req.body.password && req.body.password !== '') {
|
||||||
data.password = req.body.password;
|
data.password = req.body.password;
|
||||||
}
|
}
|
||||||
|
let promise;
|
||||||
Person.create(data);
|
if (req.body.key) {
|
||||||
res.redirect('/admin/people');
|
promise = Person.update(data, {
|
||||||
|
where: { key: req.body.key },
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
promise = Person.create(data);
|
||||||
|
}
|
||||||
|
promise.then(() => {
|
||||||
|
res.redirect('/admin/people');
|
||||||
|
}).catch(err => {
|
||||||
|
Rollbar.handleError(err);
|
||||||
|
next(err);
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
Rollbar.handleError(err);
|
Rollbar.handleError(err);
|
||||||
next(err);
|
next(err);
|
||||||
|
|||||||
Reference in New Issue
Block a user