initial docker setup
This commit is contained in:
21
frontend/src/helpers/FileDownloader.js
Normal file
21
frontend/src/helpers/FileDownloader.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import fileDownload from 'js-file-download';
|
||||
import HtmlClient from './HtmlClient';
|
||||
|
||||
const htmlClient = new HtmlClient();
|
||||
|
||||
class FileDownloader {
|
||||
download(fileUrl, fileName){
|
||||
htmlClient.fetch({
|
||||
url: fileUrl,
|
||||
responseType: 'arraybuffer'
|
||||
})
|
||||
.then((response) => {
|
||||
fileDownload(response.data, fileName);
|
||||
})
|
||||
.catch(error => {
|
||||
htmlClient.onError(error);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default FileDownloader;
|
||||
60
frontend/src/helpers/HtmlClient.js
Normal file
60
frontend/src/helpers/HtmlClient.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import axios from 'axios';
|
||||
import qs from 'qs';
|
||||
import {updateMessages} from '../actions/notification/notificationActions';
|
||||
import {authActivity} from '../constants/authConstants';
|
||||
import {notificationMessages} from '../constants/notificationConstants';
|
||||
import {store} from '../configureStore';
|
||||
|
||||
const getAuthLocalToken = () => {
|
||||
return localStorage.accessToken || '';
|
||||
}
|
||||
|
||||
const defaultParams = () =>({
|
||||
method: 'get',
|
||||
responseType: 'json',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + getAuthLocalToken()
|
||||
}
|
||||
});
|
||||
|
||||
const uploadParams = () =>({
|
||||
method: 'post',
|
||||
responseType: 'json',
|
||||
headers: {
|
||||
Authorization: 'Bearer ' + getAuthLocalToken(),
|
||||
'content-type': 'multipart/form-data'
|
||||
}
|
||||
});
|
||||
|
||||
class HtmlClient {
|
||||
|
||||
fetch(configParams) {
|
||||
if(configParams.data){
|
||||
configParams.data = qs.stringify(configParams.data);
|
||||
}
|
||||
const params = Object.assign({}, defaultParams(), configParams);
|
||||
authActivity.lastActivity = Date.now();
|
||||
|
||||
return axios(params);
|
||||
};
|
||||
|
||||
uploadFile(file, configParams = null) {
|
||||
let formData = new FormData();
|
||||
formData.append('file', file, file.name);
|
||||
if(configParams) {
|
||||
Object.keys(configParams.data).forEach((paramKey) => {
|
||||
formData.append(paramKey, configParams.data[paramKey]);
|
||||
});
|
||||
}
|
||||
configParams.data = formData;
|
||||
const params = Object.assign({}, uploadParams(), configParams);
|
||||
|
||||
return axios(params);
|
||||
}
|
||||
|
||||
onError(error) {
|
||||
store.dispatch(updateMessages([{code:'error', message: 'HTML_ERROR'}], notificationMessages));
|
||||
}
|
||||
}
|
||||
|
||||
export default HtmlClient;
|
||||
27
frontend/src/helpers/coMarket/PriceHelper.js
Normal file
27
frontend/src/helpers/coMarket/PriceHelper.js
Normal file
@@ -0,0 +1,27 @@
|
||||
class PriceHellper {
|
||||
sumPrices(values) {
|
||||
let total = 0;
|
||||
values.forEach((val) => {
|
||||
total += parseFloat(val);
|
||||
});
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
getSelectedPrice(curentPackage, selectedAgreement) {
|
||||
return curentPackage.prices.find(price => {
|
||||
return price.idPaymentType === selectedAgreement.idPaymentType;
|
||||
});
|
||||
}
|
||||
|
||||
hasFixedPrice(selectedPrice) {
|
||||
return selectedPrice;
|
||||
}
|
||||
|
||||
hasRecurrentPrice(selectedPrice){
|
||||
return selectedPrice && (selectedPrice.recurentExtra > 0 || selectedPrice.servicesExtra > 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PriceHellper;
|
||||
Reference in New Issue
Block a user