From 0629d5af71ef6691ca4c1679c50696d7890ed0f4 Mon Sep 17 00:00:00 2001 From: Shamalka Navod Date: Mon, 20 Apr 2020 15:09:45 +0000 Subject: [PATCH] Add app name validating feature into APPM publisher UI --- .../components/NewAppDetailsForm/index.js | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/AddNewApp/components/AddNewAppForm/components/NewAppDetailsForm/index.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/AddNewApp/components/AddNewAppForm/components/NewAppDetailsForm/index.js index c5f6c5389d0..3be2c38fc66 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/AddNewApp/components/AddNewAppForm/components/NewAppDetailsForm/index.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/scenes/Home/scenes/AddNewApp/components/AddNewAppForm/components/NewAppDetailsForm/index.js @@ -86,12 +86,52 @@ class NewAppDetailsForm extends React.Component { application.type = 'WEB_CLIP'; application.deviceType = 'ALL'; } - - this.props.onSuccessApplicationData(application); + this.validateAppName(name, application.deviceType, application); } }); }; + validateAppName = (name, deviceType, application) => { + const config = this.props.context; + axios + .get( + window.location.origin + + config.serverConfig.invoker.uri + + config.serverConfig.invoker.publisher + + `/applications/device-type/${deviceType}/app-name/${name}`, + ) + .then(res => { + if (res.status === 200) { + this.props.onSuccessApplicationData(application); + } + }) + .catch(error => { + if (error.hasOwnProperty('response') && error.response.status === 403) { + this.setState({ + loading: false, + }); + } else if ( + error.hasOwnProperty('response') && + error.response.status === 409 + ) { + this.props.form.setFields({ + name: { + value: name, + errors: [ + new Error('App name already exists, Please try another'), + ], + }, + }); + } else { + handleApiError( + error, + 'Error occurred while trying to validate app name.', + true, + ); + } + }); + }; + componentDidMount() { this.getCategories(); this.getTags(); @@ -331,6 +371,18 @@ class NewAppDetailsForm extends React.Component { )} {/* app name*/} + + } + /> {getFieldDecorator('name', { rules: [