/*! * Copyright (c) 2024 PLANKA Software GmbH * Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md */ import upperFirst from 'lodash/upperFirst'; import camelCase from 'lodash/camelCase'; import React, { useCallback, useMemo } from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { useDispatch, useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; import { Button, Icon } from 'semantic-ui-react'; import selectors from '../../../selectors'; import entryActions from '../../../entry-actions'; import Paths from '../../../constants/Paths'; import { ProjectBackgroundTypes } from '../../../constants/Enums'; import UserAvatar from '../../users/UserAvatar'; import styles from './ProjectCard.module.scss'; import globalStyles from '../../../styles.module.scss'; const Sizes = { SMALL: 'small', LARGE: 'large', }; const ProjectCard = React.memo( ({ id, size, isActive, withDescription, withTypeIndicator, withFavoriteButton, className }) => { const selectProjectById = useMemo(() => selectors.makeSelectProjectById(), []); const selectFirstBoardIdByProjectId = useMemo( () => selectors.makeSelectFirstBoardIdByProjectId(), [], ); const selectNotificationsTotalByProjectId = useMemo( () => selectors.makeSelectNotificationsTotalByProjectId(), [], ); const selectProjectManagerById = useMemo(() => selectors.makeSelectProjectManagerById(), []); const selectBackgroundImageById = useMemo(() => selectors.makeSelectBackgroundImageById(), []); const project = useSelector((state) => selectProjectById(state, id)); const firstBoardId = useSelector((state) => selectFirstBoardIdByProjectId(state, id)); const notificationsTotal = useSelector((state) => selectNotificationsTotalByProjectId(state, id), ); const ownerProjectManager = useSelector( (state) => project.ownerProjectManagerId && selectProjectManagerById(state, project.ownerProjectManagerId), ); const backgroundImageUrl = useSelector((state) => { if (!project.backgroundType || project.backgroundType !== ProjectBackgroundTypes.IMAGE) { return null; } const backgroundImage = selectBackgroundImageById(state, project.backgroundImageId); if (!backgroundImage) { return null; } return backgroundImage.thumbnailUrls.outside360; }); const dispatch = useDispatch(); const handleToggleFavoriteClick = useCallback(() => { dispatch( entryActions.updateProject(project.id, { isFavorite: !project.isFavorite, }), ); }, [project, dispatch]); const withSidebar = withTypeIndicator || (withFavoriteButton && !project.isHidden); return (
{notificationsTotal > 0 && ( {notificationsTotal} )}
{project.name}
{withDescription && project.description && (
{project.description}
)}
{withTypeIndicator && (
{ownerProjectManager ? ( ) : ( )}
)} {withFavoriteButton && !project.isHidden && ( )}
); }, ); ProjectCard.propTypes = { id: PropTypes.string.isRequired, size: PropTypes.oneOf(Object.values(Sizes)), isActive: PropTypes.bool, withDescription: PropTypes.bool, withTypeIndicator: PropTypes.bool, withFavoriteButton: PropTypes.bool, className: PropTypes.string.isRequired, }; ProjectCard.defaultProps = { size: Sizes.LARGE, isActive: undefined, withDescription: false, withTypeIndicator: false, withFavoriteButton: false, }; export default ProjectCard;