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

View File

@ -2,6 +2,9 @@ import { api } from "asc-web-common";
export const SET_SETTINGS_PAYMENTS_ENTERPRISE = export const SET_SETTINGS_PAYMENTS_ENTERPRISE =
"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) { export function setSettings(settings) {
return { 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() { export function getSettingsPayment() {
return (dispatch) => { return (dispatch) => {
return api.settings.getPaymentSettings().then((settings) => { 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 (dispatch) => {
return api.settings return api.settings
.setLicense(confirmKey, data) .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 = { const initialState = {
salesEmail: "sales@onlyoffice.com", salesEmail: "sales@onlyoffice.com",
@ -6,6 +10,7 @@ const initialState = {
buyUrl: buyUrl:
"https://www.onlyoffice.com/enterprise-edition.aspx?type=buyenterprise", "https://www.onlyoffice.com/enterprise-edition.aspx?type=buyenterprise",
standaloneMode: true, standaloneMode: true,
licenseUpload: null,
currentLicense: { currentLicense: {
expiresDate: new Date("2021-09-14T01:59:59"), expiresDate: new Date("2021-09-14T01:59:59"),
trialMode: false, trialMode: false,
@ -25,7 +30,15 @@ const paymentsReducer = (state = initialState, action) => {
trialMode: action.settings.currentLicense.trial, 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: default:
return state; return state;
} }