@@ -61,6 +61,18 @@ import {
6161} from '../FormComponents'
6262import { doFormikInitialValueFixes } from '../ModelForm'
6363
64+ function isConstitutionRequired (
65+ club : Club | Partial < Club > ,
66+ isEdit : boolean = false ,
67+ ) : boolean {
68+ // if on edit page and club already has constitution, it's not required
69+ if ( isEdit && club . has_constitution ) {
70+ return false
71+ }
72+
73+ return ! club . has_constitution
74+ }
75+
6476export const CLUB_APPLICATIONS = [
6577 {
6678 value : ClubApplicationRequired . Open ,
@@ -289,6 +301,11 @@ export default function ClubEditCard({
289301 delete data . image
290302 }
291303
304+ const constitution = data . constitution
305+ if ( constitution !== null ) {
306+ delete data . constitution
307+ }
308+
292309 const entries = Object . entries ( data )
293310 let body = { }
294311
@@ -433,6 +450,25 @@ export default function ClubEditCard({
433450 msg += ` However, failed to upload ${ OBJECT_NAME_SINGULAR } image file!`
434451 }
435452 }
453+
454+ if ( constitution && constitution instanceof File ) {
455+ const formData = new FormData ( )
456+ formData . append ( 'file' , constitution )
457+ formData . append ( 'is_constitution' , 'true' )
458+ const resp = await doApiRequest (
459+ `/clubs/${ clubCode } /upload_file/?format=json` ,
460+ {
461+ method : 'POST' ,
462+ body : formData ,
463+ } ,
464+ )
465+ if ( resp . ok ) {
466+ msg += ` ${ OBJECT_NAME_TITLE_SINGULAR } constitution also saved.`
467+ } else {
468+ msg += ` However, failed to upload ${ OBJECT_NAME_SINGULAR } constitution file!`
469+ }
470+ }
471+
436472 await onSubmit ( { isEdit : true , club : info , message : msg } )
437473 setStatus ( { } )
438474 setSubmitting ( false )
@@ -586,6 +622,14 @@ export default function ClubEditCard({
586622 label : `${ OBJECT_NAME_TITLE_SINGULAR } Logo` ,
587623 disabled : ! REAPPROVAL_QUEUE_ENABLED ,
588624 } ,
625+ {
626+ name : 'constitution' ,
627+ help : `Upload your ${ OBJECT_NAME_SINGULAR } constitution. This is required for all clubs. Please upload a PDF, DOC, or DOCX file.` ,
628+ accept : '.pdf,.doc,.docx' ,
629+ type : 'file' ,
630+ label : `${ OBJECT_NAME_TITLE_SINGULAR } Constitution` ,
631+ required : isConstitutionRequired ( club , isEdit ) ,
632+ } ,
589633 {
590634 name : 'size' ,
591635 type : 'select' ,
@@ -971,8 +1015,8 @@ export default function ClubEditCard({
9711015 submit ( { ...values , emailOverride : false } , actions )
9721016 }
9731017 enableReinitialize
974- validate = { ( values ) => {
975- const errors : { email ?: string } = { }
1018+ validate = { ( values : any ) => {
1019+ const errors : { email ?: string ; constitution ?: string } = { }
9761020 if ( values . email . includes ( 'upenn.edu' ) && ! emailModal ) {
9771021 showEmailModal ( true )
9781022 errors . email = 'Please confirm your email'
@@ -1058,6 +1102,7 @@ export default function ClubEditCard({
10581102 multiselect : SelectField ,
10591103 select : SelectField ,
10601104 image : FileField ,
1105+ file : FileField ,
10611106 address : FormikAddressField ,
10621107 checkboxText : CheckboxTextField ,
10631108 creatableMultiSelect :
0 commit comments