import type { Route } from "./+types/newProject"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { ArrowLeft } from "lucide-react"; import { Link, Form, redirect } from "react-router"; import { db } from "@lib/db"; import { projects, columns } from "@lib/db/schema"; import { generate as generateId } from "@alikia/random-key"; import Layout from "@/components/layout"; import { getCurrentUser } from "@lib/auth-utils"; export function meta({}: Route.MetaArgs) { return [ { title: "Create New Project" }, { name: "description", content: "Create a new project for task management" } ]; } export async function action({ request }: Route.ActionArgs) { const user = await getCurrentUser(request); if (!user) { throw new Response("Unauthorized", { status: 401 }); } const formData = await request.formData(); const name = formData.get("name") as string; const description = formData.get("description") as string; if (!name) { return { error: "Project name is required" }; } try { const projectId = await generateId(6); const now = new Date(); // Create the project await db.insert(projects).values({ id: projectId, ownerId: user.id, name, description, createdAt: now, updatedAt: now }); // Create default columns for the project const defaultColumns = [ { name: "To Do", position: 0 }, { name: "In Progress", position: 1 }, { name: "Done", position: 2 } ]; for (const column of defaultColumns) { await db.insert(columns).values({ id: await generateId(6), projectId, name: column.name, position: column.position, createdAt: now, updatedAt: now }); } return redirect(`/project/${projectId}`); } catch (error) { console.error("Failed to create project:", error); return { error: "Failed to create project. Please try again." }; } } export default function NewProject() { return ( {/* Header */}

Create A New Project

{/* Project Creation Form */} Project Details Enter the basic information for your new project