From c1c0a40f7edc9783d4141b5f975ede6700fec092 Mon Sep 17 00:00:00 2001 From: Sukchan Lee Date: Mon, 3 Jul 2017 16:53:01 +0900 Subject: [PATCH] update it --- webui/src/components/Shared/Form.js | 3 ++ webui/src/components/Subscriber/Edit.js | 37 ++++----------------- webui/src/containers/Subscriber/Document.js | 21 ++++++++++-- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/webui/src/components/Shared/Form.js b/webui/src/components/Shared/Form.js index f8b8523f38..3543594c91 100644 --- a/webui/src/components/Shared/Form.js +++ b/webui/src/components/Shared/Form.js @@ -129,8 +129,11 @@ class Form extends Component { schema: PropTypes.object, uiSchema: PropTypes.object, formData: PropTypes.object, + isLoading: PropTypes.bool, + disableSubmitButton: PropTypes.bool, valdate: PropTypes.func, onHide: PropTypes.func, + onChange: PropTypes.func, onSubmit: PropTypes.func }; diff --git a/webui/src/components/Subscriber/Edit.js b/webui/src/components/Subscriber/Edit.js index ef3c7b5cff..3faf3544e9 100644 --- a/webui/src/components/Subscriber/Edit.js +++ b/webui/src/components/Subscriber/Edit.js @@ -155,10 +155,13 @@ const uiSchema = { class Edit extends Component { static propTypes = { visible: PropTypes.bool, - title: PropTypes.string, + action: PropTypes.string, formData: PropTypes.object, + isLoading: PropTypes.bool, + disableSubmitButton: PropTypes.bool, validate: PropTypes.func, onHide: PropTypes.func, + onChange: PropTypes.func, onSubmit: PropTypes.func } @@ -168,10 +171,6 @@ class Edit extends Component { this.state = this.getStateFromProps(props); } - componentWillMount() { - this.setState(this.getStateFromProps(this.props)); - } - componentWillReceiveProps(nextProps) { this.setState(this.getStateFromProps(nextProps)); } @@ -212,38 +211,14 @@ class Edit extends Component { return state; } - validate = (formData, errors) => { - if (formData && formData.pdn) { - let apns = formData.pdn.map(pdn => { return pdn.apn } ) - let duplicates = {}; - for (let i = 0; i < apns.length; i++) { - if (duplicates.hasOwnProperty(apns[i])) { - duplicates[apns[i]].push(i); - } else if (apns.lastIndexOf(apns[i]) !== i) { - duplicates[apns[i]] = [i]; - } - } - - for (let key in duplicates) { - duplicates[key].forEach(index => - errors.pdn[index].apn.addError(`'${key}' is duplicated`)); - } - } - - return this.props.validate(formData, errors); - } - render() { - const { - validate - } = this; - const { visible, action, formData, isLoading, disableSubmitButton, + validate, onHide, onChange, onSubmit @@ -255,8 +230,8 @@ class Edit extends Component { title={(action === 'update') ? 'Edit Subscriber' : 'Create Subscriber'} schema={this.state.schema} uiSchema={this.state.uiSchema} - isLoading={isLoading} formData={formData} + isLoading={isLoading} disableSubmitButton={disableSubmitButton} validate={validate} onHide={onHide} diff --git a/webui/src/containers/Subscriber/Document.js b/webui/src/containers/Subscriber/Document.js index e3d995b081..040722fb20 100644 --- a/webui/src/containers/Subscriber/Document.js +++ b/webui/src/containers/Subscriber/Document.js @@ -53,7 +53,6 @@ class Document extends Component { action: PropTypes.string, visible: PropTypes.bool, onHide: PropTypes.func, - onSubmit: PropTypes.func, } state = { @@ -95,11 +94,29 @@ class Document extends Component { errors.imsi.addError(`'${imsi}' is duplicated`); } + if (formData.pdn) { + let apns = formData.pdn.map(pdn => { return pdn.apn } ) + let duplicates = {}; + for (let i = 0; i < apns.length; i++) { + if (duplicates.hasOwnProperty(apns[i])) { + duplicates[apns[i]].push(i); + } else if (apns.lastIndexOf(apns[i]) !== i) { + duplicates[apns[i]] = [i]; + } + } + + for (let key in duplicates) { + duplicates[key].forEach(index => + errors.pdn[index].apn.addError(`'${key}' is duplicated`)); + } + } + return errors; } handleChange = (formData, errors) => { let disableSubmitButton = (Object.keys(errors).length > 0); + // I think there is a bug in React or Jsonschema library // For workaround, I'll simply add 'formData' in setState this.setState({ @@ -109,7 +126,7 @@ class Document extends Component { } handleSubmit = (formData) => { - const { dispatch, action, onHide } = this.props; + const { dispatch, action } = this.props; this.setState({ disableValidation: true })