62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
import React from "react";
|
|
import { SpinnerCircular } from 'spinners-react';
|
|
|
|
import { getFineBeforeAccrualFile, getFineAfterAccrualFile } from "../../../actions";
|
|
import LogFileDownload from "../../../components/LogFileDownload";
|
|
|
|
export default class DownloadFinesPdfButton extends LogFileDownload
|
|
{
|
|
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(() =>
|
|
{
|
|
if(this._log !== undefined) { this._log(); }
|
|
this.setState({ downloading: false });
|
|
})
|
|
.catch(() => { this.setState({ downloading: false }); });
|
|
}
|
|
else
|
|
{
|
|
getFineAfterAccrualFile({ contract, num, filename })
|
|
.then(() =>
|
|
{
|
|
if(this._log !== undefined) { this._log(); }
|
|
this.setState({ downloading: false });
|
|
})
|
|
.catch(() => { this.setState({ downloading: false }); });
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
render()
|
|
{
|
|
const { downloading } = this.state;
|
|
|
|
return (
|
|
<a style={{ cursor: "pointer" }} className="button button-blue" onClick={ () => { this._handle_onDownloadFile() }}>
|
|
{ downloading ? (
|
|
<SpinnerCircular size={24} thickness={100} speed={100} color="rgba(255, 255, 255, 1)" secondaryColor="rgba(255, 255, 255, 0.5)" />
|
|
) : "Скачать" }
|
|
</a>
|
|
)
|
|
}
|
|
} |