import React from "react" import { connect } from "react-redux" import { SpinnerCircular } from "spinners-react"; import InputMask from 'react-input-mask'; import { sendFeedback, sendNewAppeal } from "../../../actions" import { _checkStrValue } from "../../../utils"; class Rating extends React.Component { constructor(props) { super(props) this.state = { name: "", phone: "", comment: "", opened: false, hidden: false, deleted: false, rating: 0, hovered: 0, stars: [], completed: false, publish: false, loading: false, errors: [], } let outOf = props.outOf ? props.outOf : 5 for (var i = 0; i < outOf; i++) { this.state.stars.push(i + 1) } } static getDerivedStateFromProps(nextProps, prevState) { return {} } componentDidMount() {} componentDidUpdate(prevProps, prevState) {} changeRating(newRating) { this.setState({ rating: newRating }) if (this.props.onChange) this.props.onChange(newRating) } _handle_hoverRating(rating) { this.setState({ hovered: rating, }) } _handleRate = (newRating) => { this.setState({ rating: newRating, hovered: newRating, opened: true, }); this.props.onRate(true); } _handle_onFieldChange = (field, value) => { const update = { ...this.state }; update[field] = value; this.setState(update); } _handle_onSetPublished = () => { const { name, phone, comment, rating } = this.state; if(!this.state.publish) { this.setState({ publish: this.state.publish ? false : true }); sendFeedback({ name, phone, comment, rating, }) .then(() => {}) .catch(() => {}); setTimeout(() => { this.setState({ hidden: true }) this.props.onRate(false); }, 1000); setTimeout(() => { this.setState({ deleted: true }) }, 2000); } } _removeError = (name) => { const errors = [ ...this.state.errors ]; if(typeof name === "string") { if(errors.indexOf(name) > -1) { errors.splice(errors.indexOf(name), 1); } } else { for(let i in name) { if(errors.indexOf(name[i]) > -1) { errors.splice(errors.indexOf(name[i]), 1); } } } this.setState({ errors }); } _handle_onFormSubmit = (event) => { event.preventDefault(); const { name, phone, comment, rating } = this.state; const payload = { name: name, phone: phone, email: "", description: comment, contract_numbers: [], evaluation: rating, }; this.setState({ completed: true, loading: true }, () => { sendNewAppeal(payload) .then((result) => { this.setState({ completed: true, loading: false }); }); }); } render() { const { opened, hidden, deleted, stars, rating, hovered, completed, publish, loading, name, phone, comment, errors } = this.state const data = ["Очень плохо", "Плохо", "Нормально", "Хорошо", "Отлично"] if(deleted) { return null; } else { return (