Skip to content

Commit b6e7a96

Browse files
committed
Optional Zoom and Gmail Links
1 parent a50746a commit b6e7a96

6 files changed

Lines changed: 25 additions & 17 deletions

File tree

src/backend/src/routes/users.routes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ userRouter.post(
3434

3535
userRouter.post(
3636
'/schedule-settings/set',
37-
nonEmptyString(body('personalGmail')).isEmail(),
38-
nonEmptyString(body('personalZoomLink')).isURL(),
37+
body('personalGmail').isString(),
38+
body('personalZoomLink').isString(),
3939
body('availability').isArray(),
4040
intMinZero(body('availibility.*')),
4141
validateInputs,

src/backend/src/services/users.services.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,14 @@ export default class UsersService {
506506
personalZoomLink: string,
507507
availability: number[]
508508
): Promise<UserScheduleSettings> {
509-
const existingUser = await prisma.schedule_Settings.findFirst({
510-
where: { personalGmail, userId: { not: user.userId } } // excludes the current user from check
511-
});
509+
if (personalGmail !== '') {
510+
const existingUser = await prisma.schedule_Settings.findFirst({
511+
where: { personalGmail, userId: { not: user.userId } } // excludes the current user from check
512+
});
512513

513-
if (existingUser) {
514-
throw new HttpException(400, 'Email already in use');
514+
if (existingUser) {
515+
throw new HttpException(400, 'Email already in use');
516+
}
515517
}
516518

517519
const newUserScheduleSettings = await prisma.schedule_Settings.upsert({

src/backend/src/utils/users.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export const updateUserAvailability = async (
123123
const availabilityInSameWeek = userSettings.availabilities.filter((availability) =>
124124
isWithinSameWeek(availability.dateSet, dateToCheckFor)
125125
);
126-
if (availability.length > 0) {
126+
if (availabilityInSameWeek.length > 0) {
127127
await prisma.availability.update({
128128
where: { availabilityId: availabilityInSameWeek[0].availabilityId },
129129
data: {

src/frontend/src/pages/SettingsPage/UserScheduleSettings/UserScheduleSettingsEdit.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AvailabilityEditModal from './Availability/AvailabilityEditModal';
1313
import { useState } from 'react';
1414
import { SetUserScheduleSettingsArgs } from 'shared';
1515
import ExternalLink from '../../../components/ExternalLink';
16+
import { useToast } from '../../../hooks/toasts.hooks';
1617

1718
interface UserScheduleSettingsEditProps {
1819
onSubmit: (data: ScheduleSettingsPayload) => Promise<void>;
@@ -21,17 +22,19 @@ interface UserScheduleSettingsEditProps {
2122

2223
const schema = yup.object().shape({
2324
personalGmail: yup.string().email('Must be an email address').optional(),
24-
personalZoomLink: yup
25-
.string()
26-
.optional()
27-
.test('zoom-link', 'Must be a valid zoom link', (value) => value!.includes('zoom.us/'))
25+
personalZoomLink: yup.string().optional()
2826
});
2927

3028
const UserScheduleSettingsEdit: React.FC<UserScheduleSettingsEditProps> = ({ onSubmit, defaultValues }) => {
3129
const [editAvailabilityOpen, setEditAvailability] = useState(false);
3230
const [availabilities, setAvailabilities] = useState<number[]>(defaultValues?.availability || []);
31+
const toast = useToast();
3332

3433
const onFormSubmit = (data: ScheduleSettingsFormInput) => {
34+
if (data.personalZoomLink !== '' && !data.personalZoomLink.startsWith('https://zoom.us/j/')) {
35+
toast.error('Invalid Zoom Link Format. Must start with "https://zoom.us/j/"');
36+
return;
37+
}
3538
onSubmit({ availability: availabilities, ...data });
3639
};
3740

@@ -66,10 +69,8 @@ const UserScheduleSettingsEdit: React.FC<UserScheduleSettingsEditProps> = ({ onS
6669
<Controller
6770
name="personalGmail"
6871
control={control}
69-
rules={{ required: true }}
7072
render={({ field: { onChange, value } }) => (
7173
<TextField
72-
required
7374
id="email-input"
7475
autoComplete="off"
7576
onChange={onChange}
@@ -93,10 +94,8 @@ const UserScheduleSettingsEdit: React.FC<UserScheduleSettingsEditProps> = ({ onS
9394
<Controller
9495
name="personalZoomLink"
9596
control={control}
96-
rules={{ required: true }}
9797
render={({ field: { onChange, value } }) => (
9898
<TextField
99-
required
10099
id="zoom-link-input"
101100
autoComplete="off"
102101
onChange={onChange}

src/frontend/vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ export default defineConfig({
1717
globals: true,
1818
environment: 'jsdom',
1919
setupFiles: 'src/tests/setup-tests.ts'
20-
}
20+
},
21+
optimizeDeps: { exclude: ['@shared'] },
2122
});

src/shared/src/date-utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ const isWithinSameWeek = (date1: Date, date2: Date): boolean => {
6464
};
6565

6666
const getMostRecentAvailability = (availabilities: Availability[]): Availability => {
67+
if (availabilities.length === 0)
68+
return {
69+
availability: [],
70+
dateSet: new Date()
71+
};
72+
console.log(availabilities);
6773
return availabilities.reduce((prev, current) => (prev.dateSet > current.dateSet ? prev : current));
6874
};
6975

0 commit comments

Comments
 (0)