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 Form extends React.Component { constructor(props) { super(props); this.state = { name: "", email: "", selection: false, selected_companies_all: false, selected_companies_list: [], }; } _handle_onChange = (field, value) => { this.setState({ [ field ]: value }); } _handle_onCompaniesSelection = () => { this.setState({ selection: this.state.selection ? false : true }); } _handle_onChangeCompanies_all = () => { const { selected_companies_all } = this.state; this.setState({ selected_companies_all: selected_companies_all ? false : true }); } _handle_onCompanySelect = (company) => { const { selected_companies_list } = this.state; const selected_companies = []; let add = true; for(let i in selected_companies_list) { if(selected_companies_list[i].inn !== company.inn) { selected_companies.push(selected_companies_list[i]); } else { add = false; } } if(add) { selected_companies.push(company); } this.setState({ selected_companies_list: selected_companies }); } render() { const { companies } = this.props; const { name, email, selection, selected_companies_all, selected_companies_list, } = this.state; return (
{ this._handle_onChange("name", event.target.value) } }/>
{ this._handle_onChange("email", event.target.value) } }/>
Пользователь
{ companies !== undefined && companies !== null && companies.map((company, index) => (
this._handle_onCompanySelect(company) }/>
)) }
-
) } } class AdminPage extends React.Component { constructor(props) { super(props); this.state = { loading: false, user: {}, users: null, companies: null, add: false, edit: false, }; } static getDerivedStateFromProps(nextProps, prevState) { return { user: nextProps.user, users: nextProps.users, companies: nextProps.companies, }; } componentDidMount() { this.setState({ loading: true }, () => { getUsers({ dispatch: this.props.dispatch }) .then(() => { this.setState({ loading: false, }) }) .catch(() => { }); }); } _handle_onAdd = () => { this.setState({ add: true }); } _handle_onEdit = () => { this.setState({ edit: true }); } _handle_onSave = () => { this.setState({ add: false, edit: false }); } render() { const { user, users, companies, add, edit } = this.state; console.log("users"); console.log(users); console.log(".".repeat(100)); console.log("user"); console.log(user); console.log(".".repeat(100)); console.log("companies"); console.log(companies); return ( ЛК Эволюция автолизинга

Личный кабинет

Настройки доступа к личному кабинету

{ add || edit ? ( ) : ( <> ) }
ФИО пользователя
Почта
Роль
Доступные организации
Статус
{ users !== undefined && users !== null && users.map((entry, index) => { if(entry.email === user.email) { return (
{ entry.name } (Вы)
{ entry.email }
Администратор
Все организации
Активен
) } return null; }) } { users !== undefined && users !== null && users.map((entry, index) => { if(entry.email !== user.email) { return (
{ entry.name }
{ entry.email }
Администратор
{ entry.companies.map((company, c_index) => (

{ company.title }

)) }
Активен
) } return null; }) } {/*} { user !== undefined && user !== null && user.email !== undefined && user.email !== null && (
{ `${ user.lastname } ${ user.name } ${ user.secondname }` }
{ user.email }
Администратор
Все организации
Активен
) } {*/} {/*}
Иванов Иван Иванович
iivanov@mail.com
Администратор
Все организации
Активен
{*/} { add && (
) } {/*} {*/}