Initial commit: Timepickr event scheduling app

- Next.js 14 with App Router and TypeScript
- Prisma ORM with PostgreSQL database
- Event creation with share links
- Calendar availability selection
- Password-protected analytics dashboard
- Stripe-inspired UI design
- Docker configuration for deployment
This commit is contained in:
2026-01-04 20:46:16 +00:00
commit 6f5e7b74b7
31 changed files with 9290 additions and 0 deletions

8
.env.example Normal file
View File

@@ -0,0 +1,8 @@
# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/timepickr?schema=public"
# For Docker
# DATABASE_URL="postgresql://postgres:postgres@db:5432/timepickr?schema=public"
# App
NEXT_PUBLIC_APP_URL="http://localhost:3000"

44
.gitignore vendored Normal file
View File

@@ -0,0 +1,44 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*
# env files (can opt-in for committing if needed)
.env*
!.env.example
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
/src/generated/prisma

49
Dockerfile Normal file
View File

@@ -0,0 +1,49 @@
# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
# Install dependencies
COPY package*.json ./
RUN npm ci --only=production=false
# Stage 2: Build
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Generate Prisma client
RUN npx prisma generate
# Build Next.js
ENV NEXT_TELEMETRY_DISABLED=1
RUN npm run build
# Stage 3: Production
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Add non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
USER nextjs
EXPOSE 3000
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

10
Dockerfile.migrate Normal file
View File

@@ -0,0 +1,10 @@
# Migration Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY prisma ./prisma
CMD ["npx", "prisma", "migrate", "deploy"]

99
README.md Normal file
View File

@@ -0,0 +1,99 @@
# Timepickr
A modern event scheduling app that helps groups find the perfect time to meet. Create an event, share a link, and let everyone pick their available dates.
![Timepickr](https://img.shields.io/badge/Next.js-14-black) ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-16-blue) ![Docker](https://img.shields.io/badge/Docker-Ready-2496ED)
## Features
- 📅 **Easy Event Creation** - Set a date range and get a shareable link instantly
- 🗓️ **Visual Calendar** - Guests can click to select their available dates
- 📊 **Analytics Dashboard** - See who's available when with a heatmap view
- 🔒 **Password Protected** - Only you can access the analytics
- 🐳 **Dockerized** - Deploy anywhere with a single command
## Quick Start
### Using Docker (Recommended)
```bash
# Clone the repository
git clone <your-repo-url>
cd timepickr
# Start the application
docker-compose up -d
# Run migrations
docker-compose run --rm migrate
# Open http://localhost:3000
```
### Local Development
```bash
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env
# Edit .env with your PostgreSQL database URL
# Generate Prisma client
npx prisma generate
# Run migrations
npx prisma migrate dev
# Start development server
npm run dev
# Open http://localhost:3000
```
## Tech Stack
- **Frontend**: Next.js 14 (App Router), React, CSS
- **Backend**: Next.js API Routes
- **Database**: PostgreSQL with Prisma ORM
- **Containerization**: Docker & Docker Compose
## Project Structure
```
timepickr/
├── src/
│ ├── app/
│ │ ├── api/events/ # API routes
│ │ ├── event/[code]/ # Event & analytics pages
│ │ ├── page.tsx # Home page
│ │ └── globals.css # Stripe-inspired styles
│ ├── components/ # Reusable components
│ └── lib/ # Database client
├── prisma/ # Database schema
├── Dockerfile # Production build
├── docker-compose.yml # Container orchestration
└── README.md
```
## Environment Variables
| Variable | Description | Default |
|----------|-------------|---------|
| `DATABASE_URL` | PostgreSQL connection string | - |
| `NEXT_PUBLIC_APP_URL` | Public URL of the app | `http://localhost:3000` |
## API Endpoints
| Method | Endpoint | Description |
|--------|----------|-------------|
| `POST` | `/api/events` | Create a new event |
| `GET` | `/api/events/:code` | Get event details |
| `POST` | `/api/events/:code/responses` | Submit availability |
| `GET` | `/api/events/:code/responses` | Get all responses |
| `POST` | `/api/events/:code/analytics` | Get analytics (auth required) |
## License
MIT

45
docker-compose.yml Normal file
View File

@@ -0,0 +1,45 @@
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/timepickr?schema=public
- NEXT_PUBLIC_APP_URL=http://localhost:3000
depends_on:
db:
condition: service_healthy
restart: unless-stopped
db:
image: postgres:16-alpine
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=timepickr
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
restart: unless-stopped
# Migration runner - runs once and exits
migrate:
build:
context: .
dockerfile: Dockerfile.migrate
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/timepickr?schema=public
depends_on:
db:
condition: service_healthy
volumes:
postgres_data:

18
eslint.config.mjs Normal file
View File

@@ -0,0 +1,18 @@
import { defineConfig, globalIgnores } from "eslint/config";
import nextVitals from "eslint-config-next/core-web-vitals";
import nextTs from "eslint-config-next/typescript";
const eslintConfig = defineConfig([
...nextVitals,
...nextTs,
// Override default ignores of eslint-config-next.
globalIgnores([
// Default ignores of eslint-config-next:
".next/**",
"out/**",
"build/**",
"next-env.d.ts",
]),
]);
export default eslintConfig;

7
next.config.ts Normal file
View File

@@ -0,0 +1,7 @@
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: 'standalone',
};
export default nextConfig;

6705
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "timepickr",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "eslint"
},
"dependencies": {
"@prisma/client": "^5.22.0",
"bcryptjs": "^3.0.3",
"dotenv": "^17.2.3",
"nanoid": "^5.1.6",
"next": "16.1.1",
"prisma": "^5.22.0",
"react": "19.2.3",
"react-dom": "19.2.3"
},
"devDependencies": {
"@tailwindcss/postcss": "^4",
"@types/bcryptjs": "^2.4.6",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "16.1.1",
"tailwindcss": "^4",
"typescript": "^5"
}
}

7
postcss.config.mjs Normal file
View File

@@ -0,0 +1,7 @@
const config = {
plugins: {
"@tailwindcss/postcss": {},
},
};
export default config;

32
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,32 @@
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Event {
id String @id @default(uuid())
title String
description String?
startDate DateTime @db.Date
endDate DateTime @db.Date
shareCode String @unique
adminPasswordHash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
responses Response[]
}
model Response {
id String @id @default(uuid())
eventId String
name String
availableDates Json // Array of date strings
createdAt DateTime @default(now())
event Event @relation(fields: [eventId], references: [id], onDelete: Cascade)
@@index([eventId])
}

1
public/file.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>

After

Width:  |  Height:  |  Size: 391 B

1
public/globe.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

