theming, date, time localisation, additional features, seeding initial cleanup
This commit is contained in:
@@ -5,14 +5,14 @@ import { timeSlots } from '@/lib/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { logActivity, ACTIONS, ENTITY_TYPES } from '@/lib/activity-logger';
|
||||
|
||||
export async function PUT(request: NextRequest, { params }: { params: { id: string } }) {
|
||||
export async function PUT(request: NextRequest, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session || session.role !== 'admin') {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = params;
|
||||
const { id } = await context.params;
|
||||
const { dayOfWeek, startTime, endTime, isActive } = await request.json();
|
||||
|
||||
// Check if time slot exists
|
||||
@@ -68,14 +68,14 @@ export async function PUT(request: NextRequest, { params }: { params: { id: stri
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
|
||||
export async function DELETE(request: NextRequest, context: { params: Promise<{ id: string }> }) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session || session.role !== 'admin') {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { id } = params;
|
||||
const { id } = await context.params;
|
||||
|
||||
// Check if time slot exists
|
||||
const existingTimeSlot = await db.select().from(timeSlots).where(eq(timeSlots.id, id)).limit(1);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getSession } from '@/lib/session';
|
||||
import { db } from '@/lib/db';
|
||||
import { bookings } from '@/lib/db/schema';
|
||||
import { bookings, settings } from '@/lib/db/schema';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { logActivity, ACTIONS, ENTITY_TYPES } from '@/lib/activity-logger';
|
||||
|
||||
@@ -28,15 +28,38 @@ export async function PATCH(request: NextRequest, { params }: { params: { id: st
|
||||
|
||||
const booking = existingBooking[0];
|
||||
|
||||
// Check if booking can be modified (more than 2 hours before start time)
|
||||
// Check if booking modifications are allowed
|
||||
const modificationSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'allow_booking_modifications'))
|
||||
.limit(1);
|
||||
|
||||
if (modificationSetting.length > 0 && modificationSetting[0].value !== 'true') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking modifications are currently disabled by administrator' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get the time restriction setting
|
||||
const timeSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'booking_modification_hours_before'))
|
||||
.limit(1);
|
||||
|
||||
const requiredHours = timeSetting.length > 0 ? parseFloat(timeSetting[0].value) : 2;
|
||||
|
||||
// Check if booking can be modified (more than required hours before start time)
|
||||
const bookingDateTime = new Date(`${booking.date}T${booking.startTime}`);
|
||||
const now = new Date();
|
||||
const timeDiff = bookingDateTime.getTime() - now.getTime();
|
||||
const hoursDiff = timeDiff / (1000 * 60 * 60);
|
||||
|
||||
if (hoursDiff <= 2) {
|
||||
if (hoursDiff <= requiredHours) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking can only be modified more than 2 hours before the session' },
|
||||
{ error: `Booking can only be modified more than ${requiredHours} hours before the session` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
@@ -97,15 +120,38 @@ export async function DELETE(request: NextRequest, { params }: { params: { id: s
|
||||
|
||||
const booking = existingBooking[0];
|
||||
|
||||
// Check if booking can be cancelled (more than 2 hours before start time)
|
||||
// Check if booking modifications are allowed
|
||||
const modificationSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'allow_booking_modifications'))
|
||||
.limit(1);
|
||||
|
||||
if (modificationSetting.length > 0 && modificationSetting[0].value !== 'true') {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking modifications are currently disabled by administrator' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Get the time restriction setting
|
||||
const timeSetting = await db
|
||||
.select()
|
||||
.from(settings)
|
||||
.where(eq(settings.key, 'booking_modification_hours_before'))
|
||||
.limit(1);
|
||||
|
||||
const requiredHours = timeSetting.length > 0 ? parseFloat(timeSetting[0].value) : 2;
|
||||
|
||||
// Check if booking can be cancelled (more than required hours before start time)
|
||||
const bookingDateTime = new Date(`${booking.date}T${booking.startTime}`);
|
||||
const now = new Date();
|
||||
const timeDiff = bookingDateTime.getTime() - now.getTime();
|
||||
const hoursDiff = timeDiff / (1000 * 60 * 60);
|
||||
|
||||
if (hoursDiff <= 2) {
|
||||
if (hoursDiff <= requiredHours) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Booking can only be cancelled more than 2 hours before the session' },
|
||||
{ error: `Booking can only be cancelled more than ${requiredHours} hours before the session` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ export async function GET(request: NextRequest) {
|
||||
name: users.name,
|
||||
surname: users.surname,
|
||||
role: users.role,
|
||||
themePreference: users.themePreference,
|
||||
createdAt: users.createdAt,
|
||||
})
|
||||
.from(users)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getSession } from '@/lib/session';
|
||||
import { db } from '@/lib/db';
|
||||
import { users } from '@/lib/db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const user = await db
|
||||
.select({
|
||||
themePreference: users.themePreference,
|
||||
})
|
||||
.from(users)
|
||||
.where(eq(users.id, session.userId))
|
||||
.limit(1);
|
||||
|
||||
if (user.length === 0) {
|
||||
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
themePreference: user[0].themePreference,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching theme preference:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const { themePreference } = await request.json();
|
||||
|
||||
if (!themePreference || !['light', 'dark', 'system'].includes(themePreference)) {
|
||||
return NextResponse.json({ error: 'Invalid theme preference' }, { status: 400 });
|
||||
}
|
||||
|
||||
await db
|
||||
.update(users)
|
||||
.set({
|
||||
themePreference,
|
||||
updatedAt: new Date(),
|
||||
})
|
||||
.where(eq(users.id, session.userId));
|
||||
|
||||
return NextResponse.json({
|
||||
message: 'Theme preference updated successfully',
|
||||
themePreference,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error updating theme preference:', error);
|
||||
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export default async function DashboardPage() {
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100'>
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800'>
|
||||
<DashboardHeader user={userWithSession} />
|
||||
|
||||
<main className='container mx-auto px-4 py-8'>
|
||||
@@ -46,12 +46,12 @@ export default async function DashboardPage() {
|
||||
{/* Main Content */}
|
||||
<div className='lg:col-span-2 space-y-6'>
|
||||
<div>
|
||||
<h1 className='text-3xl font-bold text-gray-900 mb-2'>
|
||||
<h1 className='text-3xl font-bold text-foreground mb-2'>
|
||||
Welcome back,{' '}
|
||||
{user.name && user.surname ? `${user.name} ${user.surname}` : user.email.split('@')[0]}!
|
||||
🏓
|
||||
</h1>
|
||||
<p className='text-gray-600'>Book your table tennis court and enjoy your game</p>
|
||||
<p className='text-muted-foreground'>Book your table tennis court and enjoy your game</p>
|
||||
</div>
|
||||
|
||||
<EnhancedBookingCalendar />
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
return (
|
||||
<html lang='en' suppressHydrationWarning>
|
||||
<body className={inter.className}>
|
||||
<ThemeProvider attribute='class' defaultTheme='light' enableSystem disableTransitionOnChange>
|
||||
<ThemeProvider attribute='class' defaultTheme='system' enableSystem disableTransitionOnChange>
|
||||
{children}
|
||||
<Toaster />
|
||||
</ThemeProvider>
|
||||
|
||||
+5
-5
@@ -3,18 +3,18 @@ import { LoginForm } from '@/components/auth/LoginForm';
|
||||
|
||||
export default function LoginPage() {
|
||||
return (
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center px-4'>
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 flex items-center justify-center px-4'>
|
||||
<div className='w-full max-w-md space-y-6'>
|
||||
<div className='text-center'>
|
||||
<h1 className='text-3xl font-bold text-gray-900 mb-2'>🏓 TT Booking</h1>
|
||||
<p className='text-gray-600'>Professional table tennis court booking system</p>
|
||||
<h1 className='text-3xl font-bold text-foreground mb-2'>🏓 TT Booking</h1>
|
||||
<p className='text-muted-foreground'>Professional table tennis court booking system</p>
|
||||
</div>
|
||||
|
||||
<LoginForm />
|
||||
|
||||
<div className='text-center text-sm'>
|
||||
<span className='text-gray-600'>Don't have an account? </span>
|
||||
<Link href='/register' className='text-blue-600 hover:text-blue-800 font-medium'>
|
||||
<span className='text-muted-foreground'>Don't have an account? </span>
|
||||
<Link href='/register' className='text-primary hover:text-primary/80 font-medium'>
|
||||
Sign up
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -3,18 +3,18 @@ import { RegisterForm } from '@/components/auth/RegisterForm';
|
||||
|
||||
export default function RegisterPage() {
|
||||
return (
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex items-center justify-center px-4'>
|
||||
<div className='min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 dark:from-gray-900 dark:to-gray-800 flex items-center justify-center px-4'>
|
||||
<div className='w-full max-w-md space-y-6'>
|
||||
<div className='text-center'>
|
||||
<h1 className='text-3xl font-bold text-gray-900 mb-2'>🏓 TT Booking</h1>
|
||||
<p className='text-gray-600'>Join our table tennis community</p>
|
||||
<h1 className='text-3xl font-bold text-foreground mb-2'>🏓 TT Booking</h1>
|
||||
<p className='text-muted-foreground'>Join our table tennis community</p>
|
||||
</div>
|
||||
|
||||
<RegisterForm />
|
||||
|
||||
<div className='text-center text-sm'>
|
||||
<span className='text-gray-600'>Already have an account? </span>
|
||||
<Link href='/login' className='text-blue-600 hover:text-blue-800 font-medium'>
|
||||
<span className='text-muted-foreground'>Already have an account? </span>
|
||||
<Link href='/login' className='text-primary hover:text-primary/80 font-medium'>
|
||||
Sign in
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user