diff --git a/README.md b/README.md index 2fa546d..6be715a 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,10 @@ Design drodling finner man her: [Nettside design](https://www.figma.com/design/Z ## Komme i gang -For å kjøre koden loaklt: +For å kjøre koden lokalt: 1. Be om environment variabler for lokal testing i kanalen [#tmp_arrangementsoversikt](). - Du må selv opprette en `.env.local` fil i /studio og /app. + Du må selv opprette en `.env.local` fil i både /studio og /app. Hvis du trenger tilgang til Sanity Studio, eventuelt Google Console, Vercel og Supabase, må dette også spesifikt forespørres. diff --git a/app/src/app.html b/app/src/app.html index a8c568b..251ad04 100644 --- a/app/src/app.html +++ b/app/src/app.html @@ -5,7 +5,7 @@ - + %sveltekit.head% diff --git a/app/src/components/external/UnregistrationFormExternal.svelte b/app/src/components/external/UnregistrationFormExternal.svelte index dd9165d..54c1d47 100644 --- a/app/src/components/external/UnregistrationFormExternal.svelte +++ b/app/src/components/external/UnregistrationFormExternal.svelte @@ -20,12 +20,12 @@

Ønsker du å melde deg av?

diff --git a/app/src/components/shared/EventSummary.svelte b/app/src/components/shared/EventSummary.svelte index e636ad6..5f81810 100644 --- a/app/src/components/shared/EventSummary.svelte +++ b/app/src/components/shared/EventSummary.svelte @@ -43,7 +43,7 @@
diff --git a/app/src/components/shared/Footer.svelte b/app/src/components/shared/Footer.svelte index 1fe7f4a..0b2ba61 100644 --- a/app/src/components/shared/Footer.svelte +++ b/app/src/components/shared/Footer.svelte @@ -20,31 +20,31 @@
Sertifiseringer
Miljøfyrtårn-sertifisering - DNV-sertifisering - + DNV-sertifisering +
diff --git a/app/src/models/database.model.ts b/app/src/models/database.model.ts index 51b3b76..b0c8496 100644 --- a/app/src/models/database.model.ts +++ b/app/src/models/database.model.ts @@ -44,6 +44,32 @@ export type Database = { }, ]; }; + event_invitation: { + Row: { + email: string; + event_id: number; + full_name: string | null; + }; + Insert: { + email: string; + event_id: number; + full_name?: string | null; + }; + Update: { + email?: string; + event_id?: number; + full_name?: string | null; + }; + Relationships: [ + { + foreignKeyName: "event_invitation_event_id_fkey"; + columns: ["event_id"]; + isOneToOne: false; + referencedRelation: "event"; + referencedColumns: ["event_id"]; + }, + ]; + }; event_participant: { Row: { attending: boolean; diff --git a/studio/components/event/EventFoodPreference.tsx b/studio/components/event/EventFoodPreference.tsx index f667db4..b48b61c 100644 --- a/studio/components/event/EventFoodPreference.tsx +++ b/studio/components/event/EventFoodPreference.tsx @@ -1,12 +1,12 @@ import React from "react"; import { useQuery } from "@tanstack/react-query"; import { Card, Flex, Grid, Heading, Spinner, Stack, Text } from "@sanity/ui"; -import { getEventFoodPreferences } from "../../supabase/queries"; +import { getEventFoodPreferenceList } from "../../supabase/queries"; export default function EventFoodPreference({ documentId }: { documentId: string }) { const { data, isLoading, isError } = useQuery({ queryKey: ["event-food-preference-list", documentId], - queryFn: () => getEventFoodPreferences({ documentId }), + queryFn: () => getEventFoodPreferenceList({ documentId }), }); const cardProps = { border: true, padding: 3, radius: 2 }; diff --git a/studio/components/event/EventInvitation.tsx b/studio/components/event/EventInvitation.tsx new file mode 100644 index 0000000..b3a370f --- /dev/null +++ b/studio/components/event/EventInvitation.tsx @@ -0,0 +1,207 @@ +import React, { useState } from "react"; +import { useQuery, useQueryClient } from "@tanstack/react-query"; +import { + Box, + Button, + Card, + Flex, + Grid, + Heading, + Label, + Spinner, + Stack, + Text, + TextInput, + useToast, +} from "@sanity/ui"; +import { getEvent, getEventInvitationList, insertInvitation } from "../../supabase/queries"; +import { AddIcon } from "@sanity/icons"; + +export default function EventInvitation({ documentId }: { documentId: string }) { + const toast = useToast(); + + const [email, setEmail] = useState(""); + const [fullName, setFullName] = useState(""); + + const { data: event } = useQuery({ + queryKey: ["event", documentId], + queryFn: () => getEvent({ document_id: documentId }), + }); + + const { data, isLoading, isError } = useQuery({ + queryKey: ["event-invitation-list", documentId], + queryFn: () => getEventInvitationList({ documentId }), + }); + + const queryClient = useQueryClient(); + + async function handleInvitationAdd() { + const emailRegex = new RegExp("^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{1,}$"); + if (!email || !emailRegex.test(email)) return; + + try { + await insertInvitation({ document_id: documentId }, { full_name: fullName, email }); + + queryClient.invalidateQueries({ queryKey: ["event-invitation-list"] }); + + setEmail(""); + setFullName(""); + + toast.push({ + status: "success", + title: `${email} ble lagt til i listen`, + }); + } catch (error) { + if (error instanceof Error) { + toast.push({ + status: "error", + title: error.message, + }); + } + } + } + + const cardProps = { border: true, padding: 3, radius: 2 }; + + if (isLoading) { + return ( + + + + ); + } + + if (isError) + return ( + + + Arrangement + + + En feil har oppstått + + + ); + + if (!data?.length) { + return ( + + + Arrangement + + + Ingen invitasjoner + + + {event?.data ? ( + <> + + + + Fulltnavn + + setFullName(event.currentTarget.value)} + padding={2} + value={fullName} + /> + + + + E-post* + + setEmail(event.currentTarget.value)} + padding={2} + value={email} + /> + + + +