diff --git a/actions/authActions.js b/actions/authActions.js index d98a4e3..7b3057e 100644 --- a/actions/authActions.js +++ b/actions/authActions.js @@ -6,6 +6,8 @@ import moment from 'moment'; import * as actionTypes from '../constants/actionTypes'; import * as currentState from '../reducers/initialState'; +import { getCompanyInfo } from './companyActions'; + if(process.browser) { FormData.prototype.appendObject = function(obj, namespace) @@ -37,15 +39,20 @@ export const sendLoginFormEmail = ({ email, password, dispatch }) => const cookies = new Cookies(); cookies.set('jwt', response.data.token, new Date(moment().add(7, 'day').toDate())); - console.log("try to actionTypes.COMPANY", actionTypes.COMPANY); - console.log("response.data.company", response.data.company); + getCompanyInfo({ dispatch }) + .then(() => + { + dispatch({ type: actionTypes.AUTH, data: { logged: true } }); + dispatch({ type: actionTypes.USER, data: response.data.user }); - dispatch({ type: actionTypes.AUTH, data: { logged: true } }); - dispatch({ type: actionTypes.USER, data: response.data.user }); - dispatch({ type: actionTypes.COMPANY, data: response.data.company }); - - resolve(); - Router.push('/'); + resolve(); + Router.push('/'); + }) + .catch(() => + { + reject(); + }); + //dispatch({ type: actionTypes.COMPANY, data: response.data.company }); } else { diff --git a/actions/companyActions.js b/actions/companyActions.js new file mode 100644 index 0000000..a8a58a9 --- /dev/null +++ b/actions/companyActions.js @@ -0,0 +1,47 @@ +import axios from 'axios'; +import { Cookies } from 'react-cookie'; +import Router from 'next/router'; +import moment from 'moment'; + +import * as actionTypes from '../constants/actionTypes'; + +if(process.browser) +{ + FormData.prototype.appendObject = function(obj, namespace) + { + let keyName; + for (var key in obj) + { + if (obj.hasOwnProperty(key)) + { + keyName = [namespace, '[', key, ']'].join(''); + this.append(keyName, obj[key]); + } + } + }; +} + +export const getCompanyInfo = ({ dispatch }) => +{ + console.log("getCompanyInfo"); + return new Promise((resolve, reject) => + { + axios.post(`${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/company`, {}, { + withCredentials: true, + }) + .then((response) => + { + console.log("getCompanyInfo", "response", response.data); + + dispatch({ type: actionTypes.COMPANY, data: response.data }); + resolve(); + }) + .catch((error) => + { + console.log("error"); + console.error(error); + + reject(); + }); + }); +} diff --git a/actions/index.js b/actions/index.js index fde2506..9fea2eb 100644 --- a/actions/index.js +++ b/actions/index.js @@ -1,4 +1,5 @@ export * from './authActions'; export * from './contractsActions'; export * from './contractActions'; -export * from './calendarActions'; \ No newline at end of file +export * from './calendarActions'; +export * from './companyActions'; \ No newline at end of file diff --git a/next.config.js b/next.config.js index 9d086d8..cf8d0ce 100644 --- a/next.config.js +++ b/next.config.js @@ -4,7 +4,7 @@ const withLess = require("next-with-less"); module.exports = withImages(withFonts(withLess({ images: { - domains: [ 'evo-lk.quickcode.ru', 'wow.evoleasing.ru', 'www.evoleasing.ru', 'lk.evoleasing.ru', 'evoleasing.ru', 'localhost', 'localhost:3000'], + domains: [ 'lk-evo.quickcode.ru', 'wow.evoleasing.ru', 'www.evoleasing.ru', 'lk.evoleasing.ru', 'evoleasing.ru', 'localhost', 'localhost:3000'], }, reactStrictMode: true, /* diff --git a/package.json b/package.json index 49cf791..52f1680 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "react-redux": "^7.2.6", "react-widgets": "^5.5.1", "redux": "^4.1.2", - "redux-persist": "^6.0.0" + "redux-persist": "^6.0.0", + "spinners-react": "^1.0.6" }, "devDependencies": { "eslint": "^8.3.0", diff --git a/pages/api/calendar.js b/pages/api/calendar.js index 2cdc59b..5315cf8 100644 --- a/pages/api/calendar.js +++ b/pages/api/calendar.js @@ -16,18 +16,9 @@ export default async function handler(req, res) if(cookies.jwt !== undefined && cookies.jwt !== null) { - console.log("cookies.jwt"); - console.log(cookies.jwt); - var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - console.log("client_jwt_decoded", client_jwt_decoded); - console.log("crm_jwt", crm_jwt); - - console.log(`URL`); - console.log(`${ process.env.CRM_API_HOST }/lk/Account/GetPaymentCalendar/`); - try { axios.get(`${ process.env.CRM_API_HOST }/lk/Account/GetPaymentCalendar/`, { @@ -38,8 +29,6 @@ export default async function handler(req, res) }) .then((crm_response) => { - console.log("crm_response"); - console.log(crm_response); res.status(200).json(crm_response.data); }) .catch((error) => diff --git a/pages/api/company.js b/pages/api/company.js new file mode 100644 index 0000000..c9e5261 --- /dev/null +++ b/pages/api/company.js @@ -0,0 +1,51 @@ +// Next.js API route support: https://nextjs.org/docs/api-routes/introduction +import axios from 'axios'; +import { Cookies } from 'react-cookie'; +import cookie from 'cookie'; +import moment from 'moment'; +import jwt from 'jsonwebtoken'; +import { cors } from '../../lib/cors'; + +export default async function handler(req, res) +{ + await cors(req, res); + + if(req.headers.cookie !== undefined) + { + const cookies = cookie.parse(req.headers?.cookie ? req.headers?.cookie : ""); + + if(cookies.jwt !== undefined && cookies.jwt !== null) + { + var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); + var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); + + try + { + axios.get(`${ process.env.CRM_API_HOST }/lk/Account/GetCompanyInfo/`, { + params: client_jwt_decoded, + headers: { + "Authorization": `Bearer ${ crm_jwt }`, + } + }) + .then((crm_response) => + { + res.status(200).json(crm_response.data); + }) + .catch((error) => + { + console.error(error); + res.status(500); + }); + } + catch(e) + { + console.error(e); + res.status(500); + } + } + else + { + res.status(403); + } + } +} \ No newline at end of file diff --git a/pages/api/contract/documents.js b/pages/api/contract/documents.js index b2320c3..ba2b331 100644 --- a/pages/api/contract/documents.js +++ b/pages/api/contract/documents.js @@ -18,28 +18,33 @@ export default async function handler(req, res) var client_jwt_decoded = jwt.verify(cookies.jwt, process.env.JWT_SECRET_CLIENT); var crm_jwt = jwt.sign(client_jwt_decoded, process.env.JWT_SECRET_CRM, { noTimestamp: true }); - try + const result = { + upd: null, + fines: null, + }; + + await Promise.all([ + new Promise((resolve) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetUPDListByContract`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { result.upd = crm_response.data; resolve(); }) + .catch((error) => { console.error(error); resolve(); }); + }), + new Promise((resolve) => { + axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetFineGIBDDList`, { + params: { ...client_jwt_decoded, contract_number: req.body.number }, + headers: { "Authorization": `Bearer ${ crm_jwt }`, }, + }) + .then((crm_response) => { result.fines = crm_response.data; resolve(); }) + .catch((error) => { console.error(error); resolve(); }); + }), + ]) + .then(() => { - await axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetUPDListByContract`, { - params: { ...client_jwt_decoded, contract_number: req.body.number }, - headers: { "Authorization": `Bearer ${ crm_jwt }`, }, - withCredentials: true, - }) - .then((crm_response) => - { - res.status(200).json(crm_response.data); - }) - .catch((error) => - { - console.error(error); - res.status(500); - }); - } - catch(e) - { - console.error(e); - res.status(500); - } + res.status(200).json(result); + }); } else { diff --git a/pages/api/contract/insurance.js b/pages/api/contract/insurance.js index 98571b5..287816e 100644 --- a/pages/api/contract/insurance.js +++ b/pages/api/contract/insurance.js @@ -39,26 +39,26 @@ export default async function handler(req, res) await Promise.all([ new Promise((resolve) => { axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetOsago`, { - params: client_jwt_decoded, + params: { ...client_jwt_decoded, contract_number: req.body.number }, headers: { "Authorization": `Bearer ${ crm_jwt }`, }, }) - .then((crm_response) => { result.osago = crm_response; resolve(); }) + .then((crm_response) => { result.osago = crm_response.data; resolve(); }) .catch((error) => { console.error(error); resolve(); }); }), new Promise((resolve) => { axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetKasko`, { - params: client_jwt_decoded, + params: { ...client_jwt_decoded, contract_number: req.body.number }, headers: { "Authorization": `Bearer ${ crm_jwt }`, }, }) - .then((crm_response) => { result.kasko = crm_response; resolve(); }) + .then((crm_response) => { result.kasko = crm_response.data; resolve(); }) .catch((error) => { console.error(error); resolve(); }); }), new Promise((resolve) => { axios.get(`${ process.env.CRM_API_HOST }/lk/Contract/GetNsib`, { - params: client_jwt_decoded, + params: { ...client_jwt_decoded, contract_number: req.body.number }, headers: { "Authorization": `Bearer ${ crm_jwt }`, }, }) - .then((crm_response) => { result.nsib = crm_response; resolve(); }) + .then((crm_response) => { result.nsib = crm_response.data; resolve(); }) .catch((error) => { console.error(error); resolve(); }); }), ]) diff --git a/pages/contract/index.js b/pages/contract/index.js index 15a3265..9b2b6c6 100644 --- a/pages/contract/index.js +++ b/pages/contract/index.js @@ -3,6 +3,8 @@ import Head from 'next/head'; import Image from 'next/image'; import { connect } from "react-redux"; import { withRouter } from 'next/router'; +import { SpinnerCircular } from 'spinners-react'; + import { reduxWrapper } from '../../store'; import Header from '../components/Header'; @@ -75,7 +77,7 @@ class ContractSchedulePage extends React.Component render() { - const { payments, contract_date, full, opened } = this.state; + const { payments, contract_date, full, opened, loading } = this.state; const { number } = this.props; console.log("RENDER", "payments"); @@ -121,83 +123,91 @@ class ContractSchedulePage extends React.Component
№{ invoice.number } от { moment(invoice.date, "DD-MM-YYYY").format("DD.MM.YYYY") } на сумму { numeral(invoice.total_amount).format('') } ₽
-№{ invoice.number } от { moment(invoice.date, "DD-MM-YYYY").format("DD.MM.YYYY") } на сумму { numeral(invoice.total_amount).format('') } ₽
+