Skip to content
Snippets Groups Projects
DegreeCourseItem.js 3.78 KiB
Newer Older
import React, { Component } from "react";
import Button from "react-bootstrap/esm/Button";
import Card from 'react-bootstrap/Card';
Orlando Piñero's avatar
Orlando Piñero committed
import Table from "react-bootstrap/esm/Table";
Orlando Piñero's avatar
Orlando Piñero committed
import { connect } from "react-redux";

const mapStateToProps = state => {
    return {
        isAdmin: state.AuthenticationReducer.isAdmin
    };
}

class DegreeCourseItem extends Component {
    render() {
        let degreeCourse = this.props.degreeCourse
        let editButtonID = "DegreeCourseItemEditButton" + degreeCourse.id
        let deleteButtonID = "DegreeCourseItemDeleteButton" + degreeCourse.id
        let itemID = "DegreeCourseItem" + degreeCourse.id
Orlando Piñero's avatar
Orlando Piñero committed
        let applicationID = "CreateDegreeCourseApplicationForDegreeCourse" + degreeCourse.id
        let dialogData = {
            dialogID: "DeleteDialogDegreeCourse" + degreeCourse.id,
            name: degreeCourse.name,
            degreeCourseID: degreeCourse.id
        let cardHeader
        if (degreeCourse.shortName) {
Orlando Piñero's avatar
Orlando Piñero committed
            cardHeader = <Card.Header><b>{degreeCourse.shortName}: {degreeCourse.name}</b></Card.Header>
Orlando Piñero's avatar
Orlando Piñero committed
            cardHeader = <Card.Header><b>{degreeCourse.name}</b></Card.Header>
Orlando Piñero's avatar
Orlando Piñero committed

        let cardFooter
        if (this.props.isAdmin) {
            cardFooter =
                <>
                    <Button variant="primary" onClick={(e) => this.props.handleShowEditPage(e, degreeCourse)} id={editButtonID}  >
                        Edit
                    </Button>
                    <Button variant="primary" type="submit" onClick={(e) => this.props.handleShowDeleteModal(e, dialogData)} id={deleteButtonID} style={{ background: '#ffc800', color: 'black', border: 'none' }}>
                        Delete
                    </Button>
                    <Button variant="primary" onClick={(e) => this.props.handleShowCreateApplication(e, degreeCourse)} id={applicationID} style={{ background: '#05b361', border: 'none' }}>
                        Create Application
                    </Button>
                </>
        } else {
            cardFooter =
Orlando Piñero's avatar
Orlando Piñero committed
                <Button variant="primary" onClick={(e) => this.props.handleShowCreateApplication(e, degreeCourse)} id={applicationID} style={{ background: '#05b361', border: 'none' }}>
                    Create Application
                </Button>
Orlando Piñero's avatar
Orlando Piñero committed
        }

        return (
            <div>
Orlando Piñero's avatar
Orlando Piñero committed
                    <Card style={{ width: "25rem", background: '#ebebeb', margin: '0.5rem' }} id={itemID}>
                        {cardHeader}
Orlando Piñero's avatar
Orlando Piñero committed
                        <Table responsive="sm">
                            <tbody>
                                <tr id="UniversityName">
                                    <td><b>Universität:</b></td>
                                    <td style={{ textAlign: 'left' }}>{degreeCourse.universityName}</td>
                                </tr>
                                <tr id="DepartmentName">
                                    <td><b>Fachbereich:</b></td>
                                    <td style={{ textAlign: 'left' }}>{degreeCourse.departmentName}</td>
                                </tr>
                                <tr id="Name">
                                    <td><b>Studiengang:</b></td>
                                    <td style={{ textAlign: 'left' }}>{degreeCourse.name}</td>
                                </tr>
                            </tbody>
                        </Table>
                        <Card.Footer style={{ display: 'flex', justifyContent: 'space-evenly' }}>
Orlando Piñero's avatar
Orlando Piñero committed
                            {cardFooter}
                        </Card.Footer>
                    </Card>
                </div>
Orlando Piñero's avatar
Orlando Piñero committed
const ConnectedDegreeCourseItem = connect(mapStateToProps)(DegreeCourseItem)
export default ConnectedDegreeCourseItem