Skip to content

Commit

Permalink
Merge branch 'master' into site-and-navroot
Browse files Browse the repository at this point in the history
  • Loading branch information
erral authored Sep 11, 2023
2 parents 9e92439 + 244daf8 commit dbf27ed
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 515 deletions.
1 change: 1 addition & 0 deletions news/4076.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor Navigation -@Tishasoumya-02
1 change: 1 addition & 0 deletions news/4926.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Messages Component Refactor - @Tishasoumya-02
1 change: 1 addition & 0 deletions news/4933.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor Login -@Tishasoumya-02
1 change: 1 addition & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export {
login,
loginRenew,
logout,
resetLoginRequest,
} from '@plone/volto/actions/userSession/userSession';
export {
getVocabulary,
Expand Down
18 changes: 17 additions & 1 deletion src/actions/userSession/userSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* @module actions/search/search
*/

import { LOGIN, LOGIN_RENEW, LOGOUT } from '@plone/volto/constants/ActionTypes';
import {
LOGIN,
LOGIN_RENEW,
LOGOUT,
RESET_LOGIN_REQUEST,
} from '@plone/volto/constants/ActionTypes';

/**
* Login function.
Expand Down Expand Up @@ -52,3 +57,14 @@ export function logout() {
},
};
}

/**
* Reset login request data function
* @function resetLoginRequest
* @returns {Object} Get content action
*/
export function resetLoginRequest() {
return {
type: RESET_LOGIN_REQUEST,
};
}
131 changes: 32 additions & 99 deletions src/components/manage/Messages/Messages.jsx
Original file line number Diff line number Diff line change
@@ -1,107 +1,40 @@
/**
* Messages component.
* @module components/manage/Messages/Messages
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { useDispatch, useSelector, shallowEqual } from 'react-redux';
import { Message, Container } from 'semantic-ui-react';
import { map } from 'lodash';

import { removeMessage } from '@plone/volto/actions';

/**
* Messages container class.
* @class Messages
* @extends Component
*/
class Messages extends Component {
/**
* Property types.
* @property {Object} propTypes Property types.
* @static
*/
static propTypes = {
removeMessage: PropTypes.func.isRequired,
messages: PropTypes.arrayOf(
PropTypes.shape({
title: PropTypes.string,
body: PropTypes.string,
level: PropTypes.string,
}),
).isRequired,
};

/**
* Constructor
* @method constructor
* @param {Object} props Component properties
* @constructs Messages
*/
constructor(props) {
super(props);
this.onDismiss = this.onDismiss.bind(this);
}
const Messages = () => {
const dispatch = useDispatch();

// /**
// * Component will receive props
// * @method componentWillReceiveProps
// * @param {Object} nextProps Next properties
// * @returns {undefined}
// */
// componentWillReceiveProps(nextProps) {
// if (nextProps.messages.length > this.props.messages.length) {
// window.setTimeout(() => {
// if (this.props.messages.length > 0) {
// this.props.removeMessage(-1);
// }
// }, 6000);
// }
// }
const messages = useSelector(
(state) => state.messages.messages,
shallowEqual,
);

/**
* On dismiss
* @method onDismiss
* @param {Object} event Event object
* @param {number} value Index of message
* @returns {undefined}
*/
onDismiss(event, { value }) {
this.props.removeMessage(value);
}

/**
* Render method.
* @method render
* @returns {string} Markup for the component.
*/
render() {
return (
this.props.messages && (
<Container className="messages">
{map(this.props.messages, (message, index) => (
<Message
key={message.id}
value={index}
onDismiss={this.onDismiss}
error={message.level === 'error'}
success={message.level === 'success'}
warning={message.level === 'warning'}
info={message.level === 'info'}
header={message.title}
content={message.body}
/>
))}
</Container>
)
);
}
}
const onDismiss = (event, { value }) => {
dispatch(removeMessage(value));
};

export default connect(
(state) => ({
messages: state.messages.messages,
}),
{ removeMessage },
)(Messages);
return (
messages && (
<Container className="messages">
{map(messages, (message, index) => (
<Message
key={message.id}
value={index}
onDismiss={onDismiss}
error={message.level === 'error'}
success={message.level === 'success'}
warning={message.level === 'warning'}
info={message.level === 'info'}
header={message.title}
content={message.body}
/>
))}
</Container>
)
);
};

export default Messages;
1 change: 0 additions & 1 deletion src/components/manage/Messages/Messages.test.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-redux';
Expand Down
Loading

0 comments on commit dbf27ed

Please sign in to comment.