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

Frontend/fix calendar mutation race #317

Merged
merged 3 commits into from
Aug 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const EditEventModal = (props: EditEventProps) => {
setModalState(null);
};

const handleEditEvent = () => {
const handleEditEvent = async () => {
const start = startDate;
const end = endDate;
const timeDeltaStart = start.getTime() - occurrence.start.getTime();
Expand Down Expand Up @@ -160,7 +160,7 @@ export const EditEventModal = (props: EditEventProps) => {
? dateToEventISO(moment(erpDate).endOf("day").toDate())
: null,
};
updateEvent(editedEvent);
await updateEvent(editedEvent);
// Revalidate everything, since new event could have created many new occurrences.
mutate(undefined, undefined, { sendRequest: false });
setModalState(null);
Expand All @@ -175,8 +175,7 @@ export const EditEventModal = (props: EditEventProps) => {
setModalState(null);
};

const handleDeleteEvent = () => {
deleteEvent(occurrence.event.id);
const handleDeleteEvent = async () => {
// Optimistically delete all without revalidation, then revalidate all.
occurrences.forEach(
(o) =>
Expand All @@ -187,8 +186,9 @@ export const EditEventModal = (props: EditEventProps) => {
revalidate: false,
})
);
mutate(undefined, undefined, { sendRequest: false });
setModalState(null);
await deleteEvent(occurrence.event.id);
mutate(undefined, undefined, { sendRequest: false });
};

const handleClose = () => {
Expand Down Expand Up @@ -241,7 +241,7 @@ export const EditEventModal = (props: EditEventProps) => {
title={`Delete ${
occurrence.event.rule ? "Recurring " : ""
}Event`}
occurrenceText="Delete This Event"
occurrenceText="Cancel This Event"
eventText={
occurrence.event.rule
? "Delete All Events"
Expand Down Expand Up @@ -327,7 +327,7 @@ export const NewEventModal = (props: NewEventProps) => {
}
}, [show]);

const handleCreateEvent = () => {
const handleCreateEvent = async () => {
const newEvent: ApiPartialEvent = {
title,
start: dateToEventISO(startDate),
Expand All @@ -348,8 +348,7 @@ export const NewEventModal = (props: NewEventProps) => {
? dateToEventISO(moment(erpDate).endOf("day").toDate())
: null,
};
createEvent(newEvent);

await createEvent(newEvent);
mutate(undefined, undefined, { sendRequest: false });
if (isRecurring) setLastSubmittedErp(erpDate);
setModalState(false);
Expand Down
Loading