114 lines
2.5 KiB
JavaScript
114 lines
2.5 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 { withRouter } from 'next/router';
|
|
import { reduxWrapper } from '../store';
|
|
|
|
import Header from './components/Header';
|
|
import Footer from './components/Footer';
|
|
import Pagination from './components/Pagination';
|
|
|
|
import { logout } from '../actions';
|
|
|
|
class IndexPage extends React.Component
|
|
{
|
|
constructor(props)
|
|
{
|
|
super(props);
|
|
this.state = {
|
|
};
|
|
}
|
|
|
|
static getDerivedStateFromProps(nextProps, prevState)
|
|
{
|
|
return {
|
|
};
|
|
}
|
|
|
|
_handle_onLogout = () =>
|
|
{
|
|
logout({ dispatch: this.props.dispatch }).then().catch();
|
|
}
|
|
|
|
render()
|
|
{
|
|
const { loading, page, pages, search, date_from, date_from_type, date_to, date_to_type, contracts, sort_number, sort_date, sort_status } = this.state;
|
|
console.log("contracts");
|
|
console.log(contracts);
|
|
const contract_status = {
|
|
"Действующий": "opened",
|
|
"Закрыт": "closed",
|
|
};
|
|
|
|
return (
|
|
<React.Fragment>
|
|
<Head>
|
|
<title>ЛК Эволюция автолизинга</title>
|
|
<meta
|
|
name="description"
|
|
content="ЛК Эволюция автолизинга"
|
|
/>
|
|
</Head>
|
|
<Header { ...this.props }/>
|
|
<main>
|
|
<section>
|
|
<div className="clear"></div>
|
|
<div className="container">
|
|
<h1 className="section_title">Настройки</h1>
|
|
<button onClick={ this._handle_onLogout }>Выйти из личного кабинета</button>
|
|
</div>
|
|
</section>
|
|
</main>
|
|
<Footer/>
|
|
</React.Fragment>
|
|
)
|
|
}
|
|
}
|
|
|
|
function mapStateToProps(state, ownProps)
|
|
{
|
|
return {
|
|
}
|
|
}
|
|
|
|
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)); |