Changed reducer and actions: added setLicenseUpload and resetUploadedLicense

This commit is contained in:
TatianaLopaeva 2020-09-15 14:16:12 +03:00
parent ed85445dcc
commit ce32451441
3 changed files with 49 additions and 15 deletions

View File

@ -11,8 +11,9 @@ import AdvantagesContainer from "./sub-components/advantages-container";
import ButtonContainer from "./sub-components/button-container";
import ContactContainer from "./sub-components/contact-container";
import {
setLicense,
setPaymentsLicense,
getSettingsPayment,
resetUploadedLicense,
} from "../../../store/payments/actions";
import { createI18N } from "../../../helpers/i18n";
@ -46,7 +47,6 @@ class Body extends React.PureComponent {
this.state = {
errorMessage: null,
isErrorLicense: false,
isLicenseSet: false,
};
document.title = `${t("Payments")} ${t("OrganizationName")}`;
@ -59,32 +59,36 @@ class Body extends React.PureComponent {
setCurrentProductId,
} = this.props;
currentProductId !== "payments" && setCurrentProductId("payments");
getSettingsPayment();
//getSettingsPayment();
}
componentDidUpdate(prevProps) {
const { getSettingsPayment, currentProductId } = this.props;
const { isLicenseSet } = this.state;
const {
getSettingsPayment,
currentProductId,
licenseUpload,
resetUploadedLicense,
} = this.props;
// if (currentProductId !== prevProps.currentProductId) {
// this.fetchData(currentProductId);
// }
if (isLicenseSet) {
if (licenseUpload) {
getSettingsPayment();
resetUploadedLicense();
}
}
onButtonClickUpload = (file) => {
const { setLicense, t } = this.props;
const { setPaymentsLicense, t } = this.props;
let fd = new FormData();
fd.append("files", file);
setLicense(null, fd)
setPaymentsLicense(null, fd)
.then(() => {
toastr.success(t("LoadingLicenseSuccess"), "", 0, true);
this.setState({
isLicenseSet: true,
});
})
.catch((error) => {
toastr.error(t("LoadingLicenseError"), t("LicenseIsNotValid"), 0, true);
@ -137,10 +141,12 @@ PaymentsEnterprise.propTypes = {
function mapStateToProps(state) {
return {
isLoaded: state.auth.isLoaded,
licenseUpload: state.payments.licenseUpload,
};
}
export default connect(mapStateToProps, {
setLicense,
setPaymentsLicense,
setCurrentProductId,
getSettingsPayment,
resetUploadedLicense,
})(withRouter(PaymentsEnterprise));

View File

@ -2,6 +2,9 @@ import { api } from "asc-web-common";
export const SET_SETTINGS_PAYMENTS_ENTERPRISE =
"SET_SETTINGS_PAYMENTS_ENTERPRISE";
export const SET_UPLOAD_PAYMENTS_ENTERPRISE_LICENSE =
"SET_UPLOAD_PAYMENTS_ENTERPRISE_LICENSE";
export const RESET_UPLOADED_LICENSE = "RESET_UPLOADED_LICENSE";
export function setSettings(settings) {
return {
@ -10,6 +13,18 @@ export function setSettings(settings) {
};
}
export function setLicenseUpload(message) {
return {
type: SET_UPLOAD_PAYMENTS_ENTERPRISE_LICENSE,
message,
};
}
export function resetUploadedLicense() {
return {
type: RESET_UPLOADED_LICENSE,
};
}
export function getSettingsPayment() {
return (dispatch) => {
return api.settings.getPaymentSettings().then((settings) => {
@ -17,10 +32,10 @@ export function getSettingsPayment() {
});
};
}
export function setLicense(confirmKey, data) {
export function setPaymentsLicense(confirmKey, data) {
return (dispatch) => {
return api.settings
.setLicense(confirmKey, data)
.then((res) => console.log(res));
.then((res) => dispatch(setLicenseUpload(res)));
};
}

View File

@ -1,4 +1,8 @@
import { SET_SETTINGS_PAYMENTS_ENTERPRISE } from "./actions";
import {
SET_SETTINGS_PAYMENTS_ENTERPRISE,
SET_UPLOAD_PAYMENTS_ENTERPRISE_LICENSE,
RESET_UPLOADED_LICENSE,
} from "./actions";
const initialState = {
salesEmail: "sales@onlyoffice.com",
@ -6,6 +10,7 @@ const initialState = {
buyUrl:
"https://www.onlyoffice.com/enterprise-edition.aspx?type=buyenterprise",
standaloneMode: true,
licenseUpload: null,
currentLicense: {
expiresDate: new Date("2021-09-14T01:59:59"),
trialMode: false,
@ -25,7 +30,15 @@ const paymentsReducer = (state = initialState, action) => {
trialMode: action.settings.currentLicense.trial,
}),
});
case SET_UPLOAD_PAYMENTS_ENTERPRISE_LICENSE:
return Object.assign({}, state, {
licenseUpload: action.message,
});
case RESET_UPLOADED_LICENSE:
return Object.assign({}, state, {
licenseUpload: null,
});
default:
return state;
}