@@ -31,13 +31,16 @@ const TeamEventCreditForm: React.FC = () => {
31
31
} ) ;
32
32
} , [ ] ) ;
33
33
34
- const approvedTECDates : Date [ ] = approvedAttendance
34
+ const approvedTECDates = approvedAttendance
35
35
. map ( ( attendance ) => {
36
36
const matchingEvent = teamEventInfoList . find ( ( event ) => event . uuid === attendance . eventUuid ) ;
37
- return matchingEvent ? new Date ( matchingEvent . date ) : null ;
37
+ return matchingEvent
38
+ ? {
39
+ date : new Date ( matchingEvent . date ) ,
40
+ credits : parseFloat ( matchingEvent . numCredits )
41
+ } : null ;
38
42
} )
39
- . filter ( ( date ) : date is Date => date !== null ) ;
40
- console . log ( `approved Dates:${ approvedTECDates } ` ) ;
43
+ . filter ( ( entry ) : entry is { date : Date ; credits : number } => entry !== null ) ;
41
44
42
45
const getTECPeriod = ( submissionDate : Date ) => {
43
46
const currentPeriodIndex = TEC_DEADLINES . findIndex ( ( date ) => submissionDate <= date ) ;
@@ -48,9 +51,9 @@ const TeamEventCreditForm: React.FC = () => {
48
51
} ;
49
52
50
53
const tecCounts : number [ ] = Array . from ( { length : TEC_DEADLINES . length } , ( ) => 0 ) ;
51
- approvedTECDates . forEach ( ( date ) => {
54
+ approvedTECDates . forEach ( ( { date, credits } ) => {
52
55
const period = getTECPeriod ( date ) ;
53
- if ( period < tecCounts . length ) tecCounts [ period ] += 1 ;
56
+ if ( period < tecCounts . length ) tecCounts [ period ] += credits ;
54
57
} ) ;
55
58
56
59
const calculateCredits = ( ) => {
@@ -61,13 +64,13 @@ const TeamEventCreditForm: React.FC = () => {
61
64
const previousPeriodCredits = previousPeriod !== null ? tecCounts [ currentPeriod - 1 ] : 1 ;
62
65
63
66
if ( currentPeriod === 0 ) {
64
- return periodCredits < 1 ? 1 : 0 ;
67
+ return periodCredits < 1 ? 1 - periodCredits : 0 ;
65
68
}
66
- if ( previousPeriodCredits === 0 ) {
67
- return periodCredits < 2 ? 2 - periodCredits : 0 ;
69
+ if ( previousPeriodCredits < 1 ) {
70
+ return periodCredits + previousPeriodCredits < 2 ? 2 - previousPeriodCredits - periodCredits : 0 ;
68
71
}
69
72
70
- return periodCredits < 1 ? 1 : 0 ;
73
+ return periodCredits < 1 ? 1 - periodCredits : 0 ;
71
74
} ;
72
75
73
76
const requiredCredits = calculateCredits ( ) ;
@@ -141,9 +144,8 @@ const TeamEventCreditForm: React.FC = () => {
141
144
} else if ( submittedCredits + creditsToSubmit > Number ( teamEvent . maxCredits ) ) {
142
145
Emitters . generalError . emit ( {
143
146
headerMsg : 'Maximum Credits Violated' ,
144
- contentMsg : `You have ${ submittedCredits } pending or approved credit(s) for the event! Submitting a total of ${
145
- submittedCredits + creditsToSubmit
146
- } credit(s) exceeds the event credit limit of ${ teamEvent . maxCredits } credit(s).`
147
+ contentMsg : `You have ${ submittedCredits } pending or approved credit(s) for the event! Submitting a total of ${ submittedCredits + creditsToSubmit
148
+ } credit(s) exceeds the event credit limit of ${ teamEvent . maxCredits } credit(s).`
147
149
} ) ;
148
150
} else {
149
151
await Promise . all (
@@ -195,9 +197,9 @@ const TeamEventCreditForm: React.FC = () => {
195
197
Select a Team Event: < span className = { styles . red_color } > *</ span >
196
198
</ label >
197
199
< div className = { styles . bold } >
198
- { requiredCredits === 2 && (
200
+ { requiredCredits > 1 && (
199
201
< span className = { styles . red_color } >
200
- You did not submit a TEC last period so you must submit 2 TEC for this 5-week
202
+ You submitted { 2 - requiredCredits } TEC last period so you must submit at least { requiredCredits } TEC for this 5-week
201
203
period.
202
204
</ span >
203
205
) }
@@ -221,9 +223,8 @@ const TeamEventCreditForm: React.FC = () => {
221
223
value = { teamEvent ?. uuid ?? '' }
222
224
text = {
223
225
teamEvent
224
- ? `${ teamEvent . name } - ${ teamEvent . numCredits } credit(s) ${
225
- teamEvent . hasHours ? 'per hour' : ''
226
- } `
226
+ ? `${ teamEvent . name } - ${ teamEvent . numCredits } credit(s) ${ teamEvent . hasHours ? 'per hour' : ''
227
+ } `
227
228
: ''
228
229
}
229
230
options = { teamEventInfoList
@@ -245,11 +246,9 @@ const TeamEventCreditForm: React.FC = () => {
245
246
> </ Label >
246
247
247
248
< Label
248
- content = { `${ event . numCredits } ${
249
- Number ( event . numCredits ) === 1 ? 'credit' : 'credits'
250
- } ${
251
- event . maxCredits > event . numCredits ? `(${ event . maxCredits } max)` : ''
252
- } ${ event . hasHours ? 'per hour' : '' } `}
249
+ content = { `${ event . numCredits } ${ Number ( event . numCredits ) === 1 ? 'credit' : 'credits'
250
+ } ${ event . maxCredits > event . numCredits ? `(${ event . maxCredits } max)` : ''
251
+ } ${ event . hasHours ? 'per hour' : '' } `}
253
252
> </ Label >
254
253
</ div >
255
254
</ div >
0 commit comments