diff --git a/src/components/EventRegistration/EventRegistration.js b/src/components/EventRegistration/EventRegistration.js new file mode 100644 index 0000000000..6faadecfda --- /dev/null +++ b/src/components/EventRegistration/EventRegistration.js @@ -0,0 +1,137 @@ +// import React, { useState, useEffect } from 'react'; +// import { ApiEndpoint, ENDPOINTS } from '../../utils/URL'; + +// const EventRegistration = () => { +// const [formValues, setFormValues] = useState({ +// eventName: '', +// }); +// const [errors, setErrors] = useState({}); +// const [message, setMessage] = useState(''); +// const [events, setEvents] = useState([]); + +// useEffect(() => { +// fetchEvents(); +// }, []); + +// const fetchEvents = async () => { +// const token = localStorage.getItem('token'); // Replace with actual key +// if (!token) { +// console.error('No token found. Please log in.'); +// return; +// } +// const APIEndpoint = +// process.env.REACT_APP_APIENDPOINT || 'https://hgn-rest-beta.azurewebsites.net/api'; +// console.log('api endpoint: ', ApiEndpoint); +// try { +// const response = await fetch(`${APIEndpoint}/EventRegistration`, { +// headers: { +// Authorization: `Bearer ${token}`, // Add Authorization header +// }, +// }); + +// if (response.ok) { +// const data = await response.json(); +// setEvents(data); +// } else { +// console.error('Failed to fetch events'); +// } +// } catch (error) { +// console.error('Error fetching events:', error); +// } +// }; + +// const handleChange = e => { +// const { name, value } = e.target; +// setFormValues(prev => ({ +// ...prev, +// [name]: value, +// })); +// setErrors(prev => ({ +// ...prev, +// [name]: '', +// })); +// }; + +// const handleSubmit = async e => { +// e.preventDefault(); +// const newErrors = {}; +// if (!formValues.eventName.trim()) { +// newErrors.eventName = 'Event Name is required.'; +// } + +// if (Object.keys(newErrors).length > 0) { +// setErrors(newErrors); +// } else { +// const APIEndpoint = +// process.env.REACT_APP_APIENDPOINT || 'https://hgn-rest-beta.azurewebsites.net/api'; +// console.log('api endpoint: ', ApiEndpoint); +// try { +// const response = await fetch(`${APIEndpoint}/EventRegistration`, { +// method: 'POST', +// headers: { +// 'Content-Type': 'application/json', +// Authorization: `Bearer ${token}`, // Add Authorization header +// }, +// body: JSON.stringify(formValues), // Convert formValues to JSON +// }); + +// if (!response.ok) { +// throw new Error(`HTTP error! Status: ${response.status}`); +// } + +// const data = await response.json(); +// console.log('Event registered successfully:', data); +// setMessage('Event registered successfully!'); +// setFormValues({ eventName: '' }); +// } catch (error) { +// console.error('Error registering event:', error); +// } +// } +// }; + +// const handleCancel = () => { +// setFormValues({ eventName: '' }); +// setErrors({}); +// setMessage(''); +// }; + +// return ( +//
+//

Event Registration

+//
+//
+// +// +// {errors.eventName &&

