src/components/EditableTimer.js
import React from 'react';
import TimerForm from './TimerForm';
import Timer from './Timer';
/**
* This component is a Timer that can be opened to be edited
*/
export default class EditableTimer extends React.Component {
state = {
editFormOpen: false
};
handleEditClick = () => {
this.openForm();
};
handleFormClose = () => {
this.closeForm();
};
handleSubmit = (timer) => {
this.props.onFormSubmit(timer);
this.closeForm();
};
closeForm = () => {
this.setState({ editFormOpen: false });
};
openForm = () => {
this.setState({ editFormOpen: true });
};
/**
* Render Method
* @returns {XML}
*/
render() {
if (this.state.editFormOpen) {
return (
<TimerForm
id={this.props.id}
title={this.props.title}
project={this.props.project}
onFormSubmit={this.handleSubmit}
onFormClose={this.handleFormClose}
/>
);
} else {
return ( <Timer
id={this.props.id}
title={this.props.title}
project={this.props.project}
elapsed={this.props.elapsed}
runningSince={this.props.runningSince}
onEditClick={this.handleEditClick}
onTrashClick={this.props.onTrashClick}
onStartClick={this.props.onStartClick}
onStopClick={this.props.onStopClick}
/>
);
}
}
}