2019-08-31 04:07:25 +05:00
|
|
|
import { bindActionCreators } from 'redux';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
import selectors from '../selectors';
|
|
|
|
import entryActions from '../entry-actions';
|
2022-08-19 14:00:40 +02:00
|
|
|
import { BoardMembershipRoles } from '../constants/Enums';
|
2019-08-31 04:07:25 +05:00
|
|
|
import List from '../components/List';
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
2022-08-04 13:31:14 +02:00
|
|
|
const selectListById = selectors.makeSelectListById();
|
|
|
|
const selectCardIdsByListId = selectors.makeSelectCardIdsByListId();
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return (state, { id, index }) => {
|
2022-08-04 13:31:14 +02:00
|
|
|
const { name, isPersisted } = selectListById(state, id);
|
|
|
|
const cardIds = selectCardIdsByListId(state, id);
|
2022-08-19 14:00:40 +02:00
|
|
|
const currentUserMembership = selectors.selectCurrentUserMembershipForCurrentBoard(state);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-12-26 21:10:50 +01:00
|
|
|
const isCurrentUserEditor =
|
|
|
|
!!currentUserMembership && currentUserMembership.role === BoardMembershipRoles.EDITOR;
|
|
|
|
|
2019-08-31 04:07:25 +05:00
|
|
|
return {
|
|
|
|
id,
|
|
|
|
index,
|
|
|
|
name,
|
|
|
|
isPersisted,
|
|
|
|
cardIds,
|
2022-12-26 21:10:50 +01:00
|
|
|
canEdit: isCurrentUserEditor,
|
2019-08-31 04:07:25 +05:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
const mapDispatchToProps = (dispatch, { id }) =>
|
|
|
|
bindActionCreators(
|
|
|
|
{
|
2022-08-04 13:31:14 +02:00
|
|
|
onUpdate: (data) => entryActions.updateList(id, data),
|
|
|
|
onDelete: () => entryActions.deleteList(id),
|
|
|
|
onCardCreate: (data) => entryActions.createCard(id, data),
|
2020-02-03 18:42:31 +05:00
|
|
|
},
|
|
|
|
dispatch,
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2021-06-24 01:05:22 +05:00
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(List);
|