184 lines
5.1 KiB
JavaScript
184 lines
5.1 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 Select from 'react-select';
|
||
import NoSSR from "@mpth/react-no-ssr";
|
||
|
||
|
||
import { withRouter } from 'next/router';
|
||
import { reduxWrapper } from '../../store';
|
||
|
||
import InnerMenu from "./components/InnerMenu";
|
||
import Header from '../components/Header';
|
||
import Footer from '../components/Footer';
|
||
import Pagination from '../components/Pagination';
|
||
import Company from "../components/Company";
|
||
|
||
import { sendPhoneChangeNumber, sendPhoneChangeNumberSmsCode, setUserPhone } from '../../actions';
|
||
import AccountLayout from "../components/Layout/Account";
|
||
import { getEDOList } from "../../actions/edoActions";
|
||
|
||
class IndexPage extends React.Component
|
||
{
|
||
constructor(props)
|
||
{
|
||
super(props);
|
||
this.state = {
|
||
loading: false,
|
||
operator: undefined,
|
||
oparators: [
|
||
{ "value": "1", "label": "Диадок" },
|
||
{ "value": "2", "label": "Такском" },
|
||
{ "value": "3", "label": "Тензор" },
|
||
{ "value": "4", "label": "Калуга Астрал" },
|
||
{ "value": "5", "label": "КОРУС Консалтинг" },
|
||
{ "value": "6", "label": "АйтиКом" },
|
||
]
|
||
};
|
||
}
|
||
|
||
static getDerivedStateFromProps(nextProps, prevState)
|
||
{
|
||
return {
|
||
observer: nextProps.observer,
|
||
user: nextProps.user,
|
||
};
|
||
}
|
||
|
||
componentDidMount()
|
||
{
|
||
const { dispatch } = this.props;
|
||
|
||
getEDOList({ dispatch })
|
||
.then(() =>
|
||
{
|
||
|
||
})
|
||
.catch(() =>
|
||
{
|
||
|
||
});
|
||
}
|
||
|
||
_handle_onFormSubmit = (event) =>
|
||
{
|
||
event.preventDefault();
|
||
}
|
||
|
||
_handle_onOperatorChange = (operator) =>
|
||
{
|
||
this.setState({ operator });
|
||
}
|
||
|
||
render()
|
||
{
|
||
const { user, oparators, operator, loading, } = 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>
|
||
<Company { ...this.props }/>
|
||
</div>
|
||
<NoSSR>
|
||
<div className="aside_container about">
|
||
<InnerMenu { ...this.props } user={ user }/>
|
||
<article className="questionnaire edo_detail">
|
||
<p>Выберите своего оператора. Мы отправим вашей организации приглашение.</p>
|
||
<p><br/></p>
|
||
<form ref={ this.ref_form } onSubmit={ this._handle_onFormSubmit } onKeyDown={(e) => {if (e.key === 'Enter') e.preventDefault() }}>
|
||
<div className="form_field">
|
||
<label>Оператор ЭДО <sup className="required_label">*</sup></label>
|
||
<Select
|
||
id="edo_oparators_list"
|
||
name="edo_oparators_list"
|
||
options={ oparators }
|
||
placeholder="Выберите оператора"
|
||
noOptionsMessage={ ({ inputValue }) => !inputValue ? "" :"Ничего не найдено" }
|
||
isSearchable={ true }
|
||
className="autocomlete autocomlete_with_indicators"
|
||
classNamePrefix="react-select"
|
||
value={ operator !== undefined ? operator : undefined }
|
||
onChange={ (element) => { this._handle_onOperatorChange(element) } }
|
||
required={ true }
|
||
/>
|
||
</div>
|
||
<div className="form_field" style={{ display: "flex", justifyContent: "flex-end" }}>
|
||
<button type="submit" className="button button-blue" disabled={ operator === undefined ? true : false }>
|
||
{ 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>
|
||
</div>
|
||
</form>
|
||
</article>
|
||
</div>
|
||
</NoSSR>
|
||
</AccountLayout>
|
||
<Footer/>
|
||
</React.Fragment>
|
||
)
|
||
}
|
||
}
|
||
|
||
function mapStateToProps(state, ownProps)
|
||
{
|
||
return {
|
||
observer: state.auth.observer,
|
||
user: state.user,
|
||
}
|
||
}
|
||
|
||
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)(IndexPage)); |