import React, { Component } from 'react' import PropTypes from 'prop-types' import { withRouter } from 'react-router-dom' import Button from '@material-ui/core/Button' import AddIcon from '@material-ui/icons/Add' import TextField from '@material-ui/core/TextField' import Dialog from '@material-ui/core/Dialog' import DialogActions from '@material-ui/core/DialogActions' import DialogContent from '@material-ui/core/DialogContent' import DialogContentText from '@material-ui/core/DialogContentText' import DialogTitle from '@material-ui/core/DialogTitle' import Typography from '@material-ui/core/Typography' import { getItem } from '../../../utils/local-storage' export class CreateTeamDialog extends Component { constructor (props) { super(props) this.handleClickOpen = this.handleClickOpen.bind(this) this.handleClose = this.handleClose.bind(this) this.handlePost = this.handlePost.bind(this) this.slugify = this.slugify.bind(this) this.handleChange = this.handleChange.bind(this) this.state = { open: false, name: '' } } handleClickOpen () { this.setState({ open: true }) } handleClose () { this.setState({ open: false }) } handleChange (e) { this.setState({ name: e.target.value }) } render () { console.log(this.props) return (
Subscribe Team Creation Name your team!
) } slugify (string) { const a = 'àáäâãåèéëêìíïîòóöôùúüûñçßÿœæŕśńṕẃǵǹḿǘẍźḧ·/_,:;' const b = 'aaaaaaeeeeiiiioooouuuuncsyoarsnpwgnmuxzh------' const p = new RegExp(a.split('').join('|'), 'g') return string .toString() .toLowerCase() .replace(/\s+/g, '-') // Replace spaces with - .replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters .replace(/&/g, '-and-') // Replace & with 'and' .replace(/[^\w-]+/g, '') // Remove all non-word characters .replace(/--+/g, '-') // Replace multiple - with single - .replace(/^-+/, '') // Trim - from start of text .replace(/-+$/, '') // Trim - from end of text } async handlePost (e) { e.preventDefault() const { name } = this.state const slug = this.slugify(name) const currentUser = await getItem('user') let authId = JSON.parse(currentUser) authId = authId.sub console.log('createPage cu:', JSON.parse(currentUser)) await this.props.createTeamMutation({ variables: { name, slug, owner: authId } }) this.setState({ open: false }) } } CreateTeamDialog.propTypes = { classes: PropTypes.object.isRequired, createTeamMutation: PropTypes.function } export default withRouter(CreateTeamDialog)