11import { FC , useState } from "react" ;
2- import { Button , DialogActions , DialogContent , Grid , TextField } from "@mui/material" ;
2+ import { Button , DialogActions , DialogContent , Grid } from "@mui/material" ;
33import apiSingleton from "../../api/ApiSingleton" ;
44import { LoadingButton } from "@mui/lab" ;
5+ import Utils from "@/services/Utils" ;
56
67interface DownloadStatsProps {
78 courseId : number | undefined
@@ -10,14 +11,15 @@ interface DownloadStatsProps {
1011}
1112
1213const DownloadStats : FC < DownloadStatsProps > = ( props : DownloadStatsProps ) => {
13- const [ fileName , setFileName ] = useState < string > ( "" )
1414 const [ loading , setLoading ] = useState < boolean > ( false )
1515
1616 const handleFileDownloading = ( ) => {
17+ const statsDatetime = Utils . toStringForFileName ( new Date ( ) )
1718 setLoading ( true )
1819 apiSingleton . statisticsApi . statisticsGetFile ( props . courseId , props . userId , "Лист 1" )
1920 . then ( ( response ) => response . blob ( ) )
2021 . then ( ( blob ) => {
22+ const fileName = `StatsReport_${ statsDatetime } `
2123 const url = window . URL . createObjectURL ( new Blob ( [ blob ] ) ) ;
2224 const link = document . createElement ( "a" ) ;
2325 link . href = url ;
@@ -31,20 +33,8 @@ const DownloadStats: FC<DownloadStatsProps> = (props: DownloadStatsProps) => {
3133
3234 return (
3335 < DialogContent >
34- < DialogActions style = { { padding : 0 , marginTop : 6 } } >
36+ < DialogActions style = { { padding : 0 } } >
3537 < Grid item >
36- < TextField
37- fullWidth
38- size = "small"
39- label = "Название файла"
40- value = { fileName }
41- onChange = { event => {
42- event . persist ( ) ;
43- setFileName ( event . target . value ) ;
44- } }
45- />
46- </ Grid >
47- < Grid >
4838 < LoadingButton
4939 variant = "text"
5040 color = "primary"
@@ -55,7 +45,7 @@ const DownloadStats: FC<DownloadStatsProps> = (props: DownloadStatsProps) => {
5545 Скачать
5646 </ LoadingButton >
5747 </ Grid >
58- < Grid >
48+ < Grid item >
5949 < Button variant = "text" color = "inherit" type = "button"
6050 onClick = { props . onCancellation } >
6151 Отмена
0 commit comments