-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
629 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import PropTypes from "prop-types"; | ||
import { Form, Input } from "antd"; | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import { LanguageSelect } from "../../Inputs/LanguageSelect/LanguageSelect"; | ||
|
||
/** | ||
* text create form | ||
*/ | ||
function TextEditForm(props) { | ||
const { | ||
form: { getFieldDecorator }, | ||
editDetail | ||
} = props; | ||
|
||
return ( | ||
<Form> | ||
<Form.Item> | ||
{getFieldDecorator("language", { initialValue: editDetail.language })( | ||
<LanguageSelect /> | ||
)} | ||
</Form.Item> | ||
<Form.Item> | ||
{getFieldDecorator("title", { initialValue: editDetail.title })( | ||
<Input placeholder="Title" /> | ||
)} | ||
</Form.Item> | ||
<Form.Item> | ||
{getFieldDecorator("content", { initialValue: editDetail.content })( | ||
<Input.TextArea | ||
autosize={{ minRows: 10, maxRows: 20 }} | ||
placeholder="Please input text content here ..." | ||
/> | ||
)} | ||
</Form.Item> | ||
</Form> | ||
); | ||
} | ||
|
||
export default Form.create()( | ||
connect( | ||
state => ({ | ||
currentLanguage: state.language.currentLanguage | ||
}), | ||
null | ||
)(TextEditForm) | ||
); | ||
|
||
TextEditForm.propTypes = { | ||
editDetail: PropTypes.shape({}).isRequired, | ||
form: PropTypes.shape({ | ||
getFieldDecorator: PropTypes.func.isRequired | ||
}).isRequired | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import PropTypes from "prop-types"; | ||
import { Modal } from "antd"; | ||
import React from "react"; | ||
import { connect } from "react-redux"; | ||
import TextEditForm from "../../Forms/TextEditForm"; | ||
import { | ||
editTextAction, | ||
getTextEditDetailAction | ||
} from "../../../Actions/TextAction"; | ||
import { selectEditDetail } from "../../../Reducers/TextReducer"; | ||
|
||
/** | ||
* text create modal | ||
*/ | ||
class TextEditModal extends React.Component { | ||
formRef = null; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.saveFormRef = this.saveFormRef.bind(this); | ||
this.handleOk = this.handleOk.bind(this); | ||
this.handleCancel = this.handleCancel.bind(this); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
const { hide, editingText, getEditDetail, editDetail } = this.props; | ||
if (prevProps.editingText !== editingText && editingText) { | ||
getEditDetail(editingText); | ||
} | ||
if (prevProps.editDetail !== editDetail) { | ||
if (!editDetail) { | ||
hide(); | ||
} | ||
} | ||
} | ||
|
||
handleOk() { | ||
const { form } = this.formRef.props; | ||
const { editText, hide, editingText, onEdit } = this.props; | ||
form.validateFields((err, values) => { | ||
if (err) { | ||
return; | ||
} | ||
editText(editingText, values).then(onEdit); | ||
form.resetFields(); | ||
hide(); | ||
}); | ||
} | ||
|
||
handleCancel() { | ||
const { hide } = this.props; | ||
const { form } = this.formRef.props; | ||
form.resetFields(); | ||
hide(); | ||
} | ||
|
||
saveFormRef(formRef) { | ||
this.formRef = formRef; | ||
} | ||
|
||
render() { | ||
const { visible, editDetail } = this.props; | ||
if (!editDetail) { | ||
return null; | ||
} | ||
return ( | ||
<Modal | ||
visible={visible} | ||
title="Edit text" | ||
okText="Save" | ||
onOk={this.handleOk} | ||
onCancel={this.handleCancel} | ||
> | ||
<TextEditForm | ||
editDetail={editDetail} | ||
wrappedComponentRef={this.saveFormRef} | ||
/> | ||
</Modal> | ||
); | ||
} | ||
} | ||
|
||
export default connect( | ||
state => ({ | ||
editDetail: selectEditDetail(state) | ||
}), | ||
{ | ||
editText: editTextAction, | ||
getEditDetail: getTextEditDetailAction | ||
} | ||
)(TextEditModal); | ||
|
||
TextEditModal.defaultProps = { | ||
editingText: null, | ||
editDetail: null | ||
}; | ||
|
||
TextEditModal.propTypes = { | ||
editText: PropTypes.func.isRequired, | ||
hide: PropTypes.func.isRequired, | ||
visible: PropTypes.bool.isRequired, | ||
onEdit: PropTypes.func.isRequired, | ||
editDetail: PropTypes.shape({}), | ||
getEditDetail: PropTypes.func.isRequired, | ||
editingText: PropTypes.string | ||
}; |
Oops, something went wrong.