VIBN Frontend for Coolify deployment
This commit is contained in:
41
app/[workspace]/projects/layout.tsx
Normal file
41
app/[workspace]/projects/layout.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
"use client";
|
||||
|
||||
import { WorkspaceLeftRail } from "@/components/layout/workspace-left-rail";
|
||||
import { RightPanel } from "@/components/layout/right-panel";
|
||||
import { ProjectAssociationPrompt } from "@/components/project-association-prompt";
|
||||
import { ReactNode, useState } from "react";
|
||||
import { useParams } from "next/navigation";
|
||||
import { Toaster } from "sonner";
|
||||
|
||||
export default function ProjectsLayout({
|
||||
children,
|
||||
}: {
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const params = useParams();
|
||||
const workspace = params.workspace as string;
|
||||
const [activeSection, setActiveSection] = useState<string>("projects");
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex h-screen w-full overflow-hidden bg-background">
|
||||
{/* Left Rail - Workspace Navigation */}
|
||||
<WorkspaceLeftRail activeSection={activeSection} onSectionChange={setActiveSection} />
|
||||
|
||||
{/* Main Content Area */}
|
||||
<main className="flex-1 flex flex-col overflow-hidden">
|
||||
{children}
|
||||
</main>
|
||||
|
||||
{/* Right Panel - AI Chat */}
|
||||
<RightPanel />
|
||||
</div>
|
||||
|
||||
{/* Project Association Prompt - Detects new workspaces */}
|
||||
<ProjectAssociationPrompt workspace={workspace} />
|
||||
|
||||
<Toaster position="top-center" />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
8
app/[workspace]/projects/new/layout.tsx
Normal file
8
app/[workspace]/projects/new/layout.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function NewProjectLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return children;
|
||||
}
|
||||
|
||||
462
app/[workspace]/projects/new/page.tsx
Normal file
462
app/[workspace]/projects/new/page.tsx
Normal file
@@ -0,0 +1,462 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { ArrowLeft, ArrowRight, Check, Sparkles, Code2 } from "lucide-react";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
type ProjectType = "scratch" | "existing" | null;
|
||||
|
||||
export default function NewProjectPage() {
|
||||
const router = useRouter();
|
||||
const [step, setStep] = useState(1);
|
||||
const [projectName, setProjectName] = useState("");
|
||||
const [projectType, setProjectType] = useState<ProjectType>(null);
|
||||
|
||||
// Product vision (can skip)
|
||||
const [productVision, setProductVision] = useState("");
|
||||
|
||||
// Product details
|
||||
const [productName, setProductName] = useState("");
|
||||
const [isForClient, setIsForClient] = useState<boolean | null>(null);
|
||||
const [hasLogo, setHasLogo] = useState<boolean | null>(null);
|
||||
const [hasDomain, setHasDomain] = useState<boolean | null>(null);
|
||||
const [hasWebsite, setHasWebsite] = useState<boolean | null>(null);
|
||||
const [hasGithub, setHasGithub] = useState<boolean | null>(null);
|
||||
const [hasChatGPT, setHasChatGPT] = useState<boolean | null>(null);
|
||||
|
||||
const [isCheckingSlug, setIsCheckingSlug] = useState(false);
|
||||
const [slugAvailable, setSlugAvailable] = useState<boolean | null>(null);
|
||||
|
||||
const generateSlug = (name: string) => {
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
};
|
||||
|
||||
const checkSlugAvailability = async (name: string) => {
|
||||
const slug = generateSlug(name);
|
||||
if (!slug) return;
|
||||
|
||||
setIsCheckingSlug(true);
|
||||
// TODO: Replace with actual API call
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
// Mock check - in reality, check against database
|
||||
const isAvailable = !["test", "demo", "admin"].includes(slug);
|
||||
setSlugAvailable(isAvailable);
|
||||
setIsCheckingSlug(false);
|
||||
};
|
||||
|
||||
const handleProductNameChange = (value: string) => {
|
||||
setProductName(value);
|
||||
setSlugAvailable(null);
|
||||
if (value.length > 2) {
|
||||
checkSlugAvailability(value);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNext = () => {
|
||||
if (step === 1 && projectName && projectType) {
|
||||
setStep(2);
|
||||
} else if (step === 2) {
|
||||
// Can skip questions
|
||||
setStep(3);
|
||||
} else if (step === 3 && productName && slugAvailable) {
|
||||
handleCreateProject();
|
||||
}
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (step > 1) setStep(step - 1);
|
||||
};
|
||||
|
||||
const handleSkipQuestions = () => {
|
||||
setStep(3);
|
||||
};
|
||||
|
||||
const handleCreateProject = async () => {
|
||||
const slug = generateSlug(productName);
|
||||
|
||||
const projectData = {
|
||||
projectName,
|
||||
projectType,
|
||||
slug,
|
||||
vision: productVision,
|
||||
product: {
|
||||
name: productName,
|
||||
isForClient,
|
||||
hasLogo,
|
||||
hasDomain,
|
||||
hasWebsite,
|
||||
hasGithub,
|
||||
hasChatGPT,
|
||||
},
|
||||
};
|
||||
|
||||
// TODO: API call to create project
|
||||
console.log("Creating project:", projectData);
|
||||
|
||||
// Redirect to the new project
|
||||
router.push(`/${slug}/overview`);
|
||||
};
|
||||
|
||||
const canProceedStep1 = projectName.trim() && projectType;
|
||||
const canProceedStep3 = productName.trim() && slugAvailable;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background p-6">
|
||||
<div className="mx-auto max-w-2xl">
|
||||
{/* Header */}
|
||||
<div className="mb-8">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => router.push("/projects")}
|
||||
className="mb-4"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
Back to Projects
|
||||
</Button>
|
||||
<h1 className="text-3xl font-bold">Create New Project</h1>
|
||||
<p className="text-muted-foreground mt-2">
|
||||
Step {step} of 3
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Progress */}
|
||||
<div className="flex gap-2 mb-8">
|
||||
{[1, 2, 3].map((s) => (
|
||||
<div
|
||||
key={s}
|
||||
className={`h-2 flex-1 rounded-full transition-colors ${
|
||||
s <= step ? "bg-primary" : "bg-muted"
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Step 1: Project Setup */}
|
||||
{step === 1 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Project Setup</CardTitle>
|
||||
<CardDescription>
|
||||
Give your project a name and choose how you want to start
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="projectName">Project Name</Label>
|
||||
<Input
|
||||
id="projectName"
|
||||
placeholder="My Awesome Project"
|
||||
value={projectName}
|
||||
onChange={(e) => setProjectName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<Label>Starting Point</Label>
|
||||
<div className="grid gap-3">
|
||||
<button
|
||||
onClick={() => setProjectType("scratch")}
|
||||
className={`text-left p-4 rounded-lg border-2 transition-colors ${
|
||||
projectType === "scratch"
|
||||
? "border-primary bg-primary/5"
|
||||
: "border-border hover:border-primary/50"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-start gap-3">
|
||||
<Sparkles className="h-5 w-5 mt-0.5 text-primary" />
|
||||
<div>
|
||||
<div className="font-medium">Start from scratch</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Build a new project with AI assistance
|
||||
</div>
|
||||
</div>
|
||||
{projectType === "scratch" && (
|
||||
<Check className="h-5 w-5 ml-auto text-primary" />
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={() => setProjectType("existing")}
|
||||
className={`text-left p-4 rounded-lg border-2 transition-colors ${
|
||||
projectType === "existing"
|
||||
? "border-primary bg-primary/5"
|
||||
: "border-border hover:border-primary/50"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-start gap-3">
|
||||
<Code2 className="h-5 w-5 mt-0.5 text-primary" />
|
||||
<div>
|
||||
<div className="font-medium">Existing project</div>
|
||||
<div className="text-sm text-muted-foreground">
|
||||
Import and enhance an existing codebase
|
||||
</div>
|
||||
</div>
|
||||
{projectType === "existing" && (
|
||||
<Check className="h-5 w-5 ml-auto text-primary" />
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Step 2: Product Vision */}
|
||||
{step === 2 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Describe your product vision</CardTitle>
|
||||
<CardDescription>
|
||||
Help us understand your project (you can skip this)
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Textarea
|
||||
placeholder="Describe who you're building for, what problem they have, and how you plan to solve it..."
|
||||
value={productVision}
|
||||
onChange={(e) => setProductVision(e.target.value)}
|
||||
rows={8}
|
||||
className="resize-none"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="w-full"
|
||||
onClick={handleSkipQuestions}
|
||||
>
|
||||
Skip this step
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Step 3: Product Details */}
|
||||
{step === 3 && (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Product Details</CardTitle>
|
||||
<CardDescription>
|
||||
Tell us about your product
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="productName">Product Name *</Label>
|
||||
<Input
|
||||
id="productName"
|
||||
placeholder="Taskify"
|
||||
value={productName}
|
||||
onChange={(e) => handleProductNameChange(e.target.value)}
|
||||
/>
|
||||
{productName && (
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{isCheckingSlug ? (
|
||||
<span>Checking availability...</span>
|
||||
) : slugAvailable === true ? (
|
||||
<span className="text-green-600">
|
||||
✓ URL available: vibn.app/{generateSlug(productName)}
|
||||
</span>
|
||||
) : slugAvailable === false ? (
|
||||
<span className="text-red-600">
|
||||
✗ This name is already taken
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Client or Self */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Is this for a client or yourself?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={isForClient === true ? "default" : "outline"}
|
||||
onClick={() => setIsForClient(true)}
|
||||
size="sm"
|
||||
className="w-20 h-8"
|
||||
>
|
||||
Client
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={isForClient === false ? "default" : "outline"}
|
||||
onClick={() => setIsForClient(false)}
|
||||
size="sm"
|
||||
className="w-20 h-8"
|
||||
>
|
||||
Myself
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Logo */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Does it have a logo?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasLogo === true ? "default" : "outline"}
|
||||
onClick={() => setHasLogo(true)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasLogo === false ? "default" : "outline"}
|
||||
onClick={() => setHasLogo(false)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Domain */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Does it have a domain?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasDomain === true ? "default" : "outline"}
|
||||
onClick={() => setHasDomain(true)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasDomain === false ? "default" : "outline"}
|
||||
onClick={() => setHasDomain(false)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Website */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Does it have a website?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasWebsite === true ? "default" : "outline"}
|
||||
onClick={() => setHasWebsite(true)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasWebsite === false ? "default" : "outline"}
|
||||
onClick={() => setHasWebsite(false)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* GitHub */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Do you have a GitHub repository?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasGithub === true ? "default" : "outline"}
|
||||
onClick={() => setHasGithub(true)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasGithub === false ? "default" : "outline"}
|
||||
onClick={() => setHasGithub(false)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* ChatGPT */}
|
||||
<div className="flex items-center justify-between">
|
||||
<Label className="text-sm font-normal">Do you have your ideas in a ChatGPT project?</Label>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasChatGPT === true ? "default" : "outline"}
|
||||
onClick={() => setHasChatGPT(true)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
Yes
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={hasChatGPT === false ? "default" : "outline"}
|
||||
onClick={() => setHasChatGPT(false)}
|
||||
size="sm"
|
||||
className="w-16 h-8"
|
||||
>
|
||||
No
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Navigation */}
|
||||
<div className="flex gap-3 mt-6">
|
||||
{step > 1 && (
|
||||
<Button variant="outline" onClick={handleBack}>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
Back
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
className="ml-auto"
|
||||
onClick={handleNext}
|
||||
disabled={
|
||||
(step === 1 && !canProceedStep1) ||
|
||||
(step === 3 && !canProceedStep3) ||
|
||||
isCheckingSlug
|
||||
}
|
||||
>
|
||||
{step === 3 ? "Create Project" : "Next"}
|
||||
{step < 3 && <ArrowRight className="h-4 w-4 ml-2" />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
407
app/[workspace]/projects/page.tsx
Normal file
407
app/[workspace]/projects/page.tsx
Normal file
@@ -0,0 +1,407 @@
|
||||
"use client";
|
||||
// Force rebuild - v3
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Plus, Sparkles, Loader2, MoreVertical, Trash2 } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useParams } from "next/navigation";
|
||||
import { db, auth } from "@/lib/firebase/config";
|
||||
import { collection, query, where, orderBy, getDocs } from "firebase/firestore";
|
||||
import { ProjectCreationModal } from "@/components/project-creation-modal";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { toast } from "sonner";
|
||||
|
||||
interface ProjectWithStats {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
productName: string;
|
||||
productVision?: string;
|
||||
workspacePath?: string;
|
||||
status?: string;
|
||||
createdAt: { toDate?: () => Date } | Date | string | number | null;
|
||||
updatedAt: { toDate?: () => Date } | Date | string | number | null;
|
||||
stats: {
|
||||
sessions: number;
|
||||
costs: number;
|
||||
};
|
||||
}
|
||||
|
||||
export default function ProjectsPage() {
|
||||
const params = useParams();
|
||||
const workspace = params.workspace as string;
|
||||
|
||||
const [projects, setProjects] = useState<ProjectWithStats[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [showCreationModal, setShowCreationModal] = useState(false);
|
||||
const [projectToDelete, setProjectToDelete] = useState<ProjectWithStats | null>(null);
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
|
||||
const fetchProjects = async (user: { uid: string }) => {
|
||||
try {
|
||||
// Fetch projects for this user
|
||||
const projectsRef = collection(db, 'projects');
|
||||
const projectsQuery = query(
|
||||
projectsRef,
|
||||
where('userId', '==', user.uid),
|
||||
orderBy('createdAt', 'desc')
|
||||
);
|
||||
const projectsSnapshot = await getDocs(projectsQuery);
|
||||
|
||||
// Fetch sessions to calculate stats
|
||||
const sessionsRef = collection(db, 'sessions');
|
||||
const sessionsQuery = query(
|
||||
sessionsRef,
|
||||
where('userId', '==', user.uid)
|
||||
);
|
||||
const sessionsSnapshot = await getDocs(sessionsQuery);
|
||||
|
||||
// Group sessions by project
|
||||
const sessionsByProject = new Map<string, { count: number; totalCost: number }>();
|
||||
sessionsSnapshot.docs.forEach(doc => {
|
||||
const session = doc.data();
|
||||
const projectId = session.projectId || 'unassigned';
|
||||
const existing = sessionsByProject.get(projectId) || { count: 0, totalCost: 0 };
|
||||
sessionsByProject.set(projectId, {
|
||||
count: existing.count + 1,
|
||||
totalCost: existing.totalCost + (session.cost || 0),
|
||||
});
|
||||
});
|
||||
|
||||
// Map projects with stats
|
||||
const projectsWithStats: ProjectWithStats[] = projectsSnapshot.docs.map(doc => {
|
||||
const project = doc.data();
|
||||
const stats = sessionsByProject.get(doc.id) || { count: 0, totalCost: 0 };
|
||||
|
||||
return {
|
||||
id: doc.id,
|
||||
name: project.name,
|
||||
slug: project.slug,
|
||||
productName: project.productName,
|
||||
productVision: project.productVision,
|
||||
workspacePath: project.workspacePath,
|
||||
status: project.status || 'active',
|
||||
createdAt: project.createdAt,
|
||||
updatedAt: project.updatedAt,
|
||||
stats: {
|
||||
sessions: stats.count,
|
||||
costs: stats.totalCost,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
setProjects(projectsWithStats);
|
||||
} catch (err: unknown) {
|
||||
console.error('Error fetching projects:', err);
|
||||
setError(err instanceof Error ? err.message : 'Unknown error');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = auth.onAuthStateChanged(async (user) => {
|
||||
if (!user) {
|
||||
setError('Not authenticated');
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
fetchProjects(user);
|
||||
});
|
||||
|
||||
return () => unsubscribe();
|
||||
}, []);
|
||||
|
||||
const handleDeleteProject = async () => {
|
||||
if (!projectToDelete) return;
|
||||
|
||||
setIsDeleting(true);
|
||||
try {
|
||||
const user = auth.currentUser;
|
||||
if (!user) {
|
||||
toast.error('You must be signed in');
|
||||
return;
|
||||
}
|
||||
|
||||
const token = await user.getIdToken();
|
||||
|
||||
const response = await fetch('/api/projects/delete', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
projectId: projectToDelete.id,
|
||||
}),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
toast.success('Project deleted successfully', {
|
||||
description: data.sessionsPreserved > 0
|
||||
? `${data.sessionsPreserved} sessions preserved and can be reassigned`
|
||||
: undefined
|
||||
});
|
||||
|
||||
// Remove from local state
|
||||
setProjects(projects.filter(p => p.id !== projectToDelete.id));
|
||||
setProjectToDelete(null);
|
||||
} else {
|
||||
const error = await response.json();
|
||||
toast.error(error.error || 'Failed to delete project');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting project:', error);
|
||||
toast.error('An error occurred while deleting');
|
||||
} finally {
|
||||
setIsDeleting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const getTimeAgo = (timestamp: { toDate?: () => Date } | Date | string | number | null | undefined) => {
|
||||
if (!timestamp) return 'Recently';
|
||||
|
||||
let date: Date;
|
||||
if (typeof timestamp === 'object' && timestamp !== null && 'toDate' in timestamp && timestamp.toDate) {
|
||||
date = timestamp.toDate();
|
||||
} else {
|
||||
date = new Date(timestamp as string | number | Date);
|
||||
}
|
||||
|
||||
const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
||||
|
||||
if (seconds < 60) return 'Just now';
|
||||
if (seconds < 3600) return `${Math.floor(seconds / 60)} minutes ago`;
|
||||
if (seconds < 86400) return `${Math.floor(seconds / 3600)} hours ago`;
|
||||
if (seconds < 2592000) return `${Math.floor(seconds / 86400)} days ago`;
|
||||
return date.toLocaleDateString();
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Header */}
|
||||
<div className="flex h-14 items-center justify-between border-b px-6">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold">Projects</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Manage your product development projects
|
||||
</p>
|
||||
</div>
|
||||
<Button onClick={() => setShowCreationModal(true)}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
New Project
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Content */}
|
||||
<div className="flex-1 overflow-auto p-6">
|
||||
<div className="mx-auto max-w-7xl space-y-8">
|
||||
{/* Loading State */}
|
||||
{loading && (
|
||||
<div className="flex items-center justify-center py-16">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Error State */}
|
||||
{error && (
|
||||
<Card className="border-red-500/50 bg-red-500/5">
|
||||
<CardContent className="py-6">
|
||||
<p className="text-sm text-red-600">Error: {error}</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{/* Projects Grid */}
|
||||
{!loading && !error && projects.length > 0 && (
|
||||
<section>
|
||||
<h2 className="text-base font-semibold mb-4">Your Projects</h2>
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
|
||||
{projects.map((project) => {
|
||||
const projectHref = `/${workspace}/project/${project.id}/overview`;
|
||||
return (
|
||||
<div key={project.id} className="relative">
|
||||
<Link href={projectHref}>
|
||||
<Card className="hover:border-primary transition-all cursor-pointer h-full">
|
||||
<CardHeader>
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="text-3xl">📦</div>
|
||||
<div>
|
||||
<CardTitle className="text-base">{project.productName}</CardTitle>
|
||||
<CardDescription className="text-xs mt-0.5">
|
||||
{getTimeAgo(project.updatedAt)}
|
||||
</CardDescription>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className={`px-2 py-0.5 rounded-full text-xs font-medium ${
|
||||
project.status === "active"
|
||||
? "bg-green-500/10 text-green-600"
|
||||
: "bg-gray-500/10 text-gray-600"
|
||||
}`}
|
||||
>
|
||||
{project.status}
|
||||
</div>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild onClick={(e: React.MouseEvent) => e.preventDefault()}>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
className="text-red-600 focus:text-red-600"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.preventDefault();
|
||||
setProjectToDelete(project);
|
||||
}}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
Delete Project
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<p className="text-sm text-muted-foreground mb-4 line-clamp-2">
|
||||
{project.productVision || 'No description'}
|
||||
</p>
|
||||
{project.workspacePath && (
|
||||
<p className="text-xs text-muted-foreground font-mono mb-4 truncate" title={project.workspacePath}>
|
||||
📁 {project.workspacePath.split('/').pop()}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center justify-between text-xs">
|
||||
<div>
|
||||
<span className="text-muted-foreground">Sessions:</span>{" "}
|
||||
<span className="font-medium">{project.stats.sessions}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-muted-foreground">Costs:</span>{" "}
|
||||
<span className="font-medium">${project.stats.costs.toFixed(2)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* New Project Card */}
|
||||
<Card
|
||||
className="hover:border-primary transition-all cursor-pointer border-dashed h-full"
|
||||
onClick={() => setShowCreationModal(true)}
|
||||
>
|
||||
<CardContent className="flex flex-col items-center justify-center h-full min-h-[200px] p-6">
|
||||
<div className="rounded-full bg-muted p-4 mb-4">
|
||||
<Plus className="h-6 w-6 text-muted-foreground" />
|
||||
</div>
|
||||
<h3 className="font-semibold mb-1">Create New Project</h3>
|
||||
<p className="text-sm text-muted-foreground text-center">
|
||||
Start tracking a new product
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{/* Empty State (show when no projects) */}
|
||||
{!loading && !error && projects.length === 0 && (
|
||||
<Card className="border-dashed">
|
||||
<CardContent className="flex flex-col items-center justify-center py-16">
|
||||
<div className="rounded-full bg-muted p-6 mb-4">
|
||||
<Sparkles className="h-12 w-12 text-muted-foreground" />
|
||||
</div>
|
||||
<h3 className="text-lg font-semibold mb-2">No projects yet</h3>
|
||||
<p className="text-sm text-muted-foreground text-center max-w-md mb-6">
|
||||
Create your first project to start tracking your AI-powered development
|
||||
workflow, manage costs, and maintain living documentation.
|
||||
</p>
|
||||
<Button size="lg" onClick={() => setShowCreationModal(true)}>
|
||||
<Plus className="mr-2 h-4 w-4" />
|
||||
Create Your First Project
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Creation Modal */}
|
||||
<ProjectCreationModal
|
||||
open={showCreationModal}
|
||||
onOpenChange={(open) => {
|
||||
setShowCreationModal(open);
|
||||
if (!open) {
|
||||
// Refresh projects list when modal closes
|
||||
const user = auth.currentUser;
|
||||
if (user) fetchProjects(user);
|
||||
}
|
||||
}}
|
||||
workspace={workspace}
|
||||
/>
|
||||
|
||||
{/* Delete Project Confirmation Dialog */}
|
||||
<AlertDialog open={!!projectToDelete} onOpenChange={(open) => !open && setProjectToDelete(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action will delete the project "{projectToDelete?.productName}".
|
||||
All associated sessions and data will be preserved but unlinked from this project.
|
||||
You can reassign them to another project later.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDeleteProject} disabled={isDeleting} className="bg-red-600 hover:bg-red-700">
|
||||
{isDeleting ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
Delete Project
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user