Skip to content

Commit

Permalink
feat(event): clean up postgres after content deletion (#89)
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 26, 2024
1 parent df0b274 commit 9e50c16
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 108 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

4 changes: 0 additions & 4 deletions .github/renovate.json

This file was deleted.

6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ pnpm playwright test example.spec.ts

Vil du klikke deg rundt i browser for å se hva som skjer i testene, sleng på `--ui` på slutten 🚀 Vi trenger flere tester 👷!

## Plausible

Plausible tilbyr en måte å analysere trafikk på nettstedet. Den er fritt for cookies og samler ingen personopplysninger. Vi trenger derfor ingen cookie consent. For å integrere Plausible er det lagt til et sporingsskriptet i HTML-headeren. Sporingen for å måle og analysere besøksstatistikk vises i et Sanity dashboard.

Vi er på en trial-plan foreløpig 👷

## Slack

Når et arrangement publiseres for første gang, vil det automatisk genereres en Slack-melding til kanalen #tmp_arrangementer. For å bygge meldingen kan man benytte [Block Kit Builder](https://app.slack.com/block-kit-builder). Denne tjenesten lar deg visuelt designe layouten av meldingen med ulike blokker som knapper, tekstfelter og bilder.
Expand Down
6 changes: 5 additions & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Use `.env` for any secrets, and ensure it is not added to source control
# Use `.env.local` for any local secrets, and ensure it is not added to source control

PUBLIC_APP_BASE_URL=""
APP_SECRET=""
APP_API_TOKEN=""
CRON_SECRET=""

PUBLIC_SANITY_PROJECT_ID=""
PUBLIC_SANITY_DATASET=""
Expand All @@ -15,6 +18,7 @@ GOOGLE_CLIENT_SECRET=""

PUBLIC_SUPABASE_URL=""
PUBLIC_SUPABASE_KEY=""
SUPABASE_CONNECTION_STRING=""

SMTP_HOST=""
SMTP_AUTH_USER=""
Expand Down
7 changes: 1 addition & 6 deletions app/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
<link rel="stylesheet" href="%sveltekit.assets%/global.css" />
<meta name="viewport" content="width=device-width" />
<meta name="description" content="Arrangementer | Capra Liflig Fryde">
<!-- Plausible is cookieless, collects no personal data, and does not engage in cross-site or cross-device tracking -->
<script
defer
data-domain="capra-web.vercel.app"
src="https://plausible.io/js/script.js"
></script>

%sveltekit.head%
</head>
<body
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/actions/internal/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const submitRegistrationInternal: Actions["submitRegistrationInternal"] =
}

