-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability for super admins to edit events (#160)
- Loading branch information
1 parent
85bd265
commit 04af57e
Showing
9 changed files
with
441 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use server"; | ||
|
||
import { superAdminAction } from "@/lib/safe-action"; | ||
import { newEventFormSchema as editEventFormSchema } from "@/validators/event"; | ||
import { editEvent as modifyEvent } from "db/functions"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export const editEvent = superAdminAction | ||
.schema(editEventFormSchema) | ||
.action(async ({ parsedInput }) => { | ||
const { id, ...options } = parsedInput; | ||
|
||
if (id === undefined) { | ||
throw new Error("The event's ID is not defined"); | ||
} | ||
|
||
try { | ||
await modifyEvent(id, options); | ||
revalidatePath("/admin/events"); | ||
revalidatePath("/dash/schedule"); | ||
revalidatePath(`/schedule/${id}`); | ||
} catch (e) { | ||
console.error(e); | ||
throw new Error( | ||
"Event update failed. Check the server console for errors.", | ||
); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getEventById } from "db/functions"; | ||
import { notFound } from "next/navigation"; | ||
import EditEventForm from "@/components/events/admin/EditEventForm"; | ||
|
||
export default async function EditEventPage({ | ||
params, | ||
}: { | ||
params: { slug: string }; | ||
}) { | ||
const eventId = parseInt(params.slug); | ||
|
||
if (!eventId) { | ||
return notFound(); | ||
} | ||
|
||
const event = await getEventById(eventId); | ||
|
||
if (!event) { | ||
return notFound(); | ||
} | ||
|
||
return ( | ||
<div className="mx-auto max-w-3xl pt-32"> | ||
<div className="grid grid-cols-2"> | ||
<h1 className="text-3xl font-bold tracking-tight"> | ||
Edit Event | ||
</h1> | ||
</div> | ||
<div className="mt-2 rounded-xl border border-muted p-5"> | ||
<EditEventForm {...event} /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.