feat: implement complete invoicing application with CSV import and PDF export

- Add comprehensive CSV import system with drag-and-drop upload and validation
- Create UniversalTable component with advanced filtering, searching, and batch actions
- Implement invoice management (view, edit, delete) with professional PDF export
- Add client management with full CRUD operations
- Set up authentication with NextAuth.js and email/password login
- Configure database schema with users, clients, invoices, and invoice_items tables
- Build responsive UI with shadcn/ui components and emerald branding
- Add type-safe API layer with tRPC and Zod validation
- Include proper error handling and user feedback with toast notifications
- Set up development environment with Bun, TypeScript, and Tailwind CSS
This commit is contained in:
2025-07-10 04:07:19 -04:00
commit 2d217fab47
85 changed files with 17074 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
import { handlers } from "~/server/auth";
export const { GET, POST } = handlers;
+60
View File
@@ -0,0 +1,60 @@
import bcrypt from "bcryptjs";
import { eq } from "drizzle-orm";
import { type NextRequest, NextResponse } from "next/server";
import { z } from "zod";
import { db } from "~/server/db";
import { users } from "~/server/db/schema";
const registerSchema = z.object({
firstName: z.string().min(1, "First name is required"),
lastName: z.string().min(1, "Last name is required"),
email: z.string().email("Invalid email address"),
password: z.string().min(6, "Password must be at least 6 characters"),
});
export async function POST(request: NextRequest) {
try {
const body = await request.json() as z.infer<typeof registerSchema>;
const { firstName, lastName, email, password } = registerSchema.parse(body);
// Check if user already exists
const existingUser = await db.query.users.findFirst({
where: eq(users.email, email),
});
if (existingUser) {
return NextResponse.json(
{ error: "User with this email already exists" },
{ status: 400 }
);
}
// Hash password
const hashedPassword = await bcrypt.hash(password, 12);
// Create user
await db.insert(users).values({
name: `${firstName} ${lastName}`,
email,
password: hashedPassword,
});
return NextResponse.json(
{ message: "User created successfully" },
{ status: 201 }
);
} catch (error) {
if (error instanceof z.ZodError) {
return NextResponse.json(
{ error: error.errors[0]?.message ?? "Validation error" },
{ status: 400 }
);
}
console.error("Registration error:", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 }
);
}
}
+34
View File
@@ -0,0 +1,34 @@
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
import { type NextRequest } from "next/server";
import { env } from "~/env";
import { appRouter } from "~/server/api/root";
import { createTRPCContext } from "~/server/api/trpc";
/**
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
* handling a HTTP request (e.g. when you make requests from Client Components).
*/
const createContext = async (req: NextRequest) => {
return createTRPCContext({
headers: req.headers,
});
};
const handler = (req: NextRequest) =>
fetchRequestHandler({
endpoint: "/api/trpc",
req,
router: appRouter,
createContext: () => createContext(req),
onError:
env.NODE_ENV === "development"
? ({ path, error }) => {
console.error(
`❌ tRPC failed on ${path ?? "<no-path>"}: ${error.message}`,
);
}
: undefined,
});
export { handler as GET, handler as POST };
+161
View File
@@ -0,0 +1,161 @@
"use client";
import Link from "next/link";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Input } from "~/components/ui/input";
import { Button } from "~/components/ui/button";
import { Label } from "~/components/ui/label";
import { toast } from "sonner";
import { Logo } from "~/components/logo";
import { User, Mail, Lock, ArrowRight } from "lucide-react";
export default function RegisterPage() {
const router = useRouter();
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
async function handleRegister(e: React.FormEvent) {
e.preventDefault();
setLoading(true);
const res = await fetch("/api/auth/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
firstName,
lastName,
email,
password
}),
});
setLoading(false);
if (res.ok) {
toast.success("Account created successfully! Please sign in.");
router.push("/auth/signin");
} else {
const error = await res.text();
toast.error(error || "Failed to create account");
}
}
return (
<div className="min-h-screen bg-gradient-to-br from-green-50 to-emerald-100 flex items-center justify-center p-4">
<div className="w-full max-w-md space-y-8">
{/* Logo and Welcome */}
<div className="text-center space-y-4">
<Logo size="lg" className="mx-auto" />
<div>
<h1 className="text-2xl font-bold text-gray-900">Join beenvoice</h1>
<p className="text-gray-600 mt-2">Create your account to get started</p>
</div>
</div>
{/* Registration Form */}
<Card className="shadow-xl border-0">
<CardHeader className="space-y-1">
<CardTitle className="text-xl text-center">Create Account</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleRegister} className="space-y-4">
<div className="grid grid-cols-2 gap-4">
<div className="space-y-2">
<Label htmlFor="firstName">First Name</Label>
<div className="relative">
<User className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="firstName"
type="text"
value={firstName}
onChange={e => setFirstName(e.target.value)}
required
autoFocus
className="pl-10"
placeholder="First name"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="lastName">Last Name</Label>
<div className="relative">
<User className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="lastName"
type="text"
value={lastName}
onChange={e => setLastName(e.target.value)}
required
className="pl-10"
placeholder="Last name"
/>
</div>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="email"
type="email"
value={email}
onChange={e => setEmail(e.target.value)}
required
className="pl-10"
placeholder="Enter your email"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="password"
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
minLength={6}
className="pl-10"
placeholder="Create a password"
/>
</div>
<p className="text-xs text-gray-500">Must be at least 6 characters</p>
</div>
<Button type="submit" className="w-full" disabled={loading}>
{loading ? (
"Creating account..."
) : (
<>
Create Account
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm">
<span className="text-gray-600">Already have an account? </span>
<Link href="/auth/signin" className="text-green-600 hover:text-green-700 font-medium">
Sign in here
</Link>
</div>
</CardContent>
</Card>
{/* Features */}
<div className="text-center space-y-4">
<p className="text-sm text-gray-500">Start invoicing like a pro</p>
<div className="flex justify-center space-x-6 text-xs text-gray-400">
<span> Free to start</span>
<span> No credit card</span>
<span> Cancel anytime</span>
</div>
</div>
</div>
</div>
);
}
+124
View File
@@ -0,0 +1,124 @@
"use client";
import Link from "next/link";
import { useState } from "react";
import { useRouter } from "next/navigation";
import { signIn } from "next-auth/react";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Input } from "~/components/ui/input";
import { Button } from "~/components/ui/button";
import { Label } from "~/components/ui/label";
import { toast } from "sonner";
import { Logo } from "~/components/logo";
import { Mail, Lock, ArrowRight } from "lucide-react";
export default function SignInPage() {
const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
async function handleSignIn(e: React.FormEvent) {
e.preventDefault();
setLoading(true);
const result = await signIn("credentials", {
email,
password,
redirect: false,
});
setLoading(false);
if (result?.error) {
toast.error("Invalid email or password");
} else {
toast.success("Signed in successfully!");
router.push("/dashboard");
router.refresh();
}
}
return (
<div className="min-h-screen bg-gradient-to-br from-green-50 to-emerald-100 flex items-center justify-center p-4">
<div className="w-full max-w-md space-y-8">
{/* Logo and Welcome */}
<div className="text-center space-y-4">
<Logo size="lg" className="mx-auto" />
<div>
<h1 className="text-2xl font-bold text-gray-900">Welcome back</h1>
<p className="text-gray-600 mt-2">Sign in to your beenvoice account</p>
</div>
</div>
{/* Sign In Form */}
<Card className="shadow-xl border-0">
<CardHeader className="space-y-1">
<CardTitle className="text-xl text-center">Sign In</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSignIn} className="space-y-4">
<div className="space-y-2">
<Label htmlFor="email">Email</Label>
<div className="relative">
<Mail className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="email"
type="email"
value={email}
onChange={e => setEmail(e.target.value)}
required
autoFocus
className="pl-10"
placeholder="Enter your email"
/>
</div>
</div>
<div className="space-y-2">
<Label htmlFor="password">Password</Label>
<div className="relative">
<Lock className="absolute left-3 top-3 h-4 w-4 text-gray-400" />
<Input
id="password"
type="password"
value={password}
onChange={e => setPassword(e.target.value)}
required
className="pl-10"
placeholder="Enter your password"
/>
</div>
</div>
<Button type="submit" className="w-full" disabled={loading}>
{loading ? (
"Signing in..."
) : (
<>
Sign In
<ArrowRight className="ml-2 h-4 w-4" />
</>
)}
</Button>
</form>
<div className="mt-6 text-center text-sm">
<span className="text-gray-600">Don&apos;t have an account? </span>
<Link href="/auth/register" className="text-green-600 hover:text-green-700 font-medium">
Create one now
</Link>
</div>
</CardContent>
</Card>
{/* Features */}
<div className="text-center space-y-4">
<p className="text-sm text-gray-500">Simple invoicing for freelancers and small businesses</p>
<div className="flex justify-center space-x-6 text-xs text-gray-400">
<span> Easy client management</span>
<span> Professional invoices</span>
<span> Payment tracking</span>
</div>
</div>
</div>
</div>
);
}
@@ -0,0 +1,45 @@
import { auth } from "~/server/auth";
import { HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { ClientForm } from "~/components/client-form";
import Link from "next/link";
interface EditClientPageProps {
params: Promise<{ id: string }>;
}
export default async function EditClientPage({ params }: EditClientPageProps) {
const session = await auth();
const { id } = await params;
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to edit clients</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
return (
<div>
<div className="mb-8">
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Edit Client</h1>
<p className="text-gray-600 mt-1 text-lg">Update client information below.</p>
</div>
<HydrateClient>
<ClientForm mode="edit" clientId={id} />
</HydrateClient>
</div>
);
}
+203
View File
@@ -0,0 +1,203 @@
import { notFound } from "next/navigation";
import { api } from "~/trpc/server";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Button } from "~/components/ui/button";
import { Badge } from "~/components/ui/badge";
import Link from "next/link";
import { Edit, Mail, Phone, MapPin, Building, Calendar, DollarSign } from "lucide-react";
interface ClientDetailPageProps {
params: Promise<{ id: string }>;
}
export default async function ClientDetailPage({ params }: ClientDetailPageProps) {
const { id } = await params;
const client = await api.clients.getById({ id });
if (!client) {
notFound();
}
const formatDate = (date: Date) => {
return new Intl.DateTimeFormat("en-US", {
year: "numeric",
month: "long",
day: "numeric",
}).format(date);
};
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
}).format(amount);
};
const totalInvoiced = client.invoices?.reduce((sum, invoice) => sum + invoice.totalAmount, 0) || 0;
const paidInvoices = client.invoices?.filter(invoice => invoice.status === "paid").length || 0;
const pendingInvoices = client.invoices?.filter(invoice => invoice.status === "sent").length || 0;
return (
<div className="p-4 md:p-6 md:ml-72 md:mr-4">
<div className="max-w-4xl mx-auto space-y-6">
{/* Header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">
{client.name}
</h1>
<p className="text-muted-foreground">Client Details</p>
</div>
<Link href={`/clients/${client.id}/edit`}>
<Button className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700">
<Edit className="mr-2 h-4 w-4" />
Edit Client
</Button>
</Link>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Client Information Card */}
<div className="lg:col-span-2">
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm">
<CardHeader>
<CardTitle className="flex items-center space-x-2 text-emerald-700">
<Building className="h-5 w-5" />
<span>Contact Information</span>
</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
{/* Basic Info */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
{client.email && (
<div className="flex items-center space-x-3">
<div className="p-2 bg-emerald-100 rounded-lg">
<Mail className="h-4 w-4 text-emerald-600" />
</div>
<div>
<p className="text-sm font-medium text-gray-500">Email</p>
<p className="text-sm">{client.email}</p>
</div>
</div>
)}
{client.phone && (
<div className="flex items-center space-x-3">
<div className="p-2 bg-emerald-100 rounded-lg">
<Phone className="h-4 w-4 text-emerald-600" />
</div>
<div>
<p className="text-sm font-medium text-gray-500">Phone</p>
<p className="text-sm">{client.phone}</p>
</div>
</div>
)}
</div>
{/* Address */}
{(client.addressLine1 ?? client.city ?? client.state) && (
<div className="space-y-4">
<div className="flex items-center space-x-3">
<div className="p-2 bg-emerald-100 rounded-lg">
<MapPin className="h-4 w-4 text-emerald-600" />
</div>
<div>
<p className="text-sm font-medium text-gray-500">Address</p>
</div>
</div>
<div className="ml-11 space-y-1 text-sm">
{client.addressLine1 && <p>{client.addressLine1}</p>}
{client.addressLine2 && <p>{client.addressLine2}</p>}
{(client.city ?? client.state ?? client.postalCode) && (
<p>
{[client.city, client.state, client.postalCode].filter(Boolean).join(", ")}
</p>
)}
{client.country && <p>{client.country}</p>}
</div>
</div>
)}
{/* Client Since */}
<div className="flex items-center space-x-3">
<div className="p-2 bg-emerald-100 rounded-lg">
<Calendar className="h-4 w-4 text-emerald-600" />
</div>
<div>
<p className="text-sm font-medium text-gray-500">Client Since</p>
<p className="text-sm">{formatDate(client.createdAt)}</p>
</div>
</div>
</CardContent>
</Card>
</div>
{/* Stats Card */}
<div className="space-y-6">
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm">
<CardHeader>
<CardTitle className="flex items-center space-x-2 text-emerald-700">
<DollarSign className="h-5 w-5" />
<span>Invoice Summary</span>
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<div className="text-center">
<p className="text-2xl font-bold text-emerald-600">
{formatCurrency(totalInvoiced)}
</p>
<p className="text-sm text-gray-500">Total Invoiced</p>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="text-center">
<p className="text-lg font-semibold text-green-600">{paidInvoices}</p>
<p className="text-xs text-gray-500">Paid</p>
</div>
<div className="text-center">
<p className="text-lg font-semibold text-orange-600">{pendingInvoices}</p>
<p className="text-xs text-gray-500">Pending</p>
</div>
</div>
</CardContent>
</Card>
{/* Recent Invoices */}
{client.invoices && client.invoices.length > 0 && (
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm">
<CardHeader>
<CardTitle className="text-lg">Recent Invoices</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
{client.invoices.slice(0, 3).map((invoice) => (
<div key={invoice.id} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
<div>
<p className="font-medium text-sm">{invoice.invoiceNumber}</p>
<p className="text-xs text-gray-500">{formatDate(invoice.issueDate)}</p>
</div>
<div className="text-right">
<p className="font-medium text-sm">{formatCurrency(invoice.totalAmount)}</p>
<Badge
variant={
invoice.status === "paid" ? "default" :
invoice.status === "sent" ? "secondary" : "outline"
}
className="text-xs"
>
{invoice.status}
</Badge>
</div>
</div>
))}
</div>
</CardContent>
</Card>
)}
</div>
</div>
</div>
</div>
);
}
+40
View File
@@ -0,0 +1,40 @@
import { auth } from "~/server/auth";
import { HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { ClientForm } from "~/components/client-form";
import Link from "next/link";
export default async function NewClientPage() {
const session = await auth();
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to create clients</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
return (
<div>
<div className="mb-8">
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Add Client</h1>
<p className="text-gray-600 mt-1 text-lg">Enter client details below to add a new client.</p>
</div>
<HydrateClient>
<ClientForm mode="create" />
</HydrateClient>
</div>
);
}
+51
View File
@@ -0,0 +1,51 @@
import Link from "next/link";
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { UniversalTable } from "~/components/ui/universal-table";
import { Plus } from "lucide-react";
export default async function ClientsPage() {
const session = await auth();
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to view clients</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
// Prefetch clients data
void api.clients.getAll.prefetch();
return (
<div>
<div className="flex flex-col md:flex-row md:items-center md:justify-between mb-8 gap-4">
<div>
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Clients</h1>
<p className="text-gray-600 mt-1 text-lg">Manage your clients and their information.</p>
</div>
<Button asChild size="lg" className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl">
<Link href="/dashboard/clients/new">
<Plus className="mr-2 h-5 w-5" /> Add Client
</Link>
</Button>
</div>
<HydrateClient>
<UniversalTable resource="clients" />
</HydrateClient>
</div>
);
}
@@ -0,0 +1,53 @@
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { InvoiceForm } from "~/components/invoice-form";
import Link from "next/link";
import { notFound } from "next/navigation";
interface EditInvoicePageProps {
params: Promise<{ id: string }>;
}
export default async function EditInvoicePage({ params }: EditInvoicePageProps) {
const session = await auth();
const { id } = await params;
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to edit invoices</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
// Prefetch invoice data
try {
await api.invoices.getById.prefetch({ id: id });
} catch (error) {
notFound();
}
return (
<div>
<div className="mb-8">
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Edit Invoice</h1>
<p className="text-gray-600 mt-1 text-lg">Update the invoice details below.</p>
</div>
<HydrateClient>
<InvoiceForm invoiceId={id} />
</HydrateClient>
</div>
);
}
+63
View File
@@ -0,0 +1,63 @@
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { InvoiceView } from "~/components/invoice-view";
import Link from "next/link";
import { notFound } from "next/navigation";
import { Edit } from "lucide-react";
interface InvoicePageProps {
params: Promise<{ id: string }>;
}
export default async function InvoicePage({ params }: InvoicePageProps) {
const session = await auth();
const { id } = await params;
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to view invoices</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
// Prefetch invoice data
try {
await api.invoices.getById.prefetch({ id: id });
} catch (error) {
notFound();
}
return (
<div>
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between mb-8 gap-4">
<div>
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Invoice Details</h1>
<p className="text-gray-600 mt-1 text-lg">View and manage invoice information.</p>
</div>
<div className="flex gap-3">
<Button asChild variant="outline" size="lg" className="bg-white/80 border-gray-200 hover:bg-gray-50 text-gray-700 font-medium shadow-lg hover:shadow-xl">
<Link href={`/dashboard/invoices/${id}/edit`}>
<Edit className="mr-2 h-5 w-5" /> Edit Invoice
</Link>
</Button>
</div>
</div>
<HydrateClient>
<InvoiceView invoiceId={id} />
</HydrateClient>
</div>
);
}
@@ -0,0 +1,41 @@
import Link from "next/link";
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { CSVImportPage } from "~/components/csv-import-page";
export default async function ImportPage() {
const session = await auth();
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to import invoices</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
return (
<div>
<div className="mb-8">
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Import Invoices</h1>
<p className="text-gray-600 mt-1 text-lg">Upload CSV files to create invoices in batch.</p>
</div>
<HydrateClient>
<CSVImportPage />
</HydrateClient>
</div>
);
}
+40
View File
@@ -0,0 +1,40 @@
import { auth } from "~/server/auth";
import { HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import Link from "next/link";
import { InvoiceForm } from "~/components/invoice-form";
export default async function NewInvoicePage() {
const session = await auth();
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to create invoices</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
return (
<div>
<div className="mb-8">
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Create Invoice</h1>
<p className="text-gray-600 mt-1 text-lg">Fill out the details below to create a new invoice.</p>
</div>
<HydrateClient>
<InvoiceForm />
</HydrateClient>
</div>
);
}
+58
View File
@@ -0,0 +1,58 @@
import Link from "next/link";
import { auth } from "~/server/auth";
import { api, HydrateClient } from "~/trpc/server";
import { Button } from "~/components/ui/button";
import { UniversalTable } from "~/components/ui/universal-table";
import { Plus, Upload } from "lucide-react";
export default async function InvoicesPage() {
const session = await auth();
if (!session?.user) {
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-emerald-50 via-white to-teal-50">
<div className="text-center">
<h1 className="text-4xl font-bold mb-4 bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Access Denied</h1>
<p className="text-muted-foreground mb-8">Please sign in to view invoices</p>
<Link href="/api/auth/signin">
<Button
size="lg"
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
Sign In
</Button>
</Link>
</div>
</div>
);
}
// Prefetch invoices data
void api.invoices.getAll.prefetch();
return (
<div>
<div className="flex flex-col md:flex-row md:items-center md:justify-between mb-8 gap-4">
<div>
<h1 className="text-3xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">Invoices</h1>
<p className="text-gray-600 mt-1 text-lg">Manage your invoices and payments.</p>
</div>
<div className="flex gap-3">
<Button asChild variant="outline" size="lg" className="bg-white/80 border-gray-200 hover:bg-gray-50 text-gray-700 font-medium shadow-lg hover:shadow-xl">
<Link href="/dashboard/invoices/import">
<Upload className="mr-2 h-5 w-5" /> Import CSV
</Link>
</Button>
<Button asChild size="lg" className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl">
<Link href="/dashboard/invoices/new">
<Plus className="mr-2 h-5 w-5" /> Add Invoice
</Link>
</Button>
</div>
</div>
<HydrateClient>
<UniversalTable resource="invoices" />
</HydrateClient>
</div>
);
}
+18
View File
@@ -0,0 +1,18 @@
import { Navbar } from "~/components/Navbar";
import { Sidebar } from "~/components/Sidebar";
import { DashboardBreadcrumbs } from "~/components/dashboard-breadcrumbs";
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
return (
<>
<Navbar />
<Sidebar />
<main className="min-h-screen pt-24 ml-70">
<div className="px-8 pt-6 pb-6">
<DashboardBreadcrumbs />
{children}
</div>
</main>
</>
);
}
+191
View File
@@ -0,0 +1,191 @@
import { redirect } from "next/navigation";
import { auth } from "~/server/auth";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Button } from "~/components/ui/button";
import {
Users,
FileText,
TrendingUp,
Calendar,
Plus,
ArrowRight
} from "lucide-react";
import Link from "next/link";
export default async function DashboardPage() {
const session = await auth();
if (!session?.user) {
redirect("/auth/signin");
}
return (
<div>
{/* Header */}
<div className="mb-8">
<h1 className="text-4xl font-bold bg-gradient-to-r from-emerald-600 to-teal-600 bg-clip-text text-transparent">
Welcome back, {session.user.name?.split(" ")[0] ?? "User"}!
</h1>
<p className="text-gray-600 mt-2 text-lg">
Here&apos;s what&apos;s happening with your invoicing business
</p>
</div>
{/* Quick Stats */}
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-gray-700">Total Clients</CardTitle>
<div className="p-2 bg-emerald-100 rounded-lg">
<Users className="h-4 w-4 text-emerald-600" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold text-emerald-600">0</div>
<p className="text-xs text-gray-500">
+0 from last month
</p>
</CardContent>
</Card>
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-gray-700">Total Invoices</CardTitle>
<div className="p-2 bg-blue-100 rounded-lg">
<FileText className="h-4 w-4 text-blue-600" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold text-blue-600">0</div>
<p className="text-xs text-gray-500">
+0 from last month
</p>
</CardContent>
</Card>
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-gray-700">Revenue</CardTitle>
<div className="p-2 bg-teal-100 rounded-lg">
<TrendingUp className="h-4 w-4 text-teal-600" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold text-teal-600">$0</div>
<p className="text-xs text-gray-500">
+0% from last month
</p>
</CardContent>
</Card>
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-gray-700">Pending Invoices</CardTitle>
<div className="p-2 bg-orange-100 rounded-lg">
<Calendar className="h-4 w-4 text-orange-600" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold text-orange-600">0</div>
<p className="text-xs text-gray-500">
Due this month
</p>
</CardContent>
</Card>
</div>
{/* Quick Actions */}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-emerald-700">
<div className="p-2 bg-emerald-100 rounded-lg">
<Users className="h-5 w-5" />
</div>
Manage Clients
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<p className="text-gray-600">
Add new clients and manage your existing client relationships.
</p>
<div className="flex gap-3">
<Button
asChild
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
<Link href="/dashboard/clients/new">
<Plus className="mr-2 h-4 w-4" />
Add Client
</Link>
</Button>
<Button
variant="outline"
asChild
className="border-gray-300 text-gray-700 hover:bg-gray-50 font-medium"
>
<Link href="/dashboard/clients">
View All Clients
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
</Button>
</div>
</CardContent>
</Card>
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm hover:shadow-2xl transition-all duration-300">
<CardHeader>
<CardTitle className="flex items-center gap-2 text-emerald-700">
<div className="p-2 bg-emerald-100 rounded-lg">
<FileText className="h-5 w-5" />
</div>
Create Invoices
</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
<p className="text-gray-600">
Generate professional invoices and track payments.
</p>
<div className="flex gap-3">
<Button
asChild
className="bg-gradient-to-r from-emerald-600 to-teal-600 hover:from-emerald-700 hover:to-teal-700 text-white font-medium shadow-lg hover:shadow-xl transition-all duration-200"
>
<Link href="/dashboard/invoices/new">
<Plus className="mr-2 h-4 w-4" />
New Invoice
</Link>
</Button>
<Button
variant="outline"
asChild
className="border-gray-300 text-gray-700 hover:bg-gray-50 font-medium"
>
<Link href="/dashboard/invoices">
View All Invoices
<ArrowRight className="ml-2 h-4 w-4" />
</Link>
</Button>
</div>
</CardContent>
</Card>
</div>
{/* Recent Activity */}
<Card className="shadow-xl border-0 bg-white/80 backdrop-blur-sm">
<CardHeader>
<CardTitle className="text-emerald-700">Recent Activity</CardTitle>
</CardHeader>
<CardContent>
<div className="text-center py-12 text-gray-500">
<div className="p-4 bg-gray-100 rounded-full w-20 h-20 mx-auto mb-4 flex items-center justify-center">
<FileText className="h-8 w-8 text-gray-400" />
</div>
<p className="text-lg font-medium mb-2">No recent activity</p>
<p className="text-sm">Start by adding your first client or creating an invoice</p>
</div>
</CardContent>
</Card>
</div>
);
}
+31
View File
@@ -0,0 +1,31 @@
import "~/styles/globals.css";
import { type Metadata } from "next";
import { Geist } from "next/font/google";
import { TRPCReactProvider } from "~/trpc/react";
import { Toaster } from "~/components/ui/toaster";
export const metadata: Metadata = {
title: "beenvoice - Invoicing Made Simple",
description: "Simple and efficient invoicing for freelancers and small businesses",
icons: [{ rel: "icon", url: "/favicon.ico" }],
};
const geist = Geist({
subsets: ["latin"],
variable: "--font-geist-sans",
});
export default function RootLayout({
children,
}: Readonly<{ children: React.ReactNode }>) {
return (
<html lang="en" className={`${geist.variable}`}>
<body className="relative min-h-screen font-sans antialiased overflow-x-hidden bg-gradient-to-br from-emerald-100 via-white via-60% to-teal-100 before:content-[''] before:fixed before:inset-0 before:z-0 before:pointer-events-none before:bg-[radial-gradient(ellipse_at_80%_0%,rgba(16,185,129,0.10)_0%,transparent_60%)]">
<TRPCReactProvider>{children}</TRPCReactProvider>
<Toaster />
</body>
</html>
);
}
+266
View File
@@ -0,0 +1,266 @@
import Link from "next/link";
import { redirect } from "next/navigation";
import { auth } from "~/server/auth";
import { Button } from "~/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/components/ui/card";
import { Logo } from "~/components/logo";
import {
Users,
FileText,
DollarSign,
Calendar,
CheckCircle,
ArrowRight,
Star,
Zap,
Shield,
Clock
} from "lucide-react";
export default async function HomePage() {
const session = await auth();
if (session?.user) {
redirect("/dashboard");
}
// Landing page for non-authenticated users
return (
<div className="min-h-screen bg-gradient-to-br from-green-50 to-emerald-100">
{/* Header */}
<header className="border-b border-green-200 bg-white/80 backdrop-blur-sm">
<div className="container mx-auto px-4 py-4">
<div className="flex items-center justify-between">
<Logo />
<div className="flex items-center space-x-4">
<Link href="/auth/signin">
<Button variant="ghost">Sign In</Button>
</Link>
<Link href="/auth/register">
<Button>Get Started</Button>
</Link>
</div>
</div>
</div>
</header>
{/* Hero Section */}
<section className="py-20 px-4">
<div className="container mx-auto text-center max-w-4xl">
<h1 className="text-5xl md:text-6xl font-bold text-gray-900 mb-6">
Simple Invoicing for
<span className="text-green-600"> Freelancers</span>
</h1>
<p className="text-xl text-gray-600 mb-8 max-w-2xl mx-auto">
Create professional invoices, manage clients, and get paid faster with beenvoice.
The invoicing app that works as hard as you do.
</p>
<div className="flex flex-col sm:flex-row gap-4 justify-center">
<Link href="/auth/register">
<Button size="lg" className="text-lg px-8 py-6">
Start Free Trial
<ArrowRight className="ml-2 h-5 w-5" />
</Button>
</Link>
<Link href="#features">
<Button variant="outline" size="lg" className="text-lg px-8 py-6">
See How It Works
</Button>
</Link>
</div>
</div>
</section>
{/* Features Section */}
<section id="features" className="py-20 px-4 bg-white">
<div className="container mx-auto max-w-6xl">
<div className="text-center mb-16">
<h2 className="text-4xl font-bold text-gray-900 mb-4">
Everything you need to invoice like a pro
</h2>
<p className="text-xl text-gray-600 max-w-2xl mx-auto">
Powerful features designed for freelancers and small businesses
</p>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
<Card className="border-0 shadow-lg">
<CardHeader>
<Users className="h-12 w-12 text-green-600 mb-4" />
<CardTitle>Client Management</CardTitle>
<CardDescription>
Keep all your client information organized in one place
</CardDescription>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm text-gray-600">
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Store contact details and addresses
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Track client history and invoices
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Search and filter clients easily
</li>
</ul>
</CardContent>
</Card>
<Card className="border-0 shadow-lg">
<CardHeader>
<FileText className="h-12 w-12 text-green-600 mb-4" />
<CardTitle>Professional Invoices</CardTitle>
<CardDescription>
Create beautiful, detailed invoices with line items
</CardDescription>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm text-gray-600">
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Add multiple line items with dates
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Automatic calculations and totals
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Professional invoice numbering
</li>
</ul>
</CardContent>
</Card>
<Card className="border-0 shadow-lg">
<CardHeader>
<DollarSign className="h-12 w-12 text-green-600 mb-4" />
<CardTitle>Payment Tracking</CardTitle>
<CardDescription>
Monitor invoice status and track payments
</CardDescription>
</CardHeader>
<CardContent>
<ul className="space-y-2 text-sm text-gray-600">
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Track draft, sent, paid, and overdue status
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
View outstanding amounts at a glance
</li>
<li className="flex items-center">
<CheckCircle className="h-4 w-4 text-green-500 mr-2" />
Payment history and analytics
</li>
</ul>
</CardContent>
</Card>
</div>
</div>
</section>
{/* Benefits Section */}
<section className="py-20 px-4 bg-gray-50">
<div className="container mx-auto max-w-4xl text-center">
<h2 className="text-4xl font-bold text-gray-900 mb-16">
Why choose beenvoice?
</h2>
<div className="grid md:grid-cols-2 gap-12">
<div className="space-y-6">
<div className="flex items-start space-x-4">
<Zap className="h-8 w-8 text-green-600 mt-1" />
<div className="text-left">
<h3 className="text-xl font-semibold mb-2">Lightning Fast</h3>
<p className="text-gray-600">Create invoices in seconds, not minutes. Our streamlined interface gets you back to work faster.</p>
</div>
</div>
<div className="flex items-start space-x-4">
<Shield className="h-8 w-8 text-green-600 mt-1" />
<div className="text-left">
<h3 className="text-xl font-semibold mb-2">Secure & Private</h3>
<p className="text-gray-600">Your data is encrypted and secure. We never share your information with third parties.</p>
</div>
</div>
</div>
<div className="space-y-6">
<div className="flex items-start space-x-4">
<Star className="h-8 w-8 text-green-600 mt-1" />
<div className="text-left">
<h3 className="text-xl font-semibold mb-2">Professional Quality</h3>
<p className="text-gray-600">Generate invoices that look professional and build trust with your clients.</p>
</div>
</div>
<div className="flex items-start space-x-4">
<Clock className="h-8 w-8 text-green-600 mt-1" />
<div className="text-left">
<h3 className="text-xl font-semibold mb-2">Save Time</h3>
<p className="text-gray-600">Automated calculations, templates, and client management save you hours every month.</p>
</div>
</div>
</div>
</div>
</div>
</section>
{/* CTA Section */}
<section className="py-20 px-4 bg-green-600">
<div className="container mx-auto text-center max-w-2xl">
<h2 className="text-4xl font-bold text-white mb-4">
Ready to get started?
</h2>
<p className="text-xl text-green-100 mb-8">
Join thousands of freelancers who trust beenvoice for their invoicing needs.
</p>
<Link href="/auth/register">
<Button size="lg" variant="secondary" className="text-lg px-8 py-6">
Start Your Free Trial
<ArrowRight className="ml-2 h-5 w-5" />
</Button>
</Link>
<p className="text-green-200 mt-4 text-sm">
No credit card required Cancel anytime
</p>
</div>
</section>
{/* Footer */}
<footer className="py-12 px-4 bg-gray-900 text-white">
<div className="container mx-auto text-center">
<Logo className="mx-auto mb-4" />
<p className="text-gray-400 mb-4">
Simple invoicing for freelancers and small businesses
</p>
<div className="flex justify-center space-x-6 text-sm text-gray-400">
<Link href="/auth/signin" className="hover:text-white">Sign In</Link>
<Link href="/auth/register" className="hover:text-white">Register</Link>
</div>
</div>
</footer>
</div>
);
}
// Client components for stats and activity
function DashboardStats({ type }: { type: "clients" | "invoices" | "revenue" | "outstanding" }) {
// This will be implemented with tRPC queries
return <span>0</span>;
}
function RecentActivity() {
// This will be implemented with tRPC queries
return (
<div className="space-y-4">
<p className="text-sm text-muted-foreground">No recent activity</p>
</div>
);
}