-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to edit events. Relies upon members_api adjust_event_route_and_permissions #10
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ | |
|
||
echo "Starting up. PORT is $PORT" | ||
export PATH=$PATH:$(pwd)/node_modules/.bin | ||
yarn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes should probably be discarded |
||
#yarn run start | ||
npm run start |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ import Forgot from './pages/forgot'; | |
import UpdatePassword from './pages/updatepassword'; | ||
import Events from './pages/events'; | ||
import Event from './pages/event'; | ||
import EventEdit from './pages/event_edit'; | ||
import Certs from './pages/certs'; | ||
import CertDetails from './pages/cert_details'; | ||
|
||
|
@@ -59,6 +60,7 @@ render(( | |
<PrivateRoute exact path="/users/:id" component={UserDetails} /> | ||
<PrivateRoute exact path="/events" component={Events} /> | ||
<PrivateRoute exact path="/events/:event_id" component={Event} /> | ||
<PrivateRoute exact path="/events/:event_id/edit" component={EventEdit} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Upon rebasing from the latest develop you'll notice that this section changed slightly. |
||
<PrivateRoute exact path="/certs" component={Certs} /> | ||
<PrivateRoute exact path="/certs/:id" component={CertDetails} /> | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,11 @@ | |
|
||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import CircularProgress from '@material-ui/core/CircularProgress'; | ||
|
||
import Header from '../components/header'; | ||
import { getOne, formatDateRange } from '../state/events'; | ||
|
||
const actionCreators = { getOne }; | ||
import { read, formatDateRange } from '../state/events'; | ||
|
||
const baseStyles = { | ||
eventDescription: { | ||
|
@@ -27,36 +27,51 @@ const baseStyles = { | |
}; | ||
|
||
class App extends Component { | ||
componentDidMount(){ | ||
this.props.getOne(this.props.match.params.event_id); | ||
state = { | ||
id: null, | ||
name: '', | ||
frequency: '', | ||
location: '', | ||
description: '', | ||
start_date: null, | ||
end_date: null | ||
}; | ||
|
||
async componentDidMount(){ | ||
// this.props.read(this.props.match.params.event_id); | ||
const { id, name, frequency, location, description, start_date, end_date } = await this.props.read(this.props.match.params.event_id); | ||
this.setState({ id, name, frequency, location, description, start_date, end_date }); | ||
} | ||
|
||
render() { | ||
const { events } = this.props; | ||
// const event = this.props.getOne(1); //this.props.match.params.event_id | ||
// const { events } = this.props; | ||
// const event = this.props.read(1); //this.props.match.params.event_id | ||
|
||
let eventList = ''; | ||
const ev = events.one; | ||
// let eventList = ''; | ||
// const ev = this.props.read; | ||
const { read } = this.props.events; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: it would be nice to alias this name to something human friendly. "Read" is kid of a vague name for a variable
Comment on lines
+42
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call made line 42 will eventually populate the read variable line 52, we should not store the data loaded for redux in the component state |
||
|
||
if(ev) { | ||
var dateRange = formatDateRange(ev); | ||
|
||
eventList = ( | ||
<div> | ||
<h2>{ev.name}</h2> | ||
<h5>{dateRange.full_date_string} ({ev.frequency})</h5> | ||
<i>{ev.location}</i> | ||
return ( | ||
<div style={baseStyles.container}> | ||
<Header/> | ||
{read ? ( | ||
<> | ||
<h2>{this.state.name}</h2> | ||
<h5> | ||
{formatDateRange(this.state.start_date, this.state.end_date).full_date_string} | ||
({this.state.frequency}) | ||
</h5> | ||
<i>{this.state.location}</i> | ||
<p style={baseStyles.eventDescription}> | ||
{ev.description} | ||
{this.state.description} | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div style={baseStyles.container}> | ||
<Header/> | ||
{eventList} | ||
</div> | ||
<Link to={`/events/${this.state.id}/edit`}>Edit</Link> | ||
</> | ||
) : ( | ||
<CircularProgress/> | ||
)} | ||
</div> | ||
); | ||
} | ||
} | ||
|
@@ -67,4 +82,4 @@ function mapStateToProps(state) { | |
} | ||
|
||
|
||
export default connect(mapStateToProps, actionCreators)(App); | ||
export default connect(mapStateToProps, { read })(App); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
// Copyright 2019 Iced Development, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import CircularProgress from '@material-ui/core/CircularProgress'; | ||
import TextField from '@material-ui/core/TextField'; | ||
import Button from '@material-ui/core/Button'; | ||
import { DataGrid } from '@material-ui/data-grid'; | ||
import Header from '../components/header'; | ||
import { read, edit, add } from '../state/events'; | ||
|
||
|
||
const styles = { | ||
eventDescription: { | ||
whiteSpace: 'pre-line', | ||
}, | ||
tableContainer: { | ||
// margin: '10px', | ||
}, | ||
gridContainer: { | ||
width: '100%', | ||
display: 'flex', | ||
height: 450 | ||
}, | ||
nameField: { | ||
fontSize: '1.5em', | ||
magin: '5px', | ||
}, | ||
descriptionFeild: { | ||
width: '125ch', | ||
magin: '5px', | ||
}, | ||
form: { | ||
width: '90%', | ||
margin: '5px', | ||
}, | ||
formButton: { | ||
margin: '5px', | ||
}, | ||
}; | ||
|
||
const columns = [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless I'm missing something this is unused? |
||
{ field: 'id', hide: true }, | ||
{ | ||
field: 'user_name', | ||
headerName: 'Name', | ||
align: 'left', | ||
width: 250, | ||
renderCell: (params) => { | ||
return <Link to={`/users/${params.data.user_id}`}>{params.value}</Link> | ||
}, | ||
}, | ||
{ | ||
field: 'created_at', | ||
headerName: 'Created', | ||
align: 'right', | ||
valueFormatter: (params) => { | ||
return new Date(params.value).toLocaleDateString(); | ||
}, | ||
}, | ||
]; | ||
|
||
class Events extends Component { | ||
state = { | ||
name: '', | ||
frequency: '', | ||
location: '', | ||
description: '', | ||
start_date: '', | ||
end_date: '' | ||
}; | ||
|
||
nameChange = (e) => { | ||
this.setState({name: e.target.value}); | ||
}; | ||
|
||
frequencyChange = (e) => { | ||
this.setState({frequency: e.target.value}); | ||
}; | ||
|
||
locationChange = (e) => { | ||
this.setState({location: e.target.value}); | ||
}; | ||
|
||
descriptionChange = (e) => { | ||
this.setState({description: e.target.value}); | ||
}; | ||
|
||
startDateChange = (e) => { | ||
this.setState({start_date: e.target.value}); | ||
}; | ||
|
||
endDateChange = (e) => { | ||
this.setState({end_date: e.target.value}); | ||
}; | ||
|
||
submitForm = () => { | ||
const { event_id } = this.props.match.params; | ||
const { name, frequency, description } = this.state; | ||
this.props.edit(event_id, { name, frequency, description }); | ||
}; | ||
|
||
async componentDidMount(){ | ||
const { event_id } = this.props.match.params; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reference to props.match.Paramus will break after the update. Tldr is react router stopped supporting classes and we have to use a hack to get access to the params (on my big update PR, look for withRouter calls.) |
||
const { id, name, frequency, location, description, start_date, end_date } = await this.props.read(event_id); | ||
this.setState({ id, name, frequency, location, description, start_date, end_date }); | ||
} | ||
|
||
render() { | ||
|
||
const { read } = this.props.events; | ||
const { auth } = this.props.user; | ||
return ( | ||
<div style={styles.container}> | ||
<Header/> | ||
{auth.isAdmin && read ? ( | ||
<div style={styles.form}> | ||
<TextField | ||
label="Name" | ||
style={styles.nameField} | ||
value={this.state.name} | ||
onChange={this.nameChange} | ||
/> | ||
<br/> | ||
<TextField | ||
label="Frequency" | ||
style={styles.frequencyField} | ||
value={this.state.frequency} | ||
onChange={this.frequencyChange} | ||
/> | ||
<br/> | ||
<TextField | ||
label="Location" | ||
style={styles.locationField} | ||
value={this.state.location} | ||
onChange={this.locationChange} | ||
/> | ||
<br/> | ||
<TextField | ||
label="Description" | ||
fullWidth | ||
multiline | ||
style={styles.nameField} | ||
value={this.state.description} | ||
onChange={this.descriptionChange} | ||
/> | ||
<TextField | ||
label="Start Date" | ||
style={styles.startDateField} | ||
value={this.state.start_date} | ||
onChange={this.startDateChange} | ||
/> | ||
<TextField | ||
label="End Date" | ||
style={styles.endDateField} | ||
value={this.state.end_date} | ||
onChange={this.endDateChange} | ||
/> | ||
<br/> | ||
<Button | ||
style={styles.formButton} | ||
variant="contained" | ||
color="primary" | ||
onClick={this.submitForm} | ||
> | ||
Update | ||
</Button> | ||
<Link to={`/events/${this.state.id}`}>Back</Link> | ||
</div> | ||
) : ( | ||
<> | ||
<h1>{read ? read.name : ''}</h1> | ||
<h2>{read ? read.description : ''}</h2> | ||
</> | ||
)} | ||
|
||
</div> | ||
); | ||
} | ||
} | ||
|
||
function mapStateToProps(state) { | ||
const { events } = state; | ||
return { events }; | ||
} | ||
|
||
|
||
export default connect(mapStateToProps, { read, edit, add })(Events); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,17 +53,17 @@ class App extends Component { | |
render() { | ||
const { events } = this.props; | ||
let allEventList = ''; | ||
console.log(events); | ||
|
||
if(events.all) { | ||
if(events.getAll) { | ||
allEventList = ( | ||
<div> | ||
<h2>All Events</h2> | ||
<div> | ||
{events.all.map((e) => { | ||
const dateRange = formatDateRange(e); | ||
{events.getAll.map((e) => { | ||
return <div key={e.id} style={baseStyles.card}> | ||
<h5><Link to={`/events/${e.id}`}>{e.name}</Link></h5> | ||
{dateRange.full_date_string} ({e.frequency}) <br/> | ||
{formatDateRange(e.start_date, e.end_date).full_date_string} ({e.frequency}) <br/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: This should probably be memoized to avoid having to execute the same function every time the page is retendered. |
||
<i>{e.location}</i> | ||
<p>{e.description}</p> | ||
</div>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes should probably be discarded