1
public/next.svg Normal file
View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

1
public/vercel.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>

After

Width:  |  Height:  |  Size: 128 B

1
public/window.svg Normal file
View File

@@ -0,0 +1 @@
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>

After

Width:  |  Height:  |  Size: 385 B

View File

@@ -0,0 +1,99 @@
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
import bcrypt from 'bcryptjs';
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ code: string }> }
) {
try {
const { code } = await params;
const body = await request.json();
const { adminPassword } = body;
if (!adminPassword) {
return NextResponse.json(
{ error: 'Admin password is required' },
{ status: 400 }
);
}
// Find event with responses
const event = await prisma.event.findUnique({
where: { shareCode: code },
include: {
responses: {
orderBy: { createdAt: 'desc' },
select: {
id: true,
name: true,
availableDates: true,
createdAt: true,
}
}
}
});
if (!event) {
return NextResponse.json(
{ error: 'Event not found' },
{ status: 404 }
);
}
// Verify password
const isValid = await bcrypt.compare(adminPassword, event.adminPasswordHash);
if (!isValid) {
return NextResponse.json(
{ error: 'Invalid admin password' },
{ status: 401 }
);
}
// Calculate analytics
const dateBreakdown: Record<string, { count: number; names: string[] }> = {};
for (const response of event.responses) {
const dates = response.availableDates as string[];
for (const date of dates) {
if (!dateBreakdown[date]) {
dateBreakdown[date] = { count: 0, names: [] };
}
dateBreakdown[date].count++;
dateBreakdown[date].names.push(response.name);
}
}
// Sort dates by count to find best dates
const sortedDates = Object.entries(dateBreakdown)
.sort((a, b) => b[1].count - a[1].count)
.map(([date]) => date);
return NextResponse.json({
event: {
id: event.id,
title: event.title,
description: event.description,
startDate: event.startDate,
endDate: event.endDate,
createdAt: event.createdAt,
},
totalResponses: event.responses.length,
respondents: event.responses.map((r: { name: string; availableDates: unknown; createdAt: Date }) => ({
name: r.name,
availableDates: r.availableDates,
createdAt: r.createdAt,
})),
dateBreakdown,
bestDates: sortedDates.slice(0, 5),
});
} catch (error) {
console.error('Error fetching analytics:', error);
return NextResponse.json(
{ error: 'Failed to fetch analytics' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,116 @@
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ code: string }> }
) {
try {
const { code } = await params;
const body = await request.json();
const { name, availableDates } = body;
// Validation
if (!name || !availableDates || !Array.isArray(availableDates)) {
return NextResponse.json(
{ error: 'Missing required fields: name, availableDates (array)' },
{ status: 400 }
);
}
if (name.trim().length === 0) {
return NextResponse.json(
{ error: 'Name cannot be empty' },
{ status: 400 }
);
}
// Find event
const event = await prisma.event.findUnique({
where: { shareCode: code },
});
if (!event) {
return NextResponse.json(
{ error: 'Event not found' },
{ status: 404 }
);
}
// Validate dates are within event range
const startDate = new Date(event.startDate);
const endDate = new Date(event.endDate);
const validDates = availableDates.filter(dateStr => {
const date = new Date(dateStr);
return date >= startDate && date <= endDate;
});
// Create response
const response = await prisma.response.create({
data: {
eventId: event.id,
name: name.trim(),
availableDates: validDates,
},
});
return NextResponse.json({
id: response.id,
name: response.name,
availableDates: response.availableDates,
createdAt: response.createdAt,
}, { status: 201 });
} catch (error) {
console.error('Error creating response:', error);
return NextResponse.json(
{ error: 'Failed to submit response' },
{ status: 500 }
);
}
}
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ code: string }> }
) {
try {
const { code } = await params;
// Find event with responses
const event = await prisma.event.findUnique({
where: { shareCode: code },
include: {
responses: {
orderBy: { createdAt: 'desc' },
select: {
id: true,
name: true,
availableDates: true,
createdAt: true,
}
}
}
});
if (!event) {
return NextResponse.json(
{ error: 'Event not found' },
{ status: 404 }
);
}
return NextResponse.json({
eventId: event.id,
responses: event.responses,
});
} catch (error) {
console.error('Error fetching responses:', error);
return NextResponse.json(
{ error: 'Failed to fetch responses' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,52 @@
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ code: string }> }
) {
try {
const { code } = await params;
const event = await prisma.event.findUnique({
where: { shareCode: code },
select: {
id: true,
title: true,
description: true,
startDate: true,
endDate: true,
shareCode: true,
createdAt: true,
_count: {
select: { responses: true }
}
}
});
if (!event) {
return NextResponse.json(
{ error: 'Event not found' },
{ status: 404 }
);
}
return NextResponse.json({
id: event.id,
title: event.title,
description: event.description,
startDate: event.startDate,
endDate: event.endDate,
shareCode: event.shareCode,
createdAt: event.createdAt,
responseCount: event._count.responses,
});
} catch (error) {
console.error('Error fetching event:', error);
return NextResponse.json(
{ error: 'Failed to fetch event' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,63 @@
import { NextRequest, NextResponse } from 'next/server';
import { prisma } from '@/lib/db';
import { nanoid } from 'nanoid';
import bcrypt from 'bcryptjs';
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { title, description, startDate, endDate, adminPassword } = body;
// Validation
if (!title || !startDate || !endDate || !adminPassword) {
return NextResponse.json(
{ error: 'Missing required fields: title, startDate, endDate, adminPassword' },
{ status: 400 }
);
}
const start = new Date(startDate);
const end = new Date(endDate);
if (start > end) {
return NextResponse.json(
{ error: 'Start date must be before or equal to end date' },
{ status: 400 }
);
}
// Generate unique share code
const shareCode = nanoid(8);
// Hash admin password
const adminPasswordHash = await bcrypt.hash(adminPassword, 12);
// Create event
const event = await prisma.event.create({
data: {
title,
description: description || null,
startDate: start,
endDate: end,
shareCode,
adminPasswordHash,
},
});
const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000';
return NextResponse.json({
id: event.id,
shareCode: event.shareCode,
shareUrl: `${appUrl}/event/${event.shareCode}`,
analyticsUrl: `${appUrl}/event/${event.shareCode}/analytics`,
}, { status: 201 });
} catch (error) {
console.error('Error creating event:', error);
return NextResponse.json(
{ error: 'Failed to create event' },
{ status: 500 }
);
}
}

View File

@@ -0,0 +1,310 @@
'use client';
import { useState, useEffect, use, useMemo } from 'react';
import Calendar from '@/components/Calendar';
interface EventData {
id: string;
title: string;
description: string | null;
startDate: string;
endDate: string;
createdAt: string;
}
interface Respondent {
name: string;
availableDates: string[];
createdAt: string;
}
interface AnalyticsData {
event: EventData;
totalResponses: number;
respondents: Respondent[];
dateBreakdown: Record<string, { count: number; names: string[] }>;
bestDates: string[];
}
export default function AnalyticsPage({ params }: { params: Promise<{ code: string }> }) {
const resolvedParams = use(params);
const [password, setPassword] = useState('');
const [authenticated, setAuthenticated] = useState(false);
const [analytics, setAnalytics] = useState<AnalyticsData | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const handleAuth = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError('');
try {
const response = await fetch(`/api/events/${resolvedParams.code}/analytics`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ adminPassword: password }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to authenticate');
}
setAnalytics(data);
setAuthenticated(true);
} catch (err) {
setError(err instanceof Error ? err.message : 'Something went wrong');
} finally {
setLoading(false);
}
};
// Build heatmap data
const heatmapData = useMemo(() => {
if (!analytics) return {};
const result: Record<string, number> = {};
for (const [date, info] of Object.entries(analytics.dateBreakdown)) {
result[date] = info.count;
}
return result;
}, [analytics]);
const maxHeat = useMemo(() => {
return Math.max(...Object.values(heatmapData), 1);
}, [heatmapData]);
if (!authenticated) {
return (
<div style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-secondary)'
}}>
<div className="card-elevated" style={{ maxWidth: 400, width: '100%' }}>
<div className="text-center mb-6">
<div style={{ fontSize: '3rem', marginBottom: 'var(--space-3)' }}>🔒</div>
<h2 className="mb-2">Analytics Dashboard</h2>
<p style={{ color: 'var(--text-secondary)' }}>
Enter your admin password to view event analytics.
</p>
</div>
<form onSubmit={handleAuth}>
<div className="form-group">
<label htmlFor="password" className="form-label">Admin Password</label>
<input
type="password"
id="password"
className="form-input"
placeholder="Enter password"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
/>
</div>
{error && (
<div className="form-error mb-4" style={{ textAlign: 'center' }}>
{error}
</div>
)}
<button
type="submit"
className="btn btn-primary btn-lg w-full"
disabled={loading}
>
{loading ? (
<>
<span className="spinner" />
Verifying...
</>
) : (
'Access Analytics'
)}
</button>
</form>
</div>
</div>
);
}
if (!analytics) {
return (
<div style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-secondary)'
}}>
<div className="spinner" style={{ width: 40, height: 40, borderWidth: 3 }} />
</div>
);
}
const startDate = new Date(analytics.event.startDate);
const endDate = new Date(analytics.event.endDate);
return (
<div style={{ minHeight: '100vh', background: 'var(--bg-secondary)' }}>
{/* Header */}
<div className="hero-gradient" style={{ padding: 'var(--space-12) 0' }}>
<div className="hero-content container-md text-center">
<div className="badge badge-primary mb-4">Analytics Dashboard</div>
<h1 style={{ color: 'white', marginBottom: 'var(--space-3)', fontSize: '2.5rem' }}>
{analytics.event.title}
</h1>
<p style={{ color: 'rgba(255,255,255,0.6)', fontSize: '0.875rem' }}>
Created on {new Date(analytics.event.createdAt).toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
})}
</p>
</div>
</div>
{/* Stats */}
<div className="container-md" style={{ padding: 'var(--space-8) var(--space-6)', marginTop: '-40px' }}>
<div className="stats-grid mb-8">
<div className="stat-card">
<div className="stat-value">{analytics.totalResponses}</div>
<div className="stat-label">Total Responses</div>
</div>
<div className="stat-card">
<div className="stat-value">
{Object.keys(analytics.dateBreakdown).length}
</div>
<div className="stat-label">Dates Selected</div>
</div>
<div className="stat-card">
<div className="stat-value" style={{ color: 'var(--success)' }}>
{analytics.bestDates[0] ? maxHeat : 0}
</div>
<div className="stat-label">Max Availability</div>
</div>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'var(--space-6)' }}>
{/* Left Column - Calendar Heatmap */}
<div className="card">
<h3 className="mb-4">Availability Heatmap</h3>
<Calendar
startDate={startDate}
endDate={endDate}
selectedDates={[]}
onDateToggle={() => { }}
mode="heatmap"
heatmapData={heatmapData}
maxHeat={maxHeat}
/>
<div className="mt-4" style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
gap: 'var(--space-2)',
fontSize: '0.75rem',
color: 'var(--text-tertiary)'
}}>
<span>Less</span>
<div style={{ display: 'flex', gap: 2 }}>
{[1, 2, 3, 4, 5].map(level => (
<div
key={level}
style={{
width: 16,
height: 16,
borderRadius: 3,
background: `rgba(99, 91, 255, ${level * 0.2})`
}}
/>
))}
</div>
<span>More</span>
</div>
</div>
{/* Right Column - Best Dates */}
<div className="card">
<h3 className="mb-4">Best Dates</h3>
{analytics.bestDates.length > 0 ? (
<div className="best-dates-list">
{analytics.bestDates.slice(0, 5).map((date, index) => {
const info = analytics.dateBreakdown[date];
return (
<div key={date} className="best-date-item">
<div className={`best-date-rank ${index === 0 ? 'gold' : ''}`}>
{index + 1}
</div>
<div className="best-date-info">
<div className="best-date-date">
{new Date(date + 'T12:00:00').toLocaleDateString('en-US', {
weekday: 'long',
month: 'long',
day: 'numeric'
})}
</div>
<div className="best-date-count">
{info.count} {info.count === 1 ? 'person' : 'people'} available
</div>
</div>
</div>
);
})}
</div>
) : (
<p style={{ color: 'var(--text-tertiary)', textAlign: 'center', padding: 'var(--space-8)' }}>
No responses yet
</p>
)}
</div>
</div>
{/* Respondents */}
<div className="card mt-6">
<h3 className="mb-4">All Responses ({analytics.totalResponses})</h3>
{analytics.respondents.length > 0 ? (
<div className="respondent-list">
{analytics.respondents.map((respondent, index) => (
<div key={index} className="respondent-item">
<div className="respondent-avatar">
{respondent.name.charAt(0).toUpperCase()}
</div>
<div className="respondent-info">
<div className="respondent-name">{respondent.name}</div>
<div className="respondent-dates">
{respondent.availableDates.length} dates selected
Responded {new Date(respondent.createdAt).toLocaleDateString()}
</div>
</div>
<div style={{ color: 'var(--text-tertiary)', fontSize: '0.875rem' }}>
{respondent.availableDates.sort().slice(0, 3).map(d =>
new Date(d + 'T12:00:00').toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
).join(', ')}
{respondent.availableDates.length > 3 && ` +${respondent.availableDates.length - 3} more`}
</div>
</div>
))}
</div>
) : (
<p style={{ color: 'var(--text-tertiary)', textAlign: 'center', padding: 'var(--space-8)' }}>
No responses yet. Share your event link to collect responses!
</p>
)}
</div>
{/* Back link */}
<div className="mt-8 text-center">
<a href={`/event/${resolvedParams.code}`} className="btn btn-secondary">
Back to Event Page
</a>
</div>
</div>
</div>
);
}

