187 lines
5.6 KiB
JavaScript
187 lines
5.6 KiB
JavaScript
import React from "react";
|
|
import Head from 'next/head';
|
|
import Image from 'next/image';
|
|
import Link from "next/link";
|
|
import cookie from 'cookie';
|
|
import { connect } from "react-redux";
|
|
import numeral from "numeral";
|
|
import pluralize from 'pluralize-ru';
|
|
import { SpinnerCircular } from 'spinners-react';
|
|
|
|
import { withRouter } from 'next/router';
|
|
import { reduxWrapper } from '../../store';
|
|
|
|
import InnerMenu from "../../components/questionnaire/InnerMenu";
|
|
import Header from '../components/Header';
|
|
import Footer from '../components/Footer';
|
|
|
|
import { sendPhoneChangeNumber, sendPhoneChangeNumberSmsCode, setUserPhone, getQuestionnaire, getContractGraphicChangeSignatories, } from '../../actions';
|
|
import AccountLayout from "../components/Layout/Account";
|
|
import Form_1_Main from "../../components/questionnaire/forms/Form_1_Main";
|
|
import Form_2_Contacts from "../../components/questionnaire/forms/Form_2_Contacts";
|
|
import Form_3_Signer from "../../components/questionnaire/forms/Form_3_Signer";
|
|
import Form_4_Shareholders from "../../components/questionnaire/forms/Form_4_Shareholders";
|
|
import Form_5_Regulatory from "../../components/questionnaire/forms/Form_5_Regulatory";
|
|
import Form_6_NonProfit from "../../components/questionnaire/forms/Form_6_NonProfit";
|
|
import Form_7_Check from "../../components/questionnaire/forms/Form_7_Check";
|
|
import Form_8_Signing from "../../components/questionnaire/forms/Form_8_Signing";
|
|
|
|
class QuestionnairePage extends React.Component
|
|
{
|
|
constructor(props)
|
|
{
|
|
super(props);
|
|
this.state = {
|
|
phone: "",
|
|
phone_check_loading: false,
|
|
phone_number_format_error: false,
|
|
signatories: [],
|
|
company: {},
|
|
nko: false,
|
|
};
|
|
}
|
|
|
|
static getDerivedStateFromProps(nextProps, prevState)
|
|
{
|
|
return {
|
|
signatories: nextProps.signatories,
|
|
company: nextProps.company,
|
|
nko: nextProps.nko,
|
|
};
|
|
}
|
|
|
|
componentDidMount()
|
|
{
|
|
const { dispatch } = this.props;
|
|
|
|
getContractGraphicChangeSignatories({ dispatch });
|
|
|
|
setTimeout(() => {
|
|
this._init();
|
|
}, 10);
|
|
}
|
|
|
|
_init = () =>
|
|
{
|
|
const { company } = this.state;
|
|
const { dispatch } = this.props;
|
|
|
|
console.log("-".repeat(50));
|
|
console.log(company);
|
|
getQuestionnaire({ dispatch, id: company.questionnaire_id });
|
|
}
|
|
|
|
_check_fields_disabled = (values) =>
|
|
{
|
|
for(let i in values)
|
|
{
|
|
if(values[i] === "")
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
_handle_onNextStep = (path) =>
|
|
{
|
|
window.scrollTo(0, 0);
|
|
this.props.router.push(`/questionnaire#${ path }`);
|
|
}
|
|
|
|
_renderForm = () =>
|
|
{
|
|
const { signatories, company } = this.state;
|
|
const route = this.props.router.asPath;
|
|
|
|
if (route.indexOf("#main") > -1) return (<Form_1_Main company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#contacts") > -1) return (<Form_2_Contacts company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#signer") > -1) return (<Form_3_Signer company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#shareholders") > -1) return (<Form_4_Shareholders company={ company } signatories={ signatories } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#regulatory") > -1) return (<Form_5_Regulatory company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#non-profit") > -1) return (<Form_6_NonProfit company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
if (route.indexOf("#check") > -1) return (<Form_7_Check company={ company } signatories={ signatories } onNextStep={ this._handle_onNextStep } checking={ true }/>);
|
|
if (route.indexOf("#signing") > -1) return (<Form_8_Signing/>);
|
|
|
|
return (<Form_1_Main company={ company } onNextStep={ this._handle_onNextStep } checking={ false }/>);
|
|
}
|
|
|
|
render()
|
|
{
|
|
const { company, nko, phone, phone_check_loading, phone_number_format_error } = this.state;
|
|
|
|
return (
|
|
<React.Fragment>
|
|
<Head>
|
|
<title>ЛК Эволюция автолизинга - Анкета лизингополучателя</title>
|
|
<meta
|
|
name="description"
|
|
content="ЛК Эволюция автолизинга - Анкета лизингополучателя"
|
|
/>
|
|
</Head>
|
|
<Header { ...this.props }/>
|
|
<AccountLayout>
|
|
<div className="title_wrapper">
|
|
<div className="left">
|
|
<h1 className="section_title">Анкета лизингополучателя</h1>
|
|
</div>
|
|
</div>
|
|
<div className="aside_container about">
|
|
<InnerMenu company={ company } nko={ nko } { ...this.props }/>
|
|
<article>
|
|
{ this._renderForm() }
|
|
</article>
|
|
</div>
|
|
</AccountLayout>
|
|
<Footer/>
|
|
</React.Fragment>
|
|
)
|
|
}
|
|
}
|
|
|
|
function mapStateToProps(state, ownProps)
|
|
{
|
|
return {
|
|
company: state.company,
|
|
signatories: state.contract.change.signatories,
|
|
nko: state.questionnaire.main.nko,
|
|
}
|
|
}
|
|
|
|
export const getServerSideProps = reduxWrapper.getServerSideProps(store =>
|
|
async ({ req, res, query }) =>
|
|
{
|
|
let props = {};
|
|
|
|
if(req.headers.cookie !== undefined)
|
|
{
|
|
const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : "");
|
|
|
|
if(cookies.jwt === undefined || cookies.jwt === null)
|
|
{
|
|
res.statusCode = 302;
|
|
res.setHeader('Location', `/login`);
|
|
}
|
|
else
|
|
{
|
|
//const tokenValid = await checkToken(cookies.jwt);
|
|
const tokenValid = true;
|
|
if(!tokenValid)
|
|
{
|
|
res.statusCode = 302;
|
|
res.setHeader('Location', `/login`);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
res.statusCode = 302;
|
|
res.setHeader('Location', `/login`);
|
|
}
|
|
|
|
return { props: props };
|
|
}
|
|
);
|
|
|
|
export default withRouter(connect(mapStateToProps)(QuestionnairePage)); |