Skip to content

Commit

Permalink
squash roster bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiarba committed Feb 12, 2021
1 parent 8df642e commit 98a9e5d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 45 deletions.
11 changes: 5 additions & 6 deletions client/src/components/Roster.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as decode from 'jwt-decode';
import RosterCard from './RosterCard';
import 'antd/dist/antd.css';

const Roster = (props) => {
const Roster = props => {
const [roster, setRoster] = useState([]);
const {ismentor} = props;
const { ismentor } = props;
// state = {
// roster: [],
// isMentor: this.props.ismentor,
Expand All @@ -29,7 +29,7 @@ const Roster = (props) => {
.then(roster => {
setRoster(roster);
});
});
}, []);

const rosterCards = roster.map(person => (
<RosterCard key={person.id} person={person} mentor={ismentor} />
Expand All @@ -40,7 +40,6 @@ const Roster = (props) => {
<div className="containerGrid">{rosterCards}</div>
</div>
);
};

}

export default Roster;
export default Roster;
60 changes: 22 additions & 38 deletions client/src/components/RosterCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,19 @@ import 'antd/dist/antd.css';

const { TextArea } = Input;

const RosterCard = (props) => {
// constructor(props) {
// super(props);
// this.state = {
// showEditModal: false,
// userId: this.props.person.id,
// username: this.props.person.name,
// email: this.props.person.email,
// candy: this.props.person.candy,
// hobby: this.props.person.hobby,
// notes: this.props.person.notes,
// editedNotes: this.props.person.notes,
// };
// this.onChangeNotes = this.onChangeNotes.bind(this);
// this.editStudentProfile = this.editStudentProfile.bind(this);
// }
const { userId, username, email, candy, hobby} = props.person;
const RosterCard = props => {
const { mentor, person } = props;

const { id, username, email, candy, hobby, notes } = person;
const [showEditModal, setShowEditModal] = useState(false);
const [editedNotes, setEditedNotes] = useState('');
const [notes, setNotes] = useState(props.person.notes);
const {mentor} = props;
const [displayNotes, setDisplayNotes] = useState(notes);

console.log(props);

const onChangeNotes = (event) => {
const onChangeNotes = event => {
setEditedNotes(event.target.value);
}
};

const editStudentProfile = () => {
if (editedNotes.length >= 255) {
Expand All @@ -45,7 +32,7 @@ const RosterCard = (props) => {
method: 'POST',
body: JSON.stringify({
editedNotes,
userId,
id,
}),
headers: new Headers({
'Content-Type': 'application/json',
Expand All @@ -54,9 +41,10 @@ const RosterCard = (props) => {
.then(res => res.json())
.then(() => {
setShowEditModal(false);
setNotes(editedNotes);
});
}
setDisplayNotes(editedNotes);
})
.catch(err => console.log('unable to update roster'));
};

const renderDescription = () => {
let description;
Expand All @@ -67,7 +55,7 @@ const RosterCard = (props) => {
<p>Email: {email}</p>
<p>Favorite Candy: {candy}</p>
<p>Favorite Hobby: {hobby}</p>
<p>Notes: {notes}</p>
<p>Notes: {displayNotes}</p>
</div>
);
} else {
Expand All @@ -79,7 +67,7 @@ const RosterCard = (props) => {
);
}
return description;
}
};

const renderEditButton = () => {
// const { mentor } = this.props;
Expand All @@ -96,7 +84,7 @@ const RosterCard = (props) => {
title="Edit Student Notes"
okText="Update"
onCancel={() => setShowEditModal(false)}
onOk={editStudentProfile()}
onOk={editStudentProfile}
>
<Row>
<Col>
Expand All @@ -106,7 +94,7 @@ const RosterCard = (props) => {
addonBefore="Notes:"
autosize="true"
defaultValue={notes}
onChange={onChangeNotes()}
onChange={onChangeNotes}
/>
</Col>
</Row>
Expand All @@ -115,27 +103,23 @@ const RosterCard = (props) => {
);
}
return editButton;
}

};

const description = renderDescription();
const maybeEditButton = renderEditButton();

return (
<div>
<Card
style={{ width: 300 }}
cover={
<img alt="" src="https://image.flaticon.com/icons/svg/1141/1141771.svg" />
}
cover={<img alt="" src="https://image.flaticon.com/icons/svg/1141/1141771.svg" />}
>
{description}
{maybeEditButton}
</Card>
</div>
);
}

};

RosterCard.propTypes = {
mentor: PropTypes.bool,
Expand All @@ -144,4 +128,4 @@ RosterCard.defaultProps = {
mentor: false,
};

export default RosterCard;
export default RosterCard;
2 changes: 1 addition & 1 deletion controllers/rosters_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const getUsersBySite = async (req, res) => {
const update = async (req, res) => {
try {
const data = await knex('user')
.where({ id: req.body.userId })
.where({ id: req.body.id })
.update({ notes: req.body.editedNotes });
return res.status(200).send({ data });
} catch (error) {
Expand Down

0 comments on commit 98a9e5d

Please sign in to comment.