2020-12-21 18:25:05 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import { createAlbum } from '../actions/albums'
|
|
|
|
import { closeModal } from '../actions/modal'
|
|
|
|
import Button from '../components/button'
|
|
|
|
import Input from '../components/input'
|
|
|
|
import Form from '../components/form'
|
|
|
|
import Text from '../components/text'
|
2020-12-22 17:11:22 +00:00
|
|
|
import Divider from '../components/divider'
|
|
|
|
import Textarea from '../components/textarea'
|
2020-12-21 18:25:05 +00:00
|
|
|
|
|
|
|
class AlbumCreate extends React.PureComponent {
|
|
|
|
|
|
|
|
state = {
|
2020-12-22 17:11:22 +00:00
|
|
|
titleValue: '',
|
|
|
|
descriptionValue: '',
|
|
|
|
checked: false,
|
2020-12-21 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
2020-12-22 17:11:22 +00:00
|
|
|
onChangeTitle = (titleValue) => {
|
|
|
|
this.setState({ titleValue })
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeDescription = (descriptionValue) => {
|
|
|
|
this.setState({ descriptionValue })
|
2020-12-21 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleOnSubmit = () => {
|
2020-12-22 17:11:22 +00:00
|
|
|
const { titleValue, descriptionValue, checked } = this.state
|
|
|
|
this.props.onSubmit(titleValue, descriptionValue, checked)
|
|
|
|
}
|
|
|
|
|
|
|
|
onTogglePrivacy = (checked) => {
|
|
|
|
this.setState({ checked })
|
2020-12-21 18:25:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-12-22 17:11:22 +00:00
|
|
|
const {
|
|
|
|
titleValue,
|
|
|
|
descriptionValue,
|
|
|
|
} = this.state
|
2020-12-21 18:25:05 +00:00
|
|
|
|
2020-12-22 17:11:22 +00:00
|
|
|
const isDisabled = !titleValue
|
|
|
|
|
|
|
|
console.log("HELLO")
|
2020-12-21 18:25:05 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
<Input
|
|
|
|
title='Title'
|
|
|
|
placeholder='Album title'
|
2020-12-22 17:11:22 +00:00
|
|
|
value={titleValue}
|
|
|
|
onChange={this.onChangeTitle}
|
2020-12-21 18:25:05 +00:00
|
|
|
/>
|
2020-12-22 17:11:22 +00:00
|
|
|
<Divider isInvisible />
|
|
|
|
<Textarea
|
|
|
|
title='Description'
|
|
|
|
placeholder='Album description'
|
|
|
|
value={descriptionValue}
|
|
|
|
onChange={this.onChangeDescription}
|
|
|
|
/>
|
|
|
|
<Divider isInvisible />
|
2020-12-21 18:25:05 +00:00
|
|
|
<Button
|
|
|
|
isDisabled={isDisabled}
|
|
|
|
onClick={this.handleOnSubmit}
|
|
|
|
className={[_s.mt10].join(' ')}
|
|
|
|
>
|
|
|
|
<Text color='inherit' align='center'>
|
|
|
|
Create
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
</Form>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch, { isModal }) => ({
|
2020-12-22 17:11:22 +00:00
|
|
|
onSubmit(title, description, isPrivate) {
|
2020-12-21 18:25:05 +00:00
|
|
|
if (isModal) dispatch(closeModal())
|
2020-12-22 17:11:22 +00:00
|
|
|
dispatch(createAlbum(title, description, isPrivate))
|
2020-12-21 18:25:05 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
AlbumCreate.propTypes = {
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
|
|
|
isModal: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(null, mapDispatchToProps)(AlbumCreate)
|