Skip to content

Commit

Permalink
#165 added function in frontend to save the new resource to the db
Browse files Browse the repository at this point in the history
  • Loading branch information
cynthiac3 committed Feb 1, 2020
1 parent cc7395c commit bef799b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tutify/src/components/Resources/AddResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import DialogActions from '@material-ui/core/DialogActions';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import Avatar from '@material-ui/core/Avatar';
import axios from 'axios';
import swal from 'sweetalert';

class AddResource extends Component {
constructor(props) {
Expand All @@ -21,6 +23,21 @@ class AddResource extends Component {
};
}

addResourceToDB = () => {
axios.post('/api/addResource', {
title: this.state.title,
description: this.state.description,
image: this.state.image,
link: this.state.link,
category: this.state.category,
educationLevel: this.state.educationLevel
}).then((res) => {
console.info("Successfully added the resource");
swal("Resource successfully added!", "", "success")
})
.catch(err => console.error("Could not add the resource to the database: "+err));
}


render() {
const { open, handleClose } = this.props
Expand Down

0 comments on commit bef799b

Please sign in to comment.