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 2250fbbe32..823a9e075c 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 @@ -1,15 +1,72 @@ import React from "react"; -import {Divider, Row, Col, Typography, Button, Rate} from "antd"; +import {Divider, Row, Col, Typography, Button, Rate, notification} from "antd"; import "../../../App.css"; 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"; +import axios from "axios"; +import config from "../../../../public/conf/config.json"; const {Title, Text, Paragraph} = Typography; class ReleaseView extends React.Component { + constructor(props){ + super(props); + this.state = { + loading: false + } + } + + installApp = () =>{ + const {uuid} = this.props.release; + const payload = ["admin"]; + const request = "method=post&content-type=application/json&payload="+JSON.stringify(payload)+"&api-endpoint=/application-mgt-store/v1.0/subscription/install/"+uuid+"/user/install"; + + this.setState({ + loading: true, + }); + + axios.post('https://' + config.serverConfig.hostname + ':' + config.serverConfig.httpsPort + config.serverConfig.invokerUri, request + ).then(res => { + if (res.status === 201) { + this.setState({ + loading: false + }); + notification["success"]({ + message: 'Done!', + description: + 'App installed successfully.', + }); + }else{ + this.setState({ + loading: false + }); + notification["error"]({ + message: 'Something went wrong', + description: + "We are unable to install the app.", + }); + } + + }).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() { const release = this.props.release; return ( @@ -34,8 +91,7 @@ class ReleaseView extends React.Component {