Refactoring actions and reducer

This commit is contained in:
TatianaLopaeva 2020-09-15 11:01:54 +03:00
parent 1f887f4b5b
commit 7da745b96c
4 changed files with 33 additions and 46 deletions

View File

@ -10,7 +10,10 @@ import HeaderContainer from "./sub-components/header-container";
import AdvantagesContainer from "./sub-components/advantages-container";
import ButtonContainer from "./sub-components/button-container";
import ContactContainer from "./sub-components/contact-container";
import { setLicense, getSettings } from "../../../store/payments/actions";
import {
setLicense,
getSettingsPayment,
} from "../../../store/payments/actions";
import { createI18N } from "../../../helpers/i18n";
const i18n = createI18N({
@ -51,25 +54,22 @@ class Body extends React.PureComponent {
componentDidMount() {
const {
getSettings,
getSettingsPayment,
currentProductId,
setCurrentProductId,
} = this.props;
currentProductId !== "payments" && setCurrentProductId("payments");
// getSettings();
// getStandalone();
//getCurrentLicense();
getSettingsPayment();
}
componentDidUpdate(prevProps) {
const { getSettings } = this.props;
const { getSettingsPayment, currentProductId } = this.props;
const { isLicenseSet } = this.state;
// if (currentProductId !== prevProps.currentProductId) {
// this.fetchData(currentProductId);
// }
if (isLicenseSet) {
getSettings();
getSettingsPayment();
}
}
@ -98,12 +98,6 @@ class Body extends React.PureComponent {
window.open(e.target.value, "_blank");
};
onCloseModalDialog = () => {
this.setState({
isVisibleModalDialog: false,
});
};
render() {
const { isLoaded, t } = this.props;
@ -148,5 +142,5 @@ function mapStateToProps(state) {
export default connect(mapStateToProps, {
setLicense,
setCurrentProductId,
getSettings,
getSettingsPayment,
})(withRouter(PaymentsEnterprise));

View File

@ -59,17 +59,13 @@ const HeaderContainer = ({
require("moment/min/locales.min");
moment.locale(culture);
const currentUserDate = moment().utcOffset(utcHoursOffset);
console.log(typeof expiresDate);
return moment(
moment.utc(expiresDate).set("hour", 0).set("minute", 0).set("second", 0)
).isAfter(
currentUserDate.set("hour", 0).set("minute", 0).set("second", 0)
) ? (
return new Date(currentUserDate).setHours(0, 0, 0, 0) <
expiresDate.setHours(0, 0, 0, 0) ? (
<StyledHeader>
<Text className="payments-header">{t("Using")}</Text>
<Text className="payments-header-additional_support">
{t("SubscriptionAndUpdatesExpires")}{" "}
{moment.utc(expiresDate).format("LL")}
{t("SubscriptionAndUpdatesExpires")} {moment(expiresDate).format("LL")}
{"."}
</Text>
</StyledHeader>
@ -79,7 +75,7 @@ const HeaderContainer = ({
<Text className="payments-header-additional_support" color="#C96C27">
{t("SupportNotAvailable")}{" "}
{moment.utc(expiresDate).startOf("day").format("ddd, D MMMM , YYYY")}
{moment(expiresDate).startOf("day").format("ddd, D MMMM , YYYY")}
{". "}
{t("LicenseRenewal")}
</Text>

View File

@ -1,19 +1,22 @@
import { api } from "asc-web-common";
export const SET_SALES_EMAIL = "SET_SALES_EMAIL";
export const SET_HELP_URL = "SET_HELP_URL";
export const SET_BUY_URL = "SET_BUY_URL";
export const SET_CURRENT_LICENSE = "SET_CURRENT_LICENSE";
export const SET_SETTINGS = "SET_SETTINGS";
export const SET_STANDALONE = "SET_STANDALONE";
export const SET_SETTINGS_PAYMENTS_ENTERPRISE =
"SET_SETTINGS_PAYMENTS_ENTERPRISE";
export function setSettings(settings) {
return {
type: SET_SETTINGS,
type: SET_SETTINGS_PAYMENTS_ENTERPRISE,
settings,
};
}
export function getSettingsPayment() {
return (dispatch) => {
return api.settings.getPaymentSettings().then((settings) => {
dispatch(setSettings(settings));
});
};
}
export function setLicense(confirmKey, data) {
return (dispatch) => {
return api.settings
@ -21,11 +24,3 @@ export function setLicense(confirmKey, data) {
.then((res) => console.log(res));
};
}
export function getSettings() {
return (dispatch) => {
return api.settings.getPaymentSettings().then((settings) => {
dispatch(setSettings(settings));
});
};
}

View File

@ -1,29 +1,31 @@
import { SET_SETTINGS } from "./actions";
import { SET_SETTINGS_PAYMENTS_ENTERPRISE } from "./actions";
const initialState = {
salesEmail: "",
helpUrl: "",
buyUrl: "",
salesEmail: "sales@onlyoffice.com",
helpUrl: "https://helpdesk.onlyoffice.com",
buyUrl:
"https://www.onlyoffice.com/enterprise-edition.aspx?type=buyenterprise",
standaloneMode: true,
currentLicense: {
expiresDate: new Date("2021-10-01T23:59:59.000Z"),
expiresDate: new Date("2021-09-14T01:59:59"),
trialMode: false,
},
};
const paymentsReducer = (state = initialState, action) => {
switch (action.type) {
case SET_SETTINGS:
case SET_SETTINGS_PAYMENTS_ENTERPRISE:
return Object.assign({}, state, {
salesEmail: action.settings.salesEmail,
helpUrl: action.settings.feedbackAndSupportUrl,
buyUrl: action.settings.buyUrl,
standaloneMode: action.settings.standaloneMode,
currentLicense: Object.assign({}, state.currentLicense, {
expiresDate: action.settings.currentLicense.date,
expiresDate: new Date(action.settings.currentLicense.date),
trialMode: action.settings.currentLicense.trial,
}),
});
default:
return state;
}