2023-04-06 13:46:32 +03:00

212 lines
6.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 numeral from "numeral";
import pluralize from 'pluralize-ru';
import Select from 'react-select'
import { SpinnerCircular } from 'spinners-react';
import { connect } from "react-redux";
import { withRouter } from 'next/router';
import QuestionnaireForm from "../QuestionnaireForm";
import { reduxWrapper } from '../../../../store';
import AddressSuggests from "../../AddressSuggests";
import { saveQuestionnaire } from "../../../../actions";
class Form_2_Contacts extends QuestionnaireForm
{
constructor(props)
{
super(props);
this.state = {
contacts: {
address_type: "legal",
loading: false,
fact_address: {
name: null,
fias_id: null,
},
legal_address: {
name: null,
fias_id: null,
},
postal_address: {
name: null,
fias_id: null,
},
},
step: 1,
};
}
static getDerivedStateFromProps(nextProps, prevState)
{
return {
contacts: nextProps.questionnaire.contacts,
step: nextProps.questionnaire.step,
status: nextProps.questionnaire.status,
};
}
componentDidMount()
{
const { company } = this.props;
const { address_type } = this.state.contacts;
if(company.inn.length > 10 && address_type === "legal")
{
this.setState({ address_type: "fact" });
}
}
_handle_onFormSubmit = (event) =>
{
event.preventDefault();
this._handle_onJoinChange({ status: "draft", step: 3 });
setTimeout(() =>
{
saveQuestionnaire();
this.props.onNextStep("signer");
}, 10);
}
_checkDisabled = () =>
{
const { contacts } = this.state;
const check = ["fact_address", "legal_address", "postal_address"];
if(contacts.address_type === "fact")
{
if(contacts.fact_address.name === "")
{
return true;
}
}
if(contacts.address_type === "postal")
{
if(contacts.postal_address.name === "")
{
return true;
}
}
return false;
}
render()
{
const { company, checking } = this.props;
const { contacts, loading, status, step } = this.state;
const { address_type, legal_address, fact_address, postal_address, } = contacts;
return (
<React.Fragment>
<form onSubmit={ this._handle_onFormSubmit } className={`questionnaire questionnaire_2 ${ checking && "disabled" }`}>
<p className="title">2. Адреса лизингополучателя</p>
<div className="form_field">
<label>Фактический адрес { address_type === "fact" && <sup className="required_label">*</sup> }</label>
<AddressSuggests
value={ this._checkStrValue(fact_address.name) }
fias={ this._checkStrValue(fact_address.fias_id) }
onChange={ (data) => this._handle_onTextFieldChange("contacts.fact_address", data) }
required={ address_type === "fact" ? true : false }
disabled={ checking ? true : address_type === "fact" ? false : true }
/>
<p>для юр.диц - заполняется, если отличается от указанного в ЕГРЮЛ; для ИП - заполняется всегда</p>
</div>
<p><b>Прошу оригиналы счетов-фактур и актов отказанных услуг по заключенному договору лизинга направлять:</b></p>
<div className="form_field">
<div style={{ width: "100%" }}>
{ company.inn.length < 11 && (
<div className="form_field checkbox">
<input type="radio" hidden=""
value="legal"
id="contacts.address_type_legal"
name="contacts.address_type"
checked={ address_type === "legal" ? true : false }
onChange={ (event) => this._handle_onCheckboxFieldChange(event.target.name, event.target.value) }
disabled={ checking }
/>
<label htmlFor="contacts.address_type_legal" className="unselectable">По юридическому адресу, указанному в ЕГРЮЛ</label>
</div>
) }
<div className="form_field checkbox">
<input type="radio" hidden=""
value="fact"
id="contacts.address_type_fact"
name="contacts.address_type"
checked={ address_type === "fact" ? true : false }
onChange={ (event) => this._handle_onCheckboxFieldChange(event.target.name, event.target.value) }
disabled={ checking }
/>
<label htmlFor="contacts.address_type_fact" className="unselectable">По фактическому адресу, указанному в настоящей анкете</label>
</div>
<div className="form_field checkbox">
<input type="radio" hidden=""
value="postal"
id="contacts.address_type_postal"
name="contacts.address_type"
checked={ address_type === "postal" ? true : false }
onChange={ (event) => this._handle_onCheckboxFieldChange(event.target.name, event.target.value) }
disabled={ checking }
/>
<label htmlFor="contacts.address_type_postal" className="unselectable" style={{ width: "100%" }}>
<span>По следующему адресу { address_type === "postal" && <sup className="required_label">*</sup> }</span>
<AddressSuggests
value={ this._checkStrValue(postal_address.name) }
fias={ this._checkStrValue(postal_address.fias_id) }
onChange={ (data) => this._handle_onTextFieldChange("contacts.postal_address", data) }
required={ true }
disabled={ !checking && address_type === "postal" ? false : true }
/>
</label>
</div>
</div>
</div>
{ !checking && (
<div className="action">
<button type="submit" className="button button-blue" disabled={ this._checkDisabled() }>
{ loading ? (
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" style={{ marginTop: "4px" }}/>
) : "Продолжить" }
</button>
{ status !== "empty" && (
<>
<br/><br/>
<a style={{ cursor: "pointer" }} onClick={ this._handle_onReset }>Отменить изменения в анкете</a>
</>
) }
</div>
) }
</form>
</React.Fragment>
)
}
}
function mapStateToProps(state, ownProps)
{
return {
questionnaire: state.questionnaire,
}
}
export const getServerSideProps = reduxWrapper.getServerSideProps(store =>
async ({ req, res, query }) =>
{
}
);
export default connect(mapStateToProps)(Form_2_Contacts);