Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor isCommunity field #587

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/src/dao/TeamEventsDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class TeamEventsDao {
/* Returns all team event information details through 'TeamEventInfo' objects */
static async getAllTeamEventInfo(): Promise<TeamEventInfo[]> {
const docRefs = await teamEventsCollection
.select('name', 'date', 'numCredits', 'hasHours', 'uuid')
.select('name', 'date', 'numCredits', 'hasHours', 'uuid', 'isInitiativeEvent')
.get();
return docRefs.docs.map((doc) => doc.data() as TeamEventInfo);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/data/createData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const fakeTeamEvent = (): TeamEvent => {
requests: [fakeTeamEventAttendance()],
attendees: [],
uuid: faker.datatype.uuid(),
isCommunity: getRandomBoolean()
isInitiativeEvent: getRandomBoolean()
};
return TE;
};
Expand Down
3 changes: 2 additions & 1 deletion common-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ interface TeamEventInfo {
readonly numCredits: string;
readonly hasHours: boolean;
readonly uuid: string;
readonly isCommunity: boolean;
readonly isCommunity?: boolean;
readonly isInitiativeEvent: boolean;
}

interface TeamEvent extends TeamEventInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const calculateMemberCreditsForEvent = (
event: TeamEvent,
isInitiativeEvent: boolean
): number =>
isInitiativeEvent && !event.isCommunity
isInitiativeEvent && !event.isInitiativeEvent
? 0
: event.requests
.filter((req) => req.status === 'approved')
Expand Down Expand Up @@ -104,7 +104,7 @@ const TeamEventDashboard: React.FC = () => {
0
);
const initiativeCredits = teamEvents.reduce(
(val, event) => calculateInitiativeCreditsForEvent(member, event),
(val, event) => val + calculateInitiativeCreditsForEvent(member, event),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

0
);
const totalCreditsMet =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const defaultTeamEvent: TeamEvent = {
hasHours: false,
requests: [],
uuid: '',
isCommunity: false
isInitiativeEvent: false
};

type AttendanceDisplayProps = {
Expand Down Expand Up @@ -130,7 +130,7 @@ const TeamEventDetails: React.FC = () => {
<h3 className={styles.eventDetails}>Has Hours: {teamEvent.hasHours ? 'yes' : 'no'}</h3>
{INITIATIVE_EVENTS && (
<h3 className={styles.eventDetails}>
Initiative Event: {teamEvent.isCommunity ? 'Yes' : 'No'}
Initiative Event: {teamEvent.isInitiativeEvent ? 'Yes' : 'No'}
</h3>
)}
</div>
Expand Down
17 changes: 10 additions & 7 deletions frontend/src/components/Admin/TeamEvent/TeamEventForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const TeamEventForm = (props: Props): JSX.Element => {
const [teamEventDate, setTeamEventDate] = useState(teamEvent?.date || '');
const [teamEventCreditNum, setTeamEventCreditNum] = useState(teamEvent?.numCredits || '');
const [teamEventHasHours, setTeamEventHasHours] = useState(teamEvent?.hasHours || false);
const [isCommunity, setIsCommunity] = useState<boolean>(teamEvent?.isCommunity || false);
const [isInitiativeEvent, setisInitiativeEvent] = useState<boolean>(
teamEvent?.isInitiativeEvent || false
);

const submitTeamEvent = () => {
if (!teamEventName) {
Expand Down Expand Up @@ -53,7 +55,8 @@ const TeamEventForm = (props: Props): JSX.Element => {
date: teamEventDate,
numCredits: teamEventCreditNum,
hasHours: teamEventHasHours,
isCommunity
isCommunity: isInitiativeEvent,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

isInitiativeEvent
};
editTeamEvent(editedTeamEvent);
Emitters.generalSuccess.emit({
Expand All @@ -67,7 +70,7 @@ const TeamEventForm = (props: Props): JSX.Element => {
date: teamEventDate,
numCredits: teamEventCreditNum,
hasHours: teamEventHasHours,
isCommunity
isInitiativeEvent
};
TeamEventsAPI.createTeamEventForm(newTeamEventInfo).then((val) => {
if (val.error) {
Expand Down Expand Up @@ -165,16 +168,16 @@ const TeamEventForm = (props: Props): JSX.Element => {
<Radio
label="Yes"
value="Yes"
checked={isCommunity}
onChange={() => setIsCommunity(true)}
checked={isInitiativeEvent}
onChange={() => setisInitiativeEvent(true)}
/>
</Form.Field>
<Form.Field>
<Radio
label="No"
value="No"
checked={!isCommunity}
onChange={() => setIsCommunity(false)}
checked={!isInitiativeEvent}
onChange={() => setisInitiativeEvent(false)}
/>
</Form.Field>
</Form.Group>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Admin/TeamEvent/TeamEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const TeamEventsDisplay: React.FC<TeamEventsDisplayProps> = ({ isLoading, teamEv
</Card.Meta>
{INITIATIVE_EVENTS && (
<Card.Meta>
Initiative Event: {teamEvent.isCommunity ? 'Yes' : 'No'}
Initiative Event: {teamEvent.isInitiativeEvent ? 'Yes' : 'No'}
</Card.Meta>
)}
</Card.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ const TeamEventCreditForm: React.FC = () => {
<div className={styles.flex_space_center}>
<div className={styles.flex_start}>{event.name}</div>
<div className={styles.flex_end}>
{INITIATIVE_EVENTS && event.isCommunity && <Label content="initiative" />}
{INITIATIVE_EVENTS && event.isInitiativeEvent && (
<Label content="initiative" />
)}
<Label
content={`${new Date(event.date).toLocaleDateString('en-us', {
month: 'short',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const TeamEventCreditDashboard = (props: {
? Number(event.numCredits) * getHoursAttended(attendance)
: Number(event.numCredits);
approvedCredits += currCredits;
approvedInitiativeCredits += event.isCommunity ? currCredits : 0;
approvedInitiativeCredits += event.isInitiativeEvent ? currCredits : 0;
}
});

Expand Down Expand Up @@ -134,7 +134,9 @@ const TeamEventCreditDashboard = (props: {
)}
</Card.Meta>
{INITIATIVE_EVENTS && (
<Card.Meta>Initiative Event: {teamEvent.isCommunity ? 'Yes' : 'No'}</Card.Meta>
<Card.Meta>
Initiative Event: {teamEvent.isInitiativeEvent ? 'Yes' : 'No'}
</Card.Meta>
)}
</Card.Content>
</Card>
Expand Down
Loading