From c0ff4ba34ddc75db8da20bb493d4fe7c3f824c73 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 7 Jun 2019 14:39:20 +0530 Subject: [PATCH] Add temporary button to install --- .../components/apps/release/ReleaseView.js | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) 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 2250fbbe32c..823a9e075c4 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 {
- - +