View File

@@ -0,0 +1,274 @@
'use client';
import { useState, useEffect, use } from 'react';
import Calendar from '@/components/Calendar';
interface EventData {
id: string;
title: string;
description: string | null;
startDate: string;
endDate: string;
shareCode: string;
responseCount: number;
}
export default function EventPage({ params }: { params: Promise<{ code: string }> }) {
const resolvedParams = use(params);
const [event, setEvent] = useState<EventData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState('');
const [selectedDates, setSelectedDates] = useState<string[]>([]);
const [name, setName] = useState('');
const [submitting, setSubmitting] = useState(false);
const [submitted, setSubmitted] = useState(false);
useEffect(() => {
const fetchEvent = async () => {
try {
const response = await fetch(`/api/events/${resolvedParams.code}`);
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Event not found');
}
setEvent(data);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load event');
} finally {
setLoading(false);
}
};
fetchEvent();
}, [resolvedParams.code]);
const handleDateToggle = (date: string) => {
setSelectedDates(prev =>
prev.includes(date)
? prev.filter(d => d !== date)
: [...prev, date]
);
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!name.trim()) {
return;
}
if (selectedDates.length === 0) {
alert('Please select at least one available date');
return;
}
setSubmitting(true);
try {
const response = await fetch(`/api/events/${resolvedParams.code}/responses`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: name.trim(),
availableDates: selectedDates,
}),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to submit response');
}
setSubmitted(true);
} catch (err) {
alert(err instanceof Error ? err.message : 'Something went wrong');
} finally {
setSubmitting(false);
}
};
if (loading) {
return (
<div style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-secondary)'
}}>
<div className="spinner" style={{ width: 40, height: 40, borderWidth: 3 }} />
</div>
);
}
if (error || !event) {
return (
<div style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-secondary)'
}}>
<div className="card text-center" style={{ maxWidth: 400 }}>
<h2 className="mb-2">Event Not Found</h2>
<p className="mb-6">{error || 'This event may have been deleted or the link is incorrect.'}</p>
<a href="/" className="btn btn-primary">
Create Your Own Event
</a>
</div>
</div>
);
}
if (submitted) {
return (
<div style={{
minHeight: '100vh',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: 'var(--bg-secondary)'
}}>
<div className="card-elevated text-center" style={{ maxWidth: 450 }}>
<div className="success-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="20 6 9 17 4 12" />
</svg>
</div>
<h2 className="mb-2">You&apos;re all set!</h2>
<p className="mb-6">
Your availability has been recorded. The event organizer will be able to see
which dates work best for everyone.
</p>
<div className="flex gap-4" style={{ justifyContent: 'center' }}>
<button
onClick={() => {
setSubmitted(false);
setSelectedDates([]);
setName('');
}}
className="btn btn-secondary"
>
Submit Another Response
</button>
<a href="/" className="btn btn-primary">
Create Your Own Event
</a>
</div>
</div>
</div>
);
}
const startDate = new Date(event.startDate);
const endDate = new Date(event.endDate);
return (
<div style={{ minHeight: '100vh', background: 'var(--bg-secondary)' }}>
{/* Header */}
<div className="hero-gradient" style={{ padding: 'var(--space-12) 0' }}>
<div className="hero-content container-md text-center">
<div className="badge badge-primary mb-4">Event Invitation</div>
<h1 style={{ color: 'white', marginBottom: 'var(--space-3)', fontSize: '2.5rem' }}>
{event.title}
</h1>
{event.description && (
<p style={{ color: 'rgba(255,255,255,0.7)', fontSize: '1.125rem', maxWidth: '600px', margin: '0 auto' }}>
{event.description}
</p>
)}
<div style={{ marginTop: 'var(--space-4)', color: 'rgba(255,255,255,0.5)', fontSize: '0.875rem' }}>
{event.responseCount} {event.responseCount === 1 ? 'person has' : 'people have'} responded
</div>
</div>
</div>
{/* Main Content */}
<div className="container-md" style={{ padding: 'var(--space-8) var(--space-6)', marginTop: '-40px' }}>
<div className="card-elevated">
<form onSubmit={handleSubmit}>
{/* Name Input */}
<div className="form-group">
<label htmlFor="name" className="form-label">Your Name *</label>
<input
type="text"
id="name"
className="form-input"
placeholder="Enter your name"
value={name}
onChange={(e) => setName(e.target.value)}
required
/>
</div>
{/* Instructions */}
<div className="mb-6">
<h3 className="mb-2">Select Your Available Dates</h3>
<p style={{ color: 'var(--text-secondary)' }}>
Click on the dates when you&apos;re available to attend this event.
{selectedDates.length > 0 && (
<span className="badge badge-success" style={{ marginLeft: 'var(--space-2)' }}>
{selectedDates.length} selected
</span>
)}
</p>
</div>
{/* Calendar */}
<div className="mb-6">
<Calendar
startDate={startDate}
endDate={endDate}
selectedDates={selectedDates}
onDateToggle={handleDateToggle}
mode="select"
/>
</div>
{/* Selected Dates Summary */}
{selectedDates.length > 0 && (
<div className="mb-6" style={{
background: 'var(--bg-secondary)',
borderRadius: 'var(--radius-md)',
padding: 'var(--space-4)'
}}>
<p style={{ fontWeight: 500, marginBottom: 'var(--space-2)' }}>Your Selected Dates:</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 'var(--space-2)' }}>
{selectedDates.sort().map(date => (
<span key={date} className="badge badge-primary">
{new Date(date + 'T12:00:00').toLocaleDateString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric'
})}
</span>
))}
</div>
</div>
)}
{/* Submit Button */}
<button
type="submit"
className="btn btn-primary btn-lg w-full"
disabled={submitting || selectedDates.length === 0 || !name.trim()}
>
{submitting ? (
<>
<span className="spinner" />
Submitting...
</>
) : (
'Submit My Availability'
)}
</button>
</form>
</div>
</div>
</div>
);
}

