@eeacms/volto-clms-theme 1.1.113 → 1.1.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,11 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [1.1.113](https://github.com/eea/volto-clms-theme/compare/1.1.112...1.1.113) - 19 February 2024
7
+ ### [1.1.114](https://github.com/eea/volto-clms-theme/compare/1.1.113...1.1.114) - 21 February 2024
8
8
 
9
9
  #### :hammer_and_wrench: Others
10
10
 
11
- - link to contact_email [Mikel Larreategi - [`0b000f5`](https://github.com/eea/volto-clms-theme/commit/0b000f58cf1928fd7dae548ab49e7857fd53e1c4)]
11
+ - console removed [Unai Etxaburu - [`70b039e`](https://github.com/eea/volto-clms-theme/commit/70b039e299724cc2d2ede3fd01eee371408ac56f)]
12
+ - base volto logout component and user in header appears if token and user id exists [Unai Etxaburu - [`650864f`](https://github.com/eea/volto-clms-theme/commit/650864f870356651041b2e5fc96df55ae2f794d5)]
13
+ ### [1.1.113](https://github.com/eea/volto-clms-theme/compare/1.1.112...1.1.113) - 19 February 2024
14
+
12
15
  ### [1.1.112](https://github.com/eea/volto-clms-theme/compare/1.1.111...1.1.112) - 16 February 2024
13
16
 
14
17
  ### [1.1.111](https://github.com/eea/volto-clms-theme/compare/1.1.110...1.1.111) - 13 February 2024
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-clms-theme",
3
- "version": "1.1.113",
3
+ "version": "1.1.114",
4
4
  "description": "volto-clms-theme: Volto theme for CLMS site",
5
5
  "main": "src/index.js",
6
6
  "author": "CodeSyntax for the European Environment Agency",
@@ -216,7 +216,7 @@ class Header extends Component {
216
216
  <li className="header-vertical-line">
217
217
  <div>|</div>
218
218
  </li>
219
- {(this.props.user?.id && (
219
+ {(this.props.token && this.props.user?.id && (
220
220
  <>
221
221
  <li className="header-dropdown">
222
222
  <HeaderDropdown user={this.props.user} />
@@ -1,36 +1,108 @@
1
- import { useEffect, useMemo } from 'react';
2
- import { useDispatch, useSelector, shallowEqual } from 'react-redux';
3
- import { useHistory } from 'react-router-dom';
1
+ /**
2
+ * Login container.
3
+ * @module components/theme/Logout/Logout
4
+ */
5
+
6
+ import React, { Component } from 'react';
7
+ import PropTypes from 'prop-types';
8
+ import { connect } from 'react-redux';
9
+ import { compose } from 'redux';
10
+ import { defineMessages, injectIntl } from 'react-intl';
4
11
  import qs from 'query-string';
12
+
13
+ import { Login } from '@plone/volto/components';
5
14
  import { logout, purgeMessages } from '@plone/volto/actions';
15
+ import { toast } from 'react-toastify';
16
+ import { Toast } from '@plone/volto/components';
6
17
 
7
- const Logout = ({ location }) => {
8
- const token = useSelector((state) => state.userSession.token, shallowEqual);
9
- const history = useHistory();
10
- const dispatch = useDispatch();
11
-
12
- const returnUrl = useMemo(
13
- () =>
14
- qs.parse(location.search).return_url ||
15
- location.pathname
16
- .replace(/\/login\/?$/, '')
17
- .replace(/\/logout\/?$/, '') ||
18
- '/',
19
- [location],
20
- );
21
-
22
- useEffect(() => {
23
- dispatch(logout());
24
- dispatch(purgeMessages());
25
- }, [dispatch]);
26
-
27
- useEffect(() => {
28
- if (!token) {
29
- window.location.href = '/';
30
- }
31
- }, [history, returnUrl, token]);
18
+ const messages = defineMessages({
19
+ loggedOut: {
20
+ id: 'Logged out',
21
+ defaultMessage: 'Logged out',
22
+ },
23
+ loggedOutContent: {
24
+ id: 'You have been logged out from the site.',
25
+ defaultMessage: 'You have been logged out from the site.',
26
+ },
27
+ });
28
+
29
+ /**
30
+ * Logout class.
31
+ * @class Logout
32
+ * @extends Component
33
+ */
34
+ class Logout extends Component {
35
+ /**
36
+ * Property types.
37
+ * @property {Object} propTypes Property types.
38
+ * @static
39
+ */
40
+ static propTypes = {
41
+ logout: PropTypes.func.isRequired,
42
+ purgeMessages: PropTypes.func.isRequired,
43
+ query: PropTypes.shape({
44
+ return_url: PropTypes.string,
45
+ }),
46
+ };
32
47
 
33
- return '';
34
- };
48
+ /**
49
+ * Default properties.
50
+ * @property {Object} defaultProps Default properties.
51
+ * @static
52
+ */
53
+ static defaultProps = {
54
+ query: null,
55
+ };
56
+
57
+ componentDidMount() {
58
+ this.props.logout();
59
+ this.props.purgeMessages();
60
+ }
61
+
62
+ /**
63
+ * Component will receive props
64
+ * @method componentWillReceiveProps
65
+ * @param {Object} nextProps Next properties
66
+ * @returns {undefined}
67
+ */
68
+ UNSAFE_componentWillReceiveProps(nextProps) {
69
+ if (!nextProps.token) {
70
+ this.props.history.replace(this.props.returnUrl || '/');
71
+ if (!toast.isActive('loggedOut')) {
72
+ toast.success(
73
+ <Toast
74
+ success
75
+ title={this.props.intl.formatMessage(messages.loggedOut)}
76
+ content={this.props.intl.formatMessage(messages.loggedOutContent)}
77
+ />,
78
+ { autoClose: false, toastId: 'loggedOut' },
79
+ );
80
+ }
81
+ }
82
+ }
35
83
 
36
- export default Logout;
84
+ /**
85
+ * Render method.
86
+ * @method render
87
+ * @returns {string} Markup for the component.
88
+ */
89
+ render() {
90
+ return <Login location={{ query: this.props.location.query }} />;
91
+ }
92
+ }
93
+ export default compose(
94
+ injectIntl,
95
+ connect(
96
+ (state, props) => ({
97
+ query: qs.parse(props.location.search),
98
+ token: state.userSession.token,
99
+ returnUrl:
100
+ qs.parse(props.location.search).return_url ||
101
+ props.location.pathname
102
+ .replace(/\/login\/?$/, '')
103
+ .replace(/\/logout\/?$/, '') ||
104
+ '/',
105
+ }),
106
+ { logout, purgeMessages },
107
+ ),
108
+ )(Logout);