UNPKG

ih-portal

Version:

A project for connecting interaction hub services with catalyst-ui components

67 lines (54 loc) 1.86 kB
import React, { Component, PropTypes } from 'react'; import ObjectInspector from 'react-object-inspector'; const { func, object } = PropTypes; export default class ClassSchedule extends Component { componentDidMount() { const { classSchedule } = this.props; if (!classSchedule || (classSchedule.lastAction && classSchedule.lastAction.status === 'error') || !classSchedule.data) { const requestParams = { url: __CLASS_SCHEDULE_URL__, auth: [__USERNAME__, __PASSWORD__], }; this.props.fetch(requestParams); } } invalidateClassSchedule() { const requestParams = { url: __CLASS_SCHEDULE_URL__, auth: [__USERNAME__, __PASSWORD__], }; this.props.invalidate(requestParams); } copyToClipboard() { const copyText = JSON.stringify(this.props.classSchedule.data); window.prompt('Copy Response:', copyText); } render() { let isFetching = false; let hasData = false; let responseDisp = ''; if (this.props.classSchedule) { isFetching = this.props.classSchedule.isFetching; if (this.props.classSchedule.data) { hasData = true; const json = this.props.classSchedule.data; responseDisp = <ObjectInspector data={json} />; } } return ( <div> <h2>Class Schedule Service</h2> <input className="invalidateBtn" type="button" value="Invalidate Class Schedule" onClick={() => this.invalidateClassSchedule()} /> <input className="copyBtn" type="button" value="Copy Response" onClick={() => this.copyToClipboard()} disabled={isFetching || !hasData} /> <br /><br /> {isFetching ? <p>Fetching Data...</p> : responseDisp} <br /> </div> ); } } ClassSchedule.propTypes = { classSchedule: object, fetch: func.isRequired, invalidate: func.isRequired, };