From e3180037efead4934709e2f552c1a71aea3af189 Mon Sep 17 00:00:00 2001 From: pluto <99231462+pluto-bell@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:01:42 -0700 Subject: [PATCH 1/3] blacklist arr for event naming --- .../utilities/validateEventForm.js | 5 +++-- client/src/utils/blacklist.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 client/src/utils/blacklist.js diff --git a/client/src/components/manageProjects/utilities/validateEventForm.js b/client/src/components/manageProjects/utilities/validateEventForm.js index 6128e1b03..5f297b898 100644 --- a/client/src/components/manageProjects/utilities/validateEventForm.js +++ b/client/src/components/manageProjects/utilities/validateEventForm.js @@ -1,5 +1,6 @@ import validator from 'validator'; import { isWordInArrayInString } from './../../../utils/stringUtils.js'; +import { eventNameBlacklistArr } from '../../../utils/blacklist.js'; const validateEventForm = (vals, projectToEdit) => { let newErrors = {}; @@ -11,13 +12,13 @@ const validateEventForm = (vals, projectToEdit) => { newErrors = { ...newErrors, name: 'Event name is required' }; } else if ( isWordInArrayInString( - ['meeting', 'mtg'], + eventNameBlacklistArr, vals[key].toLowerCase() ) ) { newErrors = { ...newErrors, - name: "Event name cannot contain 'meeting' or 'mtg'", + name: `Event name cannot contain: ${vals[key]}`, }; } else if ( isWordInArrayInString( diff --git a/client/src/utils/blacklist.js b/client/src/utils/blacklist.js new file mode 100644 index 000000000..e22888e6f --- /dev/null +++ b/client/src/utils/blacklist.js @@ -0,0 +1,19 @@ +export const eventNameBlacklistArr = [ + 'general', + 'meet', + 'meeting', + 'mtg', + 'onboarding', + 'onboard', + 'team', + 'semi', + 'bi', + 'weekly', + 'monthly', + 'annual', + 'annually', + 'bi-weekly', + 'twice-weekly', + 'semi-annual', + 'semi-annually', +] \ No newline at end of file From 79647e06540a627cef48b9a185cbf240051e3ec9 Mon Sep 17 00:00:00 2001 From: pluto <99231462+pluto-bell@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:37:53 -0700 Subject: [PATCH 2/3] rewrote util for better err handling --- .../manageProjects/utilities/validateEventForm.js | 3 ++- client/src/utils/stringUtils.js | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/components/manageProjects/utilities/validateEventForm.js b/client/src/components/manageProjects/utilities/validateEventForm.js index 5f297b898..9f23021c0 100644 --- a/client/src/components/manageProjects/utilities/validateEventForm.js +++ b/client/src/components/manageProjects/utilities/validateEventForm.js @@ -16,9 +16,10 @@ const validateEventForm = (vals, projectToEdit) => { vals[key].toLowerCase() ) ) { + const blacklistedString = isWordInArrayInString(eventNameBlacklistArr, vals[key].toLowerCase()) newErrors = { ...newErrors, - name: `Event name cannot contain: ${vals[key]}`, + name: `Event name cannot contain: ${blacklistedString.join(', ')}`, }; } else if ( isWordInArrayInString( diff --git a/client/src/utils/stringUtils.js b/client/src/utils/stringUtils.js index 987e632ba..5b8ceced8 100644 --- a/client/src/utils/stringUtils.js +++ b/client/src/utils/stringUtils.js @@ -1,9 +1,13 @@ export const isWordInArrayInString = (arr, str) => { const words = str.split(' '); + let foundWords = [] for (let word of words) { if (arr.includes(word)) { - return true; + foundWords.push(word) } } + if(foundWords.length > 0) { + return foundWords + } return false; }; From ecc71579b64ffcdfbcf2f2533869902cfc8f9bee Mon Sep 17 00:00:00 2001 From: pluto <99231462+pluto-bell@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:50:50 -0700 Subject: [PATCH 3/3] refactor --- .../manageProjects/utilities/validateEventForm.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/client/src/components/manageProjects/utilities/validateEventForm.js b/client/src/components/manageProjects/utilities/validateEventForm.js index 9f23021c0..1976e1240 100644 --- a/client/src/components/manageProjects/utilities/validateEventForm.js +++ b/client/src/components/manageProjects/utilities/validateEventForm.js @@ -5,21 +5,16 @@ import { eventNameBlacklistArr } from '../../../utils/blacklist.js'; const validateEventForm = (vals, projectToEdit) => { let newErrors = {}; Object.keys(vals).forEach((key) => { + let blacklistedStrings = isWordInArrayInString( eventNameBlacklistArr, vals[key].toLowerCase() ); switch (key) { case 'name': // Required if (!vals[key]) { newErrors = { ...newErrors, name: 'Event name is required' }; - } else if ( - isWordInArrayInString( - eventNameBlacklistArr, - vals[key].toLowerCase() - ) - ) { - const blacklistedString = isWordInArrayInString(eventNameBlacklistArr, vals[key].toLowerCase()) + } else if (blacklistedStrings) { newErrors = { ...newErrors, - name: `Event name cannot contain: ${blacklistedString.join(', ')}`, + name: `Event name cannot contain: ${blacklistedStrings.join(', ')}`, }; } else if ( isWordInArrayInString(