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 { reduxWrapper } from "../../store"; import Header from "../components/Header"; import Footer from "../components/Footer"; import Company from "../components/Company"; import InnerMenu from "./components/InnerMenu"; import DownloadPdfButton from "../components/DownloadPdfButton"; import { getContractInfo, getContractAgreement, getContractRules, getFile, } from "../../actions"; import AccountLayout from "../components/Layout/Account"; import ContractHeader from "./components/ContractHeader"; class ContractPage extends React.Component { constructor(props) { super(props); this.state = { loading: false, contracts_info: {}, unsigned: null, signed: null, rules: null, }; } static getDerivedStateFromProps(nextProps, prevState) { return { contracts_info: nextProps.contracts_info, unsigned: nextProps.unsigned, signed: nextProps.signed, rules: nextProps.rules, }; } componentDidMount() { const { dispatch, number} = this.props; if (!this.state.loading && number !== undefined) { this.setState({ loading: true }, () => { if(this.state.contracts_info[ number ] === undefined) { getContractInfo({ dispatch, number }) .then((contract_info) => { const { date } = contract_info; this._loadData(date); }); } else { const { date } = this.state.contracts_info[ number ]; this._loadData(date); } }); } } _loadData = (date) => { const { dispatch, number} = this.props; getContractRules({ dispatch, date: moment(date, "YYYY-MM-DD").format("DD.MM.YYYY"), }) .then(() => {}) .catch(() => {}); getContractAgreement({ dispatch, number, }) .then(() => { this.setState({ loading: false }); }) .catch(() => {}); } _renderDocuments = (documents, type) => { const types = { contracts: "Договор", redemptions: "Выкупные документы", agreements: "Дополнительное соглашение", assignments: "Договор цессии", }; return documents[ type ].map((file, file_index) => { console.log("file", file); return (

{ types[ type ] } { file.number } от{" "}{ moment(file.date).format("DD.MM.YYYY") } { file.type !== undefined && ({ file.type }) }

{/*} Подписать по ЭДО {*/}
); }); } render() { const { number } = this.props; const { loading, contracts_info, unsigned, signed, rules } = this.state; let { date, car, status } = contracts_info[ number ] !== undefined ? contracts_info[ number ] : {}; console.log("rules", rules); console.log("unsigned", unsigned); console.log("signed", signed); const types = { contracts: "Договор", redemptions: "Выкупные документы", agreements: "Дополнительное соглашение", assignments: "Договор цессии", }; return ( ЛК Эволюция автолизинга
{ loading ? (
) : (
{ unsigned !== undefined && unsigned !== null && unsigned.documents !== undefined && unsigned.documents !== null && unsigned.count > 0 && ( <>

К подписанию

{ this._renderDocuments(unsigned.documents, "contracts") } { this._renderDocuments(unsigned.documents, "agreements") } { this._renderDocuments(unsigned.documents, "assignments") } { this._renderDocuments(unsigned.documents, "redemptions") } ) } { signed !== undefined && signed !== null && signed.documents !== undefined && signed.documents !== null && signed.count > 0 && ( <>

Действующие

{ this._renderDocuments(signed.documents, "contracts") } { this._renderDocuments(signed.documents, "agreements") } { this._renderDocuments(signed.documents, "assignments") } { this._renderDocuments(signed.documents, "redemptions") } ) } { rules !== undefined && rules !== null && rules.map((document, index) => (

{ document.name } Дата вступления в силу: { document.active_from }

)) }
) }