Skip to content

Commit

Permalink
Merge pull request #2215 from Northeastern-Electric-Racing/2136-desig…
Browse files Browse the repository at this point in the history
…n-review-calendar-design-review-edit-page

#2136 finalize design review modal
  • Loading branch information
RChandler234 authored Mar 20, 2024
2 parents 61a3485 + 41cc3b6 commit cac50af
Show file tree
Hide file tree
Showing 21 changed files with 665 additions and 199 deletions.
4 changes: 2 additions & 2 deletions src/backend/src/controllers/design-reviews.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class DesignReviewsController {
try {
const {
dateScheduled,
teamType,
teamTypeId,
requiredMembersIds,
optionalMembersIds,
isOnline,
Expand All @@ -91,7 +91,7 @@ export default class DesignReviewsController {
user,
designReviewId,
dateScheduled,
teamType.teamTypeId,
teamTypeId,
requiredMembersIds,
optionalMembersIds,
isOnline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ const designReviewQueryArgs = Prisma.validator<Prisma.Design_ReviewArgs>()({
teamType: true,
requiredMembers: true,
optionalMembers: true,
confirmedMembers: true,
confirmedMembers: {
include: {
drScheduleSettings: true
}
},
deniedMembers: true,
attendees: true,
userDeleted: true,
Expand Down
14 changes: 10 additions & 4 deletions src/backend/src/services/users.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
RoleEnum,
isHead,
UserSecureSettings,
UserScheduleSettings
UserScheduleSettings,
UserWithScheduleSettings
} from 'shared';
import authUserQueryArgs from '../prisma-query-args/auth-user.query-args';
import prisma from '../prisma/prisma';
Expand All @@ -23,17 +24,22 @@ import projectQueryArgs from '../prisma-query-args/projects.query-args';
import userSecureSettingsTransformer from '../transformers/user-secure-settings.transformer';
import { validateUserIsPartOfFinanceTeam } from '../utils/reimbursement-requests.utils';
import userScheduleSettingsTransformer from '../transformers/user-schedule-settings.transformer';
import userWithScheduleSettingsTransformer from '../transformers/designReviewUser.transformer';

export default class UsersService {
/**
* Gets all of the users from the database
* @returns a list of all the users
*/
static async getAllUsers(): Promise<User[]> {
const users = await prisma.user.findMany();
static async getAllUsers(): Promise<UserWithScheduleSettings[]> {
const users = await prisma.user.findMany({
include: {
drScheduleSettings: true
}
});
users.sort((a, b) => a.firstName.localeCompare(b.firstName));

return users.map(userTransformer);
return users.map(userWithScheduleSettingsTransformer);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/backend/src/transformers/design-reviews.transformer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Prisma } from '@prisma/client';
import { DesignReview, DesignReviewStatus } from 'shared';
import userTransformer from './user.transformer';
import userWithScheduleSettingsTransformer from './designReviewUser.transformer';
import { wbsNumOf } from '../utils/utils';
import designReviewQueryArgs from '../prisma-query-args/design-reviews.query-args';

Expand All @@ -15,7 +16,7 @@ export const designReviewTransformer = (
userCreated: userTransformer(designReview.userCreated),
requiredMembers: designReview.requiredMembers.map(userTransformer),
optionalMembers: designReview.optionalMembers.map(userTransformer),
confirmedMembers: designReview.confirmedMembers.map(userTransformer),
confirmedMembers: designReview.confirmedMembers.map(userWithScheduleSettingsTransformer),
deniedMembers: designReview.deniedMembers.map(userTransformer),
location: designReview.location ?? undefined,
isOnline: designReview.isOnline,
Expand Down
19 changes: 19 additions & 0 deletions src/backend/src/transformers/designReviewUser.transformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Prisma } from '@prisma/client';
import { UserWithScheduleSettings } from 'shared';
import userScheduleSettingsTransformer from './user-schedule-settings.transformer';

const userWithScheduleSettingsTransformer = (
user: Prisma.UserGetPayload<{ include: { drScheduleSettings: true } }>
): UserWithScheduleSettings => {
return {
userId: user.userId,
firstName: user.firstName,
lastName: user.lastName,
email: user.email,
emailId: user.emailId,
role: user.role,
scheduleSettings: user.drScheduleSettings ? userScheduleSettingsTransformer(user.drScheduleSettings) : undefined
};
};

export default userWithScheduleSettingsTransformer;
88 changes: 81 additions & 7 deletions src/backend/tests/test-data/design-reviews.test-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,18 @@ export const prismaDesignReview1: Prisma.Design_ReviewGetPayload<typeof designRe
wbsElementId: 1,
requiredMembers: [batman],
optionalMembers: [],
confirmedMembers: [batman],
confirmedMembers: [
{
...batman,
drScheduleSettings: {
drScheduleSettingsId: '123',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/123456789',
availability: [1, 2, 3],
userId: 1
}
}
],
deniedMembers: [],
attendees: [batman],
userDeleted: null,
Expand All @@ -90,7 +101,18 @@ export const prismaDesignReview2: Prisma.Design_ReviewGetPayload<typeof designRe
userCreated: wonderwoman,
requiredMembers: [wonderwoman],
optionalMembers: [],
confirmedMembers: [wonderwoman],
confirmedMembers: [
{
...wonderwoman,
drScheduleSettings: {
drScheduleSettingsId: '123',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/123456789',
availability: [1, 2, 3],
userId: 1
}
}
],
deniedMembers: [],
attendees: [wonderwoman],
userDeleted: null,
Expand All @@ -117,7 +139,18 @@ export const prismaDesignReview3: Prisma.Design_ReviewGetPayload<typeof designRe
userCreated: batman,
requiredMembers: [batman],
optionalMembers: [],
confirmedMembers: [batman],
confirmedMembers: [
{
...batman,
drScheduleSettings: {
drScheduleSettingsId: '123',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/123456789',
availability: [1, 2, 3],
userId: 1
}
}
],
deniedMembers: [],
attendees: [batman],
userDeleted: null,
Expand Down Expand Up @@ -145,7 +178,18 @@ export const prismaDesignReview5: Prisma.Design_ReviewGetPayload<typeof designRe
wbsElementId: 1,
requiredMembers: [batman],
optionalMembers: [wonderwomanWithScheduleSettings],
confirmedMembers: [batman],
confirmedMembers: [
{
...batman,
drScheduleSettings: {
drScheduleSettingsId: 'bmschedule',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/gotham',
availability: [],
userId: 69
}
}
],
deniedMembers: [],
attendees: [wonderwoman],
userDeleted: null,
Expand All @@ -169,7 +213,17 @@ export const designReview3: DesignReview = {
wbsNum: { carNumber: 1, projectNumber: 2, workPackageNumber: 0 },
requiredMembers: [sharedBatman],
optionalMembers: [],
confirmedMembers: [sharedBatman],
confirmedMembers: [
{
...sharedBatman,
scheduleSettings: {
drScheduleSettingsId: '123',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/123456789',
availability: [1, 2, 3]
}
}
],
deniedMembers: [],
attendees: [sharedBatman],
userDeleted: undefined,
Expand All @@ -187,7 +241,17 @@ export const sharedDesignReview1: SharedDesignReview = {
isInPerson: false,
requiredMembers: [sharedBatman],
optionalMembers: [],
confirmedMembers: [sharedBatman],
confirmedMembers: [
{
...sharedBatman,
scheduleSettings: {
drScheduleSettingsId: '123',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/123456789',
availability: [1, 2, 3]
}
}
],
deniedMembers: [],
attendees: [sharedBatman],
teamType: teamType1,
Expand All @@ -207,7 +271,17 @@ export const designReview5: DesignReview = {
isInPerson: false,
requiredMembers: [],
optionalMembers: [wonderwomanMarkedWithScheduleSettings],
confirmedMembers: [sharedBatman],
confirmedMembers: [
{
...sharedBatman,
scheduleSettings: {
drScheduleSettingsId: 'bmschedule',
personalGmail: '[email protected]',
personalZoomLink: 'https://zoom.us/j/gotham',
availability: []
}
}
],
deniedMembers: [],
attendees: [wonderwoman],
wbsName: 'car',
Expand Down
5 changes: 4 additions & 1 deletion src/backend/tests/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ describe('Users', () => {
expect(prisma.user.findMany).toHaveBeenCalledTimes(1);
// note that batman was sorted to the front because his first name is before supermans alphabetically
// and also that we don't return the google auth id for security reasons
expect(res).toStrictEqual([restOfBatman, restOfSuperman]);
expect(res).toStrictEqual([
{ scheduleSettings: undefined, ...restOfBatman },
{ scheduleSettings: undefined, ...restOfSuperman }
]);
});

test('getSingleUser', async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/apis/users.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import axios from '../utils/axios';
import { Project, User, UserScheduleSettings, UserSecureSettings } from 'shared';
import { Project, User, UserScheduleSettings, UserSecureSettings, UserWithScheduleSettings } from 'shared';
import { apiUrls } from '../utils/urls';
import { authUserTransformer, userTransformer } from './transformers/users.transformers';
import { AuthenticatedUser, UserSettings } from 'shared';
Expand All @@ -14,7 +14,7 @@ import { projectTransformer } from './transformers/projects.transformers';
* Fetches all users.
*/
export const getAllUsers = () => {
return axios.get<User[]>(apiUrls.users(), {
return axios.get<UserWithScheduleSettings[]>(apiUrls.users(), {
transformResponse: (data) => JSON.parse(data).map(userTransformer)
});
};
Expand Down
28 changes: 4 additions & 24 deletions src/frontend/src/components/TimeSlot.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Box } from '@mui/system';
import { ReactElement } from 'react';
import WarningIcon from '@mui/icons-material/Warning';
import BuildIcon from '@mui/icons-material/Build';
import ComputerIcon from '@mui/icons-material/Computer';
import ElectricalServicesIcon from '@mui/icons-material/ElectricalServices';
import { Icon } from '@mui/material';

interface TimeSlotProps {
text?: string;
Expand All @@ -28,23 +24,6 @@ const TimeSlot: React.FC<TimeSlotProps> = ({
onMouseUp,
onMouseOver
}) => {
const getIcon = (icon: string, small: boolean): ReactElement | null => {
const iconFont = small ? { fontSize: '1.4em' } : { fontSize: '2em' };

switch (icon) {
case 'warning':
return <WarningIcon sx={iconFont} />;
case 'build':
return <BuildIcon sx={iconFont} />;
case 'computer':
return <ComputerIcon sx={iconFont} />;
case 'electrical':
return <ElectricalServicesIcon sx={iconFont} />;
default:
return null;
}
};

return (
<Box
sx={{
Expand All @@ -61,14 +40,15 @@ const TimeSlot: React.FC<TimeSlotProps> = ({
fontWeight: 'bold',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center'
justifyContent: 'center',
alignItems: 'center'
}}
onMouseDown={onMouseDown}
onMouseEnter={onMouseEnter}
onMouseUp={onMouseUp}
onMouseOver={onMouseOver}
>
{icon && <Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{getIcon(icon, small)}</Box>}
{icon && <Icon>{icon}</Icon>}
{text}
</Box>
);
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/hooks/design-reviews.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export interface EditDesignReviewPayload {
optionalMembersIds: number[];
isOnline: boolean;
isInPerson: boolean;
zoomLink: string | null;
location: string | null;
docTemplateLink: string | null;
zoomLink?: string;
location?: string;
docTemplateLink?: string;
status: DesignReviewStatus;
attendees: number[];
meetingTimes: number[];
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/src/hooks/users.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
UpdateUserRolePayload,
Project,
UserSecureSettings,
UserScheduleSettings
UserScheduleSettings,
UserWithScheduleSettings
} from 'shared';
import { useAuth } from './auth.hooks';
import { useContext } from 'react';
Expand All @@ -45,7 +46,7 @@ export const useCurrentUser = (): AuthenticatedUser => {
* Custom React Hook to supply all users.
*/
export const useAllUsers = () => {
return useQuery<User[], Error>(['users'], async () => {
return useQuery<UserWithScheduleSettings[], Error>(['users'], async () => {
const { data } = await getAllUsers();
return data;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { userToAutocompleteOption } from '../../utils/teams.utils';
import { useQuery } from '../../hooks/utils.hooks';
import NERAutocomplete from '../../components/NERAutocomplete';
import { useAllWorkPackages } from '../../hooks/work-packages.hooks';
import { HOURS } from '../../utils/design-review.utils';

const schema = yup.object().shape({
date: yup.date().required('Date is required'),
Expand Down Expand Up @@ -63,7 +64,6 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (
teamTypes,
defaultDate
}) => {
const HOURS: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
const query = useQuery();

const toast = useToast();
Expand All @@ -82,8 +82,9 @@ export const DesignReviewCreateModal: React.FC<DesignReviewCreateModalProps> = (

const onSubmit = async (data: CreateDesignReviewFormInput) => {
const day = data.date.getDay();
const adjustedDay = day === 0 ? 6 : day - 1;
const times = [];
for (let i = day * 12 + data.startTime; i <= day * 12 + data.endTime; i++) {
for (let i = adjustedDay * 12 + data.startTime; i < adjustedDay * 12 + data.endTime; i++) {
times.push(i);
}
try {
Expand Down
Loading

0 comments on commit cac50af

Please sign in to comment.