Skip to content

add form validation for zoom google meet #1812

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

Merged
1 change: 1 addition & 0 deletions client/src/components/manageProjects/createNewEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const CreateNewEvent = ({
handleInputChange={handleInputChange}
formValues={formValues}
formErrors={formErrors}
setFormErrors={setFormErrors}
title="Create New Recurring Event"
>
<div className="button-box">
Expand Down
9 changes: 8 additions & 1 deletion client/src/components/manageProjects/eventForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { createClockHours } from '../../utils/createClockHours';
import validateEventForm from './utilities/validateEventForm';
import {
Box,
TextField,
Expand All @@ -14,12 +15,18 @@ const EventForm = ({
title,
formValues,
formErrors,
setFormErrors,
handleInputChange,
children,
}) => {
// This creates the clock hours for the form
const clockHours = createClockHours();

const handleInputChangeWithValidation = (e) => {
const { name, value } = e.target;
handleInputChange(e);
const errors = validateEventForm({ ...formValues, [name]: value });
setFormErrors(errors || {});
};
return (
<Box className="event-form-box">
{title && <h3 className="event-form-title">{title}</h3>}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import validator from 'validator';
import { isWordInArrayInString } from './../../../utils/stringUtils.js';
import { eventNameBlacklistArr } from '../../../utils/blacklist.js';

const validateEventForm = (vals, projectToEdit) => {
let newErrors = {};
Object.keys(vals).forEach((key) => {
let blacklistedStrings = isWordInArrayInString( eventNameBlacklistArr, vals[key].toLowerCase() );
let blacklistedStrings = isWordInArrayInString(
eventNameBlacklistArr,
vals[key].toLowerCase()
);
switch (key) {
case 'name':
// Required
Expand Down Expand Up @@ -58,6 +60,10 @@ const validateEventForm = (vals, projectToEdit) => {

export default validateEventForm;

function validateLink(str) {
return validator.isURL(str);
function validateLink(url) {
const ZoomMeetRegex =
/^(?:https:\/\/)?(?:www\.)?(?:[a-z0-9-]+\.)?zoom\.us\/j\/[0-9]+(\?pwd=[a-zA-Z0-9]+)?$/;
const GoogleMeetRegex =
/^(?:https:\/\/)?(?:[a-z0-9-]+\.)?meet\.google\.com\/[a-zA-Z0-9-]+$/;
return ZoomMeetRegex.test(url) || GoogleMeetRegex.test(url);
}
Loading