Files

71 lines
2.5 KiB
TypeScript
Raw Permalink Normal View History

2025-05-18 20:46:59 +02:00
import {PageParams} from "@/types/next";
2026-05-24 17:09:12 +02:00
import {CardsWithPagination} from "@/components/common/cards-with-pagination";
2025-05-18 20:46:59 +02:00
import {Page, PageActions, PageContent, PageHeader, PageTitle} from "@/features/layout/page";
2026-05-24 17:09:12 +02:00
import {ProjectCard} from "@/features/projects/project-card";
2025-05-18 20:46:59 +02:00
import {db} from "@/db";
import {notFound} from "next/navigation";
2025-11-01 14:50:08 +01:00
import {getActiveMember, getOrganization} from "@/lib/auth/auth";
2026-05-24 17:09:12 +02:00
import {EmptyStatePlaceholder} from "@/components/common/empty-state-placeholder";
2025-11-04 08:48:46 +01:00
import {Metadata} from "next";
2026-05-24 17:09:12 +02:00
import {ProjectDialog} from "@/features/projects/project-dialog";
2026-01-28 15:54:03 +01:00
import {DatabaseWith} from "@/db/schema/07_database";
2026-04-10 18:37:35 +02:00
import {getOrganizationAvailableDatabases} from "@/db/services/database";
2024-12-16 20:01:30 +01:00
2025-11-04 08:48:46 +01:00
export const metadata: Metadata = {
title: "Projects",
};
2025-11-03 11:37:14 +01:00
2025-11-01 14:50:08 +01:00
export default async function RoutePage(props: PageParams<{}>) {
2024-11-29 19:25:44 +01:00
2025-07-16 12:36:11 +02:00
const organization = await getOrganization({});
2025-11-01 14:50:08 +01:00
const activeMember = await getActiveMember()
2024-11-29 19:25:44 +01:00
2025-07-16 12:36:11 +02:00
if (!organization) {
2025-05-16 15:54:17 +02:00
notFound();
}
2024-11-30 21:05:47 +01:00
2025-05-16 15:54:17 +02:00
const projects = await db.query.project.findMany({
2025-05-18 20:46:59 +02:00
where: (project, {
eq,
and,
not
}) => and(eq(project.organizationId, organization.id), not(eq(project.isArchived, true))),
2025-05-16 15:54:17 +02:00
with: {
databases: true,
2024-11-30 21:05:47 +01:00
},
2025-05-16 15:54:17 +02:00
});
2025-11-01 14:50:08 +01:00
const isMember = activeMember?.role === "member";
2026-04-10 18:37:35 +02:00
const availableDatabases = await getOrganizationAvailableDatabases(organization.id)
2026-01-28 15:54:03 +01:00
2024-11-29 19:25:44 +01:00
return (
<Page>
<PageHeader>
2025-05-16 15:54:17 +02:00
<PageTitle>Projects</PageTitle>
2025-11-01 14:50:08 +01:00
{(projects.length > 0 && !isMember) && (
2024-11-29 19:25:44 +01:00
<PageActions>
2026-01-29 19:10:59 +01:00
<ProjectDialog databases={availableDatabases} organization={organization}/>
2024-11-29 19:25:44 +01:00
</PageActions>
)}
</PageHeader>
2025-07-26 22:23:00 +02:00
<PageContent>
2025-05-16 15:54:17 +02:00
{projects.length > 0 ? (
2025-11-01 14:50:08 +01:00
<CardsWithPagination
organizationSlug={organization.slug}
data={projects}
cardItem={ProjectCard}
cardsPerPage={12}
2026-01-07 13:33:23 +01:00
numberOfColumns={3}
pageSizeOptions={[12, 24, 48]}
2025-08-02 08:48:45 +02:00
/>
2025-11-01 14:50:08 +01:00
) : isMember ? (
2026-04-10 18:37:35 +02:00
<EmptyStatePlaceholder state={"empty"} text="No project available"/>
2025-11-01 14:50:08 +01:00
) : (
2026-01-29 19:10:59 +01:00
<ProjectDialog databases={availableDatabases} organization={organization} isEmpty={true}/>
2025-05-16 15:54:17 +02:00
)}
2024-11-29 19:25:44 +01:00
</PageContent>
</Page>
2025-05-16 15:54:17 +02:00
);
2026-01-28 15:54:03 +01:00
}