SHARE
TWEET

Untitled

a guest Jun 16th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #viewset class from python
  2. class feedbackViewSet(viewsets.ModelViewSet):
  3.     queryset = feedback.objects.all()
  4.     permission_classes = [
  5.         permissions.AllowAny
  6.     ]
  7.     serializer_class = feedbackSerializer
  8.      
  9. //axios post method
  10. export const addFeedback = feedback => dispatch => {
  11.   axios
  12.     .post("/api/feedbacks/", feedback)
  13.     .then(res => {
  14.       dispatch({
  15.         type: ADD_FEEDBACK,
  16.         payload: res.data
  17.       });
  18.     })
  19.     .catch(err => console.log(err));
  20. };
  21.      
  22. //form component code
  23. import React, { Component } from "react";
  24.  
  25. import { connect } from "react-redux";
  26. import PropTypes from "prop-types";
  27. import { addFeedback } from "../../actions/feedbacks";
  28.  
  29. export class Form extends Component {
  30.   state = {
  31.     name: "",
  32.     email: "",
  33.     description: ""
  34.   };
  35.  
  36.   static propTypes = {
  37.     addFeedback: PropTypes.func.isRequired
  38.   };
  39.  
  40.   onChange = e => this.setState({ [e.target.name]: e.target.value });
  41.  
  42.   onSubmit = e => {
  43.     e.preventDefault();
  44.     const { name, email, description } = this.state;
  45.     const feedback = { name, email, description };
  46.     this.props.addFeedback(feedback);
  47.   };
  48.   render() {
  49.     const { name, email, description } = this.state;
  50.     return (
  51.       //some form generation code
  52.     );
  53.   }
  54. }
  55.  
  56. export default connect(
  57.   null,
  58.   { addFeedback }
  59. )(Form);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top