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 Card from '../components/Card';
|
|
|
|
|
|
|
|
const makeMapStateToProps = () => {
|
2022-08-04 13:31:14 +02:00
|
|
|
const selectCardById = selectors.makeSelectCardById();
|
|
|
|
const selectUsersByCardId = selectors.makeSelectUsersByCardId();
|
|
|
|
const selectLabelsByCardId = selectors.makeSelectLabelsByCardId();
|
|
|
|
const selectTasksByCardId = selectors.makeSelectTasksByCardId();
|
|
|
|
const selectNotificationsTotalByCardId = selectors.makeSelectNotificationsTotalByCardId();
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return (state, { id, index }) => {
|
2022-08-04 13:31:14 +02:00
|
|
|
const { projectId } = selectors.selectPath(state);
|
|
|
|
const allProjectsToLists = selectors.selectProjectsToListsForCurrentUser(state);
|
|
|
|
const allBoardMemberships = selectors.selectMembershipsForCurrentBoard(state);
|
|
|
|
const allLabels = selectors.selectLabelsForCurrentBoard(state);
|
2022-08-19 14:00:40 +02:00
|
|
|
const currentUserMembership = selectors.selectCurrentUserMembershipForCurrentBoard(state);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
const { name, dueDate, timer, coverUrl, boardId, listId, isPersisted } = selectCardById(
|
2020-05-05 01:30:06 +05:00
|
|
|
state,
|
|
|
|
id,
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2022-08-04 13:31:14 +02:00
|
|
|
const users = selectUsersByCardId(state, id);
|
|
|
|
const labels = selectLabelsByCardId(state, id);
|
|
|
|
const tasks = selectTasksByCardId(state, id);
|
|
|
|
const notificationsTotal = selectNotificationsTotalByCardId(state, id);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
|
|
|
return {
|
|
|
|
id,
|
|
|
|
index,
|
|
|
|
name,
|
2019-10-05 06:12:36 +05:00
|
|
|
dueDate,
|
2019-08-31 04:07:25 +05:00
|
|
|
timer,
|
2020-04-23 03:02:53 +05:00
|
|
|
coverUrl,
|
2020-05-05 01:30:06 +05:00
|
|
|
boardId,
|
2020-08-04 01:32:46 +05:00
|
|
|
listId,
|
2020-05-05 01:30:06 +05:00
|
|
|
projectId,
|
2019-08-31 04:07:25 +05:00
|
|
|
isPersisted,
|
|
|
|
notificationsTotal,
|
|
|
|
users,
|
|
|
|
labels,
|
|
|
|
tasks,
|
2020-05-05 01:30:06 +05:00
|
|
|
allProjectsToLists,
|
2021-06-24 01:05:22 +05:00
|
|
|
allBoardMemberships,
|
2019-08-31 04:07:25 +05:00
|
|
|
allLabels,
|
2022-08-19 14:00:40 +02:00
|
|
|
canEdit:
|
|
|
|
!!currentUserMembership && currentUserMembership.role === BoardMembershipRoles.EDITOR,
|
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.updateCard(id, data),
|
|
|
|
onMove: (listId, index) => entryActions.moveCard(id, listId, index),
|
|
|
|
onTransfer: (boardId, listId) => entryActions.transferCard(id, boardId, listId),
|
|
|
|
onDelete: () => entryActions.deleteCard(id),
|
|
|
|
onUserAdd: (userId) => entryActions.addUserToCard(userId, id),
|
|
|
|
onUserRemove: (userId) => entryActions.removeUserFromCard(userId, id),
|
|
|
|
onBoardFetch: entryActions.fetchBoard,
|
|
|
|
onLabelAdd: (labelId) => entryActions.addLabelToCard(labelId, id),
|
|
|
|
onLabelRemove: (labelId) => entryActions.removeLabelFromCard(labelId, id),
|
|
|
|
onLabelCreate: (data) => entryActions.createLabelInCurrentBoard(data),
|
|
|
|
onLabelUpdate: (labelId, data) => entryActions.updateLabel(labelId, data),
|
|
|
|
onLabelDelete: (labelId) => entryActions.deleteLabel(labelId),
|
2020-02-03 18:42:31 +05:00
|
|
|
},
|
|
|
|
dispatch,
|
|
|
|
);
|
2019-08-31 04:07:25 +05:00
|
|
|
|
2020-02-03 18:42:31 +05:00
|
|
|
export default connect(makeMapStateToProps, mapDispatchToProps)(Card);
|