@@ -9,6 +9,7 @@ import moment from 'moment'
9
9
import _ from 'lodash'
10
10
import { STUDIO_URL , SUBMISSION_REVIEW_APP_URL , getTCMemberURL } from '../../../config/constants'
11
11
import { PrimaryButton } from '../../Buttons'
12
+ import AlertModal from '../../Modal/AlertModal'
12
13
import cn from 'classnames'
13
14
import ReactSVG from 'react-svg'
14
15
import {
@@ -20,17 +21,23 @@ import {
20
21
checkAdmin
21
22
} from '../../../util/tc'
22
23
import {
23
- getTopcoderReactLib
24
+ getTopcoderReactLib ,
25
+ isValidDownloadFile
24
26
} from '../../../util/topcoder-react-lib'
25
27
import {
26
28
compressFiles
27
29
} from '../../../util/files'
28
30
import styles from './Submissions.module.scss'
31
+ import modalStyles from '../../../styles/modal.module.scss'
29
32
const assets = require . context ( '../../../assets/images' , false , / s v g / )
30
33
const ArrowDown = './arrow-down.svg'
31
34
const Lock = './lock.svg'
32
35
const Download = './IconSquareDownload.svg'
33
36
37
+ const theme = {
38
+ container : modalStyles . modalContainer
39
+ }
40
+
34
41
class SubmissionsComponent extends React . Component {
35
42
constructor ( props ) {
36
43
super ( props )
@@ -42,7 +49,8 @@ class SubmissionsComponent extends React.Component {
42
49
isShowInformation : false ,
43
50
memberOfModal : '' ,
44
51
sortedSubmissions : [ ] ,
45
- downloadingAll : false
52
+ downloadingAll : false ,
53
+ alertMessage : ''
46
54
}
47
55
this . getSubmissionsSortParam = this . getSubmissionsSortParam . bind ( this )
48
56
this . updateSortedSubmissions = this . updateSortedSubmissions . bind ( this )
@@ -222,7 +230,7 @@ class SubmissionsComponent extends React.Component {
222
230
const { field, sort } = this . getSubmissionsSortParam ( )
223
231
const revertSort = sort === 'desc' ? 'asc' : 'desc'
224
232
225
- const { sortedSubmissions, downloadingAll } = this . state
233
+ const { sortedSubmissions, downloadingAll, alertMessage } = this . state
226
234
227
235
const renderSubmission = s => (
228
236
< div className = { styles . submission } key = { s . id } >
@@ -544,19 +552,27 @@ class SubmissionsComponent extends React.Component {
544
552
const submissionsService = getService ( token )
545
553
submissionsService . downloadSubmission ( s . id )
546
554
. then ( ( blob ) => {
547
- // eslint-disable-next-line no-undef
548
- const url = window . URL . createObjectURL ( new Blob ( [ blob ] ) )
549
- const link = document . createElement ( 'a' )
550
- link . href = url
551
- let fileName = s . legacySubmissionId
552
- if ( ! fileName ) {
553
- fileName = s . id
554
- }
555
- fileName = fileName + '.zip'
556
- link . setAttribute ( 'download' , `${ fileName } ` )
557
- document . body . appendChild ( link )
558
- link . click ( )
559
- link . parentNode . removeChild ( link )
555
+ isValidDownloadFile ( blob ) . then ( ( isValidFile ) => {
556
+ if ( isValidFile . success ) {
557
+ // eslint-disable-next-line no-undef
558
+ const url = window . URL . createObjectURL ( new Blob ( [ blob ] ) )
559
+ const link = document . createElement ( 'a' )
560
+ link . href = url
561
+ let fileName = s . legacySubmissionId
562
+ if ( ! fileName ) {
563
+ fileName = s . id
564
+ }
565
+ fileName = fileName + '.zip'
566
+ link . setAttribute ( 'download' , `${ fileName } ` )
567
+ document . body . appendChild ( link )
568
+ link . click ( )
569
+ link . parentNode . removeChild ( link )
570
+ } else {
571
+ this . setState ( {
572
+ alertMessage : isValidFile . message || 'Can not download this submission.'
573
+ } )
574
+ }
575
+ } )
560
576
} )
561
577
} }
562
578
>
@@ -611,10 +627,14 @@ class SubmissionsComponent extends React.Component {
611
627
fileName = fileName + '.zip'
612
628
submissionsService . downloadSubmission ( submission . id )
613
629
. then ( ( blob ) => {
614
- const file = new window . File ( [ blob ] , `${ fileName } ` )
615
- allFiles . push ( file )
616
- downloadedFile += 1
617
- checkToCompressFiles ( )
630
+ isValidDownloadFile ( blob ) . then ( ( isValidFile ) => {
631
+ if ( isValidFile . success ) {
632
+ const file = new window . File ( [ blob ] , `${ fileName } ` )
633
+ allFiles . push ( file )
634
+ }
635
+ downloadedFile += 1
636
+ checkToCompressFiles ( )
637
+ } )
618
638
} ) . catch ( ( ) => {
619
639
downloadedFile += 1
620
640
checkToCompressFiles ( )
@@ -625,6 +645,20 @@ class SubmissionsComponent extends React.Component {
625
645
</ div >
626
646
</ div > ) : null }
627
647
</ div >
648
+
649
+ { alertMessage ? (
650
+ < AlertModal
651
+ title = ''
652
+ message = { alertMessage }
653
+ theme = { theme }
654
+ closeText = 'OK'
655
+ onClose = { ( ) => {
656
+ this . setState ( {
657
+ alertMessage : ''
658
+ } )
659
+ } }
660
+ />
661
+ ) : null }
628
662
</ >
629
663
)
630
664
}
0 commit comments