BIN
src/app/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

769
src/app/globals.css Normal file
View File

@@ -0,0 +1,769 @@
/* Timepickr - Stripe-inspired Design System */
/* ===== CSS RESET & BASE ===== */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* ===== CSS VARIABLES ===== */
:root {
/* Primary colors - Stripe's signature gradient */
--primary-50: #f5f3ff;
--primary-100: #ede9fe;
--primary-200: #ddd6fe;
--primary-300: #c4b5fd;
--primary-400: #a78bfa;
--primary-500: #8b5cf6;
--primary-600: #7c3aed;
--primary-700: #6d28d9;
--primary-800: #5b21b6;
--primary-900: #4c1d95;
/* Accent - Stripe blue-to-purple */
--accent-start: #635bff;
--accent-mid: #a960ee;
--accent-end: #f637cf;
/* Neutral grays */
--gray-50: #fafafa;
--gray-100: #f4f4f5;
--gray-200: #e4e4e7;
--gray-300: #d4d4d8;
--gray-400: #a1a1aa;
--gray-500: #71717a;
--gray-600: #52525b;
--gray-700: #3f3f46;
--gray-800: #27272a;
--gray-900: #18181b;
/* Semantic colors */
--success: #22c55e;
--success-bg: #dcfce7;
--warning: #eab308;
--warning-bg: #fef9c3;
--error: #ef4444;
--error-bg: #fee2e2;
/* Background */
--bg-primary: #ffffff;
--bg-secondary: #fafafa;
--bg-tertiary: #f4f4f5;
/* Text */
--text-primary: #18181b;
--text-secondary: #52525b;
--text-tertiary: #71717a;
--text-inverse: #ffffff;
/* Borders */
--border-light: #e4e4e7;
--border-medium: #d4d4d8;
/* Shadows - Stripe style */
--shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
--shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
--shadow-glow: 0 0 60px -15px rgba(99, 91, 255, 0.4);
/* Radius */
--radius-sm: 6px;
--radius-md: 8px;
--radius-lg: 12px;
--radius-xl: 16px;
--radius-full: 9999px;
/* Transitions */
--transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
--transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
--transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
/* Spacing scale */
--space-1: 4px;
--space-2: 8px;
--space-3: 12px;
--space-4: 16px;
--space-5: 20px;
--space-6: 24px;
--space-8: 32px;
--space-10: 40px;
--space-12: 48px;
--space-16: 64px;
--space-20: 80px;
}
/* ===== BASE STYLES ===== */
html {
font-size: 16px;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
min-height: 100vh;
}
/* ===== TYPOGRAPHY ===== */
h1, h2, h3, h4, h5, h6 {
font-weight: 600;
line-height: 1.3;
color: var(--text-primary);
}
h1 { font-size: 3rem; letter-spacing: -0.02em; }
h2 { font-size: 2rem; letter-spacing: -0.01em; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1rem; }
p {
color: var(--text-secondary);
}
/* ===== LAYOUT ===== */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 var(--space-6);
}
.container-sm {
max-width: 640px;
margin: 0 auto;
padding: 0 var(--space-6);
}
.container-md {
max-width: 800px;
margin: 0 auto;
padding: 0 var(--space-6);
}
/* ===== HERO GRADIENT ===== */
.hero-gradient {
background: linear-gradient(
135deg,
#0a0a0a 0%,
#1a1a2e 25%,
#16213e 50%,
#1a1a2e 75%,
#0a0a0a 100%
);
position: relative;
overflow: hidden;
}
.hero-gradient::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background:
radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 91, 255, 0.3), transparent),
radial-gradient(ellipse 60% 40% at 80% 50%, rgba(169, 96, 238, 0.2), transparent),
radial-gradient(ellipse 50% 30% at 20% 80%, rgba(246, 55, 207, 0.15), transparent);
pointer-events: none;
}
.hero-content {
position: relative;
z-index: 1;
}
/* ===== CARDS ===== */
.card {
background: var(--bg-primary);
border: 1px solid var(--border-light);
border-radius: var(--radius-lg);
padding: var(--space-6);
box-shadow: var(--shadow-sm);
transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.card:hover {
box-shadow: var(--shadow-md);
}
.card-elevated {
background: var(--bg-primary);
border-radius: var(--radius-xl);
padding: var(--space-8);
box-shadow: var(--shadow-xl), var(--shadow-glow);
}
/* ===== BUTTONS ===== */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: var(--space-2);
padding: var(--space-3) var(--space-5);
font-size: 0.9375rem;
font-weight: 500;
line-height: 1.5;
border-radius: var(--radius-md);
border: none;
cursor: pointer;
transition: all var(--transition-fast);
text-decoration: none;
white-space: nowrap;
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.btn-primary {
background: linear-gradient(135deg, var(--accent-start), var(--primary-600));
color: var(--text-inverse);
box-shadow: 0 1px 2px 0 rgba(99, 91, 255, 0.4), inset 0 1px 0 0 rgba(255, 255, 255, 0.1);
}
.btn-primary:hover:not(:disabled) {
background: linear-gradient(135deg, #5753e8, var(--primary-700));
transform: translateY(-1px);
box-shadow: 0 4px 12px 0 rgba(99, 91, 255, 0.4), inset 0 1px 0 0 rgba(255, 255, 255, 0.1);
}
.btn-primary:active:not(:disabled) {
transform: translateY(0);
}
.btn-secondary {
background: var(--bg-primary);
color: var(--text-primary);
border: 1px solid var(--border-medium);
}
.btn-secondary:hover:not(:disabled) {
background: var(--bg-secondary);
border-color: var(--gray-400);
}
.btn-ghost {
background: transparent;
color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
background: var(--bg-tertiary);
color: var(--text-primary);
}
.btn-lg {
padding: var(--space-4) var(--space-8);
font-size: 1rem;
border-radius: var(--radius-lg);
}
.btn-sm {
padding: var(--space-2) var(--space-3);
font-size: 0.875rem;
}
/* ===== FORM ELEMENTS ===== */
.form-group {
margin-bottom: var(--space-5);
}
.form-label {
display: block;
font-size: 0.875rem;
font-weight: 500;
color: var(--text-primary);
margin-bottom: var(--space-2);
}
.form-input {
width: 100%;
padding: var(--space-3) var(--space-4);
font-size: 1rem;
line-height: 1.5;
color: var(--text-primary);
background: var(--bg-primary);
border: 1px solid var(--border-medium);
border-radius: var(--radius-md);
transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-input:focus {
outline: none;
border-color: var(--accent-start);
box-shadow: 0 0 0 3px rgba(99, 91, 255, 0.15);
}
.form-input::placeholder {
color: var(--text-tertiary);
}
textarea.form-input {
resize: vertical;
min-height: 100px;
}
.form-hint {
font-size: 0.8125rem;
color: var(--text-tertiary);
margin-top: var(--space-1);
}
.form-error {
font-size: 0.8125rem;
color: var(--error);
margin-top: var(--space-1);
}
/* ===== CALENDAR STYLES ===== */
.calendar {
width: 100%;
user-select: none;
}
.calendar-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: var(--space-4);
}
.calendar-title {
font-size: 1.125rem;
font-weight: 600;
}
.calendar-nav {
display: flex;
gap: var(--space-2);
}
.calendar-nav-btn {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
background: var(--bg-secondary);
border: 1px solid var(--border-light);
border-radius: var(--radius-md);
cursor: pointer;
transition: all var(--transition-fast);
color: var(--text-secondary);
}
.calendar-nav-btn:hover {
background: var(--bg-tertiary);
color: var(--text-primary);
}
.calendar-weekdays {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
margin-bottom: var(--space-2);
}
.calendar-weekday {
text-align: center;
font-size: 0.75rem;
font-weight: 600;
color: var(--text-tertiary);
text-transform: uppercase;
letter-spacing: 0.05em;
padding: var(--space-2) 0;
}
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
}
.calendar-day {
aspect-ratio: 1;
display: flex;
align-items: center;
justify-content: center;
font-size: 0.9375rem;
font-weight: 500;
border-radius: var(--radius-md);
cursor: pointer;
transition: all var(--transition-fast);
background: var(--bg-primary);
border: 1px solid transparent;
color: var(--text-primary);
}
.calendar-day:hover:not(.disabled):not(.outside) {
background: var(--bg-tertiary);
border-color: var(--border-medium);
}
.calendar-day.selected {
background: linear-gradient(135deg, var(--accent-start), var(--primary-600));
color: var(--text-inverse);
border-color: transparent;
box-shadow: 0 2px 8px rgba(99, 91, 255, 0.3);
}
.calendar-day.selected:hover {
background: linear-gradient(135deg, #5753e8, var(--primary-700));
}
.calendar-day.today {
border-color: var(--accent-start);
}
.calendar-day.outside {
color: var(--text-tertiary);
opacity: 0.4;
cursor: default;
}
.calendar-day.disabled {
color: var(--text-tertiary);
opacity: 0.3;
cursor: not-allowed;
background: var(--bg-tertiary);
}
/* Heatmap calendar for analytics */
.calendar-day.heat-1 { background: rgba(99, 91, 255, 0.1); }
.calendar-day.heat-2 { background: rgba(99, 91, 255, 0.25); }
.calendar-day.heat-3 { background: rgba(99, 91, 255, 0.4); }
.calendar-day.heat-4 { background: rgba(99, 91, 255, 0.6); color: var(--text-inverse); }
.calendar-day.heat-5 { background: rgba(99, 91, 255, 0.8); color: var(--text-inverse); }
.calendar-day.heat-max {
background: linear-gradient(135deg, var(--accent-start), var(--primary-600));
color: var(--text-inverse);
box-shadow: 0 2px 8px rgba(99, 91, 255, 0.3);
}
/* ===== SHARE LINK ===== */
.share-link-container {
display: flex;
gap: var(--space-2);
align-items: stretch;
}
.share-link-input {
flex: 1;
padding: var(--space-3) var(--space-4);
font-size: 0.875rem;
font-family: 'SF Mono', Monaco, 'Consolas', monospace;
background: var(--bg-tertiary);
border: 1px solid var(--border-light);
border-radius: var(--radius-md);
color: var(--text-primary);
}
.share-link-btn {
padding: var(--space-3) var(--space-4);
display: flex;
align-items: center;
gap: var(--space-2);
}
/* ===== BADGES ===== */
.badge {
display: inline-flex;
align-items: center;
padding: var(--space-1) var(--space-3);
font-size: 0.75rem;
font-weight: 600;
border-radius: var(--radius-full);
text-transform: uppercase;
letter-spacing: 0.02em;
}
.badge-primary {
background: var(--primary-100);
color: var(--primary-700);
}
.badge-success {
background: var(--success-bg);
color: #166534;
}
/* ===== MODAL ===== */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(4px);
display: flex;
align-items: center;
justify-content: center;
padding: var(--space-4);
z-index: 100;
animation: fadeIn 0.2s ease;
}
.modal {
background: var(--bg-primary);
border-radius: var(--radius-xl);
padding: var(--space-8);
max-width: 400px;
width: 100%;
box-shadow: var(--shadow-xl);
animation: slideUp 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* ===== SUCCESS STATE ===== */
.success-icon {
width: 64px;
height: 64px;
background: var(--success-bg);
border-radius: var(--radius-full);
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto var(--space-4);
}
.success-icon svg {
width: 32px;
height: 32px;
color: var(--success);
}
/* ===== STATS GRID ===== */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: var(--space-4);
}
.stat-card {
background: var(--bg-secondary);
border-radius: var(--radius-lg);
padding: var(--space-5);
text-align: center;
}
.stat-value {
font-size: 2rem;
font-weight: 700;
color: var(--text-primary);
line-height: 1;
margin-bottom: var(--space-1);
}
.stat-label {
font-size: 0.875rem;
color: var(--text-tertiary);
}
/* ===== RESPONDENT LIST ===== */
.respondent-list {
display: flex;
flex-direction: column;
gap: var(--space-3);
}
.respondent-item {
display: flex;
align-items: center;
gap: var(--space-3);
padding: var(--space-3) var(--space-4);
background: var(--bg-secondary);
border-radius: var(--radius-md);
}
.respondent-avatar {
width: 40px;
height: 40px;
border-radius: var(--radius-full);
background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
display: flex;
align-items: center;
justify-content: center;
color: var(--text-inverse);
font-weight: 600;
font-size: 1rem;
}
.respondent-info {
flex: 1;
}
.respondent-name {
font-weight: 500;
color: var(--text-primary);
}
.respondent-dates {
font-size: 0.8125rem;
color: var(--text-tertiary);
}
/* ===== BEST DATES ===== */
.best-dates-list {
display: flex;
flex-direction: column;
gap: var(--space-2);
}
.best-date-item {
display: flex;
align-items: center;
gap: var(--space-3);
padding: var(--space-3) var(--space-4);
background: var(--bg-secondary);
border-radius: var(--radius-md);
}
.best-date-rank {
width: 28px;
height: 28px;
border-radius: var(--radius-full);
background: var(--primary-100);
color: var(--primary-700);
display: flex;
align-items: center;
justify-content: center;
font-weight: 600;
font-size: 0.875rem;
}
.best-date-rank.gold {
background: linear-gradient(135deg, #fbbf24, #f59e0b);
color: white;
}
.best-date-info {
flex: 1;
}
.best-date-date {
font-weight: 500;
color: var(--text-primary);
}
.best-date-count {
font-size: 0.8125rem;
color: var(--text-tertiary);
}
/* ===== LOADING STATES ===== */
.spinner {
width: 20px;
height: 20px;
border: 2px solid transparent;
border-top-color: currentColor;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.skeleton {
background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-secondary) 50%, var(--bg-tertiary) 75%);
background-size: 200% 100%;
animation: shimmer 1.5s infinite;
border-radius: var(--radius-md);
}
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
/* ===== UTILITY CLASSES ===== */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.w-full { width: 100%; }
/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
h1 { font-size: 2.25rem; }
h2 { font-size: 1.75rem; }
.container,
.container-sm,
.container-md {
padding: 0 var(--space-4);
}
.card-elevated {
padding: var(--space-6);
}
.calendar-day {
font-size: 0.875rem;
}
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
h1 { font-size: 1.875rem; }
.btn-lg {
width: 100%;
}
.share-link-container {
flex-direction: column;
}
.stats-grid {
grid-template-columns: 1fr;
}
}

