UNPKG

ih-portal

Version:

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

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