if (foodPreference) {
await insertEventFoodPreference(transaction, { event_id, text: foodPreference });
await insertEventFoodPreference(transaction, { event_id, value: foodPreference });
}
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/server/kysley/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const insertEventParticipantOptions = async (

export const insertEventFoodPreference = async (
transaction: Transaction<KyselyDatabase>,
values: Pick<Tables<"event_food_preference">, "event_id" | "text">
values: Pick<Tables<"event_food_preference">, "event_id" | "value">
) => {
return await transaction.insertInto("event_food_preference").values(values).execute();
};
18 changes: 9 additions & 9 deletions app/src/models/database.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export type Database = {
Row: {
event_food_preference_id: number;
event_id: number;
text: string;
value: string | null;
};
Insert: {
event_food_preference_id?: number;
event_id: number;
text: string;
value?: string | null;
};
Update: {
event_food_preference_id?: number;
event_id?: number;
text?: string;
value?: string | null;
};
Relationships: [
{
Expand All @@ -47,8 +47,8 @@ export type Database = {
event_participant: {
Row: {
attending: boolean;
attending_digital: boolean | null;
created_at: string | null;
attending_digital: boolean;
created_at: string;
email: string;
event_id: number;
event_participant_id: number;
Expand All @@ -58,8 +58,8 @@ export type Database = {
};
Insert: {
attending?: boolean;
attending_digital?: boolean | null;
created_at?: string | null;
attending_digital?: boolean;
created_at?: string;
email: string;
event_id: number;
event_participant_id?: number;
Expand All @@ -69,8 +69,8 @@ export type Database = {
};
Update: {
attending?: boolean;
attending_digital?: boolean | null;
created_at?: string | null;
attending_digital?: boolean;
created_at?: string;
email?: string;
event_id?: number;
event_participant_id?: number;
Expand Down
7 changes: 3 additions & 4 deletions studio/.env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# Use `.env.local` for any local secrets, and ensure it is not added to source control

SANITY_STUDIO_PROJECT_ID=""
SANITY_STUDIO_DATASET=""
SANITY_STUDIO_PREVIEW_URL=""

SANITY_STUDIO_APP_BASE_URL=""
SANITY_STUDIO_APP_API_TOKEN=""

SANITY_STUDIO_SUPABASE_URL=""
SANITY_STUDIO_SUPABASE_KEY=""

SANITY_STUDIO_SLACK_HOOK=""

SANITY_STUDIO_APP_BASE_URL=""

SANITY_STUDIO_PLAUSIBLE_URL=""
2 changes: 2 additions & 0 deletions studio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/.pnp
.pnp.js
.env
.env.*
!.env.example

# Compiled Sanity Studio
/dist
Expand Down
33 changes: 33 additions & 0 deletions studio/actions/delete-event.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Event } from "../../app/src/models/sanity.model";
import { DocumentActionProps, DocumentActionComponent } from "sanity";
import { deleteEvent } from "../supabase/queries";

export function createExtendedEventDeleteAction(originalDeleteAction: DocumentActionComponent) {
const EventDeleteAction: DocumentActionComponent = (props: DocumentActionProps) => {
const originalResult = originalDeleteAction(props);
const publishedEvent = props.published as Event | null;

return {
...originalResult,
label: "Slett",
onHandle: () => {
if (publishedEvent) {
handleDeleteEvent(props.id);
}

if (originalResult?.onHandle) {
originalResult.onHandle();
}
},
};
};
return EventDeleteAction;
}

const handleDeleteEvent = async (id: string) => {
try {
await deleteEvent({ document_id: id });
} catch (error) {
console.error("Error handling event deletion:", error);
}
};
4 changes: 2 additions & 2 deletions studio/components/event/EventFoodPreference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export default function EventFoodPreference({ documentId }: { documentId: string
</Grid>

<Grid gap={4} style={{ maxHeight: "400px", overflowY: "scroll", marginTop: "3rem" }}>
{data.map(({ text }, index) => (
{data.map(({ value }, index) => (
<Card {...cardProps} key={index}>
<Stack space={4}>
<Flex align="center">
<Text>{text}</Text>
<Text>{value}</Text>
</Flex>
</Stack>
</Card>
Expand Down
1 change: 1 addition & 0 deletions studio/config/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { SanityImageSource } from "@sanity/image-url/lib/types/types";
export const client = createClient({
projectId: process.env.SANITY_STUDIO_PROJECT_ID,
dataset: process.env.SANITY_STUDIO_DATASET,
apiVersion: "2024-03-15",
useCdn: true,
});

Expand Down
5 changes: 4 additions & 1 deletion studio/lib/event-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const createSlackMessage = async (
id: string,
{ title, category, place, start, summary, image }: Event
) => {
const imageUrl = urlFor(image).width(400).url();
if (process.env.MODE === "development") return;

const imageUrl = image ? urlFor(image).width(400).url() : null;
const eventUrl = `${process.env.SANITY_STUDIO_APP_BASE_URL}/event/${id}`;

const startDate = new Date(start).toLocaleDateString("nb-NO", {
Expand Down Expand Up @@ -84,6 +86,7 @@ export const createSlackMessage = async (
fields,
});
}

try {
await fetch(process.env.SANITY_STUDIO_SLACK_HOOK!, {
method: "POST",
Expand Down
18 changes: 9 additions & 9 deletions studio/models/database.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export type Database = {
Row: {
event_food_preference_id: number;
event_id: number;
text: string;
value: string | null;
};
Insert: {
event_food_preference_id?: number;
event_id: number;
text: string;
value?: string | null;
};
Update: {
event_food_preference_id?: number;
event_id?: number;
text?: string;
value?: string | null;
};
Relationships: [
{
Expand All @@ -47,8 +47,8 @@ export type Database = {
event_participant: {
Row: {
attending: boolean;
attending_digital: boolean | null;
created_at: string | null;
attending_digital: boolean;
created_at: string;
email: string;
event_id: number;
event_participant_id: number;
Expand All @@ -58,8 +58,8 @@ export type Database = {
};
Insert: {
attending?: boolean;
attending_digital?: boolean | null;
created_at?: string | null;
attending_digital?: boolean;
created_at?: string;
email: string;
event_id: number;
event_participant_id?: number;
Expand All @@ -69,8 +69,8 @@ export type Database = {
};
Update: {
attending?: boolean;
attending_digital?: boolean | null;
created_at?: string | null;
attending_digital?: boolean;
created_at?: string;
email?: string;
event_id?: number;
event_participant_id?: number;
Expand Down
1 change: 0 additions & 1 deletion studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"react-dom": "^18.3.1",
"react-is": "^18.3.1",
"sanity": "^3.52.2",
"sanity-plugin-plausible-analytics": "^1.0.0",
"styled-components": "^6.1.11",
"xlsx": "^0.18.5"
},
Expand Down
42 changes: 0 additions & 42 deletions studio/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 9e50c16

@vercel
Copy link

@vercel vercel bot commented on 9e50c16 Jul 26, 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.