diff --git a/src/components/EventRegistration/EventRegistration.js b/src/components/EventRegistration/EventRegistration.js new file mode 100644 index 0000000000..af8bd8def4 --- /dev/null +++ b/src/components/EventRegistration/EventRegistration.js @@ -0,0 +1,318 @@ +// import React, { useState } from "react"; + +// const TestEventRegistration = () => { +// // State to store the event name and error message +// const [formValues, setFormValues] = useState({ +// eventName: "", + +// }); +// const [errors, setErrors] = useState({}); +// const [message, setMessage] = useState(""); +// const [events, setEvents] = useState([]); + +// useEffect(() => { +// fetchEvents(); +// }, []); + +// const fetchEvents = async () => { +// try { +// const response = await fetch("/EventRegistration"); +// 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); +// } +// }; + +// // 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 +// }; + +// // Handle form submission +// 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 { +// try { +// const response = await fetch("/EventRegistration", { +// method: 'POST', +// headers: { +// 'Content-Type': 'application/json', +// }, +// body: JSON.stringify({ eventName: formValues.eventName }), +// }); + +// const data = await response.json(); + +// if (response.ok) { +// setMessage(data.message); +// setFormValues({ eventName: "" }); +// fetchEvents(); // Refresh the events list +// } else { +// setErrors({ eventName: data.error }); +// } +// } catch (error) { +// setErrors({ eventName: "An error occurred. Please try again." }); +// } +// } +// }; + +// // Handle cancel button +// const handleCancel = () => { +// setFormValues({ +// eventName: "", +// }); +// setErrors({}); +// }; + +// return ( +//
+//
+// +// +// {errors.eventName && ( +// {errors.eventName} +// )} +//
+//
+// +// +//
+//
+// ); +// }; + +// export default TestEventRegistration; + +import React, { useState, useEffect } from 'react'; +import { ApiEndpoint, ENDPOINTS } from '../../utils/URL'; +import axios from 'axios'; +//import httpService from '../../services/httpService'; + +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 token = localStorage.getItem("token"); + // console.log("token: ",token) + // 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`, + { + 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); + } + // console.log(formValues.eventName); + // const token = localStorage.getItem('tokenKey'); + // fetch('https://hgn-rest-beta.azurewebsites.net/api/EventRegistration', { + // method: 'POST', + // headers: { + // 'Content-Type': 'application/json', + // Authorization: + // 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOiI2NzM2YTc3MjJjNzYwMTIxMjRiZDhiNTgiLCJyb2xlIjoiT3duZXIiLCJwZXJtaXNzaW9ucyI6eyJmcm9udFBlcm1pc3Npb25zIjpbXSwiYmFja1Blcm1pc3Npb25zIjpbXX0sImFjY2VzcyI6eyJjYW5BY2Nlc3NCTVBvcnRhbCI6ZmFsc2V9LCJlbWFpbCI6InByYXR5dXNocHNhaHUyQGdtYWlsLmNvbSIsImV4cGlyeVRpbWVzdGFtcCI6IjIwMjUtMDEtMDdUMDk6MTA6NTcuODQzWiIsImlhdCI6MTczNTM3NzA1N30.ys7M4U9Zr4MZFo2XUE5gmmsKUzUZDvlxiy9FJI0cY1Q', + // }, + // body: JSON.stringify(formValues), // Convert formValues to JSON + // }) + // .then(response => { + // if (!response.ok) { + // throw new Error(`HTTP error! Status: ${response.status}`); + // } + // return response.json(); + // }) + // .then(data => { + // console.log('Event registered successfully:', data); + // }) + // .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..524904b896 --- /dev/null +++ b/src/components/EventRegistration/TestEventRegistration.js @@ -0,0 +1,575 @@ +import React, { useState } from "react"; + +const 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 + }; + + // Handle form submission + const handleSubmit = (e) => { + e.preventDefault(); + const newErrors = {}; + 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 (!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 { + alert(`Form submitted`); + // 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({}); + }; + + 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.includes("Others") && ( + + )} +
+ ))} + {errors.howDidYouHear && ( + {errors.howDidYouHear} + )} +
+ + + {/* buttons */} +
+ + +
+
+ ); +}; + +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. */}