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 { eachSeries } from 'async'; import * as actionTypes from '../constants/actionTypes'; import * as currentState from '../reducers/initialState'; export const getDeals = ({ dispatch, update = false }) => { 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); /* if(update) { for(let i in response.data) { if(response.data[i].opp_number == "20325") { response.data[i].statuscode_id = 101; } } } */ 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 acceptDealOffers = ({ deal_id, offers }) => { const url = `${ process.env.NEXT_PUBLIC_SELF_API_HOST }/api/deals/accept`; console.log("ACTION", "deals", "acceptDealOffers()", { url }); console.log("ACTION", "deals", "acceptDealOffers()", { deal_id, offers, }); return new Promise((resolve, reject) => { axios.post(url, { deal_id, offers }, { withCredentials: true, }) .then((response) => { console.log("ACTION", "deals", "acceptDealOffers()", "response", response.data); resolve(); }) .catch((error) => { console.error("ACTION", "deals", "acceptDealOffers()", "ERROR"); console.error(error); 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(); }); }); }