Skip to content

Commit

Permalink
fix(cancel): add clean up task and disable publish when canceled (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Lilleby <[email protected]>
  • Loading branch information
an2n and Anton Lilleby authored Jul 27, 2024
1 parent 9e50c16 commit 919004a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
28 changes: 16 additions & 12 deletions studio/actions/cancel-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useState } from "react";
import { DocumentActionProps, DocumentActionComponent, useDocumentOperation } from "sanity";
import { Event } from "../models/sanity.model";
import { sendEmailEventCanceled } from "../lib/event-email";
import { deleteEvent } from "../supabase/queries";

export const CancelAction: DocumentActionComponent = (props: DocumentActionProps) => {
const toast = useToast();
Expand All @@ -26,23 +27,24 @@ export const CancelAction: DocumentActionComponent = (props: DocumentActionProps
onConfirm: async () => {
if (publishedEvent) {
const result = await handleEventCancel(publishedEvent);
if (result) {
if (!publishedEvent.title.endsWith("Avlyst")) {
patch.execute([{ set: { title: `${publishedEvent.title} | Avlyst` } }]);
}

unpublish.execute();

toast.push({
status: "success",
title: "Arrangementet er avlyst",
});
} else {
if (!result) {
toast.push({
status: "error",
title: "En feil oppstod ved avlysing av arrangementet",
});
return;
}

if (!publishedEvent.title.endsWith("Avlyst")) {
patch.execute([{ set: { title: `${publishedEvent.title} - Avlyst` } }]);
}

unpublish.execute();

toast.push({
status: "success",
title: "Arrangementet er avlyst",
});
}
props.onComplete();
},
Expand Down Expand Up @@ -83,6 +85,8 @@ const handleEventCancel = async ({ _id, title, summary, start, end, place, organ
if (result?.error) {
return false;
}

await deleteEvent({ document_id: _id });
return true;
} catch (error) {
console.error("Error handling cancel event:", error);
Expand Down
1 change: 1 addition & 0 deletions studio/actions/publish-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function createExtendedEventPublishAction(originalPublishAction: Document
return {
...originalResult,
label: "Publiser",
disabled: !!draftEvent?.title.endsWith("Avlyst"),
onHandle: () => {
if (!originalResult?.onHandle) {
return;
Expand Down

1 comment on commit 919004a

@vercel
Copy link

@vercel vercel bot commented on 919004a Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.