From 77fa8cd6a0fca76c3b85b1a3571e6cb330d5b080 Mon Sep 17 00:00:00 2001 From: Jayasanka Weerasinghe Date: Wed, 5 Jun 2019 07:41:37 +0000 Subject: [PATCH] Improve app subscription functionality Further integrate app management component with device mgt --- .../manage/categories/ManageCategories.js | 2 +- .../components/apps/release/ReleaseView.js | 9 +- .../apps/release/review/AddReview.js | 160 ++++++++++++++++++ 3 files changed, 168 insertions(+), 3 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js index 40365d0b40..d1d7ef4157 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/components/manage/categories/ManageCategories.js @@ -256,7 +256,7 @@ class ManageCategories extends React.Component { loading: true, isEditModalVisible: false, }); - const request = "method=put&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/admin/applications/categories?from="+currentlyEditingId+"%26to="+editingValue; + const request = "method=put&content-type=application/json&payload={}&api-endpoint=/application-mgt-publisher/v1.0/admin/applications/categories/rename?from="+currentlyEditingId+"%26to="+editingValue; axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request ).then(res => { if (res.status === 200) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js index b86bc1516f..2250fbbe32 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/ReleaseView.js @@ -5,6 +5,8 @@ import ImgViewer from "../../apps/release/images/ImgViewer"; import StarRatings from "react-star-ratings"; import DetailedRating from "./DetailedRating"; import Reviews from "./review/Reviews"; +import AddReview from "./review/AddReview"; + const {Title, Text, Paragraph} = Typography; class ReleaseView extends React.Component { @@ -23,8 +25,8 @@ class ReleaseView extends React.Component { @@ -52,6 +54,9 @@ class ReleaseView extends React.Component { + + + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js new file mode 100644 index 0000000000..f242259820 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/components/apps/release/review/AddReview.js @@ -0,0 +1,160 @@ +import React from "react"; +import {Drawer, Button, Icon, Row, Col, Typography, Divider, Input,Spin,notification} from 'antd'; +import StarRatings from "react-star-ratings"; +import axios from "axios"; +import config from "../../../../../public/conf/config.json"; + +const {Title} = Typography; +const {TextArea} = Input; + +class AddReview extends React.Component { + state = { + visible: false, + content: '', + rating: 0, + loading: false + }; + + showDrawer = () => { + this.setState({ + visible: true, + content: '', + rating: 0, + loading: false + }); + }; + + onClose = () => { + this.setState({ + visible: false, + + }); + }; + changeRating = (newRating, name) => { + this.setState({ + rating: newRating + }); + }; + + onChange = (e) => { + this.setState({content: e.target.value}) + }; + + onSubmit = () => { + const {content, rating} = this.state; + const {uuid} = this.props; + this.setState({ + loading: true + }); + + const payload = { + content: content, + rating: rating + }; + + const request = "method=post&content-type=application/json&payload="+JSON.stringify(payload)+"&api-endpoint=/application-mgt-store/v1.0/reviews/"+uuid; + + axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 201) { + this.setState({ + loading: false, + visible: false + }); + notification["success"]({ + message: 'Done!', + description: + 'Your review has been posted successfully.', + }); + + setTimeout(()=>{ + window.location.reload(); + },2000) + }else{ + this.setState({ + loading: false, + visible: false + }); + notification["error"]({ + message: 'Something went wrong', + description: + "We are unable to add your review right now.", + }); + } + + }).catch((error) =>{ + if (error.response.status === 401) { + window.location.href = 'https://localhost:9443/store/login'; + } else{ + this.setState({ + loading: false, + visible: false + }); + notification["error"]({ + message: 'Something went wrong', + description: + "We are unable to add your review right now.", + }); + } + }); + + + }; + + render() { + return ( +
+ + + + + + + + Add review + +