"use client"; import { Plus } from "lucide-react"; import Link from "next/link"; import { useState } from "react"; import { toast } from "sonner"; import { useUser } from "@/hooks/useUser"; import { ProjectType } from "@/types"; import { ProjectCard } from "./project-card"; import { MAX_FREE_PROJECTS } from "@/lib/utils"; import { ProTag } from "@/components/pro-modal"; import { Button } from "@/components/ui/button"; import { useProModal } from "@/components/contexts/pro-context"; import { api } from "@/lib/api"; import { NotLogged } from "../not-logged/not-logged"; export function MyProjects() { const { user, projects, setProjects } = useUser(); const { openProModal } = useProModal(); if (!user) { return ; } const onDelete = async (project: ProjectType) => { const response = await api.delete(`/me/projects/${project.name}`); if (response.data.ok) { toast.success("Project deleted successfully!"); const newProjects = projects.filter((p) => p.id !== project.id); setProjects(newProjects); } else { toast.error(response.data.error); } }; return ( <> {user?.fullname}'s DeepSite Projects {user?.isPro ? ( "" ) : ( ({projects.length}/{MAX_FREE_PROJECTS}) )} {user?.isPro ? ( "Create, manage, and explore your DeepSite projects." ) : ( Upgrade to{" "} openProModal([])} />{" "} to create unlimited projects with DeepSite. )} {projects?.length >= MAX_FREE_PROJECTS && !user?.isPro ? ( openProModal([])} > Upgrade to PRO ) : ( // {}} /> )} {projects.length < MAX_FREE_PROJECTS || user?.isPro ? ( Create Project ) : ( openProModal([])} > Create Project )} {projects.map((project: ProjectType, index: number) => ( onDelete(project)} /> ))} > ); }
{user?.isPro ? ( "Create, manage, and explore your DeepSite projects." ) : ( Upgrade to{" "} openProModal([])} />{" "} to create unlimited projects with DeepSite. )}