Managing events
In this section we'll see how we can add events to our backend.
note
Before moving on, coming from the previous section we can do a small optimization. When we move to other routes from our /events
page and come back to it again we don't want it to fetch events from firestore again and again.For this we dispatch an action RETAIN_STATE
after we fetch events the first time. It holds either true
or false
depending on whether the routes has changed or not.
This will ensure we do not fetch the events again and we fetch them only once.
#
Creating an eventWhen we route to /createEvent
, CLEAR_SELECTED_EVENT
is dispatched by the useEffect
in the EventForm
component.
This is done so to clear the input fields in the form which can be present if we earlier had visited /manage/:id
route to update the selectedEvent
.
The routes
/createEvent
and/manage/:id
both takes us toEventForm
component.
#
Adding event to FirestoreWhen we fill the Event Form and hit submit the details are passed to addEventsToFirestore
function located in firestoreService.js
.
It then adds that event to firestore with some manually added properties.
#
Updating event in FirestoreUpdating event is simple. When we plan to update an event hosted by us we go to /manage/:id
route.
We then update details in the event form and hit submit. The details are then passed to updateEventInFirestore
located in firestoreService.js
which then simply update the details in our backend.
Please don't confuse with
event.id
property. Though when we were adding event to firestore we did not add anyid
propety. However when we select a hosted event to be managed we updateselected event
in our redux store using the belowuseFirestoreDoc
custom hook when ourEvent Detailed Page
loads.
EventDetailedPage.jsx
Also not the usage of Nullish coalescing operator below.
#
Usefull Resources- Nullish coalescing operator
- If you find something unclear or unable to visualize components you can always find pictorial representation of the components here