managing rsvps
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
import AddFirstGuestBookEntryClient from '@/components/AddFirstGuestBookEntryClient'
|
||||
import AddGuestBookEntryModal from '@/components/AddGuestBookEntryModal'
|
||||
import CreateEventClient from '@/components/CreateEventClient'
|
||||
import DashboardNavbar from '@/components/DashboardNavbar'
|
||||
import EventInfoQuickView from '@/components/EventInfoQuickView'
|
||||
import GuestBookQuickView from '@/components/GuestBookQuickView'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
@@ -9,32 +13,21 @@ import React from 'react'
|
||||
export default async function DashboardPage() {
|
||||
const events = await queries.fetchEvents();
|
||||
const guestBookEntries = await queries.fetchGuestBookEntries(5);
|
||||
const session = await getServerSession()
|
||||
const session = await getServerSession();
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: session?.user.email }
|
||||
})
|
||||
// console.log(events)
|
||||
|
||||
return (
|
||||
<div className='max-w-[100rem] mx-auto'>
|
||||
<div className='grid grid-cols-5 grid-rows-5 gap-4'>
|
||||
<div className='row-span-5 bg-[#00000008] rounded-xl p-6'>
|
||||
<div className='py-4'>
|
||||
<h2 className='text-lg font-semibold'>Hello, {user?.username}</h2>
|
||||
</div>
|
||||
<div className='bg-brand-primary-800 p-4 rounded-lg'>Overview</div>
|
||||
</div>
|
||||
<div className='col-span-3 row-span-3 bg-[#00000008] rounded-xl p-6 relative'>
|
||||
<div className='grid grid-cols-7 gap-4'>
|
||||
<div className='col-span-5 row-span-3 bg-[#00000008] rounded-xl p-6 relative'>
|
||||
<div>
|
||||
<div className='w-full flex items-center justify-between'>
|
||||
<h2 className='text-lg font-semibold py-4'>Your Events</h2>
|
||||
<button
|
||||
className='btn btn-primary h-fit'
|
||||
>
|
||||
Create Event
|
||||
</button>
|
||||
<CreateEventClient />
|
||||
</div>
|
||||
{!events.length && <>You don't have any events yet. Create your first event.</>}
|
||||
<div className='grid grid-cols-3'>
|
||||
{events.map((item) => (
|
||||
<EventInfoQuickView key={item.id} {...item} />
|
||||
@@ -45,7 +38,7 @@ export default async function DashboardPage() {
|
||||
View all
|
||||
</Link>
|
||||
</div>
|
||||
<div className='row-span-5 col-start-5 bg-[#00000008] rounded-xl p-6'>
|
||||
<div className='row-span-5 col-start-6 col-span-2 bg-[#00000008] rounded-xl p-6'>
|
||||
<div className='py-4 flex justify-between'>
|
||||
<h2 className='text-lg font-semibold'>Guest Book</h2>
|
||||
<Link
|
||||
@@ -56,34 +49,12 @@ export default async function DashboardPage() {
|
||||
</Link>
|
||||
</div>
|
||||
<div className='space-y-2'>
|
||||
{!guestBookEntries.length && <AddFirstGuestBookEntryClient />}
|
||||
{guestBookEntries.map(entry => (
|
||||
<GuestBookQuickView key={entry.id} {...entry} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className='border rounded-lg max-w-6xl mx-auto p-6 space-y-4'>
|
||||
<h2 className='text-xl font-bold'>Your Events</h2>
|
||||
{events.map((item) => (
|
||||
<Link key={item.id} href={`/events/${item.id}`} >
|
||||
<div className='hover:cursor-pointer border rounded-xl p-2'>
|
||||
<p>ID: {item.id}</p>
|
||||
<p>Name: <strong>{item.name}</strong></p>
|
||||
<p>Date: {item.date ? item.date.toISOString() : 'null'}</p>
|
||||
<p>Location: {item.location ? item.location : 'null'}</p>
|
||||
<p>Created By: {item.creator.username}</p>
|
||||
<p>Created At: {item.createdAt.toISOString()}</p>
|
||||
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
<Link
|
||||
href={'/events'}
|
||||
className='underline'
|
||||
>
|
||||
See all events
|
||||
</Link>
|
||||
</div> */}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,16 +9,13 @@ export default async function SingleEventPage({ params }: { params: { eventId: s
|
||||
console.log(data)
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className='max-w-[100rem] mx-auto'>
|
||||
{data ? (
|
||||
// @ts-ignore
|
||||
<EventInfoDisplay event={data} />
|
||||
) : (
|
||||
<p className="text-center text-gray-500 mt-10">Event not found.</p>
|
||||
)}
|
||||
{data?.name && (
|
||||
<HeadingWithEdit title={data?.name} eventId={data.id} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
'use client'
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function CreateEventPage() {
|
||||
const [name, setName] = useState('');
|
||||
const router = useRouter();
|
||||
|
||||
async function handleSubmit(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
const res = await fetch('/api/events', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ name }),
|
||||
});
|
||||
const data = await res.json();
|
||||
router.push(`/events/${data.id}`);
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="max-w-md space-y-4">
|
||||
<h2 className="text-xl font-bold">Create Event</h2>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Event Name"
|
||||
className="input input-bordered w-full"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
<button className="btn btn-primary">Create</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -1,19 +1,22 @@
|
||||
'use client'
|
||||
|
||||
import { SessionProvider, useSession } from 'next-auth/react'
|
||||
import { SessionProvider } from 'next-auth/react'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { ReactNode } from 'react'
|
||||
import Navbar from '@/components/Navbar'
|
||||
import DashboardNavbar from '@/components/DashboardNavbar'
|
||||
|
||||
export default function AuthLayout({ children }: { children: ReactNode }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SessionProvider>
|
||||
<Navbar />
|
||||
<main className="p-4">
|
||||
{/* Could also add a private header here */}
|
||||
{children}
|
||||
<main className="p-4 max-w-[100rem] mx-auto">
|
||||
<div className='grid grid-cols-5 gap-4'>
|
||||
<DashboardNavbar />
|
||||
<section className="col-span-4">
|
||||
{children}
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</SessionProvider>
|
||||
</>
|
||||
|
||||
@@ -14,11 +14,11 @@ export default function SetupPage() {
|
||||
|
||||
const res = await fetch('/api/setup', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ email, password, role }),
|
||||
body: JSON.stringify({ username, email, password, role }),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
await signIn('credentials', { email, password, callbackUrl: '/' });
|
||||
await signIn('credentials', { username, email, password, callbackUrl: '/' });
|
||||
} else {
|
||||
alert('Error setting up user');
|
||||
}
|
||||
|
||||
@@ -3,14 +3,14 @@ import { mutations } from '@/lib/mutations'
|
||||
|
||||
export async function POST(req: NextRequest, { params }: { params: { eventId: string } }) {
|
||||
const eventId = params.eventId
|
||||
const { guestBookEntryId } = await req.json()
|
||||
const { guestId } = await req.json() // ← match client
|
||||
|
||||
if (!eventId || !guestBookEntryId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestBookEntryId' }, { status: 400 })
|
||||
if (!eventId || !guestId) {
|
||||
return NextResponse.json({ message: 'Missing eventId or guestId' }, { status: 400 })
|
||||
}
|
||||
|
||||
try {
|
||||
const added = await mutations.addEventGuest({ eventId, guestBookEntryId })
|
||||
const added = await mutations.addEventGuest({ eventId, guestBookEntryId: guestId }) // ← match expected arg
|
||||
return NextResponse.json(added)
|
||||
} catch (error) {
|
||||
console.error('Add Event Guest Error:', error)
|
||||
|
||||
24
app/api/events/create/route.ts
Normal file
24
app/api/events/create/route.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
import { prisma } from '@/lib/prisma'
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user?.id) {
|
||||
return new NextResponse('Unauthorized', { status: 403 })
|
||||
}
|
||||
|
||||
const { name, date, location } = await req.json()
|
||||
|
||||
const event = await prisma.event.create({
|
||||
data: {
|
||||
name,
|
||||
date: date ? new Date(date) : undefined,
|
||||
location,
|
||||
creatorId: session.user.id,
|
||||
},
|
||||
})
|
||||
|
||||
return NextResponse.json(event)
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
|
||||
import { mutations } from '@/lib/mutations';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const session = await getServerSession(authOptions)
|
||||
if (!session?.user) return new NextResponse('Unauthorized', { status: 401 });
|
||||
|
||||
const body = await req.json();
|
||||
const { name, date, location } = body;
|
||||
|
||||
const event = await mutations.createEvent({
|
||||
name,
|
||||
date,
|
||||
location,
|
||||
creatorId: session.user.id,
|
||||
});
|
||||
|
||||
return NextResponse.json(event)
|
||||
}
|
||||
29
app/api/guestbook/search/route.ts
Normal file
29
app/api/guestbook/search/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// api/guestbook/search/route.ts
|
||||
import { prisma } from '@/lib/prisma'
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const { searchParams } = new URL(req.url)
|
||||
const query = searchParams.get('search') // ✅ Match the client-side key
|
||||
|
||||
if (!query || query.length < 2) {
|
||||
return NextResponse.json([], { status: 200 })
|
||||
}
|
||||
|
||||
const results = await prisma.guestBookEntry.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ fName: { contains: query, mode: 'insensitive' } },
|
||||
{ lName: { contains: query, mode: 'insensitive' } },
|
||||
{ email: { contains: query, mode: 'insensitive' } },
|
||||
]
|
||||
},
|
||||
orderBy: [
|
||||
{ lName: 'asc' },
|
||||
{ fName: 'asc' },
|
||||
],
|
||||
take: 10
|
||||
})
|
||||
|
||||
return NextResponse.json(results)
|
||||
}
|
||||
Reference in New Issue
Block a user