-
Notifications
You must be signed in to change notification settings - Fork 1
Edit button pushes to database, but it doesn't fully prefill #128
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
Open
Nogunmesa
wants to merge
2
commits into
development
Choose a base branch
from
feat/editcalendar
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -326,64 +326,87 @@ export default function Home() { | |
| return; | ||
| } | ||
|
|
||
| const eventWithUser: UserEvent & { | ||
| start: Date; | ||
| end?: Date; | ||
| color?: string; | ||
| } = { | ||
| ...newEvent, | ||
| user_id: user.uid, | ||
| start: new Date(newEvent.start_time), // <-- ensure start is there | ||
| end: newEvent.end_time ? new Date(newEvent.end_time) : undefined, | ||
| title: newEvent.title, | ||
| id: newEvent.id, // this is FullCalendar id | ||
| break_time: newEvent.break_time, | ||
| start_time: newEvent.start_time, | ||
| created_at: new Date().toISOString(), | ||
| description: newEvent.description, | ||
| is_generated: false, | ||
| is_recurring: newEvent.is_recurring, | ||
| location_place: newEvent.location_place, | ||
| recurrence_end_date: newEvent.recurrence_end_date, | ||
| recurrence_pattern: newEvent.recurrence_pattern, | ||
| recurrence_start_date: newEvent.recurrence_start_date, | ||
| color: colorTypes.eventByUser, | ||
| }; | ||
| if (newEvent.id) { | ||
| // Editing an existing event | ||
| axios | ||
| .put( | ||
| `${backendBaseUrl}/api/calendar/events/id/${newEvent.id}`, | ||
| newEvent | ||
| ) | ||
| .then((response) => { | ||
| console.log('Successfully updated event:', response.data); | ||
|
|
||
| axios | ||
| .post(backendBaseUrl + `/api/calendar/events`, eventWithUser) | ||
| .then((response) => { | ||
| // controller may save multiple events now. | ||
| console.log('Successfully saved events:', response); | ||
| console.log('event series', response.data.eventSeries); | ||
| const eventsToAdd: (typeof eventWithUser)[] = []; | ||
| // Update the event in the local state | ||
| setAllEvents( | ||
| allEvents.map((event) => | ||
| event.id === newEvent.id ? { ...event, ...newEvent } : event | ||
| ) | ||
| ); | ||
| }) | ||
| .catch((error) => { | ||
| console.error('Error updating event:', error); | ||
| }); | ||
| } else { | ||
| // Creating a new event | ||
|
|
||
| // const { id, start_time, end_time, ...restEvent } = eventWithUser; | ||
| const eventWithUser: UserEvent & { | ||
| start: Date; | ||
| end?: Date; | ||
| color?: string; | ||
| } = { | ||
| ...newEvent, | ||
| user_id: user.uid, | ||
| start: new Date(newEvent.start_time), // <-- ensure start is there | ||
| end: newEvent.end_time ? new Date(newEvent.end_time) : undefined, | ||
| title: newEvent.title, | ||
| id: newEvent.id, // this is FullCalendar id | ||
| break_time: newEvent.break_time, | ||
| start_time: newEvent.start_time, | ||
| created_at: new Date().toISOString(), | ||
| description: newEvent.description, | ||
| is_generated: false, | ||
| is_recurring: newEvent.is_recurring, | ||
| location_place: newEvent.location_place, | ||
| recurrence_end_date: newEvent.recurrence_end_date, | ||
| recurrence_pattern: newEvent.recurrence_pattern, | ||
| recurrence_start_date: newEvent.recurrence_start_date, | ||
| color: colorTypes.eventByUser, | ||
| }; | ||
|
|
||
| for (const newEvent of response.data.eventSeries) { | ||
| // Notice that the keys might not be in the correct order | ||
| eventsToAdd.push({ | ||
| ...eventWithUser, | ||
| id: newEvent.id, | ||
| start_time: new Date(newEvent.start_time).toISOString(), | ||
| end_time: newEvent.endTime, | ||
| start: new Date(newEvent.start_time), | ||
| end: newEvent.end_time ? new Date(newEvent.end_time) : undefined, | ||
| }); | ||
| } | ||
| axios | ||
| .post(backendBaseUrl + `/api/calendar/events`, eventWithUser) | ||
| .then((response) => { | ||
| // controller may save multiple events now. | ||
| console.log('Successfully saved events:', response); | ||
| console.log('event series', response.data.eventSeries); | ||
| const eventsToAdd: (typeof eventWithUser)[] = []; | ||
|
|
||
| setAllEvents([...allEvents, ...eventsToAdd]); | ||
| // const { id, start_time, end_time, ...restEvent } = eventWithUser; | ||
|
|
||
| // We want to be consistent and use our backend id | ||
| // const correctId = response.data.id; | ||
| // const { id, ...restEvent } = eventWithUser; | ||
| // console.log(`Replace ${id} with ${correctId}`); | ||
| // setAllEvents([...allEvents, { id: correctId, ...restEvent }]); | ||
| }) | ||
| .catch((error) => { | ||
| console.error('Error saving event:', error); | ||
| }); | ||
| for (const newEvent of response.data.eventSeries) { | ||
| // Notice that the keys might not be in the correct order | ||
| eventsToAdd.push({ | ||
| ...eventWithUser, | ||
| id: newEvent.id, | ||
| start_time: new Date(newEvent.start_time).toISOString(), | ||
| end_time: newEvent.endTime, | ||
| start: new Date(newEvent.start_time), | ||
| end: newEvent.end_time ? new Date(newEvent.end_time) : undefined, | ||
| }); | ||
| } | ||
|
|
||
| setAllEvents([...allEvents, ...eventsToAdd]); | ||
|
|
||
| // We want to be consistent and use our backend id | ||
| // const correctId = response.data.id; | ||
| // const { id, ...restEvent } = eventWithUser; | ||
| // console.log(`Replace ${id} with ${correctId}`); | ||
| // setAllEvents([...allEvents, { id: correctId, ...restEvent }]); | ||
| }) | ||
| .catch((error) => { | ||
| console.error('Error saving event:', error); | ||
| }); | ||
| } | ||
| setShowModal(false); | ||
| setNewEvent({ | ||
| ...example, | ||
|
|
@@ -602,6 +625,17 @@ export default function Home() { | |
| </div> | ||
|
|
||
| <div className="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6"> | ||
| <button | ||
| type="button" | ||
| className="inline-flex w-full justify-center rounded-md bg-blue-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-blue-500 sm:ml-3 sm:w-auto" | ||
| onClick={() => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implemented edit button |
||
| setShowModal(true); // Open the modal for editing | ||
| setNewEvent(selectedEvent); // Pre-fill the modal with the selected event's details | ||
| setIsDeadline(selectedEvent.is_recurring); // Set deadline state based on the event | ||
| }} | ||
| > | ||
| Edit | ||
| </button> | ||
| <button | ||
| type="button" | ||
| className="inline-flex w-full justify-center rounded-md bg-red-600 px-3 py-2 text-sm | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating edited event