From 8800c6e3c3b16cd30ac6df2885b7d590c818145c Mon Sep 17 00:00:00 2001 From: merelendor Date: Mon, 5 Sep 2022 02:03:06 +0300 Subject: [PATCH] admin actions update --- actions/adminActions.js | 4 +- actions/authActions.js | 24 -- actions/index.js | 3 +- pages/components/Events/InnerMenu/index.js | 14 +- .../components/CalculationsList/index.js | 4 +- pages/contract/components/InnerMenu/index.js | 4 +- pages/settings/admin.js | 216 ++++++++++-------- 7 files changed, 137 insertions(+), 132 deletions(-) diff --git a/actions/adminActions.js b/actions/adminActions.js index c0f697c..fe4cb87 100644 --- a/actions/adminActions.js +++ b/actions/adminActions.js @@ -55,11 +55,11 @@ export const sendInvite = ({ name, email, companies }) => export const removeUser = ({ email }) => { - console.log("ACTION", "removeUser()", { name, email, companies }); + console.log("ACTION", "removeUser()", { email }); return new Promise((resolve, reject) => { - axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/admin/remove`, { name, email, companies }) + axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/admin/remove`, { email }) .then(async (response) => { console.log("ACTION", "removeUser()", "response.data", response.data); diff --git a/actions/authActions.js b/actions/authActions.js index fb547b8..3d80c68 100644 --- a/actions/authActions.js +++ b/actions/authActions.js @@ -217,30 +217,6 @@ export const sendOffstageToken = ({ token, dispatch }) => }); } -export const getUsers = ({ dispatch }) => -{ - console.log("ACTION", "getUsers()"); - - return new Promise((resolve, reject) => - { - axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/admin/`, {}) - .then(async (response) => - { - console.log("getContractRules", "response.data", response.data); - dispatch({ type: actionTypes.ADMIN, data: { users: response.data.users } }); - - resolve(); - }) - .catch((error) => - { - console.error("ACTION", "getUsers()", "error"); - console.error(error); - - reject(); - }); - }); -} - export const sendSwitchAccount = ({ dispatch, acc_number }) => { console.log("ACTION", "sendSwitchAccount()", `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/auth/switch/`); diff --git a/actions/index.js b/actions/index.js index aa0c514..88c0469 100644 --- a/actions/index.js +++ b/actions/index.js @@ -9,4 +9,5 @@ export * from './formsActions'; export * from './settingsActions'; export * from './announcementsActions'; export * from './eventsActions'; -export * from './supportActions'; \ No newline at end of file +export * from './supportActions'; +export * from './adminActions'; \ No newline at end of file diff --git a/pages/components/Events/InnerMenu/index.js b/pages/components/Events/InnerMenu/index.js index 2b5b95c..14ee07a 100644 --- a/pages/components/Events/InnerMenu/index.js +++ b/pages/components/Events/InnerMenu/index.js @@ -39,17 +39,24 @@ export default class InnerMenu extends React.Component Все события - + + {/*}
  • Ограничения
  • + {*/}
  • Платежи
  • +
  • + + Банки и договоры + +
  • Дополнительные услуги @@ -60,11 +67,6 @@ export default class InnerMenu extends React.Component Штрафы
  • -
  • - - Банки - -
  • ПТС diff --git a/pages/contract/change/components/CalculationsList/index.js b/pages/contract/change/components/CalculationsList/index.js index cad8a20..a304b42 100644 --- a/pages/contract/change/components/CalculationsList/index.js +++ b/pages/contract/change/components/CalculationsList/index.js @@ -73,10 +73,10 @@ export default class CalculationsList extends React.Component

    { calculation.date_offset_type_comment !== null && (<>{ `${ calculation.date_offset_type_comment.label }: ${ calculation.date_offset_type_comment.value }` }
    ) } { calculation.number_paydate_comment !== null && (<>{ `${ calculation.number_paydate_comment.label }: ${ calculation.number_paydate_comment.value }` }
    ) } - { calculation.insurance_price_result_comment !== null && (<>{ `${ calculation.insurance_price_result_comment.label }: ${ numeral(calculation.insurance_price_result_comment.value).format(' ., ') } ` } ₽
    ) } + { calculation.insurance_price_result_comment !== null && (<>{ calculation.insurance_price_result_comment.label }: { numeral(calculation.insurance_price_result_comment.value).format(' ., ') }  ₽
    ) } { calculation.fix_last_payment_available_comment !== null && (<>{ `${ calculation.fix_last_payment_available_comment.label }: ${ calculation.fix_last_payment_available_comment.value ? "да" : "нет" }` }
    ) } { calculation.period_new_comment !== null && (<>{ `${ calculation.period_new_comment.label }: ${ calculation.period_new_comment.value }` }
    ) } - { calculation.sum_comment !== null && (<>{ `${ calculation.sum_comment.label }: ${ numeral(calculation.sum_comment.value).format(' ., ') }` } ₽
    ) } + { calculation.sum_comment !== null && (<>{ calculation.sum_comment.label }: { numeral(calculation.sum_comment.value).format(' ., ') } ₽
    ) }

    this._handle_onCalculation(calculation.addcontract_number) }>Подробнее diff --git a/pages/contract/components/InnerMenu/index.js b/pages/contract/components/InnerMenu/index.js index 859e19d..67a153e 100644 --- a/pages/contract/components/InnerMenu/index.js +++ b/pages/contract/components/InnerMenu/index.js @@ -46,8 +46,8 @@ export default class InnerMenu extends React.Component _getActiveLink = (route) => { - if (route.indexOf("/payments/") > -1) return "График платежей"; - if (route.indexOf("/change/") > -1) return "Изменить график"; + if (route.indexOf("/payments") > -1) return "График платежей"; + if (route.indexOf("/change") > -1) return "Изменить график"; if (route.indexOf("/services") > -1) return "Дополнительные услуги"; if (route.indexOf("/agreement") > -1) return "Документы по договору"; if (route.indexOf("/documents") > -1) return "Закрывающие документы"; diff --git a/pages/settings/admin.js b/pages/settings/admin.js index 788b367..4dccb11 100644 --- a/pages/settings/admin.js +++ b/pages/settings/admin.js @@ -17,7 +17,7 @@ import Footer from '../components/Footer'; import Pagination from '../components/Pagination'; import Company from "../components/Company"; -import { getUsers, sendPhoneChangeNumber, sendPhoneChangeNumberSmsCode, setUserPhone } from '../../actions'; +import { getUsers, removeUser, sendInvite, sendPhoneChangeNumber, sendPhoneChangeNumberSmsCode, setUserPhone } from '../../actions'; import AccountLayout from "../components/Layout/Account"; class Form extends React.Component @@ -222,10 +222,28 @@ class AdminPage extends React.Component _handle_onSave = () => { const { form } = this.state; + const { name, email, selected_companies_list } = form; console.log("form"); console.log(form); - this.setState({ add: false, edit: false }); + const companies = []; + for(let i in selected_companies_list) + { + companies.push(selected_companies_list[i].acc_number); + } + + this.setState({ add: false, edit: false, loading: true }, () => + { + sendInvite({ name, email, companies }) + .then(() => + { + this.setState({ loading: false }); + }) + .catch(() => + { + this.setState({ loading: false }); + }); + }); } _handle_onCancel = () => @@ -259,7 +277,7 @@ class AdminPage extends React.Component render() { - const { user, users, companies, add, edit, save } = this.state; + const { loading, user, users, companies, add, edit, save } = this.state; console.log("users"); console.log(users); @@ -291,106 +309,114 @@ class AdminPage extends React.Component
    -
    -

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

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

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

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

    + )) }
    +
    Активен
    + { edit && ( +
    + +
    + ) } +
    + ) + } + return null; + }) } + {/*} + { user !== undefined && user !== null && user.email !== undefined && user.email !== null && ( +
    +
    { `${ user.lastname } ${ user.name } ${ user.secondname }` }
    +
    { user.email }
    Администратор
    Все организации
    Активен
    - { edit && ( -
    - ) } +
    +
    - ) - } - 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 }

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