{"size": 3603, "ext": "js", "max_stars_repo_path": "frontend/src/components/project-card/ProjectCard.js", "max_stars_repo_name": "ibagomel/Visual-Flow-frontend", "max_stars_repo_stars_event_min_datetime": "2021-12-02T13:17:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-02T13:17:46.000Z", "max_issues_repo_path": "frontend/src/components/project-card/ProjectCard.js", "max_issues_repo_name": "ibagomel/Visual-Flow-frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/src/components/project-card/ProjectCard.js", "max_forks_repo_name": "ibagomel/Visual-Flow-frontend", "max_forks_repo_forks_event_min_datetime": "2021-06-05T07:00:18.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-05T07:00:18.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 33.9905660377, "max_line_length": 81, "alphanum_fraction": 0.5595337219}
/*
 * Copyright (c) 2021 IBA Group, a.s. All rights reserved.
 *
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import React from 'react';
import PropTypes from 'prop-types';
import {
    Card,
    CardActionArea,
    CardContent,
    CardHeader,
    Typography
} from '@material-ui/core';
import Skeleton from '@material-ui/lab/Skeleton';
import AddIcon from '@material-ui/icons/Add';
import DeleteIcon from '@material-ui/icons/DeleteOutline';
import IconButton from '@material-ui/core/IconButton';
import { connect } from 'react-redux';
import { useTranslation } from 'react-i18next';
import useStyles from './ProjectCard.Styles';
import { deleteProject } from '../../redux/actions/projectsActions';
import toggleConfirmationWindow from '../../redux/actions/modalsActions';

export const ProjectCardSkeleton = () => {
    const classes = useStyles();
    return <Skeleton variant="rect" className={classes.skeleton} />;
};

const ProjectCard = ({
    project: { id, name } = {},
    onClick,
    superUser,
    remove,
    confirmationWindow
}) => {
    const { t } = useTranslation();
    const classes = useStyles();

    return (
        <Card className={classes.root}>
            {id && superUser && (
                <CardHeader
                    action={
                        <IconButton
                            aria-label="Remove project"
                            onClick={() =>
                                confirmationWindow({
                                    body: `${t('main:confirm.sure')} '${name}'?`,
                                    callback: () => remove(id)
                                })
                            }
                        >
                            <DeleteIcon />
                        </IconButton>
                    }
                    className={classes.header}
                />
            )}
            <CardActionArea onClick={onClick} className={classes.content}>
                <CardContent>
                    {!id ? (
                        <AddIcon fontSize="large" color="action" />
                    ) : (
                        <Typography
                            variant="h5"
                            component="h5"
                            color="textSecondary"
                        >
                            {name}
                        </Typography>
                    )}
                </CardContent>
            </CardActionArea>
        </Card>
    );
};
ProjectCard.propTypes = {
    project: PropTypes.object,
    onClick: PropTypes.func,
    remove: PropTypes.func,
    superUser: PropTypes.bool,
    confirmationWindow: PropTypes.func.isRequired
};

const mapDispatchToProps = {
    remove: deleteProject,
    confirmationWindow: toggleConfirmationWindow
};

export default connect(null, mapDispatchToProps)(ProjectCard);
