import React from 'react'; import { Card, Fa } from '../../../components'; import { format } from '../../../commons/utils'; import FollowupCalendar from './followup-calendar'; import CalendEditor from './calend-editor'; import { server } from '../../../commons/server'; import './treat-followup.less'; /** * Display the treatment followup card */ export default class TreatFollowup extends React.Component { constructor(props) { super(props); this._calendarClick = this._calendarClick.bind(this); this.closeEditor = this.closeEditor.bind(this); this.state = { selBtn: 'DOTS' }; } _buttonClick(key) { return () => { this.setState({ selBtn: key }); }; } _calendarClick(data) { // calendar is being edited already if (this.state.editor) { return; } // create a copy of the data if (this.props.tbcase.state === 'ONTREATMENT') { this.setState({ editor: data }); } } closeEditor(data) { if (data) { const self = this; return this.saveData(data) .then(() => { const lst = self.props.treatment.followup; const index = lst.indexOf(self.state.editor); lst[index] = data; self.setState({ editor: null }); }); } this.setState({ editor: null }); return null; } /** * Post follow-up data to the server in order to update the treatment followup * of a given year/month */ saveData(data) { const req = { caseId: this.props.tbcase.id, year: data.year, month: data.month, days: data.days }; return server.post('/api/cases/case/treatment/followup', req) .then(res => { if (res.success) { return; } throw new Error(res.error); }); } renderLegend() { return (