import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { workspaceName } from '../../actions/workspaceActions'; import { setDescription, updateProject } from '../../actions/projectActions'; import Snackbar from '../Snackbar'; import Dialog from '../Dialog'; import withWidth, { isWidthDown } from '@material-ui/core/withWidth'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import Tooltip from '@material-ui/core/Tooltip'; import TextField from '@material-ui/core/TextField'; import Typography from '@material-ui/core/Typography'; import { faPen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = (theme) => ({ workspaceName: { backgroundColor: theme.palette.secondary.main, borderRadius: '25px', display: 'inline-flex', cursor: 'pointer', '&:hover': { color: theme.palette.primary.main, } } }); class WorkspaceName extends Component { constructor(props) { super(props); this.inputRef = React.createRef(); this.state = { title: '', content: '', open: false, name: props.name, description: props.description, snackbar: false, type: '', key: '', message: '' }; } componentDidUpdate(props) { if (props.name !== this.props.name) { this.setState({ name: this.props.name }); } if (props.description !== this.props.description) { this.setState({ description: this.props.description }); } } toggleDialog = () => { this.setState({ open: !this.state, title: '', content: '' }); } setFileName = (e) => { this.setState({ name: e.target.value }); } setDescription = (e) => { this.setState({ description: e.target.value }); } renameWorkspace = () => { this.props.workspaceName(this.state.name); this.toggleDialog(); if(this.props.projectType === 'project' || this.props.projectType === 'gallery' || this.state.projectType === 'gallery'){ if(this.props.projectType === 'gallery' || this.state.projectType === 'gallery'){ this.props.setDescription(this.state.description); } if(this.state.projectType === 'gallery'){ this.saveGallery(); } else { this.props.updateProject(this.props.projectType, this.props.project._id._id ? this.props.project._id._id : this.props.project._id); } } else { this.setState({ snackbar: true, type: 'success', key: Date.now(), message: `Das Projekt wurde erfolgreich in '${this.state.name}' umbenannt.` }); } } render() { return (