{errors.eventName}

} +//
+//
+// +// +//
+//
+// {message &&
{message}
} +//
+// ); +// }; + +// export default EventRegistration; diff --git a/src/components/EventRegistration/TestEventRegistration.js b/src/components/EventRegistration/TestEventRegistration.js new file mode 100644 index 0000000000..202471ffa6 --- /dev/null +++ b/src/components/EventRegistration/TestEventRegistration.js @@ -0,0 +1,630 @@ +import { useState } from 'react'; + +function TestEventRegistration() { + // State to store the event name and error message + const [formValues, setFormValues] = useState({ + eventName: '', + firstName: '', + lastName: '', + countryCode: '', + phoneNumber: '', + emailAddress: '', + dateOfBirth: '', + gender: '', + otherGender: '', + address: '', + city: '', + state: '', + country: '', + zipcode: '', + howDidYouHear: '', + otherHowDidYouHear: '', + }); + const [errors, setErrors] = useState({}); + + // Handle changes in the input field + const handleChange = e => { + const { name, value } = e.target; + setFormValues(prev => ({ + ...prev, + [name]: value, + })); + setErrors(prev => ({ + ...prev, + [name]: '', + })); // Clear error when user starts typing + }; + const [formSubmitted, setFormSubmitted] = useState(false); + // Handle form submission + const handleSubmit = e => { + e.preventDefault(); + const newErrors = {}; + const emailRegex = /[a-z0-9]+@[a-z]+\.[a-z]{2,3}/; + if (!formValues.eventName.trim()) { + newErrors.eventName = 'Event Name is required.'; + } + if (!formValues.firstName.trim()) { + newErrors.firstName = 'First Name is required.'; + } + if (!formValues.lastName.trim()) { + newErrors.lastName = 'Last Name is required.'; + } + if (!formValues.countryCode.trim()) { + newErrors.countryCode = 'Country Code is required.'; + } + if (!formValues.phoneNumber.trim() || !/^[0-9]{10}$/.test(formValues.phoneNumber)) { + newErrors.phoneNumber = 'A valid 10-digit phone number is required.'; + } + if (!formValues.emailAddress.trim()) { + newErrors.emailAddress = 'Email Address is required.'; + } + if (!emailRegex.test(formValues.emailAddress)) { + newErrors.emailAddress = 'Please enter a valid email address'; + } + if (!formValues.dateOfBirth.trim()) { + newErrors.dateOfBirth = 'Date of Birth is required.'; + } + if (!formValues.gender.trim()) { + newErrors.gender = 'Gender is required.'; + } + if (formValues.gender === 'Others' && !formValues.otherGender.trim()) { + newErrors.otherGender = 'Please specify your gender.'; + } + if (!formValues.address.trim()) { + newErrors.address = 'Address is required.'; + } + if (!formValues.city.trim()) { + newErrors.city = 'City is required.'; + } + if (!formValues.state.trim()) { + newErrors.state = 'State is required.'; + } + if (!formValues.country.trim()) { + newErrors.country = 'Country is required.'; + } + if (!formValues.zipcode.trim() || !/^[0-9]{5}$/.test(formValues.zipcode)) { + newErrors.zipcode = 'A valid 5-digit ZIP code is required.'; + } + if (!formValues.howDidYouHear.trim()) { + newErrors.howDidYouHear = 'Please select at least one option.'; + } + if (formValues.howDidYouHear.includes('Others') && !formValues.otherHowDidYouHear.trim()) { + newErrors.howDidYouHear = 'Please specify how you heard about us.'; + } + if (Object.keys(newErrors).length > 0) { + setErrors(newErrors); + } else { + setFormSubmitted(true); + // Clear the form on successful submission + setFormValues({ + eventName: '', + firstName: '', + lastName: '', + countryCode: '', + phoneNumber: '', + emailAddress: '', + dateOfBirth: '', + gender: '', + otherGender: '', + address: '', + city: '', + state: '', + country: '', + zipcode: '', + howDidYouHear: '', + otherHowDidYouHear: '', + }); + } + }; + + // Handle cancel button + const handleCancel = () => { + setFormValues({ + eventName: '', + firstName: '', + lastName: '', + countryCode: '', + phoneNumber: '', + emailAddress: '', + dateOfBirth: '', + address: '', + city: '', + state: '', + country: '', + zipcode: '', + howDidYouHear: '', + otherHowDidYouHear: '', + }); + setErrors({}); + }; + const closeModal = () => { + setFormSubmitted(false); // Close the popup + }; + + return ( +
+
+
+ + + {errors.eventName && ( + {errors.eventName} + )} +
+
+ + + {errors.firstName && ( + {errors.firstName} + )} +
+ +
+ + + {errors.lastName && ( + {errors.lastName} + )} +
+
+ +
+ + +
+ {errors.countryCode && ( + {errors.countryCode} + )} + {errors.phoneNumber && ( + {errors.phoneNumber} + )} +
+
+ + + {errors.emailAddress && ( + {errors.emailAddress} + )} +
+
+ + + {errors.dateOfBirth && ( + {errors.dateOfBirth} + )} +
+ {/* Gender Field */} +
+ +
+ + + + + +
+ + {/* Conditional Text Box for "Others" */} + {formValues.gender === 'Others' && ( +
+ + + {errors.otherGender && ( + {errors.otherGender} + )} +
+ )} + + {errors.gender && ( + {errors.gender} + )} +
+ + {/* Address Field */} +
+ + + {errors.address && ( + {errors.address} + )} +
+ + {/* City Field */} +
+ + + {errors.city && {errors.city}} +
+ + {/* State Field */} +
+ + + {errors.state && ( + {errors.state} + )} +
+ + {/* Country Field */} +
+ + + {errors.country && ( + {errors.country} + )} +
+ + {/* ZIP Code Field */} +
+ + + {errors.zipcode && ( + {errors.zipcode} + )} +
+ {/* How Did You Hear About Us Field */} +
+ + {[ + 'Search Engine (Google, Bing, etc.)', + 'Social Media', + 'Radio', + 'Television', + 'Streaming Service Ad', + 'Newspaper/Online Newspaper', + 'Billboard', + 'Word of Mouth', + 'Referral', + 'Others', + ].map(option => ( +
+ + {option === 'Others' && formValues.howDidYouHear === 'Others' && ( + + )} +
+ ))} + {errors.howDidYouHear && ( + {errors.howDidYouHear} + )} +
+ + {/* buttons */} +
+ + +
+
+ {formSubmitted && ( +
+
+

Form Submitted

+

Your form has been successfully submitted!

+ +
+
+ )} +
+ ); +} + +export default TestEventRegistration; diff --git a/src/routes.js b/src/routes.js index 0823aed610..03e77051eb 100644 --- a/src/routes.js +++ b/src/routes.js @@ -29,6 +29,9 @@ import EmailSubscribeForm from './components/EmailSubscribeForm'; import UnsubscribeForm from './components/EmailSubscribeForm/Unsubscribe'; import { EmailSender } from './components/common/EmailSender/EmailSender'; import Collaboration from './components/Collaboration'; +import EventRegistration from './components/EventRegistration/EventRegistration'; +import TestEventRegistration from './components/EventRegistration/TestEventRegistration'; + // BM Dashboard import BMProtectedRoute from './components/common/BMDashboard/BMProtectedRoute'; @@ -99,6 +102,8 @@ const Teams = lazy(() => import('./components/Teams/Teams')); export default ( + + <> {/* Comment out the Header component and its import during phase 2 development. */}