20
src/app/layout.tsx Normal file
View File

@@ -0,0 +1,20 @@
import type { Metadata } from "next";
import "./globals.css";
export const metadata: Metadata = {
title: "Timepickr - Find the perfect time for your event",
description: "Create events and let your friends pick their available dates. Find the best time that works for everyone.",
keywords: ["event planning", "scheduling", "availability", "calendar", "group planning"],
};
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}

260
src/app/page.tsx Normal file
View File

@@ -0,0 +1,260 @@
'use client';
import { useState } from 'react';
import ShareLink from '@/components/ShareLink';
interface EventResult {
shareCode: string;
shareUrl: string;
analyticsUrl: string;
}
export default function HomePage() {
const [formData, setFormData] = useState({
title: '',
description: '',
startDate: '',
endDate: '',
adminPassword: '',
});
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
const [result, setResult] = useState<EventResult | null>(null);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError('');
try {
const response = await fetch('/api/events', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Failed to create event');
}
setResult(data);
} catch (err) {
setError(err instanceof Error ? err.message : 'Something went wrong');
} finally {
setLoading(false);
}
};
const handleChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { name, value } = e.target;
setFormData(prev => ({ ...prev, [name]: value }));
};
const today = new Date().toISOString().split('T')[0];
if (result) {
return (
<div className="hero-gradient" style={{ minHeight: '100vh' }}>
<div className="hero-content">
<div className="container-sm" style={{ paddingTop: 'var(--space-20)', paddingBottom: 'var(--space-20)' }}>
<div className="card-elevated">
<div className="success-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="20 6 9 17 4 12" />
</svg>
</div>
<h2 className="text-center mb-2">Event Created!</h2>
<p className="text-center mb-8">Share this link with your friends so they can pick their available dates.</p>
<div className="mb-6">
<ShareLink url={result.shareUrl} label="Share this link with participants" />
</div>
<div className="mb-8">
<ShareLink url={result.analyticsUrl} label="Your private analytics link" />
<p className="form-hint mt-2">
Use your admin password to access the analytics dashboard.
</p>
</div>
<div className="flex gap-4" style={{ justifyContent: 'center' }}>
<button
onClick={() => {
setResult(null);
setFormData({
title: '',
description: '',
startDate: '',
endDate: '',
adminPassword: '',
});
}}
className="btn btn-secondary"
>
Create Another Event
</button>
<a href={result.shareUrl} className="btn btn-primary">
View Event
</a>
</div>
</div>
</div>
</div>
</div>
);
}
return (
<div className="hero-gradient" style={{ minHeight: '100vh' }}>
<div className="hero-content">
<div className="container-sm" style={{ paddingTop: 'var(--space-20)', paddingBottom: 'var(--space-20)' }}>
{/* Header */}
<div className="text-center mb-8">
<div className="badge badge-primary mb-4">Free & Simple</div>
<h1 style={{ color: 'white', marginBottom: 'var(--space-4)' }}>
Find the perfect time
</h1>
<p style={{ fontSize: '1.25rem', color: 'rgba(255,255,255,0.7)', maxWidth: '480px', margin: '0 auto' }}>
Create an event, share the link, and let everyone pick their available dates.
</p>
</div>
{/* Form Card */}
<div className="card-elevated">
<form onSubmit={handleSubmit}>
<div className="form-group">
<label htmlFor="title" className="form-label">Event Name *</label>
<input
type="text"
id="title"
name="title"
className="form-input"
placeholder="e.g., Summer BBQ, Team Offsite"
value={formData.title}
onChange={handleChange}
required
/>
</div>
<div className="form-group">
<label htmlFor="description" className="form-label">Description</label>
<textarea
id="description"
name="description"
className="form-input"
placeholder="Optional details about the event..."
value={formData.description}
onChange={handleChange}
rows={3}
/>
</div>
<div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 'var(--space-4)' }}>
<div className="form-group">
<label htmlFor="startDate" className="form-label">Start Date *</label>
<input
type="date"
id="startDate"
name="startDate"
className="form-input"
value={formData.startDate}
onChange={handleChange}
min={today}
required
/>
</div>
<div className="form-group">
<label htmlFor="endDate" className="form-label">End Date *</label>
<input
type="date"
id="endDate"
name="endDate"
className="form-input"
value={formData.endDate}
onChange={handleChange}
min={formData.startDate || today}
required
/>
</div>
</div>
<div className="form-group">
<label htmlFor="adminPassword" className="form-label">Admin Password *</label>
<input
type="password"
id="adminPassword"
name="adminPassword"
className="form-input"
placeholder="To access the analytics dashboard"
value={formData.adminPassword}
onChange={handleChange}
required
minLength={6}
/>
<p className="form-hint">
You&apos;ll need this to view response analytics. Min 6 characters.
</p>
</div>
{error && (
<div className="form-error mb-4" style={{ textAlign: 'center' }}>
{error}
</div>
)}
<button
type="submit"
className="btn btn-primary btn-lg w-full"
disabled={loading}
>
{loading ? (
<>
<span className="spinner" />
Creating...
</>
) : (
'Create Event & Get Share Link'
)}
</button>
</form>
</div>
{/* Features */}
<div style={{
display: 'grid',
gridTemplateColumns: 'repeat(3, 1fr)',
gap: 'var(--space-6)',
marginTop: 'var(--space-12)',
color: 'white'
}}>
<div className="text-center">
<div style={{ fontSize: '2rem', marginBottom: 'var(--space-2)' }}>📅</div>
<h4 style={{ color: 'white', marginBottom: 'var(--space-1)' }}>Easy Scheduling</h4>
<p style={{ fontSize: '0.875rem', color: 'rgba(255,255,255,0.6)' }}>
Visual calendar for picking dates
</p>
</div>
<div className="text-center">
<div style={{ fontSize: '2rem', marginBottom: 'var(--space-2)' }}>🔗</div>
<h4 style={{ color: 'white', marginBottom: 'var(--space-1)' }}>Share Link</h4>
<p style={{ fontSize: '0.875rem', color: 'rgba(255,255,255,0.6)' }}>
No accounts required for guests
</p>
</div>
<div className="text-center">
<div style={{ fontSize: '2rem', marginBottom: 'var(--space-2)' }}>📊</div>
<h4 style={{ color: 'white', marginBottom: 'var(--space-1)' }}>Analytics</h4>
<p style={{ fontSize: '0.875rem', color: 'rgba(255,255,255,0.6)' }}>
See who&apos;s available when
</p>
</div>
</div>
</div>
</div>
</div>
);
}

