import React from "react"; import { SpinnerCircular } from 'spinners-react'; import { getFineBeforeAccrualFile, getFineAfterAccrualFile } from "../../../actions"; export default class DownloadFinesPdfButton extends React.Component { constructor(props) { super(props); this.state = { downloading: false, }; } _handle_onDownloadFile = () => { const { contract, num, filename, before } = this.props; const { downloading } = this.state; if(!downloading) { this.setState({ downloading: true }, () => { if(before) { getFineBeforeAccrualFile({ contract, num, filename }) .then(() => { this.setState({ downloading: false }); }) .catch(() => { this.setState({ downloading: false }); }); } else { getFineAfterAccrualFile({ contract, num, filename }) .then(() => { this.setState({ downloading: false }); }) .catch(() => { this.setState({ downloading: false }); }); } }); } } render() { const { downloading } = this.state; return ( { this._handle_onDownloadFile() }}> { downloading ? ( ) : "Скачать" } ) } }