Skip to content

Commit

Permalink
Su talks (#179)
Browse files Browse the repository at this point in the history
* this is from pr# 150

* clears console logs

* adds toggle function to edit

* created edit and  save all/delete buttons to talks

* updated edit save and delete features
  • Loading branch information
MrExpert authored and michaelerobertsjr committed Aug 16, 2019
1 parent 608ebb9 commit 6772735
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 47 deletions.
15 changes: 7 additions & 8 deletions common/models/organizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
const { sendEmailToNewAdmin } = require('../../server/utils/sendGridEmailer');

module.exports = function(Organizer) {
Organizer.afterRemote('create', function (ctx, modelInstance, next) {
const username = ctx.result.username;
const email = ctx.result.email;
sendEmailToNewAdmin(username, email)
Organizer.afterRemote('create', function (ctx, modelInstance, next) {
const username = ctx.result.username;
const email = ctx.result.email;
sendEmailToNewAdmin(username, email)
.then(() => next())
.catch(err => {
next(new Error(err.message));
})
});

next(new Error(err.message));
});
});
};
2 changes: 1 addition & 1 deletion server/utils/formatTalkForEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function formatTalkForEmail(speakerId, eventId) {
.then(speaker => {
const speakerName = speaker.speakerName;
const speakerEmail = speaker.speakerEmail
Event.findById(eventId)
return Event.findById(eventId)
.then(selectedEvent => {
const meetupTitle = selectedEvent.name;
const meetupDate = selectedEvent.date;
Expand Down
48 changes: 23 additions & 25 deletions server/utils/talkSubmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,30 @@ const app = require('../server');
const { getMeetups } = require('./getMeetups');

function talkSubmit(speakerInfo, talkInfo, date) {
return new Promise((resolve, reject) => {
const { Talk, Speaker, Event } = app.models;
Speaker.create(speakerInfo)
.then(response => {
let speakerId = response.id
getMeetups()
.then(meetups => {
const index = meetups.findIndex((item) => item.date == date);
let name = meetups[index].name;
let details = meetups[index].description;
let meetupId = meetups[index].meetupId;
if (index === -1 )
return reject(new Error('NO meetup with that date found!'));
Event.findOrCreate({date, name, details, meetupId})
.then(event => {
let eventId = event[0].id
Talk.create( { ...talkInfo, speakerId, eventId})
.then(talk => resolve(talk))
.catch(err => console.log(err))
})
.catch(err => reject(err))
})
.catch(err => reject(err))
const { Talk, Speaker, Event } = app.models;
return getMeetups()
.then(meetups => {
const index = meetups.findIndex((item) => item.date == date);
let name = meetups[index].name;
let details = meetups[index].description;
let meetupId = meetups[index].meetupId;
if (index === -1)
return reject(new Error('NO meetup with that date found!'));
return Promise.all([
Event.findOrCreate({
date, name, details,
meetupId
}),
Speaker.create(speakerInfo)])
})
.then(([event, speaker]) => {
let eventId = event[0].id
let speakerId = speaker.id
return Talk.create({
...talkInfo,
speakerId, eventId
})
.catch(err => reject(err))
})
})
}

module.exports = { talkSubmit };
32 changes: 21 additions & 11 deletions src/components/Talks/Talks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const EditOptions = ({ talkId, handleSelect, name, children }) => {
return (
<div className='table-tableAction'>
<div className='table-tableStatus'>
<select data-type={name} name={talkId} onChange={handleSelect}>
<select data-type={name} name={talkId} onChange={handleSelect} >
<option value=''>Change {name}</option>
{children}
<option value='None'>None</option>
Expand All @@ -38,16 +38,12 @@ const ShowMore = ({ topic, description, adminNotes, talkId, toggleShowMoreFuncti
</div>
<div className='table-editTalk'>
<label>Topic: </label>
<input defaultValue={topic} name={talkId} data-type={'Topic'} onChange={handleTalkChange} />
<textarea defaultValue={topic} name={talkId} data-type={'Topic'} onChange={handleTalkChange} />
<label>Description: </label>
<textarea defaultValue={description} name={talkId} data-type={'Description'} onChange={handleTalkChange} />
<label>Admin Notes: </label>
<textarea defaultValue={adminNotes} name={talkId} data-type={'Admin Notes'} onChange={handleTalkChange} />
</div>
<div className='side-by-side-btns'>
<button className='btn' name={talkId} onClick={updateTalkInfo}>Save</button>
<button className='btn' name={talkId} onClick={toggleTalkEditFunction}>Cancel</button>
</div>
</div>
:
<div>
Expand Down Expand Up @@ -102,6 +98,7 @@ class Talks extends Component {
toggleShowMore(e) {
const { dispatch } = this.props;
dispatch(toggleShowMore(e.target.getAttribute('name'), e.target.getAttribute('value')));

}

deleteTalk(e) {
Expand All @@ -111,8 +108,9 @@ class Talks extends Component {

toggleTalkEdit(e) {
const { dispatch } = this.props;
dispatch(toggleShowMore(e.target.getAttribute('name'), e.target.getAttribute('value')));
dispatch(toggleTalkEdit(e.target.getAttribute('name'), e.target.getAttribute('value')));
}
}

handleTalkChange(e) {
const { dispatch } = this.props;
Expand Down Expand Up @@ -172,8 +170,20 @@ class Talks extends Component {
data={{
speaker: talk.speaker,
speakerEmail: <a href={`mailto:${talk.speakerEmail}`} target="_top"><i className="far fa-envelope"></i>Send Email</a>,
speakerPhone: <div><i className="fas fa-phone"></i>{talk.speakerPhone}</div>
}} />
speakerPhone: <div><i className="fas fa-phone"></i>{talk.speakerPhone}</div>,
speakerEdit: <div><br/><br/>
<div> { talk.toggleTalkEdit ? null: [
<div ><i className="far fa-edit" name={talk.talkId} value={talk.toggleTalkEdit} onClick={this.toggleTalkEdit}></i>Edit</div>,
<div><i className="fas fa-trash-alt" name={talk.talkId} onClick={this.deleteTalk}></i>Delete</div>
] }
</div>
<div className='side-by-side-btns'>{ talk.toggleTalkEdit ? [
<button className='btn' name={talk.talkId} onClick={this.updateTalkInfo}>Save all</button>,
<button className='btn' name={talk.talkId} onClick={this.toggleTalkEdit}>Cancel</button>
] : null}
</div>
</div>
}} />
case 'Talk':
return <TableRow key={i}>
<div className='options'>
Expand Down Expand Up @@ -214,7 +224,7 @@ class Talks extends Component {
handleSubmit={this.handleSubmitStatus}
toggleEditFunction={this.toggleStatusEdit}
toggleEditProp={talk.toggleStatusEdit}
name={'Status'}>
name={talk.currentStatus}>
<option value='In Contact'>In Contact</option>
<option value='Approve'>Approve</option>
<option value='Deny'>Deny</option>
Expand All @@ -237,7 +247,7 @@ class Talks extends Component {
handleSubmit={this.handleSubmitOwner}
toggleEditFunction={this.toggleOwnerEdit}
toggleEditProp={talk.toggleOwnerEdit}
name={'Owner'}
name={talk.owner}
>
{organizers.map((organizer, i) => <option key={i} value={organizer.username}>{organizer.username}</option>)}
</EditOptions>
Expand Down
1 change: 0 additions & 1 deletion src/components/Talks/TalksActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export const toggleTalkEdit = (talkId, toggle) => {
}
};


export const deleteTalk = (talkId, accessToken) => {
return {
type: 'DELETE_TALK',
Expand Down
1 change: 1 addition & 0 deletions src/components/Talks/TalksReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export default function TalksReducer(state = initialState, action) {
talkInfo: updatedTalkInfo
}
}

case 'DELETE_TALK_FULFILLED': {
const deleteIndex = state.talkInfo.findIndex((talk) => talk.talkId == payload)
const updatedTalkInfo = [...state.talkInfo]
Expand Down
5 changes: 5 additions & 0 deletions src/css/talk.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@
margin-left: 10px;
}
}

input { display: none }

input:checked + div{ display: none }


.table-editTalk {
margin: 20px 0;
Expand Down
2 changes: 1 addition & 1 deletion src/rootReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const rootReducer = combineReducers({
PastTalks : PastTalksReducer,
});

export default rootReducer;
export default rootReducer;

0 comments on commit 6772735

Please sign in to comment.