ih-portal
Version:
A project for connecting interaction hub services with catalyst-ui components
67 lines (54 loc) • 1.84 kB
JSX
import React, { Component, PropTypes } from 'react';
import ObjectInspector from 'react-object-inspector';
const { func, object } = PropTypes;
export default class Applications extends Component {
componentDidMount() {
const { applications } = this.props;
if (!applications || (applications.lastAction && applications.lastAction.status === 'error') || !applications.data) {
const requestParams = {
url: __APPLICATIONS_URL__,
auth: [__USERNAME__, __PASSWORD__],
};
this.props.fetch(requestParams);
}
}
invalidateApplications() {
const requestParams = {
url: __APPLICATIONS_URL__,
auth: [__USERNAME__, __PASSWORD__],
};
this.props.invalidate(requestParams);
}
copyToClipboard() {
const copyText = JSON.stringify(this.props.applications.data);
window.prompt('Copy Response:', copyText);
}
render() {
let isFetching = false;
let hasData = false;
let responseDisp = '';
if (this.props.applications) {
isFetching = this.props.applications.isFetching;
if (this.props.applications.data) {
hasData = true;
const json = this.props.applications.data;
responseDisp = <ObjectInspector data={json} />;
}
}
return (
<div>
<h2>Applications Service</h2>
<input className="invalidateBtn" type="button" value="Invalidate Applications" onClick={() => this.invalidateApplications()} />
<input className="copyBtn" type="button" value="Copy Response" onClick={() => this.copyToClipboard()} disabled={isFetching || !hasData} />
<br /><br />
{isFetching ? <p>Fetching Data...</p> : responseDisp}
<br />
</div>
);
}
}
Applications.propTypes = {
applications: object,
fetch: func.isRequired,
invalidate: func.isRequired,
};