164
src/components/Calendar.tsx Normal file
View File

@@ -0,0 +1,164 @@
'use client';
import { useState, useMemo } from 'react';
interface CalendarProps {
startDate: Date;
endDate: Date;
selectedDates: string[];
onDateToggle: (date: string) => void;
mode?: 'select' | 'heatmap';
heatmapData?: Record<string, number>;
maxHeat?: number;
}
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const MONTHS = [
'January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'
];
function formatDateKey(date: Date): string {
return date.toISOString().split('T')[0];
}
function getMonthData(year: number, month: number) {
const firstDay = new Date(year, month, 1);
const lastDay = new Date(year, month + 1, 0);
const startPadding = firstDay.getDay();
const days: (Date | null)[] = [];
// Add padding for days before the first of the month
for (let i = 0; i < startPadding; i++) {
days.push(null);
}
// Add all days of the month
for (let d = 1; d <= lastDay.getDate(); d++) {
days.push(new Date(year, month, d));
}
return days;
}
export default function Calendar({
startDate,
endDate,
selectedDates,
onDateToggle,
mode = 'select',
heatmapData = {},
maxHeat = 1,
}: CalendarProps) {
const [currentMonth, setCurrentMonth] = useState(() => {
return new Date(startDate.getFullYear(), startDate.getMonth(), 1);
});
const monthDays = useMemo(() => {
return getMonthData(currentMonth.getFullYear(), currentMonth.getMonth());
}, [currentMonth]);
const today = useMemo(() => formatDateKey(new Date()), []);
const isDateInRange = (date: Date): boolean => {
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
const startOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
const endOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
return dateOnly >= startOnly && dateOnly <= endOnly;
};
const getHeatClass = (count: number): string => {
if (count === 0) return '';
if (count === maxHeat) return 'heat-max';
const ratio = count / maxHeat;
if (ratio >= 0.8) return 'heat-5';
if (ratio >= 0.6) return 'heat-4';
if (ratio >= 0.4) return 'heat-3';
if (ratio >= 0.2) return 'heat-2';
return 'heat-1';
};
const handlePrevMonth = () => {
setCurrentMonth(prev => new Date(prev.getFullYear(), prev.getMonth() - 1, 1));
};
const handleNextMonth = () => {
setCurrentMonth(prev => new Date(prev.getFullYear(), prev.getMonth() + 1, 1));
};
const canGoPrev = currentMonth > new Date(startDate.getFullYear(), startDate.getMonth(), 1);
const canGoNext = currentMonth < new Date(endDate.getFullYear(), endDate.getMonth(), 1);
return (
<div className="calendar">
<div className="calendar-header">
<h3 className="calendar-title">
{MONTHS[currentMonth.getMonth()]} {currentMonth.getFullYear()}
</h3>
<div className="calendar-nav">
<button
type="button"
className="calendar-nav-btn"
onClick={handlePrevMonth}
disabled={!canGoPrev}
aria-label="Previous month"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M15 18l-6-6 6-6" />
</svg>
</button>
<button
type="button"
className="calendar-nav-btn"
onClick={handleNextMonth}
disabled={!canGoNext}
aria-label="Next month"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<path d="M9 18l6-6-6-6" />
</svg>
</button>
</div>
</div>
<div className="calendar-weekdays">
{WEEKDAYS.map(day => (
<div key={day} className="calendar-weekday">{day}</div>
))}
</div>
<div className="calendar-grid">
{monthDays.map((date, i) => {
if (!date) {
return <div key={`empty-${i}`} className="calendar-day outside" />;
}
const dateKey = formatDateKey(date);
const inRange = isDateInRange(date);
const isSelected = selectedDates.includes(dateKey);
const isToday = dateKey === today;
const heatCount = heatmapData[dateKey] || 0;
let className = 'calendar-day';
if (!inRange) className += ' disabled';
else if (mode === 'select' && isSelected) className += ' selected';
else if (mode === 'heatmap') className += ` ${getHeatClass(heatCount)}`;
if (isToday) className += ' today';
return (
<button
key={dateKey}
type="button"
className={className}
onClick={() => inRange && mode === 'select' && onDateToggle(dateKey)}
disabled={!inRange || mode === 'heatmap'}
title={mode === 'heatmap' && heatCount > 0 ? `${heatCount} available` : undefined}
>
{date.getDate()}
</button>
);
})}
</div>
</div>
);
}

View File

@@ -0,0 +1,59 @@
'use client';
import { useState } from 'react';
interface ShareLinkProps {
url: string;
label?: string;
}
export default function ShareLink({ url, label = 'Share link' }: ShareLinkProps) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(url);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
} catch (err) {
console.error('Failed to copy:', err);
}
};
return (
<div>
<label className="form-label">{label}</label>
<div className="share-link-container">
<input
type="text"
value={url}
readOnly
className="share-link-input"
onClick={(e) => (e.target as HTMLInputElement).select()}
/>
<button
type="button"
onClick={handleCopy}
className="btn btn-secondary share-link-btn"
>
{copied ? (
<>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<polyline points="20 6 9 17 4 12" />
</svg>
Copied!
</>
) : (
<>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
Copy
</>
)}
</button>
</div>
</div>
);
}

9
src/lib/db.ts Normal file
View File

@@ -0,0 +1,9 @@
import { PrismaClient } from '@prisma/client';
const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
};
export const prisma = globalForPrisma.prisma ?? new PrismaClient();
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;

34
tsconfig.json Normal file
View File

@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2017",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts",
".next/dev/types/**/*.ts",
"**/*.mts"
],
"exclude": ["node_modules"]
}