Skip to content

Commit e16bb71

Browse files
committed
accounting for 0.5 credit amount
1 parent 35a1376 commit e16bb71

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

frontend/src/components/Forms/TeamEventCreditsForm/TeamEventCreditsForm.tsx

+22-23
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@ const TeamEventCreditForm: React.FC = () => {
3131
});
3232
}, []);
3333

34-
const approvedTECDates: Date[] = approvedAttendance
34+
const approvedTECDates = approvedAttendance
3535
.map((attendance) => {
3636
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;
3842
})
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);
4144

4245
const getTECPeriod = (submissionDate: Date) => {
4346
const currentPeriodIndex = TEC_DEADLINES.findIndex((date) => submissionDate <= date);
@@ -48,9 +51,9 @@ const TeamEventCreditForm: React.FC = () => {
4851
};
4952

5053
const tecCounts: number[] = Array.from({ length: TEC_DEADLINES.length }, () => 0);
51-
approvedTECDates.forEach((date) => {
54+
approvedTECDates.forEach(({ date, credits }) => {
5255
const period = getTECPeriod(date);
53-
if (period < tecCounts.length) tecCounts[period] += 1;
56+
if (period < tecCounts.length) tecCounts[period] += credits;
5457
});
5558

5659
const calculateCredits = () => {
@@ -61,13 +64,13 @@ const TeamEventCreditForm: React.FC = () => {
6164
const previousPeriodCredits = previousPeriod !== null ? tecCounts[currentPeriod - 1] : 1;
6265

6366
if (currentPeriod === 0) {
64-
return periodCredits < 1 ? 1 : 0;
67+
return periodCredits < 1 ? 1 - periodCredits : 0;
6568
}
66-
if (previousPeriodCredits === 0) {
67-
return periodCredits < 2 ? 2 - periodCredits : 0;
69+
if (previousPeriodCredits < 1) {
70+
return periodCredits + previousPeriodCredits < 2 ? 2 - previousPeriodCredits - periodCredits : 0;
6871
}
6972

70-
return periodCredits < 1 ? 1 : 0;
73+
return periodCredits < 1 ? 1 - periodCredits : 0;
7174
};
7275

7376
const requiredCredits = calculateCredits();
@@ -141,9 +144,8 @@ const TeamEventCreditForm: React.FC = () => {
141144
} else if (submittedCredits + creditsToSubmit > Number(teamEvent.maxCredits)) {
142145
Emitters.generalError.emit({
143146
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).`
147149
});
148150
} else {
149151
await Promise.all(
@@ -195,9 +197,9 @@ const TeamEventCreditForm: React.FC = () => {
195197
Select a Team Event: <span className={styles.red_color}>*</span>
196198
</label>
197199
<div className={styles.bold}>
198-
{requiredCredits === 2 && (
200+
{requiredCredits > 1 && (
199201
<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
201203
period.
202204
</span>
203205
)}
@@ -221,9 +223,8 @@ const TeamEventCreditForm: React.FC = () => {
221223
value={teamEvent?.uuid ?? ''}
222224
text={
223225
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+
}`
227228
: ''
228229
}
229230
options={teamEventInfoList
@@ -245,11 +246,9 @@ const TeamEventCreditForm: React.FC = () => {
245246
></Label>
246247

247248
<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' : ''}`}
253252
></Label>
254253
</div>
255254
</div>

0 commit comments

Comments
 (0)