@@ -4,38 +4,43 @@ import { FaUpload } from 'react-icons/fa';
44import { useMutation } from '@tanstack/react-query' ;
55import { useParams } from 'react-router' ;
66import { toast } from 'react-toastify' ;
7- import { addSubmission } from '../../api/api' ;
7+ import { addSubmission , useConfig } from '../../api/api' ;
88import { PartyResponse , PartySubmissionFormData } from '../../api/api-models' ;
99import { useSession } from '../../user/session' ;
1010
11- const MAX_FILE_SIZE = 4 << 20 ;
12-
1311function PostPartySubmission ( { party, afterUpload } : { party : PartyResponse ; afterUpload ?: ( ) => any } ) {
1412 const [ session ] = useSession ( ) ;
1513 const { id } = useParams < { id : string } > ( ) ;
1614 const [ imgPrevSrc , setImgPrevSrc ] = useState < string | undefined > ( ) ;
1715 const form = useForm < PartySubmissionFormData > ( ) ;
1816 const { mutateAsync } = useMutation ( addSubmission ) ;
17+ const { data : appConfig } = useConfig ( ) ;
1918
2019 const file = form . watch ( 'files' ) ?. [ 0 ] ;
21- const fileTooLarge = file ?. size > MAX_FILE_SIZE ;
2220 const hasPreview = ( ) => ! ! imgPrevSrc ;
2321
2422 useEffect ( ( ) => {
25- if ( ! file || fileTooLarge ) {
23+ if ( ! file || ! appConfig ) {
24+ return ;
25+ }
26+
27+ if ( file ?. size > appConfig ?. maxUploadSize ) {
2628 return ;
2729 }
30+
2831 const reader = new FileReader ( ) ;
2932 reader . onload = function ( e : ProgressEvent < FileReader > ) {
3033 setImgPrevSrc ( e . target ! . result as string ) ;
3134 } ;
3235 reader . readAsDataURL ( file ) ;
33- } , [ file , fileTooLarge ] ) ;
36+ } , [ file , appConfig ] ) ;
3437
3538 if ( ! id ) {
3639 return < div > No party id provided</ div > ;
3740 }
3841
42+ const fileTooLarge = appConfig ?. maxUploadSize && file ?. size > appConfig ?. maxUploadSize ;
43+
3944 const onSubmit = async ( data : PartySubmissionFormData ) => {
4045 const req = await mutateAsync ( { partyId : id , submission : data , sessionToken : session ! . token } ) ;
4146 if ( req . status === 413 ) {
@@ -68,7 +73,7 @@ function PostPartySubmission({ party, afterUpload }: { party: PartyResponse; aft
6873 >
6974 < FaUpload size = { 26 } />
7075 < span className = "mt-2 text-base leading-normal uppercase" > Select a file</ span >
71- < span className = "font-light" > max { MAX_FILE_SIZE >> 20 } MB</ span >
76+ < span className = "font-light" > max { ( appConfig ?. maxUploadSize ?? 0 ) >> 20 } MB</ span >
7277 < input
7378 className = "hidden"
7479 type = "file"
0 commit comments