evoleasing-account/actions/dealsActions.js
2023-09-13 10:54:32 +03:00

218 lines
4.5 KiB
JavaScript

import axios from 'axios';
import { Cookies } from 'react-cookie';
import Router from 'next/router';
import moment from 'moment';
import { nSQL } from "@nano-sql/core";
import * as actionTypes from '../constants/actionTypes';
import * as currentState from '../reducers/initialState';
/*DEALS_LIST
/lk/ConsiderationOpportunity/quote
[{
"quote_number": "582189",
"price": 5490000,
"first_payment_perc": 30,
"first_payment_rub": 1647000,
"brand_name": "Volkswagen",
"model_name": "Touareg",
"object_count": 1,
}, {
"quote_number": "580008",
"price": 5341770,
"first_payment_perc": 30,
"first_payment_rub": 1647000,
"brand_name": "Volkswagen",
"model_name": "Touareg",
"object_count": 1,
}]
[{
"opp_number": "780",
"statuscode_id": 107,
"statuscode_name": " ",
"comment": null,
}, {
"opp_number": "37197",
"statuscode_id": 101,
"statuscode_name": " ",
"comment": null,
}]
opp_number- номер Лизинговой сделки
statuscode_id - номер этапа
statuscode_name - имя этапа
comment - сопроводительный текст для данного этапа, который надо выводить
*/
export const getDeals = ({ dispatch }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals`;
console.log("ACTION", "deals", "getDeals()", { url });
return new Promise((resolve, reject) =>
{
axios.post(url, {}, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "deals", "getDeals()", "response", response.data);
dispatch({
type: actionTypes.DEALS_LIST,
data: {
list: response.data
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "deals", "getDeals()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.DEALS_LIST,
data: {
list: []
}
});
reject();
});
});
}
export const getDealOffers = ({ dispatch, deal_id }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/offers`;
console.log("ACTION", "deals", "getDealOffers()", { url });
console.log("ACTION", "deals", "getDealOffers()", { deal_id });
return new Promise((resolve, reject) =>
{
axios.post(url, { deal_id }, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "deals", "getDealOffers()", "response", response.data);
dispatch({
type: actionTypes.DEAL_OFFERS_LIST,
data: {
deal_id,
list: response.data
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "deals", "getDealOffers()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.DEAL_OFFERS_LIST,
data: {
deal_id,
list: []
}
});
reject();
});
});
}
export const getDealDocuments = ({ dispatch, deal_id }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/documents`;
console.log("ACTION", "deals", "getDealDocuments()", { url });
console.log("ACTION", "deals", "getDealDocuments()", { deal_id, });
return new Promise((resolve, reject) =>
{
axios.post(url, { deal_id }, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "deals", "getDealDocuments()", "response", response.data);
dispatch({
type: actionTypes.DEAL_DOCUMENTS_LIST,
data: {
deal_id,
list: response.data
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "deals", "getDealDocuments()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.DEAL_DOCUMENTS_LIST,
data: {
deal_id,
list: []
}
});
reject();
});
});
}
export const getDealContracts = ({ dispatch, deal_id }) =>
{
const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/contracts`;
console.log("ACTION", "deals", "getDealContracts()", { url });
console.log("ACTION", "deals", "getDealContracts()", { deal_id, });
return new Promise((resolve, reject) =>
{
axios.post(url, { deal_id }, {
withCredentials: true,
})
.then((response) =>
{
console.log("ACTION", "deals", "getDealContracts()", "response", response.data);
dispatch({
type: actionTypes.DEAL_CONTRACTS_LIST,
data: {
deal_id,
list: response.data
}
});
resolve();
})
.catch((error) =>
{
console.error("ACTION", "deals", "getDealContracts()", "ERROR");
console.error(error);
dispatch({
type: actionTypes.DEAL_CONTRACTS_LIST,
data: {
deal_id,
list: []
}
});
reject();
});
});
}