venues and ui changes

This commit is contained in:
2025-07-24 09:42:57 -04:00
parent 049def6886
commit 27590f9509
24 changed files with 757 additions and 164 deletions

View File

@@ -1,55 +1,57 @@
import AddFirstGuestBookEntryClient from '@/components/AddFirstGuestBookEntryClient'
import CreateEventClient from '@/components/CreateEventClient'
import EventInfoQuickView from '@/components/EventInfoQuickView'
import GuestBookQuickView from '@/components/GuestBookQuickView'
import DashboardEvents from '@/components/dashboard/DashboardEvents'
import DashboardGuestBook from '@/components/dashboard/DashboardGuestBook'
import { queries } from '@/lib/queries'
import Link from 'next/link'
import React from 'react'
export default async function DashboardPage() {
const events = await queries.fetchEvents();
const events = await queries.fetchQuickViewEvents();
const guestBookData = await queries.fetchGuestBookEntries({ takeOnlyRecent: 5 });
const guestBookEntries = Array.isArray(guestBookData) ? guestBookData : guestBookData.entries;
return (
<div className='grid grid-cols-1 md:grid-cols-7 gap-4'>
<div className='md:col-span-5 md:row-span-3 bg-[#00000008] rounded-xl p-4 md:p-6 relative'>
<div>
<div className='w-full flex items-center justify-between'>
<h2 className='text-lg font-semibold py-4'>Your Events</h2>
<CreateEventClient />
<>
<div className='grid grid-cols-1 md:grid-cols-7 gap-4'>
<DashboardEvents events={events} />
<DashboardGuestBook guestBookEntries={guestBookEntries} />
{/* <div className='md:col-span-5 md:row-span-3 bg-[#00000008] rounded-xl p-4 md:p-6 relative'>
<div>
<div className='w-full flex items-center justify-between'>
<h2 className='text-lg font-semibold py-4'>Your Events</h2>
<CreateEventClient />
</div>
{!events.length && <>You don&apos;t have any events yet. Create your first event.</>}
<div className='grid grid-cols-1 md:grid-cols-3 gap-4'>
{events.map((item) => (
<EventInfoQuickView key={item.id} {...item} />
))}
</div>
</div>
{!events.length && <>You don&apos;t have any events yet. Create your first event.</>}
<div className='grid grid-cols-1 md:grid-cols-3 gap-4'>
{events.map((item) => (
<EventInfoQuickView key={item.id} {...item} />
<div className='w-full text-right mt-2'>
<Link href={'/events'} className='md:absolute bottom-4 right-4 text-sm text-brand-primary-400 hover:underline'>
View all
</Link>
</div>
</div>
<div className='md:row-span-5 md: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
href={'/guest-book'}
className='hover:cursor-pointer hover:underline text-brand-primary-500'
>
View All
</Link>
</div>
<div className='space-y-2'>
{!guestBookEntries.length && <AddFirstGuestBookEntryClient />}
{guestBookEntries.map(entry => (
<GuestBookQuickView key={entry.id} {...entry} />
))}
</div>
</div>
<div className='w-full text-right mt-2'>
<Link href={'/events'} className='md:absolute bottom-4 right-4 text-sm text-brand-primary-400 hover:underline'>
View all
</Link>
</div>
</div> */}
</div>
<div className='md:row-span-5 md: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
href={'/guest-book'}
className='hover:cursor-pointer hover:underline text-brand-primary-500'
>
View All
</Link>
</div>
<div className='space-y-2'>
{!guestBookEntries.length && <AddFirstGuestBookEntryClient />}
{guestBookEntries.map(entry => (
<GuestBookQuickView key={entry.id} {...entry} />
))}
</div>
</div>
</div>
</>
)
}

View File

@@ -1,13 +0,0 @@
import LocationsTable from '@/components/tables/LocationsTable'
import { queries } from '@/lib/queries'
import React from 'react'
export default async function LocationsPage() {
const eventLocations = await queries.fetchAllLocations()
return (
<div>
<LocationsTable eventLocations={eventLocations} />
</div>
)
}

View File

@@ -0,0 +1,13 @@
import VenuesTable from '@/components/tables/VenuesTable'
import { queries } from '@/lib/queries'
import React from 'react'
export default async function LocationsPage() {
const venues = await queries.fetchAllLocations()
return (
<div>
<VenuesTable eventLocations={venues} />
</div>
)
}

View File

@@ -0,0 +1,47 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
export async function GET(
req: NextRequest,
{ params }: { params: { eventId: string } }
) {
const session = await getServerSession(authOptions)
if (!session?.user) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
try {
const event = await prisma.event.findUnique({
where: { id: params.eventId },
include: {
creator: {
select: { id: true, name: true, email: true, role: true }
},
venue: true,
todos: {
orderBy: [
{ complete: 'asc' },
{ dueDate: 'asc' }
]
},
eventGuests: {
include: {
guestBookEntry: true
}
}
}
})
if (!event) {
return NextResponse.json({ message: 'Event not found' }, { status: 404 })
}
return NextResponse.json(event)
} catch (err) {
console.error(err)
return NextResponse.json({ message: 'Error fetching event' }, { status: 500 })
}
}

View File

@@ -1,27 +1,29 @@
import { NextRequest, NextResponse } from 'next/server';
import { mutations } from '@/lib/mutations';
import { getServerSession } from 'next-auth';
import { authOptions } from '../../auth/[...nextauth]/route';
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
export async function PATCH(req: NextRequest, { params }: { params: { eventId: string } }) {
const session = await getServerSession(authOptions);
const session = await getServerSession(authOptions)
if (!session?.user) {
return new NextResponse('Unauthorized', { status: 401 });
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
const eventId = params.eventId;
const body = await req.json();
const body = await req.json()
try {
const updated = await mutations.updateEvent(eventId, {
name: body.name,
date: body.date,
location: body.location,
notes: body.notes,
});
return NextResponse.json(updated);
} catch (error) {
console.error('[PATCH EVENT]', error);
return new NextResponse('Failed to update event', { status: 500 });
const updated = await prisma.event.update({
where: { id: params.eventId },
data: {
name: body.name,
date: body.date ? new Date(body.date) : undefined,
venueId: body.venueId || null,
},
})
return NextResponse.json(updated)
} catch (err) {
console.error(err)
return NextResponse.json({ message: 'Error updating event' }, { status: 500 })
}
}

View File

@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions)
if (!session?.user) {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 })
}
const body = await req.json()
try {
const venue = await prisma.venue.create({
data: {
name: body.name,
address: body.address,
city: body.city,
state: body.state,
postalCode: body.postalCode,
country: body.country,
phone: body.phone || undefined,
email: body.email || undefined
}
})
return NextResponse.json(venue)
} catch (err) {
console.error(err)
return NextResponse.json({ message: 'Error creating venue' }, { status: 500 })
}
}

View File

@@ -0,0 +1,12 @@
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function GET() {
try {
const venues = await prisma.venue.findMany()
return NextResponse.json(venues)
} catch (error) {
console.error('Failed to fetch venues:', error)
return new NextResponse('Failed to fetch venues', { status: 500 })
}
}