initial docker setup
This commit is contained in:
40
frontend/src/actions/bids/bidsActions.js
Normal file
40
frontend/src/actions/bids/bidsActions.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SET_BID,
|
||||
bidsTexts
|
||||
} from '../../constants/bidsConstants';
|
||||
import {fetchCartItems} from '../cart/cartActions';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
import {setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
||||
|
||||
const client = new HtmlClient();
|
||||
|
||||
const requestSetBid = () => ({
|
||||
type: REQUEST_SET_BID
|
||||
});
|
||||
|
||||
export const setBid = (idBid, idCart) => {
|
||||
return dispatch => {
|
||||
dispatch(requestSetBid());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/setBidForCart`,
|
||||
method: 'post',
|
||||
data: {idBid, idCart}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, bidsTexts.messages));
|
||||
if(response.data.messages[0].code === 'success'){
|
||||
dispatch(setDialogOpenFlag(false));
|
||||
dispatch(fetchCartItems(true));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
312
frontend/src/actions/cart/cartActions.js
Normal file
312
frontend/src/actions/cart/cartActions.js
Normal file
@@ -0,0 +1,312 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SHOP_CART_COUNT,
|
||||
RECEIVE_SHOP_CART_COUNT,
|
||||
REQUEST_SHOP_CART_ITEMS,
|
||||
RECEIVE_SHOP_CART_ITEMS,
|
||||
SET_CURRENT_STEP,
|
||||
RESET_STEPS,
|
||||
GO_TO_NEXT_STEP,
|
||||
GO_TO_PREVIOUS_STEP,
|
||||
LOAD_CART_STEPS,
|
||||
cartSteps,
|
||||
UPLOAD_DOCUMENT,
|
||||
REQUEST_CART_DOCUMENTS,
|
||||
RECEIVE_CART_DOCUMENTS,
|
||||
REQUEST_CUSTOMER_DETAILS,
|
||||
RECEIVE_CUSTOMER_DETAILS,
|
||||
SELECT_COUNTRY_DELIVERY,
|
||||
SELECT_COUNTRY_BILLING,
|
||||
SET_ORDER_INFO,
|
||||
IS_CART_ITEMS_DISABLED,
|
||||
RECEIVE_ORDER_TOTAL_PRICE,
|
||||
UPDATE_CART_ITEMS,
|
||||
SET_NEXT_STEP,
|
||||
SET_PREV_STEP,
|
||||
SET_ORDER_PLACED,
|
||||
SET_ORDER_PLACED_REDIRECT,
|
||||
cartMessages
|
||||
} from '../../constants/cartConstants';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
const client = new HtmlClient();
|
||||
|
||||
export const requestShopCartCount = () => ({type: REQUEST_SHOP_CART_COUNT});
|
||||
export const receiveShopCartCount = (json) => ({type: RECEIVE_SHOP_CART_COUNT, cartCount: json});
|
||||
|
||||
export const requestShopCartItems = () => ({
|
||||
type: REQUEST_SHOP_CART_ITEMS,
|
||||
isLoading: true
|
||||
});
|
||||
export const receiveShopCartItems = (json) => ({
|
||||
type: RECEIVE_SHOP_CART_ITEMS,
|
||||
isLoading: false,
|
||||
cartItems: json
|
||||
});
|
||||
|
||||
export const requestCustomerDetails = () => ({
|
||||
type: REQUEST_CUSTOMER_DETAILS,
|
||||
isLoading: true
|
||||
});
|
||||
export const receiveCustomerDetails = (json) => ({
|
||||
type: RECEIVE_CUSTOMER_DETAILS,
|
||||
isLoading: false,
|
||||
customerDetails: json
|
||||
});
|
||||
|
||||
export const fetchCartCount = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCartCount());
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) {
|
||||
dispatch(receiveShopCartCount(response.data.cartItemsCount));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchCartItems = (isForSteps = false) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCartItems());
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCartItems`}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'cartItems' in response.data) {
|
||||
dispatch(receiveShopCartItems(response.data.cartItems));
|
||||
dispatch(fetchCartDocuments(response.data.cartItems.map((cartItem) => cartItem.idPackage), isForSteps));
|
||||
dispatch(updateOrderTotalPrice(response.data.cartItems));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const updateOrderTotalPrice = (cartItems) => ({type: RECEIVE_ORDER_TOTAL_PRICE, cartItems});
|
||||
|
||||
const updateCartItems = (newItem)=>(
|
||||
{type: UPDATE_CART_ITEMS, newItem}
|
||||
);
|
||||
|
||||
export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
||||
const params = {
|
||||
idPackage: cartItem.idPackage || 0,
|
||||
idCustomerInstance: cartItem.idCustomerInstance || 0,
|
||||
idPrice: cartItem.idPrice || 0,
|
||||
quantity
|
||||
};
|
||||
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/updateQuantity`,
|
||||
method: 'post',
|
||||
data: params
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
const filteredMessages = response.data.messages.filter(message => {
|
||||
return message.code === 'error';
|
||||
});
|
||||
|
||||
if(filteredMessages.length > 0){
|
||||
dispatch(updateMessages(filteredMessages, cartMessages));
|
||||
}else{
|
||||
cartItem.quantity = quantity;
|
||||
dispatch(updateCartItems(cartItem));
|
||||
}
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const removeCartItem = (idCart) => {
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/removeFromCart`,
|
||||
method: 'post',
|
||||
data: {idCart}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||
response.data.messages.forEach(messageObject => {
|
||||
if (messageObject.code === 'success') {
|
||||
dispatch(fetchCartCount());
|
||||
dispatch(fetchCartItems(true));
|
||||
}
|
||||
})
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const getSteps = (whitoutUploadDoc) => {
|
||||
const newSteps = Object.assign({}, cartSteps());
|
||||
|
||||
if(whitoutUploadDoc) {
|
||||
delete newSteps.cartUploadDocuments;
|
||||
newSteps.cartCustomerDetails.previous = null;
|
||||
newSteps.cartCustomerDetails.status = 'active';
|
||||
}
|
||||
|
||||
return {
|
||||
type: LOAD_CART_STEPS,
|
||||
cartSteps: newSteps
|
||||
};
|
||||
};
|
||||
|
||||
export const loadSteps = (whitoutUploadDoc) => {
|
||||
const firstStep = whitoutUploadDoc ? 'cartCustomerDetails' : 'cartUploadDocuments';
|
||||
|
||||
return dispatch => {
|
||||
dispatch(getSteps(whitoutUploadDoc));
|
||||
dispatch(selectStep(firstStep));
|
||||
dispatch(resetSteps());
|
||||
dispatch(setCartItemsDisabled(false));
|
||||
}
|
||||
}
|
||||
|
||||
export const selectStep = (step, params={}) => {
|
||||
return {type: SET_CURRENT_STEP, currentStep: step, params};
|
||||
}
|
||||
|
||||
const resetSteps = () => ({type: RESET_STEPS});
|
||||
|
||||
export const getCustomerDetails = () => {
|
||||
return dispatch => {
|
||||
return client.fetch({url: `${API_SERVER}/cart/api/getCustomerDetails`})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && response.data.customerDetails) {
|
||||
const customerDetails = response.data.customerDetails;
|
||||
dispatch(receiveCustomerDetails(customerDetails));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const nextStep = (step) => ({type: GO_TO_NEXT_STEP});
|
||||
export const previousStep = (params) => ({type: GO_TO_PREVIOUS_STEP, params});
|
||||
|
||||
export const uploadDocumnet = () => ({type: UPLOAD_DOCUMENT});
|
||||
|
||||
export const uploadOrderDocument = (idPackage, idDocumentType, file, packages) => {
|
||||
return dispatch => {
|
||||
dispatch(uploadDocumnet());
|
||||
|
||||
return client.uploadFile(file, {
|
||||
url: `${API_SERVER}/cart/api/uploadOrderDocument`,
|
||||
data: {
|
||||
idDocumentType,
|
||||
idPackage
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||
dispatch(fetchCartDocuments(packages));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const badFile = () =>{
|
||||
return dispatch => {
|
||||
dispatch(updateMessages([{code: 'warning', message: 'INVALID_FILE'}], cartMessages));
|
||||
}
|
||||
}
|
||||
|
||||
export const requestCartDocuments = () => ({
|
||||
type: REQUEST_CART_DOCUMENTS,
|
||||
isLoading: true
|
||||
});
|
||||
export const receiveCartDocuments = (json) => ({
|
||||
type: RECEIVE_CART_DOCUMENTS,
|
||||
isLoading: false,
|
||||
cartDocuments: json
|
||||
});
|
||||
|
||||
export const fetchCartDocuments = (packages, isForSteps = false) => {
|
||||
return dispatch => {
|
||||
dispatch(requestCartDocuments());
|
||||
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/getCartDocuments`,
|
||||
method: 'post',
|
||||
data: {packages}
|
||||
}).then(response => {
|
||||
if (response.data) {
|
||||
dispatch(receiveCartDocuments(response.data));
|
||||
if(isForSteps) {
|
||||
const whitoutUploadDoc = response.data.templates.length === 0;
|
||||
dispatch(loadSteps(whitoutUploadDoc));
|
||||
}
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const selectCountryDelivery = (country) => ({type: SELECT_COUNTRY_DELIVERY, selectedCountryDelivery: country});
|
||||
export const selectCountryBilling = (country) => ({type: SELECT_COUNTRY_BILLING, selectedCountryBilling: country});
|
||||
|
||||
export const saveOrderDetails = (orderDetails, cartItems) => {
|
||||
const orderInfo = {orderDetails, cartItems};
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/saveOrderDetails`,
|
||||
method: 'post',
|
||||
data: {orderDetails, cartItems}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(getCustomerDetails());
|
||||
dispatch(setOrderInfo(orderInfo));
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const setOrderInfo = (info) => ({type: SET_ORDER_INFO, orderInfo: info});
|
||||
|
||||
export const setOrderPlacedFlag = (flag) => ({type: SET_ORDER_PLACED, orderPlaced: flag});
|
||||
export const setOrderPlacedRedirectFlag = (flag) => ({type: SET_ORDER_PLACED_REDIRECT, orderPlacedRedirect: flag});
|
||||
|
||||
export const placeOrder = (orderInfo) => {
|
||||
const {orderDetails, cartItems} = orderInfo;
|
||||
return dispatch => {
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/cart/api/placeOrder`,
|
||||
method: 'post',
|
||||
data: {orderDetails, cartItems}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||
if(!checkIfErrorMessageExists(response.data.messages)) {
|
||||
dispatch(fetchCartCount());
|
||||
dispatch(setOrderPlacedFlag(true));
|
||||
dispatch(setOrderPlacedRedirectFlag(true));
|
||||
}
|
||||
}
|
||||
}).catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const checkIfErrorMessageExists = (messagesArray) => {
|
||||
return messagesArray.some(messageObj => {
|
||||
return messageObj.code === 'error';
|
||||
});
|
||||
}
|
||||
|
||||
export const setCartItemsDisabled = (flag) => ({type: IS_CART_ITEMS_DISABLED, isCartItemsDisabled: flag});
|
||||
|
||||
export const setNextActionFct = (fct) => ({type: SET_NEXT_STEP, nextStepAction: fct});
|
||||
export const setPrevActionFct = (fct) => ({type: SET_PREV_STEP, prevStepAction: fct});
|
||||
9
frontend/src/actions/coMarket/coMarketActions.js
Normal file
9
frontend/src/actions/coMarket/coMarketActions.js
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
import {
|
||||
SET_PACKAGE_FROM_URL
|
||||
} from '../../constants/coMarketConstants';
|
||||
|
||||
export const setPackageFromUrl = (idPackage) => ({
|
||||
type: SET_PACKAGE_FROM_URL,
|
||||
idPackage
|
||||
});
|
||||
166
frontend/src/actions/coMarket/coMarketPackageDetailsActions.js
Normal file
166
frontend/src/actions/coMarket/coMarketPackageDetailsActions.js
Normal file
@@ -0,0 +1,166 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import PriceHelper from '../../helpers/coMarket/PriceHelper';
|
||||
import {
|
||||
REQUEST_PACKAGE_DETAILS,
|
||||
RECIEVE_PACKAGE_DETAILS,
|
||||
SELECT_OPTION,
|
||||
SELECT_AGREEMENT,
|
||||
SELECT_ADDITIONAL,
|
||||
REMOVE_ADDITIONAL,
|
||||
REQUEST_ADD_TO_CART,
|
||||
CLEAR_SELECTIONS,
|
||||
coMarketMessages
|
||||
} from '../../constants/coMarketConstants';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
import {fetchCartCount} from '../cart/cartActions';
|
||||
|
||||
const client = new HtmlClient();
|
||||
const priceHelper = new PriceHelper();
|
||||
|
||||
const requestPackageDetails = () => ({
|
||||
type: REQUEST_PACKAGE_DETAILS,
|
||||
isLoading: true
|
||||
});
|
||||
const recievePackageDetails = (json) => ({
|
||||
type: RECIEVE_PACKAGE_DETAILS,
|
||||
isLoading: false,
|
||||
selectedPackage: json
|
||||
});
|
||||
|
||||
const clearSelections = () => ({
|
||||
type: CLEAR_SELECTIONS,
|
||||
selectedOptions: null,
|
||||
selectedAdditionals: null,
|
||||
selectedAgreement: null
|
||||
})
|
||||
|
||||
export const fetchPackageDetails = (params) => {
|
||||
return dispatch => {
|
||||
dispatch(requestPackageDetails());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/coMarket/api/getShopPackageDetails`,
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
const jsonData = response.data;
|
||||
dispatch(clearSelections());
|
||||
if(jsonData.prices && jsonData.prices.length){
|
||||
dispatch(selectAgreement(jsonData.prices[0]));
|
||||
}
|
||||
|
||||
if(jsonData.groups){
|
||||
Object.keys(jsonData.groups).forEach((idGroup) => {
|
||||
const defaultOption = jsonData.groups[idGroup].options.find((option) => {return parseInt(option.isDefault, 10) === 1});
|
||||
if(defaultOption){
|
||||
dispatch(selectOption(idGroup, defaultOption));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispatch(recievePackageDetails(jsonData));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const generateOptions = (selectedOptions, selectedAdditionals, selectedAgreement) => {
|
||||
const extraPackages = [];
|
||||
const unavailablePackages = [];
|
||||
if(selectedAdditionals && selectedAdditionals.length){
|
||||
selectedAdditionals.forEach(additional => {
|
||||
const selectedPrice = priceHelper.getSelectedPrice(additional, selectedAgreement);
|
||||
if(!selectedPrice){
|
||||
unavailablePackages.push(additional);
|
||||
}else{
|
||||
extraPackages.push(additional.idAdditionalPackage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if(selectedOptions){
|
||||
Object.keys(selectedOptions).forEach(idGroup => {
|
||||
const selectedPrice = priceHelper.getSelectedPrice(selectedOptions[idGroup], selectedAgreement);
|
||||
if(!selectedPrice){
|
||||
unavailablePackages.push(selectedOptions[idGroup]);
|
||||
}else{
|
||||
extraPackages.push(selectedOptions[idGroup].idOptionPackage);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return {extraPackages, unavailablePackages};
|
||||
};
|
||||
|
||||
const requestAddToCart = () => ({
|
||||
type: REQUEST_ADD_TO_CART
|
||||
});
|
||||
|
||||
export const addToCart = (addParams) => {
|
||||
const options = generateOptions(addParams.selectedOptions, addParams.selectedAdditionals, addParams.selectedAgreement);
|
||||
|
||||
const params = {
|
||||
idPackage: addParams.selectedPackage.packageInfo.idPackage,
|
||||
idPrice: addParams.selectedAgreement.idPrice,
|
||||
options: options.extraPackages
|
||||
};
|
||||
|
||||
if(options.unavailablePackages.length){
|
||||
const unavailable = options.unavailablePackages.map((unavailable) =>{return unavailable.optionName || unavailable.packageName;});
|
||||
const message = coMarketMessages.UNAVAILABLE_PACKAGES + ' ' + unavailable.join();
|
||||
|
||||
return dispatch => {dispatch(updateMessages([{code: 'warning', message}], coMarketMessages))};
|
||||
}
|
||||
|
||||
return dispatch => {
|
||||
dispatch(requestAddToCart());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/coMarket/api/addToCart`,
|
||||
method: 'post',
|
||||
data: params
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, coMarketMessages));
|
||||
dispatch(fetchCartCount());
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const selectAgreement = (agreement) => {
|
||||
return {
|
||||
type: SELECT_AGREEMENT,
|
||||
selectedAgreement: agreement,
|
||||
};
|
||||
};
|
||||
|
||||
export const selectOption = (idGroup, option) => {
|
||||
const selectedOption = {};
|
||||
selectedOption[idGroup] = option;
|
||||
|
||||
return {
|
||||
type: SELECT_OPTION,
|
||||
selectedOptions: selectedOption,
|
||||
};
|
||||
};
|
||||
|
||||
export const selectAdditional = (additional) => ({
|
||||
type: SELECT_ADDITIONAL,
|
||||
selectedAdditonal: additional,
|
||||
});
|
||||
|
||||
export const removetAdditional = (additional) => ({
|
||||
type: REMOVE_ADDITIONAL,
|
||||
selectedAdditonal: additional,
|
||||
});
|
||||
86
frontend/src/actions/coMarket/coMarketPackagesActions.js
Normal file
86
frontend/src/actions/coMarket/coMarketPackagesActions.js
Normal file
@@ -0,0 +1,86 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SHOP_PACKAGES,
|
||||
RECIEVE_SHOP_PACKAGES,
|
||||
REQUEST_SHOP_COMMERCIAL_LEADS,
|
||||
RECIEVE_SHOP_COMMERCIAL_LEADS,
|
||||
SELECT_SHOP_COMMERCIAL_LEAD
|
||||
} from '../../constants/coMarketConstants';
|
||||
const client = new HtmlClient();
|
||||
|
||||
const requestShopPackages = () => ({
|
||||
type: REQUEST_SHOP_PACKAGES,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveShopPackages = (json) => ({
|
||||
type: RECIEVE_SHOP_PACKAGES,
|
||||
isLoading: false,
|
||||
shopPackages: json
|
||||
});
|
||||
|
||||
export const fetchShopPackages = (cl, search) => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopPackages());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/coMarket/api/getShopPackages`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idCommercialLead: (cl && cl.value) || 0,
|
||||
search
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.packages){
|
||||
dispatch(recieveShopPackages(response.data.packages))
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestShopCommercialLeads = () => ({
|
||||
type: REQUEST_SHOP_COMMERCIAL_LEADS
|
||||
});
|
||||
const recieveShopCommercialLeads = (json) => ({
|
||||
type: RECIEVE_SHOP_COMMERCIAL_LEADS,
|
||||
commercialLeads: json
|
||||
});
|
||||
|
||||
const generateClOptions = (commercialLeads) => {
|
||||
commercialLeads.forEach((cl) => {
|
||||
cl.value = cl.idCommercialLead;
|
||||
cl.label = cl.commercialLeadName;
|
||||
});
|
||||
|
||||
return commercialLeads;
|
||||
}
|
||||
|
||||
export const fetchShopCommercialLeads = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestShopCommercialLeads());
|
||||
return client.fetch({url: `${API_SERVER}/coMarket/api/getAllCommercialLeads`})
|
||||
.then(response => {
|
||||
if(response.data && response.data.commercialLeads){
|
||||
const clOptions = generateClOptions(response.data.commercialLeads);
|
||||
dispatch(recieveShopCommercialLeads(clOptions));
|
||||
if (clOptions.length) {
|
||||
dispatch(selectCommercialLead(clOptions[0]));
|
||||
dispatch(fetchShopPackages(clOptions[0]));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const selectCommercialLead = (cl) => ({
|
||||
type: SELECT_SHOP_COMMERCIAL_LEAD,
|
||||
selectedCommercialLead: cl
|
||||
});
|
||||
27
frontend/src/actions/dashboard/dashboardActions.js
Normal file
27
frontend/src/actions/dashboard/dashboardActions.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {REQUEST_GADGETS, RECIEVE_GADGETS} from '../../constants/dashboardConstants';
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
const requestGadgets = () => ({type: REQUEST_GADGETS});
|
||||
const recieveGadgets = (json) => ({
|
||||
type: RECIEVE_GADGETS,
|
||||
gadgets: json
|
||||
});
|
||||
|
||||
export const fetchGadgets = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestGadgets());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/dashboards/api/getMyDashboard`
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.gadgets){
|
||||
dispatch(recieveGadgets(response.data.gadgets))
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
28
frontend/src/actions/dashboard/nextActionsActions.js
Normal file
28
frontend/src/actions/dashboard/nextActionsActions.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {REQUEST_NEXT_ACTIONS, RECIEVE_NEXT_ACTIONS} from '../../constants/dashboardConstants';
|
||||
const client = new HtmlClient();
|
||||
|
||||
export const requestNextActions = () => ({
|
||||
type: REQUEST_NEXT_ACTIONS,
|
||||
isLoading: true
|
||||
});
|
||||
|
||||
export const recieveNextActions = (json) => ({
|
||||
type: RECIEVE_NEXT_ACTIONS,
|
||||
isLoading: false,
|
||||
nextActions: json
|
||||
});
|
||||
|
||||
export const fetchNextActions = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestNextActions());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/dashboards/api/getNextActionsInfo`
|
||||
})
|
||||
.then(response => dispatch(recieveNextActions(response.data)))
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
35
frontend/src/actions/dashboard/ordersActions.js
Normal file
35
frontend/src/actions/dashboard/ordersActions.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_ORDERS,
|
||||
RECEIVE_ORDERS
|
||||
} from '../../constants/dashboardConstants';
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
export const requestOrders = () => ({
|
||||
type: REQUEST_ORDERS,
|
||||
isLoading: true
|
||||
});
|
||||
|
||||
export const recieveOrders = (json) => ({
|
||||
type: RECEIVE_ORDERS,
|
||||
isLoading: false,
|
||||
orders: json
|
||||
});
|
||||
|
||||
export const fetchOrders = (viewAllOrders) => {
|
||||
return dispatch => {
|
||||
dispatch(requestOrders());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`,
|
||||
method: 'post',
|
||||
data: {
|
||||
viewAllOrders
|
||||
}
|
||||
})
|
||||
.then(response => dispatch(recieveOrders(response.data)))
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
4
frontend/src/actions/dialog/dialogActions.js
Normal file
4
frontend/src/actions/dialog/dialogActions.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import {CONTENT_MESSAGE, IS_OPENED} from '../../constants/dialogConstants';
|
||||
|
||||
export const setDialogContent = (json) => ({type: CONTENT_MESSAGE, dialogContent: json});
|
||||
export const setDialogOpenFlag = (flag) => ({type: IS_OPENED, isDialogOpen: flag});
|
||||
268
frontend/src/actions/login/authActions.js
Normal file
268
frontend/src/actions/login/authActions.js
Normal file
@@ -0,0 +1,268 @@
|
||||
import jwtDecode from 'jwt-decode';
|
||||
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import {
|
||||
LOGIN,
|
||||
LOGOUT,
|
||||
LOGIN_SUCCESS,
|
||||
LOGIN_FAIL,
|
||||
VALIDATE_TOKEN,
|
||||
REQUEST_MODULES,
|
||||
RECIEVE_MODULES,
|
||||
REQUEST_FORGOT_PASSWORD,
|
||||
FORGOT_PASSWORD,
|
||||
REFRESH_TOKEN,
|
||||
REQUEST_CHANGE,
|
||||
PASSWORD_CHANGED,
|
||||
SET_COMPANY_ADMIN_FLAG,
|
||||
authActivity
|
||||
} from '../../constants/authConstants';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
|
||||
const htmlClient = new HtmlClient();
|
||||
let refreshToken = '';
|
||||
let refreshTimer = {};
|
||||
const REFRESH_TIME = 1000 * 60 * 50; //refresh 10 minutes before expired
|
||||
|
||||
export const login = () => ({
|
||||
type: LOGIN
|
||||
});
|
||||
|
||||
export const validateToken = () => ({
|
||||
type: VALIDATE_TOKEN
|
||||
});
|
||||
|
||||
export const validateAccessToken = (token) => {
|
||||
return dispatch => {
|
||||
dispatch(validateToken());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/validateToken`
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data && response.data.status === 'success') {
|
||||
const serverTime = response.data.serverTime || 1;
|
||||
|
||||
dispatch(loggedIn({
|
||||
accessToken: token,
|
||||
userInfo: response.data.userInfo
|
||||
}));
|
||||
refreshToken = response.data.refreshToken;
|
||||
startRefreshTimer(dispatch, serverTime);
|
||||
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||
} else {
|
||||
dispatch(loginFail(response.data));
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const setUserAsCompanyAdmin = (isCompanyAdmin) => ({type: SET_COMPANY_ADMIN_FLAG, isCompanyAdmin});
|
||||
|
||||
export const validateCredentials = (username, password) => {
|
||||
return dispatch => {
|
||||
dispatch(login());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/getToken`,
|
||||
method: 'post',
|
||||
data: {
|
||||
username,
|
||||
password,
|
||||
login: true
|
||||
},
|
||||
header: {}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.status === 'success') {
|
||||
const decodedAceessToken = jwtDecode(response.data.accessToken);
|
||||
if(decodedAceessToken.data.wiaas_user_type === 'customer'){
|
||||
localStorage.setItem('accessToken', response.data.accessToken);
|
||||
const serverTime = response.data.serverTime || 1;
|
||||
refreshToken = response.data.refreshToken;
|
||||
startRefreshTimer(dispatch, serverTime);
|
||||
dispatch(loggedIn(response.data));
|
||||
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||
}else{
|
||||
dispatch(loginFail({status: 'fail', errorMessage: 'INVALID_USER_TYPE'}));
|
||||
}
|
||||
} else {
|
||||
dispatch(loginFail(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const startRefreshTimer = (dispatch, serverTime) => {
|
||||
const decodedAceessToken = jwtDecode(localStorage.accessToken);
|
||||
const TEN_MINUTES = 600;
|
||||
const tokenTimeLeft = decodedAceessToken.exp - serverTime;
|
||||
const refreshTime = tokenTimeLeft ? (tokenTimeLeft - TEN_MINUTES) * 1000 : REFRESH_TIME;
|
||||
|
||||
if(refreshTime <= 0){
|
||||
dispatch(validateRefreshToken());
|
||||
}else{
|
||||
refreshTimer = setTimeout(()=>{
|
||||
dispatch(validateRefreshToken());
|
||||
}, refreshTime);
|
||||
}
|
||||
}
|
||||
|
||||
const requestRefreshToken = () => ({
|
||||
type: REFRESH_TOKEN
|
||||
});
|
||||
|
||||
const validateRefreshToken = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestRefreshToken());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/refreshToken`,
|
||||
method: 'post',
|
||||
data: {
|
||||
refreshToken,
|
||||
lastActivity: authActivity.lastActivity
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.status === 'success') {
|
||||
localStorage.setItem('accessToken', response.data.accessToken);
|
||||
const serverTime = response.data.serverTime || 1;
|
||||
refreshToken = response.data.refreshToken;
|
||||
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||
startRefreshTimer(dispatch, serverTime);
|
||||
} else {
|
||||
dispatch(logout(response.data));
|
||||
dispatch(loginFail(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export const getModules = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestModules());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/getModules`,
|
||||
})
|
||||
.then(response => {
|
||||
dispatch(recieveModules(response.data));
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const requestModules = () => ({
|
||||
type: REQUEST_MODULES
|
||||
});
|
||||
|
||||
const recieveModules = (json) => ({
|
||||
type: RECIEVE_MODULES,
|
||||
modules: json.modules
|
||||
});
|
||||
|
||||
export const logout = () => {
|
||||
localStorage.removeItem('accessToken');
|
||||
clearInterval(refreshTimer);
|
||||
return {
|
||||
type: LOGOUT,
|
||||
isLoggedIn: false,
|
||||
errorMessage: 'LOGGED_OUT'
|
||||
}
|
||||
}
|
||||
|
||||
export const loggedIn = (jsonData) => {
|
||||
return {
|
||||
type: LOGIN_SUCCESS,
|
||||
isLoggedIn: true,
|
||||
userInfo: jsonData.userInfo
|
||||
}
|
||||
}
|
||||
|
||||
export const loginFail = (jsonData) => {
|
||||
return {
|
||||
type: LOGIN_FAIL,
|
||||
isLoggedIn: false,
|
||||
errorMessage: jsonData.errorMessage
|
||||
}
|
||||
}
|
||||
|
||||
export const generatePassword = (mail) => {
|
||||
return dispatch => {
|
||||
dispatch(requestForgotPassword());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/forgotPassword`,
|
||||
method: 'post',
|
||||
data: {mail},
|
||||
header: {}
|
||||
})
|
||||
.then(response => {
|
||||
if(typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(forgotPasswordMessage(response.data.messages[0]));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestForgotPassword = () => ({
|
||||
type: REQUEST_FORGOT_PASSWORD,
|
||||
errorMessage: 'FORGOT_REQUEST_SENT'
|
||||
});
|
||||
const forgotPasswordMessage = (jsonData) => {
|
||||
return {
|
||||
type: FORGOT_PASSWORD,
|
||||
errorMessage: jsonData.message,
|
||||
messageColor: jsonData.code
|
||||
}
|
||||
}
|
||||
|
||||
const requestChange = () => ({
|
||||
type: REQUEST_CHANGE
|
||||
});
|
||||
|
||||
const passwordChanged = (messageObj) => {
|
||||
const code = messageObj.code === 'error' ? 'danger' : messageObj.code;
|
||||
const isPasswordChanged = messageObj.message === 'PASSWORD_GENERATED' ? true : false;
|
||||
return {
|
||||
type: PASSWORD_CHANGED,
|
||||
errorMessage: messageObj.message,
|
||||
messageColor: code,
|
||||
isPasswordChanged: isPasswordChanged
|
||||
}
|
||||
};
|
||||
|
||||
export const changePassword = (token, newPassword, confirmPassword) => {
|
||||
return dispatch => {
|
||||
dispatch(requestChange());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/login/api/changePassword`,
|
||||
method: 'post',
|
||||
data: {token, newPassword, confirmPassword},
|
||||
header: {}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data.messages && response.data.messages.length > 0){
|
||||
dispatch(passwordChanged(response.data.messages[0]));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
4
frontend/src/actions/notification/notificationActions.js
Normal file
4
frontend/src/actions/notification/notificationActions.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import {UPDATE_MESSAGES, DESTROY_MESSAGE} from '../../constants/notificationConstants';
|
||||
|
||||
export const destroyMessage = () => ({type: DESTROY_MESSAGE, messages: []});
|
||||
export const updateMessages = (json, messageObj) => ({type: UPDATE_MESSAGES, updateMessages: {messageJson: json, messageObj}});
|
||||
77
frontend/src/actions/orderProjects/orderProjectsActions.js
Normal file
77
frontend/src/actions/orderProjects/orderProjectsActions.js
Normal file
@@ -0,0 +1,77 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_ORDER_PROJECTS,
|
||||
RECEIVE_ORDER_PROJECTS,
|
||||
REQUEST_ADD_PROJECT,
|
||||
orderProjectsTexts
|
||||
} from '../../constants/orderProjectsConstants';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
||||
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
const requestOrderProjects = () => ({
|
||||
type: REQUEST_ORDER_PROJECTS,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveOrderProjects = (json) => ({
|
||||
type: RECEIVE_ORDER_PROJECTS,
|
||||
isLoading: false,
|
||||
orderProjects: json
|
||||
});
|
||||
|
||||
const generateOptions = (orderProjects) => {
|
||||
orderProjects.forEach((orderProject) => {
|
||||
orderProject.value = orderProject.idProject;
|
||||
orderProject.label = orderProject.projectName;
|
||||
});
|
||||
|
||||
return orderProjects;
|
||||
}
|
||||
|
||||
export const getOrderProjects = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestOrderProjects());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orderProjects/api/getOrderProjects`
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
const orderProjects = generateOptions(response.data);
|
||||
dispatch(recieveOrderProjects(orderProjects));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestAddProject = () => ({
|
||||
type: REQUEST_ADD_PROJECT,
|
||||
isLoading: true
|
||||
});
|
||||
|
||||
export const addProject = (projectData) => {
|
||||
return dispatch => {
|
||||
dispatch(requestAddProject());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orderProjects/api/addOrderProject`,
|
||||
method: 'post',
|
||||
data: {projectData: JSON.stringify(projectData)}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, orderProjectsTexts.messages));
|
||||
if(response.data.messages[0].code === 'success'){
|
||||
dispatch(getOrderProjects());
|
||||
dispatch(setDialogOpenFlag(false));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
102
frontend/src/actions/orders/customerAcceptanceActions.js
Normal file
102
frontend/src/actions/orders/customerAcceptanceActions.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import {
|
||||
REQUEST_CUSTOMER_ACCEPTANCE,
|
||||
RECEIVE_CUSTOMER_ACCEPTANCE,
|
||||
UPLOAD_CUSTOMER_ACCEPTANCE,
|
||||
SEND_CUSTOMER_ACCEPTANCE,
|
||||
orderMessages
|
||||
} from '../../constants/ordersConstants';
|
||||
import {
|
||||
updateMessages
|
||||
} from '../notification/notificationActions';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
const requestCustomerAcceptance = () => ({
|
||||
type: REQUEST_CUSTOMER_ACCEPTANCE
|
||||
});
|
||||
const recieveCustomerAcceptance = (json) => ({
|
||||
type: RECEIVE_CUSTOMER_ACCEPTANCE,
|
||||
customerAcceptance: json
|
||||
});
|
||||
|
||||
export const fetchCustomerAcceptance = (idOrder) => {
|
||||
return dispatch => {
|
||||
dispatch(requestCustomerAcceptance());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getCustomerAcceptance`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
dispatch(recieveCustomerAcceptance(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const uploadAcceptanceAction = () => ({
|
||||
type: UPLOAD_CUSTOMER_ACCEPTANCE
|
||||
});
|
||||
|
||||
export const uploadAcceptance = (idOrder, file) => {
|
||||
return dispatch => {
|
||||
dispatch(uploadAcceptanceAction());
|
||||
return htmlClient.uploadFile(file, {
|
||||
url: `${API_SERVER}/orders/api/uploadAcceptanceDocument`,
|
||||
data: {
|
||||
idOrder
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
dispatch(fetchCustomerAcceptance(idOrder));
|
||||
}
|
||||
}).catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const badFile = () =>{
|
||||
return dispatch => {
|
||||
dispatch(updateMessages([{code: 'warning', message: 'INVALID_FILE_ACCEPTANCE'}], orderMessages));
|
||||
}
|
||||
}
|
||||
|
||||
const sendCustomerAcceptance = () => ({
|
||||
type: SEND_CUSTOMER_ACCEPTANCE
|
||||
});
|
||||
|
||||
export const acceptDeclineInstallation = (idOrder, actionType, declineReason) => {
|
||||
return dispatch => {
|
||||
dispatch(sendCustomerAcceptance());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/acceptDeclineInstallation`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder,
|
||||
actionType,
|
||||
declineReason
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
dispatch(fetchCustomerAcceptance(idOrder));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
66
frontend/src/actions/orders/ordersActions.js
Normal file
66
frontend/src/actions/orders/ordersActions.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import {API_SERVER} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_ACTIVE_ORDERS,
|
||||
RECEIVE_ACTIVE_ORDERS,
|
||||
REQUEST_HISTORY_ORDERS,
|
||||
RECEIVE_HISTORY_ORDERS,
|
||||
SET_VIEW_ALL_ORDERS
|
||||
} from '../../constants/ordersConstants';
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
const requestActiveOrders = () => ({
|
||||
type: REQUEST_ACTIVE_ORDERS,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveActiveOrders = (json) => ({
|
||||
type: RECEIVE_ACTIVE_ORDERS,
|
||||
isLoading: false,
|
||||
activeOrders: json
|
||||
});
|
||||
|
||||
export const getActiveOrders = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestActiveOrders());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getActiveOrders`
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
|
||||
dispatch(recieveActiveOrders(response.data.orders));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestHistoryOrders = () => ({
|
||||
type: REQUEST_HISTORY_ORDERS,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveHistoryOrders = (json) => ({
|
||||
type: RECEIVE_HISTORY_ORDERS,
|
||||
isLoading: false,
|
||||
historyOrders: json
|
||||
});
|
||||
|
||||
export const getHistoryOrders = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestHistoryOrders());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getHistoryOrders`
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'orders' in response.data) {
|
||||
dispatch(recieveHistoryOrders(response.data.orders));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const setViewAllOrdersFlag = (isViewAllOrdersChecked) => ({type: SET_VIEW_ALL_ORDERS, isViewAllOrdersChecked});
|
||||
344
frontend/src/actions/orders/processActions.js
Normal file
344
frontend/src/actions/orders/processActions.js
Normal file
@@ -0,0 +1,344 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import {
|
||||
orderMessages,
|
||||
REQUEST_ORDER_INFO,
|
||||
RECEIVE_ORDER_INFO,
|
||||
SEND_ORDER_COMMENT,
|
||||
REQUEST_CUSTOMER_DOCUMENTS,
|
||||
RECEIVE_CUSTOMER_DOCUMENTS,
|
||||
RE_UPLOAD_DOCUMENT,
|
||||
REQUEST_VALIDATION_COMMENTS,
|
||||
RECEIVE_VALIDATION_COMMENTS,
|
||||
REQUEST_IS_NEXT_STEP_WANTED,
|
||||
RECEIVE_IS_NEXT_STEP_WANTED,
|
||||
RECEIVE_IS_COMPONENT_DISABLED,
|
||||
SET_EARLIEST_INSTALLATION_DATE,
|
||||
SET_CONFIRMATION_DATES,
|
||||
REQUEST_INSTALLATION_COMPANIES,
|
||||
RECEIVE_INSTALLATION_COMPANIES,
|
||||
REQUEST_ALL_SHIPPING_DATES_CONFIRMED,
|
||||
RECEIVE_ALL_SHIPPING_DATES_CONFIRMED,
|
||||
SET_SUPPORT_MESSAGE,
|
||||
SET_SCHEDULING_DISABLED_FLAG
|
||||
} from '../../constants/ordersConstants';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
const requestOrderInfo = () => ({
|
||||
type: REQUEST_ORDER_INFO,
|
||||
isLoading: true
|
||||
});
|
||||
const recieveOrderInfo = (json) => ({
|
||||
type: RECEIVE_ORDER_INFO,
|
||||
isLoading: false,
|
||||
orderInfo: json
|
||||
});
|
||||
|
||||
export const fetchOrderInfo = (idOrder) => {
|
||||
return dispatch => {
|
||||
dispatch(requestOrderInfo());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getOrderInfo`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
dispatch(recieveOrderInfo(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const sendComment = () => ({
|
||||
type: SEND_ORDER_COMMENT
|
||||
})
|
||||
|
||||
export const addComment = (idOrder, comment) => {
|
||||
return dispatch => {
|
||||
dispatch(sendComment());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/addOrderComment`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder,
|
||||
comment
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data && response.data.messages) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
dispatch(fetchOrderInfo(idOrder));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestCustomerDocuments = () => ({
|
||||
type: REQUEST_CUSTOMER_DOCUMENTS
|
||||
});
|
||||
const recieveCustomerDocuments = (json) => ({
|
||||
type: RECEIVE_CUSTOMER_DOCUMENTS,
|
||||
customerDocuments: json
|
||||
});
|
||||
|
||||
export const fetchCustomerDocuments = (idOrder, documentType, idPackage = 0) => {
|
||||
return dispatch => {
|
||||
dispatch(requestCustomerDocuments());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getOrderDocumentsPerType`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder,
|
||||
idPackage,
|
||||
documentType
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'documents' in response.data) {
|
||||
dispatch(recieveCustomerDocuments(response.data.documents));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestValidationComments = () => ({
|
||||
type: REQUEST_VALIDATION_COMMENTS
|
||||
});
|
||||
const recieveValidationComments = (json) => ({
|
||||
type: RECEIVE_VALIDATION_COMMENTS,
|
||||
validationComments: json
|
||||
});
|
||||
|
||||
export const fetchValidationComments = (idOrder, idProcessStep, commentType) => {
|
||||
return dispatch => {
|
||||
dispatch(requestValidationComments());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getCommentsByType`,
|
||||
method: 'post',
|
||||
data: {
|
||||
idOrder,
|
||||
idProcessStep,
|
||||
commentType
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
dispatch(recieveValidationComments(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const reUploadDocumnet = () => ({
|
||||
type: RE_UPLOAD_DOCUMENT
|
||||
});
|
||||
|
||||
export const reUploadOrderDocument = (idPackage, idOrder, idDocument, file) => {
|
||||
return dispatch => {
|
||||
dispatch(reUploadDocumnet());
|
||||
return htmlClient.uploadFile(file, {
|
||||
url: `${API_SERVER}/orders/api/reUploadQuestionaire`,
|
||||
data: {
|
||||
idPackage,
|
||||
idOrder,
|
||||
idDocument
|
||||
}
|
||||
}).then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
dispatch(fetchCustomerDocuments(idOrder, 'orderQuestionaire', idPackage));
|
||||
}
|
||||
}).catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const badFile = () =>{
|
||||
return dispatch => {
|
||||
dispatch(updateMessages([{code: 'warning', message: 'INVALID_FILE_QUESTIONNAINRE'}], orderMessages));
|
||||
}
|
||||
}
|
||||
|
||||
export const requestIsNextStepWanted = () => ({type: REQUEST_IS_NEXT_STEP_WANTED});
|
||||
export const receiveIsNextStepWanted = (json) => ({
|
||||
type: RECEIVE_IS_NEXT_STEP_WANTED,
|
||||
isNextStepWanted: json
|
||||
});
|
||||
|
||||
const receiveIsComponentDisabled = (isComponentDisabled) => ({
|
||||
type: RECEIVE_IS_COMPONENT_DISABLED,
|
||||
isComponentDisabled
|
||||
});
|
||||
|
||||
const setEarliestInstallationDate = (earliestInstallDate) => ({
|
||||
type: SET_EARLIEST_INSTALLATION_DATE,
|
||||
earliestInstallDate
|
||||
});
|
||||
|
||||
const setConfirmationDates = (json) => ({
|
||||
type: SET_CONFIRMATION_DATES,
|
||||
confirmationDates: json
|
||||
});
|
||||
export const getInstallationConfirmationDates = (idOrder, idPackage = 0) => {
|
||||
return dispatch => {
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getInstallationDates`,
|
||||
method: 'post',
|
||||
data: {idOrder, idPackage}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'confirmationDates' in response.data) {
|
||||
dispatch(setConfirmationDates(response.data.confirmationDates));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestInstallationCompanies = () => ({type: REQUEST_INSTALLATION_COMPANIES});
|
||||
const recieveInstallationCompanies = (json) => ({
|
||||
type: RECEIVE_INSTALLATION_COMPANIES,
|
||||
installCompanies: json
|
||||
});
|
||||
|
||||
const requestAreAllShippingDatesConfirmed = ()=> ({type: REQUEST_ALL_SHIPPING_DATES_CONFIRMED});
|
||||
const receiveAreAllShippingDatesConfirmed = (json) => ({
|
||||
type: RECEIVE_ALL_SHIPPING_DATES_CONFIRMED,
|
||||
areAllShippingDatesConfirmed: json
|
||||
});
|
||||
|
||||
export const getAllDataForInstallation = (idOrder, usedForDirective, stepsNameForInstallation, fileType) => {
|
||||
const isNextStepTheOneWanted = {};
|
||||
return dispatch => {
|
||||
dispatch(requestInstallationCompanies());
|
||||
dispatch(requestIsNextStepWanted());
|
||||
dispatch(requestCustomerDocuments());
|
||||
dispatch(requestAreAllShippingDatesConfirmed());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/getAllDataForInstallation`,
|
||||
method: 'post',
|
||||
data: {idOrder, stepsNameForInstallation, fileType}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined') {
|
||||
if ('messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
}
|
||||
if('installCompanies' in response.data) {
|
||||
dispatch(recieveInstallationCompanies(response.data.installCompanies));
|
||||
}
|
||||
if('earliestInstallationDate' in response.data) {
|
||||
dispatch(setEarliestInstallationDate(response.data.earliestInstallationDate));
|
||||
}
|
||||
if ('installationDates' in response.data) {
|
||||
dispatch(setConfirmationDates(response.data.installationDates.confirmationDates));
|
||||
}
|
||||
if('isNextStepWanted' in response.data) {
|
||||
isNextStepTheOneWanted[usedForDirective] = response.data.isNextStepWanted;
|
||||
|
||||
dispatch(receiveIsNextStepWanted(isNextStepTheOneWanted));
|
||||
dispatch(receiveIsComponentDisabled(isNextStepTheOneWanted));
|
||||
}
|
||||
if('areAllShippingDatesConfirmed' in response.data) {
|
||||
dispatch(receiveAreAllShippingDatesConfirmed(response.data.areAllShippingDatesConfirmed));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export const updateInstallationDate = (idOrder, idPackage, installationDate, status, clearDateInput='') => {
|
||||
return dispatch => {
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/updateInstallationDate`,
|
||||
method: 'post',
|
||||
data: {idOrder, idPackage, installationDate, status}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
if(response.data.messages.find(messageObj => {return messageObj.code === 'success';})) {
|
||||
if(clearDateInput) {
|
||||
clearDateInput(undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
dispatch(getInstallationConfirmationDates(idOrder, idPackage));
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const removeMyDate = (idOrder, idPackage, installationDate) => {
|
||||
return dispatch => {
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/removeMyDate`,
|
||||
method: 'post',
|
||||
data: {idOrder, idPackage, installationDate}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
}
|
||||
dispatch(getInstallationConfirmationDates(idOrder, idPackage));
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const setSupportMessage = (message) => ({
|
||||
type: SET_SUPPORT_MESSAGE,
|
||||
supportText: message
|
||||
});
|
||||
|
||||
export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
|
||||
return dispatch => {
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/orders/api/sendSupportMail`,
|
||||
method: 'post',
|
||||
data: {orderInfo, orderPackages, supportText}
|
||||
})
|
||||
.then(response => {
|
||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||
dispatch(updateMessages(response.data.messages, orderMessages));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const setSchedulingFlag = (flag) => ({
|
||||
type: SET_SCHEDULING_DISABLED_FLAG,
|
||||
isSchedulingDisabled: flag
|
||||
});
|
||||
30
frontend/src/actions/page/pageActions.js
Normal file
30
frontend/src/actions/page/pageActions.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import {
|
||||
SET_PARAMS_FROM_URL,
|
||||
RESET_PARAMS,
|
||||
SET_ACTIVE_MODULE,
|
||||
SET_ACTIVE_SUB_MODULE,
|
||||
RESET_ACTIVE_SUB_MODULE
|
||||
} from '../../constants/pageConstants';
|
||||
|
||||
export const setParamsFromUrl = (params) => ({
|
||||
type: SET_PARAMS_FROM_URL,
|
||||
urlParams: params
|
||||
});
|
||||
|
||||
export const resetParamsFromUrl = () => ({
|
||||
type: RESET_PARAMS
|
||||
});
|
||||
|
||||
export const setActiveModule = (module) => ({
|
||||
type: SET_ACTIVE_MODULE,
|
||||
activeModule: module
|
||||
});
|
||||
|
||||
export const setActiveSubModule = (submodule) => ({
|
||||
type: SET_ACTIVE_SUB_MODULE,
|
||||
activeSubmodule: submodule
|
||||
});
|
||||
|
||||
export const resetActiveSubModule = () => ({
|
||||
type: RESET_ACTIVE_SUB_MODULE
|
||||
});
|
||||
118
frontend/src/actions/profileSettings/addressActions.js
Normal file
118
frontend/src/actions/profileSettings/addressActions.js
Normal file
@@ -0,0 +1,118 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_SAVE_PROFILE_ADDRESS,
|
||||
REQUEST_REMOVE_PROFILE_ADDRESS,
|
||||
REQUEST_REMOVE_BILLING_ADDRESS,
|
||||
REQUEST_SAVE_BILLING_ADDRESS,
|
||||
profileTexts
|
||||
} from '../../constants/profileSettingsConstants';
|
||||
import {fetchProfileInfo} from './profileSettingsActions';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
||||
|
||||
const client = new HtmlClient();
|
||||
|
||||
const requestSaveAddress = () => ({
|
||||
type: REQUEST_SAVE_PROFILE_ADDRESS
|
||||
});
|
||||
|
||||
export const saveProfileAddress = (idUser, profileAddress) => {
|
||||
return dispatch => {
|
||||
dispatch(requestSaveAddress());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/saveProfileAddress`,
|
||||
method: 'post',
|
||||
data: {profileAddress: JSON.stringify(profileAddress)}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
if(response.data.messages[0].code === 'success'){
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
dispatch(setDialogOpenFlag(false));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestRemoveAddress = () => ({
|
||||
type: REQUEST_REMOVE_PROFILE_ADDRESS
|
||||
});
|
||||
|
||||
export const removeProfileAddress = (idUser, idProfileAddress) => {
|
||||
return dispatch => {
|
||||
dispatch(requestRemoveAddress());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/removeProfileAddress`,
|
||||
method: 'post',
|
||||
data: {idProfileAddress}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const requestSaveBillingAddress = () => ({
|
||||
type: REQUEST_SAVE_BILLING_ADDRESS
|
||||
});
|
||||
|
||||
export const saveBillingAddress = (idUser, idCompany, billingAddress) => {
|
||||
return dispatch => {
|
||||
dispatch(requestSaveBillingAddress());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/saveBillingAddress`,
|
||||
method: 'post',
|
||||
data: {idCompany, billingAddress: JSON.stringify(billingAddress)}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
if(response.data.messages[0].code === 'success'){
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
dispatch(setDialogOpenFlag(false));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestRemoveBillingAddress = () => ({
|
||||
type: REQUEST_REMOVE_BILLING_ADDRESS
|
||||
});
|
||||
|
||||
export const removeBillingAddress = (idUser, idBillingAddress) => {
|
||||
return dispatch => {
|
||||
dispatch(requestRemoveBillingAddress());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/removeBillingAddress`,
|
||||
method: 'post',
|
||||
data: {idBillingAddress}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
}
|
||||
123
frontend/src/actions/profileSettings/profileSettingsActions.js
Normal file
123
frontend/src/actions/profileSettings/profileSettingsActions.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import {
|
||||
API_SERVER
|
||||
} from '../../config';
|
||||
import HtmlClient from '../../helpers/HtmlClient';
|
||||
import {
|
||||
REQUEST_PROFILE_INFO,
|
||||
RECIEVE_PROFILE_INFO,
|
||||
REQUEST_SAVE_PROFILE,
|
||||
REQUEST_SAVE_COMPANY,
|
||||
REQUEST_COUNTRIES,
|
||||
RECIEVE_COUNTRIES,
|
||||
profileTexts
|
||||
} from '../../constants/profileSettingsConstants';
|
||||
import {updateMessages} from '../notification/notificationActions';
|
||||
|
||||
const client = new HtmlClient();
|
||||
|
||||
const requestProfileInfo = () => ({
|
||||
type: REQUEST_PROFILE_INFO,
|
||||
isLoading: true
|
||||
});
|
||||
|
||||
export const recieveProfileInfo = (json) => ({
|
||||
type: RECIEVE_PROFILE_INFO,
|
||||
isLoading: false,
|
||||
profileInfo: json
|
||||
});
|
||||
|
||||
export const fetchProfileInfo = (idUser) => {
|
||||
return dispatch => {
|
||||
dispatch(requestProfileInfo());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/getProfileInfo`,
|
||||
method: 'post',
|
||||
data: {idUser}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
dispatch(recieveProfileInfo(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestSaveProfile = () => ({
|
||||
type: REQUEST_SAVE_PROFILE
|
||||
});
|
||||
|
||||
export const saveProfileInfo = (idUser, profile) => {
|
||||
return dispatch => {
|
||||
dispatch(requestSaveProfile());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/saveProfileInfo`,
|
||||
method: 'post',
|
||||
data: {idUser, profile: JSON.stringify(profile)}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestSaveCompany = () => ({
|
||||
type: REQUEST_SAVE_COMPANY
|
||||
});
|
||||
|
||||
export const saveCompanyInfo = (idUser, companyInfo) => {
|
||||
return dispatch => {
|
||||
dispatch(requestSaveCompany());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/saveCompanyInfo`,
|
||||
method: 'post',
|
||||
data: {companyInfo: JSON.stringify(companyInfo)}
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data && response.data.messages){
|
||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||
dispatch(fetchProfileInfo(idUser));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const requestCountries = () => ({
|
||||
type: REQUEST_COUNTRIES,
|
||||
areCountriesLoading: true
|
||||
});
|
||||
|
||||
const recieveCountries = (json) => ({
|
||||
type: RECIEVE_COUNTRIES,
|
||||
areCountriesLoading: false,
|
||||
countries: json
|
||||
});
|
||||
|
||||
export const fetchCountries = () => {
|
||||
return dispatch => {
|
||||
dispatch(requestCountries());
|
||||
return client.fetch({
|
||||
url: `${API_SERVER}/profileSettings/api/getCoutnries`,
|
||||
method: 'get'
|
||||
})
|
||||
.then(response => {
|
||||
if(response.data){
|
||||
dispatch(recieveCountries(response.data));
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
client.onError(error, dispatch);
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user