feat: save the date tracking
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"use server"
|
||||
|
||||
import { revalidatePath } from "next/cache"
|
||||
|
||||
import { auth } from "@/auth"
|
||||
import { isAdminEmail } from "@/lib/admin-auth"
|
||||
import { updateSaveTheDateSent } from "@/lib/db/queries/invitations"
|
||||
import { updateSaveTheDateSentSchema } from "@/lib/validation/invitation"
|
||||
|
||||
export interface UpdateSaveTheDateSentResult {
|
||||
ok: boolean
|
||||
error: string | null
|
||||
}
|
||||
|
||||
export async function updateSaveTheDateSentAction(input: {
|
||||
invitationId: string
|
||||
sent: boolean
|
||||
}): Promise<UpdateSaveTheDateSentResult> {
|
||||
const session = await auth()
|
||||
const adminEmail = session?.user?.email
|
||||
|
||||
if (!isAdminEmail(adminEmail)) {
|
||||
return { ok: false, error: "You are not allowed to update invitations." }
|
||||
}
|
||||
|
||||
const parsed = updateSaveTheDateSentSchema.safeParse(input)
|
||||
|
||||
if (!parsed.success) {
|
||||
return { ok: false, error: "Could not update save-the-date status." }
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await updateSaveTheDateSent({
|
||||
invitationId: parsed.data.invitationId,
|
||||
sent: parsed.data.sent,
|
||||
adminEmail: adminEmail ?? "",
|
||||
})
|
||||
|
||||
if (!updated) {
|
||||
return { ok: false, error: "This guest group no longer exists." }
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to update save-the-date status", error)
|
||||
return { ok: false, error: "Could not update save-the-date status." }
|
||||
}
|
||||
|
||||
revalidatePath("/admin/guests")
|
||||
revalidatePath("/admin")
|
||||
|
||||
return { ok: true, error: null }
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import Link from "next/link"
|
||||
|
||||
import { CopyInviteButton } from "@/components/admin/copy-invite-button"
|
||||
import { SaveTheDateCheckbox } from "@/components/admin/save-the-date-checkbox"
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
@@ -91,6 +92,7 @@ export default async function GuestsPage({
|
||||
<TableHead>Language</TableHead>
|
||||
<TableHead>Members</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Save the date</TableHead>
|
||||
<TableHead>Contact</TableHead>
|
||||
<TableHead className="text-right">Actions</TableHead>
|
||||
</TableRow>
|
||||
@@ -127,6 +129,13 @@ export default async function GuestsPage({
|
||||
{invitation.derivedStatus}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<SaveTheDateCheckbox
|
||||
invitationId={invitation.id}
|
||||
displayName={invitation.displayName}
|
||||
sent={invitation.saveTheDateSentAt !== null}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="space-y-1 text-sm">
|
||||
<p>{invitation.contactEmail ?? "—"}</p>
|
||||
|
||||
Reference in New Issue
Block a user