Skip to content
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

Ayush #89

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/(default)/events/EventCard.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ h2 {
transform: rotateY(180deg);
}


.event-card-front,
.event-card-back {
width: 100%;
Expand Down Expand Up @@ -116,7 +115,12 @@ h2 {
font-size: 1em;
}

button {
/* Updated button styles */
.toggle-form-button,
.toggle-edit-button,
.submit-event-button,
.update-event-button,
.remove-event-button {
margin-top: 70px !important;
background-color: black;
color: yellow;
Expand All @@ -129,7 +133,11 @@ button {
margin: 10px;
}

button:hover {
.toggle-form-button:hover,
.toggle-edit-button:hover,
.submit-event-button:hover,
.update-event-button:hover,
.remove-event-button:hover {
background-color: yellow;
color: black;
}
Expand Down
177 changes: 97 additions & 80 deletions app/(default)/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ const EventCard: React.FC = () => {
// Fetch admin status
useEffect(() => {
const checkAdminStatus = async () => {
const user = auth.currentUser;
if (user) {
const adminDocSnap = await getDoc(doc(db, "admin", user.uid));
setIsAdmin(adminDocSnap.exists());
}
onAuthStateChanged(auth, async (user) => {
if (user) {
const uid = user.uid;
try {
const adminDocRef = doc(db, "admin", uid);
const adminDocSnap = await getDoc(adminDocRef);
if (adminDocSnap.exists()) {
setIsAdmin(true);
}
} catch (error) {
console.log("Error getting document:", error);
}
}
});
};
onAuthStateChanged(auth, checkAdminStatus);

checkAdminStatus();
}, []);

// Fetch events from Firestore
Expand Down Expand Up @@ -219,8 +229,11 @@ const EventCard: React.FC = () => {
<div>
{isAdmin && (
<>
<button onClick={() => setFormVisible(!formVisible)}>
{formVisible ? "Hide Form" : "Show Form"}
<button
className="toggle-form-button"
onClick={() => setFormVisible(!formVisible)}
>
{formVisible ? "Hide Event Form" : "Add New Event"}
</button>

{formVisible && (
Expand Down Expand Up @@ -274,16 +287,21 @@ const EventCard: React.FC = () => {
required
/>
</div>
<button type="submit">Submit</button>
<button type="submit" className="submit-event-button">
Add Event
</button>
</form>
)}

<button onClick={() => setEditFormVisible(!editFormVisible)}>
{editFormVisible ? "Hide Edit Form" : "Show Edit Form"}
<button
className="toggle-edit-button"
onClick={() => setEditFormVisible(!editFormVisible)}
>
{editFormVisible ? "Hide Edit Form" : "Edit Event"}
</button>

{editFormVisible && (
<form onSubmit={handleEditSubmit}>
<form onSubmit={handleEditSubmit} style={{ marginBottom: "20px" }}>
<div>
<label>Select Event to Edit:</label>
<select
Expand All @@ -292,88 +310,87 @@ const EventCard: React.FC = () => {
setEventToEdit(e.target.value);
handleEventToEditChange(e.target.value);
}}
required
>
<option value="">Select an event</option>
<option value="">Select Event</option>
{events.map((event) => (
<option key={event.id} value={event.eventName}>
{event.eventName}
</option>
))}
</select>
</div>

{eventDataToEdit && (
<>
<div>
<label>Event Name:</label>
<input
type="text"
value={eventName}
onChange={(e) => setEventName(e.target.value)}
required
/>
</div>
<div>
<label>Description:</label>
<textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
required
/>
</div>
<div>
<label>Image Upload:</label>
<input
type="file"
accept="image/*"
onChange={(e) => {
if (e.target.files) {
setImageFile(e.target.files[0]);
}
}}
/>
</div>
<div>
<label>Start Date:</label>
<input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
required
/>
</div>
<div>
<label>End Date:</label>
<input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
required
/>
</div>

<button type="submit">Update</button>
<button type="button" onClick={handleRemoveEvent}>
Remove Event
</button>
</>
)}
<div>
<label>Event Name:</label>
<input
type="text"
value={eventName}
onChange={(e) => setEventName(e.target.value)}
required
/>
</div>
<div>
<label>Description:</label>
<textarea
value={description}
onChange={(e) => setDescription(e.target.value)}
required
/>
</div>
<div>
<label>Image Upload:</label>
<input
type="file"
accept="image/*"
onChange={(e) => {
if (e.target.files) {
setImageFile(e.target.files[0]);
}
}}
/>
</div>
<div>
<label>Start Date:</label>
<input
type="date"
value={startDate}
onChange={(e) => setStartDate(e.target.value)}
required
/>
</div>
<div>
<label>End Date:</label>
<input
type="date"
value={endDate}
onChange={(e) => setEndDate(e.target.value)}
required
/>
</div>
<button type="submit" className="update-event-button">
Update Event
</button>
<button
type="button"
className="remove-event-button"
onClick={handleRemoveEvent}
>
Remove Event
</button>
</form>
)}
</>
)}

<div>
<h2>Upcoming Events</h2>
{renderEventCards(upcomingEvents)}
<h2>Ongoing Events</h2>
{renderEventCards(ongoingEvents)}
<h2>Past Events</h2>
{renderEventCards(pastEvents)}
</div>
<h2>Upcoming Events</h2>
{renderEventCards(upcomingEvents)}

<h2>Ongoing Events</h2>
{renderEventCards(ongoingEvents)}

<h2>Past Events</h2>
{renderEventCards(pastEvents)}
</div>
);
};

export default EventCard;
export default EventCard;
Loading