From dc09621f5d9526149e9e2c2386d3938f902c31e4 Mon Sep 17 00:00:00 2001 From: Daniil Senkiv Date: Wed, 6 Nov 2019 18:05:55 +0300 Subject: [PATCH] Web.Api: added unconditional getting greetingSettings; Web.Client: moved greetingSettings from setting reducer to auth reducer --- .../Controllers/SettingsController.cs | 10 ++--- .../Confirm/sub-components/changePassword.js | 8 ++-- .../Confirm/sub-components/profileRemove.js | 25 +++-------- .../categories/common/customization.js | 20 ++++----- web/ASC.Web.Client/src/store/auth/actions.js | 41 +++++++++++++++++-- web/ASC.Web.Client/src/store/auth/reducer.js | 6 ++- web/ASC.Web.Client/src/store/services/api.js | 4 +- .../src/store/settings/actions.js | 32 --------------- .../src/store/settings/reducer.js | 7 +--- 9 files changed, 65 insertions(+), 88 deletions(-) diff --git a/web/ASC.Web.Api/Controllers/SettingsController.cs b/web/ASC.Web.Api/Controllers/SettingsController.cs index d97308da6e..4b5857f3c2 100644 --- a/web/ASC.Web.Api/Controllers/SettingsController.cs +++ b/web/ASC.Web.Api/Controllers/SettingsController.cs @@ -116,13 +116,9 @@ namespace ASC.Api.Settings var settings = new SettingsWrapper { Culture = Tenant.GetCulture().ToString(), + GreetingSettings = Tenant.Name }; - if (!SecurityContext.IsAuthenticated) - { - settings.GreetingSettings = Tenant.Name; - } - if (SecurityContext.IsAuthenticated) { settings.TrustedDomains = Tenant.TrustedDomains; @@ -178,11 +174,11 @@ namespace ASC.Api.Settings return listOfTimezones; } - [Read("greetingsettings")] +/* [Read("greetingsettings")] public string GetGreetingSettings() { return Tenant.Name; - } + }*/ [Create("greetingsettings")] public object SaveGreetingSettings(GreetingSettingsModel model) diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js index de17481f70..91cebf6aa0 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/changePassword.js @@ -18,7 +18,6 @@ import { getConfirmationInfo, logout } from "../../../../../src/store/auth/actions"; -import { getGreetingTitle } from '../../../../store/settings/actions'; const BodyStyle = styled(Container)` margin-top: 70px; @@ -108,13 +107,12 @@ class Form extends React.PureComponent { }; componentDidMount() { - const { getConfirmationInfo, history, getGreetingTitle } = this.props; + const { getConfirmationInfo, history } = this.props; getConfirmationInfo(this.state.key) .catch(error => { toastr.error(this.props.t(`${error}`)); history.push("/"); }); - getGreetingTitle(); window.addEventListener("keydown", this.onKeyPress); window.addEventListener("keyup", this.onKeyPress); @@ -219,11 +217,11 @@ function mapStateToProps(state) { isConfirmLoaded: state.auth.isConfirmLoaded, settings: state.auth.settings.passwordSettings, isAuthenticated: state.auth.isAuthenticated, - greetingTitle: state.settings.greetingSettings, + greetingTitle: state.auth.settings.greetingSettings, }; } export default connect( mapStateToProps, - { changePassword, getConfirmationInfo, logout, getGreetingTitle } + { changePassword, getConfirmationInfo, logout } )(withRouter(withTranslation()(ChangePasswordForm))); diff --git a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/profileRemove.js b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/profileRemove.js index a06029bff3..624b13b34c 100644 --- a/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/profileRemove.js +++ b/web/ASC.Web.Client/src/components/pages/Confirm/sub-components/profileRemove.js @@ -7,7 +7,6 @@ import PropTypes from 'prop-types'; import { withTranslation } from 'react-i18next'; import { deleteSelf } from './../../../../store/services/api'; import { logout } from '../../../../store/auth/actions'; -import { getGreetingTitle } from '../../../../store/settings/actions'; const ProfileRemoveContainer = styled.div` display: flex; @@ -30,25 +29,14 @@ const ProfileRemoveContainer = styled.div` class ProfileRemove extends React.PureComponent { - constructor(props) { - super(props); - const { greetingTitle } = props; + constructor() { + super(); this.state = { isProfileDeleted: false, - greetingTitle }; } - componentDidMount() { - const { greetingTitle } = this.state; - const { getGreetingTitle } = this.props; - if (!greetingTitle) { - getGreetingTitle() - .then(() => this.setState({ greetingTitle: this.props.greetingTitleSettings })); - } - } - onDeleteProfile = () => { this.setState({ isLoading: true }, function () { const { linkData, logout } = this.props; @@ -72,8 +60,8 @@ class ProfileRemove extends React.PureComponent { render() { console.log('profileRemove render'); - const { t } = this.props; - const { isProfileDeleted, greetingTitle } = this.state; + const { t, greetingTitle } = this.props; + const { isProfileDeleted } = this.state; return (
@@ -120,9 +108,8 @@ const ProfileRemoveForm = (props) => ( this.setState({ greetingTitle: this.props.greetingSettings })); - } + const { getCultures, portalLanguage, portalTimeZoneId, t, getPortalTimezones } = this.props; + const { timezones, languages } = this.state; if (!timezones.length && !languages.length) { let languages; @@ -98,8 +92,8 @@ class Customization extends React.Component { } componentDidUpdate(prevProps, prevState) { - const { timezones, languages, greetingTitle } = this.state; - if (greetingTitle !== null && timezones.length && languages.length && !prevState.isLoadedData) { + const { timezones, languages } = this.state; + if (timezones.length && languages.length && !prevState.isLoadedData) { this.setState({ isLoadedData: true }); } } @@ -280,11 +274,11 @@ function mapStateToProps(state) { language: state.auth.user.cultureName || state.auth.settings.culture, rawTimezones: state.auth.settings.timezones, rawCultures: state.auth.settings.cultures, - greetingSettings: state.settings.greetingSettings, + greetingSettings: state.auth.settings.greetingSettings, }; } export default connect(mapStateToProps, { getCultures, setLanguageAndTime, getPortalTimezones, - getGreetingTitle, setGreetingTitle, restoreGreetingTitle + setGreetingTitle, restoreGreetingTitle })(withTranslation()(Customization)); diff --git a/web/ASC.Web.Client/src/store/auth/actions.js b/web/ASC.Web.Client/src/store/auth/actions.js index 824bc44629..8893dd677a 100644 --- a/web/ASC.Web.Client/src/store/auth/actions.js +++ b/web/ASC.Web.Client/src/store/auth/actions.js @@ -14,6 +14,7 @@ export const GET_PORTAL_CULTURES = 'GET_PORTAL_CULTURES'; export const SET_PORTAL_LANGUAGE_AND_TIME = 'SET_PORTAL_LANGUAGE_AND_TIME'; export const GET_TIMEZONES = 'GET_TIMEZONES'; export const SET_CURRENT_PRODUCT_ID = 'SET_CURRENT_PRODUCT_ID'; +export const SET_GREETING_SETTINGS = "SET_GREETING_SETTINGS"; export function setCurrentUser(user) { return { @@ -98,6 +99,13 @@ export function setCurrentProductId(currentProductId) { }; }; +export function setGreetingSettings(title) { + return { + type: SET_GREETING_SETTINGS, + title + }; +}; + export function getUser(dispatch) { return api.getUser() .then(user => dispatch(setCurrentUser(user))); @@ -219,8 +227,35 @@ export function setLanguageAndTime(lng, timeZoneID) { export function getPortalTimezones() { return dispatch => { return api.getPortalTimezones() - .then((timezones) => { - dispatch(getTimezones(timezones)) - }); + .then((timezones) => { + dispatch(getTimezones(timezones)) + }); }; }; + + +/* export function getGreetingTitle() { + return dispatch => { + return api.getGreetingSettings() + .then(greetingTitle => dispatch(setGreetingSettings(greetingTitle))); + }; +} */ + +export function setGreetingTitle(greetingTitle) { + return dispatch => { + return api.setGreetingSettings(greetingTitle) + .then((res) => { + dispatch(setGreetingSettings(greetingTitle)) + }); + }; +} + +export function restoreGreetingTitle() { + return dispatch => { + return api.restoreGreetingSettings() + .then((res) => { + dispatch(setGreetingSettings(res.companyName)) + }); + }; +} + diff --git a/web/ASC.Web.Client/src/store/auth/reducer.js b/web/ASC.Web.Client/src/store/auth/reducer.js index 2ed986405f..1c8e703e42 100644 --- a/web/ASC.Web.Client/src/store/auth/reducer.js +++ b/web/ASC.Web.Client/src/store/auth/reducer.js @@ -1,6 +1,6 @@ import { SET_CURRENT_USER, SET_MODULES, SET_SETTINGS, SET_IS_LOADED, LOGOUT, SET_PASSWORD_SETTINGS, SET_IS_CONFIRM_LOADED, SET_NEW_EMAIL, - GET_PORTAL_CULTURES, SET_PORTAL_LANGUAGE_AND_TIME, GET_TIMEZONES, SET_CURRENT_PRODUCT_ID + GET_PORTAL_CULTURES, SET_PORTAL_LANGUAGE_AND_TIME, GET_TIMEZONES, SET_CURRENT_PRODUCT_ID, SET_GREETING_SETTINGS } from './actions'; import isEmpty from 'lodash/isEmpty'; import config from "../../../package.json"; @@ -85,6 +85,10 @@ const authReducer = (state = initialState, action) => { return Object.assign({}, state, { settings: { ...state.settings, currentProductId: action.currentProductId } }); + case SET_GREETING_SETTINGS: + return Object.assign({}, state, { + settings: { ...state.settings, greetingSettings: action.title } + }); case LOGOUT: return initialState; default: diff --git a/web/ASC.Web.Client/src/store/services/api.js b/web/ASC.Web.Client/src/store/services/api.js index 684747299c..b103f66cb3 100644 --- a/web/ASC.Web.Client/src/store/services/api.js +++ b/web/ASC.Web.Client/src/store/services/api.js @@ -182,12 +182,12 @@ export function getUserById(userId) { }); } -export function getGreetingSettings() { +/* export function getGreetingSettings() { return request({ method: "get", url: `/settings/greetingsettings.json`, }); -} +} */ export function setGreetingSettings(title) { return request({ diff --git a/web/ASC.Web.Client/src/store/settings/actions.js b/web/ASC.Web.Client/src/store/settings/actions.js index 2dfcdf0cd4..ff7b63b079 100644 --- a/web/ASC.Web.Client/src/store/settings/actions.js +++ b/web/ASC.Web.Client/src/store/settings/actions.js @@ -10,7 +10,6 @@ import { export const SET_USERS = "SET_USERS"; export const SET_ADMINS = "SET_ADMINS"; export const SET_OWNER = "SET_OWNER"; -export const SET_GREETING_SETTINGS = "SET_GREETING_SETTINGS"; export function setUsers(options) { return { @@ -34,12 +33,6 @@ export function setOwner(owner) { }; } -export function setGreetingSettings(title) { - return { - type: SET_GREETING_SETTINGS, - title - }; -} export function getListUsers() { return (dispatch, getState) => { @@ -109,28 +102,3 @@ export function getUserById(userId) { return api.getUserById(userId).then(owner => dispatch(setOwner(owner))); }; } - -export function getGreetingTitle() { - return dispatch => { - return api.getGreetingSettings() - .then(greetingTitle => dispatch(setGreetingSettings(greetingTitle))); - }; -} - -export function setGreetingTitle(greetingTitle) { - return dispatch => { - return api.setGreetingSettings(greetingTitle) - .then((res) => { - dispatch(setGreetingSettings(greetingTitle)) - }); - }; -} - -export function restoreGreetingTitle() { - return dispatch => { - return api.restoreGreetingSettings() - .then((res) => { - dispatch(setGreetingSettings(res.companyName)) - }); - }; -} diff --git a/web/ASC.Web.Client/src/store/settings/reducer.js b/web/ASC.Web.Client/src/store/settings/reducer.js index cb3091bb62..dee1e7cf4c 100644 --- a/web/ASC.Web.Client/src/store/settings/reducer.js +++ b/web/ASC.Web.Client/src/store/settings/reducer.js @@ -1,4 +1,4 @@ -import { SET_USERS, SET_ADMINS, SET_OWNER, SET_GREETING_SETTINGS } from "./actions"; +import { SET_USERS, SET_ADMINS, SET_OWNER } from "./actions"; const initialState = { @@ -7,7 +7,6 @@ const initialState = { admins: [], owner: {} }, - greetingSettings: null }; const peopleReducer = (state = initialState, action) => { @@ -30,10 +29,6 @@ const peopleReducer = (state = initialState, action) => { owner: action.owner }) }); - case SET_GREETING_SETTINGS: - return Object.assign({}, state, { - greetingSettings: action.title - }); default: return state; }