🔥
This commit is contained in:
77
src/routes/adminPerson/AdminPerson.css
Normal file
77
src/routes/adminPerson/AdminPerson.css
Normal file
@@ -0,0 +1,77 @@
|
||||
@import '../../components/variables.css';
|
||||
|
||||
.root {
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.container {
|
||||
margin: 0 auto;
|
||||
padding: 0 0 40px;
|
||||
max-width: var(--max-content-width);
|
||||
}
|
||||
|
||||
.formGroup {
|
||||
position: relative;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.label {
|
||||
display: inline-block;
|
||||
margin-bottom: 5px;
|
||||
max-width: 100%;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.input {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
padding: 10px 16px;
|
||||
width: 100%;
|
||||
height: 46px;
|
||||
outline: 0;
|
||||
border: 1px solid var(--colour-grey);
|
||||
border-radius: 0;
|
||||
background-color: #fff;
|
||||
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
|
||||
color: #616161;
|
||||
font-size: 18px;
|
||||
line-height: 1.3333333;
|
||||
transition: border-color ease-in-out 0.15s,
|
||||
box-shadow ease-in-out 0.15s,
|
||||
background-color ease-in-out 0.15s;
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
border-color: var(--colour-tertiary);
|
||||
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 8px rgba(0, 116, 194, 0.6);
|
||||
}
|
||||
|
||||
.button {
|
||||
display: block;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 10px 16px;
|
||||
width: 100%;
|
||||
outline: 0;
|
||||
border: 1px solid var(--colour-secondary);
|
||||
border-radius: 0;
|
||||
background: var(--colour-primary);;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 18px;
|
||||
line-height: 1.3333333;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: var(--colour-secondary);
|
||||
}
|
||||
|
||||
.button:focus {
|
||||
border-color: var(--colour-tertiary);
|
||||
box-shadow: 0 0 8px var(--colour-secondary);
|
||||
}
|
||||
|
||||
|
||||
101
src/routes/adminPerson/AdminPerson.js
Normal file
101
src/routes/adminPerson/AdminPerson.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import withStyles from 'isomorphic-style-loader/lib/withStyles';
|
||||
import s from './AdminPerson.css';
|
||||
|
||||
class AdminPerson extends React.Component {
|
||||
static propTypes = {
|
||||
title: PropTypes.string.isRequired,
|
||||
person: PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
firstname: PropTypes.string,
|
||||
lastname: PropTypes.string,
|
||||
completed: PropTypes.boolean,
|
||||
email: PropTypes.string,
|
||||
password: PropTypes.string,
|
||||
attending: PropTypes.boolean,
|
||||
}).isRequired,
|
||||
};
|
||||
|
||||
state = {
|
||||
firstname: this.props.person.firstname,
|
||||
lastname: this.props.person.lastname,
|
||||
};
|
||||
|
||||
handleFirstnameChange = (event) => {
|
||||
this.setState({ firstname: event.target.value });
|
||||
}
|
||||
|
||||
handleLastnameChange = (event) => {
|
||||
this.setState({ lastname: event.target.value });
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className={s.root}>
|
||||
<div className={s.container}>
|
||||
<h1>{this.state.firstname} {this.state.lastname}</h1>
|
||||
<form method="post" action="/admin/person_todo">
|
||||
<div className={s.formGroup}>
|
||||
<label className={s.label} htmlFor="firstname">
|
||||
First name:
|
||||
</label>
|
||||
<input
|
||||
className={s.input}
|
||||
id="firstname"
|
||||
type="text"
|
||||
name="firstname"
|
||||
defaultValue={this.props.person.firstname}
|
||||
onChange={this.handleFirstnameChange}
|
||||
/>
|
||||
</div>
|
||||
<div className={s.formGroup}>
|
||||
<label className={s.label} htmlFor="lastname">
|
||||
Last name:
|
||||
</label>
|
||||
<input
|
||||
className={s.input}
|
||||
id="lastname"
|
||||
type="text"
|
||||
name="lastname"
|
||||
defaultValue={this.props.person.lastname}
|
||||
onChange={this.handleLastnameChange}
|
||||
/>
|
||||
</div>
|
||||
<div className={s.formGroup}>
|
||||
<label className={s.label} htmlFor="email">
|
||||
Email:
|
||||
</label>
|
||||
<input
|
||||
className={s.input}
|
||||
id="email"
|
||||
type="text"
|
||||
name="email"
|
||||
defaultValue={this.props.person.email}
|
||||
/>
|
||||
</div>
|
||||
<div className={s.formGroup}>
|
||||
<label className={s.label} htmlFor="password">
|
||||
Password:
|
||||
</label>
|
||||
<input
|
||||
className={s.input}
|
||||
id="password"
|
||||
type="text"
|
||||
name="password"
|
||||
defaultValue={this.props.person.password}
|
||||
/>
|
||||
</div>
|
||||
<div className={s.formGroup}>
|
||||
<button className={s.button} type="submit">
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withStyles(s)(AdminPerson);
|
||||
38
src/routes/adminPerson/index.js
Normal file
38
src/routes/adminPerson/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import Layout from '../../components/Layout';
|
||||
import fetchQL from '../../core/fetchQL';
|
||||
|
||||
export default {
|
||||
|
||||
path: '/admin/person/:key',
|
||||
|
||||
async action({ params }) {
|
||||
if (!params.key) {
|
||||
return { redirect: '/admin' };
|
||||
}
|
||||
|
||||
const resp = await fetchQL('{getPersonByKey{key,firstname,lastname,email,completed,password,starter,main,dietary}}', {
|
||||
key: params.key,
|
||||
});
|
||||
|
||||
let person = await resp.json();
|
||||
if (person.data && person.data.getPersonByKey && person.data.getPersonByKey.length === 1) {
|
||||
person = person.data.getPersonByKey[0];
|
||||
} else {
|
||||
return { redirect: '/admin' };
|
||||
}
|
||||
|
||||
const AdminPerson = await new Promise((resolve) => {
|
||||
require.ensure([], (require) => resolve(require('./AdminPerson').default), 'adminPerson');
|
||||
});
|
||||
|
||||
const title = `${person.firstname} ${person.lastname}`;
|
||||
|
||||
return {
|
||||
title,
|
||||
chunk: 'admin',
|
||||
component: <Layout><AdminPerson title={title} person={person} /></Layout>,
|
||||
};
|
||||
},
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user