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 ( +//
Your form has been successfully submitted!
+ +