257 lines
9.3 KiB
JavaScript
257 lines
9.3 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/InnerMenu";
|
||
import Header from '../components/Header';
|
||
import Footer from '../components/Footer';
|
||
import Pagination from '../components/Pagination';
|
||
import Company from "../components/Company";
|
||
|
||
import { getUsers, sendPhoneChangeNumber, sendPhoneChangeNumberSmsCode, setUserPhone } from '../../actions';
|
||
|
||
class IndexPage extends React.Component
|
||
{
|
||
constructor(props)
|
||
{
|
||
super(props);
|
||
this.state = {
|
||
user: {},
|
||
loading: false,
|
||
users: null,
|
||
};
|
||
}
|
||
|
||
static getDerivedStateFromProps(nextProps, prevState)
|
||
{
|
||
return {
|
||
user: nextProps.user,
|
||
users: nextProps.users,
|
||
};
|
||
}
|
||
|
||
componentDidMount()
|
||
{
|
||
this.setState({ loading: true }, () =>
|
||
{
|
||
getUsers({ dispatch: this.props.dispatch })
|
||
.then(() =>
|
||
{
|
||
this.setState({ loading: false, })
|
||
})
|
||
.catch(() =>
|
||
{
|
||
|
||
});
|
||
});
|
||
}
|
||
|
||
render()
|
||
{
|
||
const { user, users } = this.state;
|
||
|
||
return (
|
||
<React.Fragment>
|
||
<Head>
|
||
<title>ЛК Эволюция автолизинга</title>
|
||
<meta
|
||
name="description"
|
||
content="ЛК Эволюция автолизинга"
|
||
/>
|
||
</Head>
|
||
<Header { ...this.props }/>
|
||
<main>
|
||
<section>
|
||
<div className="clear"></div>
|
||
<div className="container">
|
||
<div className="title_wrapper">
|
||
<div className="left">
|
||
<h1 className="section_title">Личный кабинет</h1>
|
||
</div>
|
||
<Company { ...this.props }/>
|
||
</div>
|
||
<div className="aside_container about">
|
||
<InnerMenu { ...this.props }/>
|
||
<article>
|
||
<div className="settings_user_control">
|
||
<p>Настройки доступа к личному кабинету</p>
|
||
<div>
|
||
<button className="button button-blue">Добавить пользователя</button>
|
||
<button className="button button-blue">Редактировать</button>
|
||
</div>
|
||
</div>
|
||
<div className="settings_table editable">
|
||
<div className="table_header table_row">
|
||
<div className="table_cell">ФИО пользователя</div>
|
||
<div className="table_cell">Почта</div>
|
||
<div className="table_cell">Роль</div>
|
||
<div className="table_cell">Доступные организации</div>
|
||
<div className="table_cell">Статус</div>
|
||
<div className="table_cell"></div>
|
||
</div>
|
||
{ users !== undefined && users !== null && users.map((entry, index) =>
|
||
{
|
||
if(entry.email === user.email)
|
||
{
|
||
return (
|
||
<div className="table_row" key={ index }>
|
||
<div className="table_cell" data-title="ФИО пользователя">{ entry.name }</div>
|
||
<div className="table_cell" data-title="Почта">{ user.email }</div>
|
||
<div className="table_cell" data-title="Роль">Администратор</div>
|
||
<div className="table_cell" data-title="Доступные организации">Все организации</div>
|
||
<div className="table_cell" data-title="Статус">Активен</div>
|
||
<div className="table_cell delete" style={{ position: 'relative' }}>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
return null;
|
||
}) }
|
||
{ users !== undefined && users !== null && users.map((entry, index) =>
|
||
{
|
||
if(entry.email !== user.email)
|
||
{
|
||
return (
|
||
<div className="table_row" key={ index }>
|
||
<div className="table_cell" data-title="ФИО пользователя">{ entry.name }</div>
|
||
<div className="table_cell" data-title="Почта">{ user.email }</div>
|
||
<div className="table_cell" data-title="Роль">Администратор</div>
|
||
<div className="table_cell" data-title="Доступные организации">{ entry.companies.map((company, c_index) => (
|
||
<p key={ c_index }>{ company.title }</p>
|
||
)) }</div>
|
||
<div className="table_cell" data-title="Статус">Активен</div>
|
||
<div className="table_cell delete" style={{ position: 'relative' }}>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
return null;
|
||
}) }
|
||
{/*}
|
||
{ user !== undefined && user !== null && user.email !== undefined && user.email !== null && (
|
||
<div className="table_row">
|
||
<div className="table_cell" data-title="ФИО пользователя">{ `${ user.lastname } ${ user.name } ${ user.secondname }` }</div>
|
||
<div className="table_cell" data-title="Почта">{ user.email }</div>
|
||
<div className="table_cell" data-title="Роль">Администратор</div>
|
||
<div className="table_cell" data-title="Доступные организации">Все организации</div>
|
||
<div className="table_cell" data-title="Статус">Активен</div>
|
||
<div className="table_cell delete" style={{ position: 'relative' }}>
|
||
</div>
|
||
</div>
|
||
) }
|
||
{*/}
|
||
{/*}
|
||
<div className="table_row">
|
||
<div className="table_cell" data-title="ФИО пользователя">Иванов Иван Иванович</div>
|
||
<div className="table_cell" data-title="Почта">iivanov@mail.com</div>
|
||
<div className="table_cell" data-title="Роль">Администратор</div>
|
||
<div className="table_cell" data-title="Доступные организации">Все организации</div>
|
||
<div className="table_cell" data-title="Статус">Активен</div>
|
||
<div className="table_cell delete" style={{ position: 'relative' }}>
|
||
<button className="delete_user" title="Удалить пользователя"></button>
|
||
</div>
|
||
</div>
|
||
<div className="table_row editable">
|
||
<div className="table_cell" data-title="ФИО пользователя">
|
||
<input type="text" placeholder="Введите ФИО" />
|
||
</div>
|
||
<div className="table_cell" data-title="Почта">
|
||
<input type="email" placeholder="Введите почту" />
|
||
</div>
|
||
<div className="table_cell" data-title="Роль">Пользователь</div>
|
||
<div className="table_cell" data-title="Доступные организации">
|
||
<button className="settings_dropdown" data-selected="false">Выберите организацию</button>
|
||
<div className="dropdown_list opened">
|
||
<div className="list_item">
|
||
<input type="checkbox" value="" name="companies_list" id="company_1" hidden />
|
||
<label htmlFor="company_1">
|
||
Все организации
|
||
</label>
|
||
</div>
|
||
<div className="list_item">
|
||
<input type="checkbox" value="" name="companies_list" id="company_2" hidden />
|
||
<label htmlFor="company_2">
|
||
ООО “Еще одно название”
|
||
<span>ИНН: 12345678765 КПП: 13432-02</span>
|
||
</label>
|
||
</div>
|
||
<div className="list_item">
|
||
<input type="checkbox" value="" name="companies_list" id="company_3" hidden />
|
||
<label htmlFor="company_3">
|
||
ООО “Друзья и КО”
|
||
<span>ИНН: 12345678765 КПП: 13432-02</span>
|
||
</label>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div className="table_cell" data-title="Статус">-</div>
|
||
<div className="table_cell delete" style={{ position: 'relative' }}>
|
||
<button className="delete_user" title="Удалить пользователя"></button>
|
||
</div>
|
||
</div>
|
||
{*/}
|
||
</div>
|
||
</article>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
<Footer/>
|
||
</React.Fragment>
|
||
)
|
||
}
|
||
}
|
||
|
||
function mapStateToProps(state, ownProps)
|
||
{
|
||
return {
|
||
user: state.user,
|
||
users: state.admin.users,
|
||
}
|
||
}
|
||
|
||
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)); |