From cb6ded3d548866e2b829774ac49d055f5ba92eb7 Mon Sep 17 00:00:00 2001 From: Felix Ohrgren <179166750+fgren@users.noreply.github.com> Date: Tue, 19 Nov 2024 23:21:17 +0100 Subject: [PATCH] Fix #235 Add cancelling feature to events (#591) * Added cancelling feature to events * Style tweaks Co-authored-by: Daniel Adu-Gyan <26229521+danieladugyan@users.noreply.github.com> * Tweaks to class check * Removed unnecessary variable --------- Co-authored-by: Daniel Adu-Gyan <26229521+danieladugyan@users.noreply.github.com> --- .../migration.sql | 2 ++ src/database/prisma/schema.prisma | 1 + src/database/schema.zmodel | 1 + src/database/seed/.snaplet/dataModel.json | 14 ++++++++++ src/lib/events/schema.ts | 1 + src/routes/(app)/events/Event.svelte | 28 +++++++++++++------ src/routes/(app)/events/EventEditor.svelte | 23 +++++++++++---- src/routes/(app)/events/SmallEventCard.svelte | 23 ++++++++++----- .../(app)/events/calendar/Calendar.svelte | 4 ++- src/translations/en.json | 3 ++ src/translations/sv.json | 3 ++ 11 files changed, 82 insertions(+), 21 deletions(-) create mode 100644 src/database/prisma/migrations/20241118182939_add_iscancelled_to_event/migration.sql diff --git a/src/database/prisma/migrations/20241118182939_add_iscancelled_to_event/migration.sql b/src/database/prisma/migrations/20241118182939_add_iscancelled_to_event/migration.sql new file mode 100644 index 000000000..6d5f16f31 --- /dev/null +++ b/src/database/prisma/migrations/20241118182939_add_iscancelled_to_event/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "events" ADD COLUMN "is_cancelled" BOOLEAN DEFAULT false; diff --git a/src/database/prisma/schema.prisma b/src/database/prisma/schema.prisma index 72343a2d0..bc9d78ca4 100644 --- a/src/database/prisma/schema.prisma +++ b/src/database/prisma/schema.prisma @@ -417,6 +417,7 @@ model Event { numberOfUpdates Int? @default(0) @map("number_of_updates") slug String? @unique(map: "events_slug_unique") @db.VarChar(255) alarmActive Boolean? @default(false) @map("alarm_active") + isCancelled Boolean? @default(false) @map("is_cancelled") /// @allow('update', has(auth().policies, 'event:delete')) removedAt DateTime? @map("removed_at") @db.Timestamptz(6) comments EventComment[] diff --git a/src/database/schema.zmodel b/src/database/schema.zmodel index 4f05464b9..7838b17b6 100644 --- a/src/database/schema.zmodel +++ b/src/database/schema.zmodel @@ -408,6 +408,7 @@ model Event { numberOfUpdates Int? @default(0) @map("number_of_updates") slug String? @unique(map: "events_slug_unique") @db.VarChar(255) alarmActive Boolean? @default(false) @map("alarm_active") + isCancelled Boolean? @default(false) @map("is_cancelled") removedAt DateTime? @map("removed_at") @db.Timestamptz(6) @allow("update", has(auth().policies, "event:delete")) comments EventComment[] going Member[] @relation("event_going") diff --git a/src/database/seed/.snaplet/dataModel.json b/src/database/seed/.snaplet/dataModel.json index 16a341609..a1f81e9f4 100644 --- a/src/database/seed/.snaplet/dataModel.json +++ b/src/database/seed/.snaplet/dataModel.json @@ -4227,6 +4227,20 @@ "isId": false, "maxLength": null }, + { + "id": "public.events.is_cancelled", + "name": "is_cancelled", + "columnName": "is_cancelled", + "type": "bool", + "isRequired": false, + "kind": "scalar", + "isList": false, + "isGenerated": false, + "sequence": false, + "hasDefaultValue": true, + "isId": false, + "maxLength": null + }, { "name": "RecurringEvent", "type": "RecurringEvent", diff --git a/src/lib/events/schema.ts b/src/lib/events/schema.ts index 9dd7ff1db..92f454d2f 100644 --- a/src/lib/events/schema.ts +++ b/src/lib/events/schema.ts @@ -42,6 +42,7 @@ export const eventSchema = z .default([]), alarmActive: z.boolean().nullable().default(null), + isCancelled: z.boolean().nullable().default(null), isRecurring: z.boolean().default(false), // see comment above and in utils/events.ts why we do it like this recurringType: z diff --git a/src/routes/(app)/events/Event.svelte b/src/routes/(app)/events/Event.svelte index 2fb1829d1..e3e1982e0 100644 --- a/src/routes/(app)/events/Event.svelte +++ b/src/routes/(app)/events/Event.svelte @@ -3,6 +3,7 @@ import MarkdownBody from "$lib/components/MarkdownBody.svelte"; import type { Event } from "@prisma/client"; import { getFileUrl } from "$lib/files/client"; + import * as m from "$paraglide/messages"; export let event: Pick< Event, | "title" @@ -11,6 +12,7 @@ | "shortDescription" | "description" | "imageUrl" + | "isCancelled" > & Partial>; @@ -21,17 +23,27 @@ {/if} -

- {event.title} - {#if event.removedAt} - Raderat +

+ {event.title} + {#if event.removedAt} + Raderat + {/if} +

+ {#if event.isCancelled} + {m.events_cancelled()} {/if} - + -
+
diff --git a/src/routes/(app)/events/EventEditor.svelte b/src/routes/(app)/events/EventEditor.svelte index 5021b103d..be99ff362 100644 --- a/src/routes/(app)/events/EventEditor.svelte +++ b/src/routes/(app)/events/EventEditor.svelte @@ -111,13 +111,13 @@ {#if $form.isRecurring}
@@ -141,6 +141,11 @@ />
{/if} +
{:else} - - {creating ? m.news_publish() : m.save()} - +
+ + {creating ? m.news_publish() : m.save()} + + {#if $form.isCancelled} + + {/if} +
{/if}