Skip to content
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
4 changes: 2 additions & 2 deletions client/src/components/manageProjects/createNewEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import validateEventForm from './utilities/validateEventForm';
import EventForm from './eventForm';

const CreateNewEvent = ({
projectName,
projectToEdit,
projectID,
createNewRecurringEvent,
setEventAlert,
Expand Down Expand Up @@ -72,7 +72,7 @@ const CreateNewEvent = ({

// Handle submission of new recurring event form
const handleFormSubmit = async () => {
const errors = validateEventForm(formValues);
const errors = validateEventForm(formValues, projectToEdit);
if (!errors) {
handleEventCreate();
setFormValues(initialFormValues);
Expand Down
3 changes: 2 additions & 1 deletion client/src/components/manageProjects/editMeetingTimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import validateEventForm from './utilities/validateEventForm';

// This component displays current meeting times for selected project and offers the option to edit those times.
const EditMeetingTimes = ({
projectToEdit,
selectedEvent,
setEventAlert,
setSelectedEvent,
Expand All @@ -21,7 +22,7 @@ const EditMeetingTimes = ({
startTimeOriginal,
durationOriginal
) => async () => {
const errors = validateEventForm(values);
const errors = validateEventForm(values, projectToEdit);
if (!errors) {
let theUpdatedEvent = {};

Expand Down
3 changes: 2 additions & 1 deletion client/src/components/manageProjects/editProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const EditProject = ({
<div>
<div className={`edit-meeting-modal ${selectedEvent ? 'active' : ''}`}>
<EditMeetingTimes
projectToEdit={projectToEdit}
selectedEvent={selectedEvent}
setEventAlert={setEventAlert}
setSelectedEvent={setSelectedEvent}
Expand All @@ -71,7 +72,7 @@ const EditProject = ({
<div className={`edit-meeting-modal ${isCreateNew ? 'active' : ''}`}>
<CreateNewEvent
createNewRecurringEvent={createNewRecurringEvent}
projectName={projectToEdit.name}
projectToEdit={projectToEdit}
// eslint-disable-next-line no-underscore-dangle
projectID={projectToEdit._id}
setEventAlert={setEventAlert}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import validator from 'validator'
import validator from 'validator';
import { isWordInArrayInString } from './../../../utils/stringUtils.js';

const validateEventForm = (vals) => {
const validateEventForm = (vals, projectToEdit) => {
let newErrors = {};
Object.keys(vals).forEach((key) => {
switch (key) {
case 'name':
// Required
if (!vals[key]) {
newErrors = { ...newErrors, name: 'Event name is required' };
} else if (
isWordInArrayInString(
['meeting', 'mtg', projectToEdit.name.toLowerCase()],
vals[key].toLowerCase()
)
) {
newErrors = {
...newErrors,
name: "Event name cannot contain 'meeting' or 'mtg' or the project name",
};
}
break;

Expand All @@ -22,8 +33,8 @@ const validateEventForm = (vals) => {
if (!validateLink(vals[key])) {
newErrors = {
...newErrors,
videoConferenceLink: 'Invalid link'
}
videoConferenceLink: 'Invalid link',
};
}
break;

Expand Down
9 changes: 9 additions & 0 deletions client/src/utils/stringUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const isWordInArrayInString = (arr, str) => {
const words = str.split(' ');
for (let word of words) {
if (arr.includes(word)) {
return true;
}
}
return false;
};