gab-social/app/javascript/gabsocial/features/bookmark_collection_create.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-12-16 07:39:07 +00:00
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { defineMessages, injectIntl } from 'react-intl'
import { createBookmarkCollection } from '../actions/bookmarks'
2020-12-16 07:39:07 +00:00
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'
class BookmarkCollectionCreate extends React.PureComponent {
state = {
value: '',
}
onChange = (value) => {
this.setState({ value })
}
handleOnSubmit = () => {
this.props.onSubmit(this.state.value)
2020-12-16 07:39:07 +00:00
}
render() {
const { value } = this.state
const isDisabled = !value
2020-12-16 07:39:07 +00:00
return (
<Form>
<Input
title='Title'
placeholder='Bookmark collection title'
value={value}
onChange={this.onChange}
/>
<Button
isDisabled={isDisabled}
onClick={this.handleOnSubmit}
className={[_s.mt10].join(' ')}
>
<Text color='inherit' align='center'>
Create
</Text>
</Button>
</Form>
)
}
}
const mapDispatchToProps = (dispatch, { isModal }) => ({
onSubmit(title) {
if (isModal) dispatch(closeModal())
dispatch(createBookmarkCollection(title))
2020-12-16 07:39:07 +00:00
},
})
BookmarkCollectionCreate.propTypes = {
onSubmit: PropTypes.func.isRequired,
isModal: PropTypes.bool,
}
export default connect(null, mapDispatchToProps)(BookmarkCollectionCreate)