import React from "react"; import Head from "next/head"; import Image from "next/image"; import { connect } from "react-redux"; import { withRouter } from "next/router"; import moment from "moment"; import { SpinnerCircular } from "spinners-react"; import Dropzone from 'react-dropzone'; import Select from 'react-select' import { reduxWrapper } from "../../store"; import Header from "../components/Header"; import Footer from "../components/Footer"; import Company from "../components/Company"; import InnerMenu from "./components/InnerMenu"; import SuccessMessage from "./components/SuccessMessage"; import { getSupportThemes, getContractsList, getBitrixFile, sendNewAppeal, sendAppealAttachments } from "../../actions"; import AccountLayout from "../components/Layout/Account"; class TemplateFile extends React.Component { constructor(props) { super(props); this.state = { downloading: false } } _handle_onDownloadFile = () => { const { filename, url } = this.props.template; const { downloading } = this.state; if(!downloading) { this.setState({ downloading: true }, () => { getBitrixFile({ url, filename }) .then(() => { this.setState({ downloading: false }); }) .catch(() => { this.setState({ downloading: false }); }); }); } } render() { const { template } = this.props; const { downloading } = this.state; return (

{ template.filename }Скачать шаблон{ downloading ? () : null }

) } } class FileDropzone extends React.Component { constructor(props) { super(props); this.state = {} } render() { const { files, onAddFile, onDeleteFile } = this.props; return ( <> { files.length > 0 && (

Приложенные файлы

{ files.map((file, index) => (

{ file.name } onDeleteFile(file.name) }>[ удалить ]

)) }
) } onAddFile(acceptedFiles) }> { ({getRootProps, getInputProps}) => (

Перенесите файлы на экран для быстрой загрузки или выберите файл с компьютера

) }
) } } class SupportRequestPage extends React.Component { constructor(props) { super(props); this.state = { loading: false, contracts: null, themes: null, themes_filtered: null, name: "", phone: "", email: "", question: "", selected_contracts: [], file: null, files: [], opened_theme: 0, opened_question: 0, success: false, }; } static getDerivedStateFromProps(nextProps, prevState) { return { contracts: nextProps.contracts, themes: nextProps.themes, }; } componentDidMount() { console.log("CDM", "SupportRequestPage", this.state); if (!this.state.loading) { this.setState({ loading: true }, () => { Promise.all([ getContractsList({ dispatch: this.props.dispatch, all: true }), getSupportThemes({ dispatch: this.props.dispatch }) ]) .then(() => { let opened_theme, opened_question; let found = false; let themes_filtered = []; for(let t in this.state.themes) { let questions = []; for(let q in this.state.themes[t].questions) { if(this.state.themes[t].questions[q].request) { questions.push(this.state.themes[t].questions[q]); } } if(questions.length > 0) { themes_filtered.push({ ...this.state.themes[t], ...{ questions } }); } } opened_theme = 0; for(let t in themes_filtered) { opened_question = 0; for(let q in themes_filtered[t].questions) { if(this.props.router.asPath.indexOf(themes_filtered[t].questions[q].id) > -1) { found = true; break; } opened_question++; } if(found) { break; } opened_theme++; } this.setState({ loading: false, themes_filtered, opened_theme: found ? opened_theme : 0, opened_question: found ? opened_question : 0 }); }) .catch(() => {}); }); } } componentDidUpdate(prevProps, prevState) { } _handle_onBack = () => { this.props.router.push('/support/faq/'); } _handle_onChangeTheme = (index) => { this.setState({ opened_theme: index, opened_question: 0 }); } _handle_onChangeField = (field, value) => { this.setState({ [ field ]: value, }); } _handle_onSendAppeal = (event) => { event.preventDefault(); if(!this._checkDisabled()) { const { name, phone, email, question, selected_contracts, files } = this.state; this.setState({ loading: true }, () => { sendNewAppeal({ phone: phone, email: email, description: question, contract_numbers: selected_contracts }) .then((result) => { console.log("SupportRequestPage", "_handle_onSendAppeal", result); if(files.length > 0) { sendAppealAttachments({ request_client_number: result.request_client_number, files: files, }) .then(() => { this.setState({ loading: false, success: true, }, () => { window.scrollTo(0, 0); }); }) .catch(() => { this.setState({ loading: false }); }); } else { this.setState({ loading: false, success: true, }, () => { window.scrollTo(0, 0); }); } }) .catch(() => { this.setState({ loading: false }); }); }); } } _handle_onContract = (options) => { const selected_contracts = []; for(let i in options) { selected_contracts.push(options[i].value); this.setState({ selected_contracts }); } } _handle_onAddFile = (files) => { console.log("_handle_onAdd", files); const existed_files = [ ...this.state.files ]; for(let nf in files) { let e = false; for(let ef in this.state.files) { if(this.state.files[ef].name === files[nf].name) { e = true; } } if(!e) { existed_files.push(files[nf]); } } this.setState({ files: existed_files }); } _handle_onDeleteFile = (file_name) => { const files = []; for(let i in this.state.files) { if(this.state.files[i].name !== file_name) { files.push(this.state.files[i]); } } this.setState({ files }); } _checkDisabled = () => { const { phone, email, question, } = this.state; if(phone === "" || email === "" || question === "") { return true; } return false; } _renderForm = () => { const { loading, contracts, themes, themes_filtered, name, phone, email, question, file, files, opened_theme, opened_question } = this.state; const contracts_list = []; for(let i in contracts) { contracts_list.push({ value: contracts[i].number, label: contracts[i].number }); } return (
{ this._handle_onChangeField("name", event.target.value) } }/>
{ this._handle_onChangeField("phone", event.target.value) } }/>
{ this._handle_onChangeField("email", event.target.value) } }/>