Skip to content

Commit

Permalink
Create projects table
Browse files Browse the repository at this point in the history
  • Loading branch information
gramliu committed Dec 5, 2023
1 parent 25f80b0 commit c2fcc29
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 28 deletions.
27 changes: 22 additions & 5 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
"use client";
import "@tldraw/tldraw/tldraw.css";
import { Toaster } from "@ui/components";
import { auth } from "@clerk/nextjs";
import { SkeletonPlaceholder, Toaster } from "@ui/components";
import { prisma } from "database";
import { Suspense } from "react";
import Header from "~/components/header";
import ProjectsTable from "~/components/projects-table";

export default async function IndexPage() {
const { userId } = auth();

const projects = await prisma.project.findMany({
where: {
userId: userId,
},
include: {
repository: true,
},
});

export default function IndexPage() {
return (
<main className="h-full w-full flex flex-col p-5 pl-10 pt-5">
<Header>
<h1 className="text-2xl font-bold">Projects</h1>
</Header>
<section className="p-4 grid grid-cols-2 items-start justify-center"></section>
<section className="p-4">
<Suspense fallback={<SkeletonPlaceholder />}>
<ProjectsTable projects={projects} />
</Suspense>
</section>
<Toaster />
</main>
);
Expand Down
3 changes: 3 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"@tldraw/tldraw": "2.0.0-canary.699502d8c479",
"axios": "^1.5.1",
"clsx": "^2.0.0",
"database": "workspace:*",
"lucide-react": "^0.293.0",
"luxon": "^3.4.4",
"million": "^2.6.4",
"next": "^14.0.3",
"react": "^18.2.0",
Expand All @@ -24,6 +26,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@types/luxon": "^3.3.7",
"@types/node": "^17.0.12",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger
DropdownMenuTrigger,
} from "@ui/components";
import { User } from "lucide-react";
import HomeIcon from "./home-icon";
Expand Down Expand Up @@ -49,7 +49,9 @@ export default function Header({ children }: Props) {
<DropdownMenuLabel>
{user?.fullName ?? "My Profile"}
</DropdownMenuLabel>
<DropdownMenuLabel className="font-light pt-0">{user?.primaryEmailAddress.emailAddress ?? ""}</DropdownMenuLabel>
<DropdownMenuLabel className="font-light pt-0">
{user?.primaryEmailAddress.emailAddress ?? ""}
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
Expand Down
48 changes: 48 additions & 0 deletions apps/web/src/components/projects-table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@ui/components";
import { Project, Repository } from "database";
import { DateTime } from "luxon";

type ProjectWithRepository = Project & {
repository: Repository;
};

interface Props {
projects: ProjectWithRepository[];
}

/**
* Table for displaying the current user's projects
*/
export default function ProjectsTable({ projects }: Props) {
return (
<Table>
<TableHeader>
<TableRow>
<TableHead>Name</TableHead>
<TableHead>GitHub</TableHead>
<TableHead>Branch</TableHead>
<TableHead>Created</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{projects.map((project) => {
return (
<TableRow key={project.id}>
<TableCell>{project.name}</TableCell>
<TableCell>{project.repository.fullName}</TableCell>
<TableCell>{project.branch}</TableCell>
<TableCell>{DateTime.fromJSDate(project.createdAt).toFormat("dd MMM yyyy")}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
);
}
4 changes: 2 additions & 2 deletions packages/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@paralleldrive/cuid2": "^2.2.2",
"@prisma/client": "^5.5.2",
"@prisma/client": "^5.6.0",
"@t3-oss/env-core": "^0.7.1",
"core": "link:@t3-oss/env/core",
"zod": "^3.22.4"
Expand All @@ -34,7 +34,7 @@
"@types/node": "^17.0.12",
"config": "workspace:*",
"eslint": "^8.12.0",
"prisma": "^5.5.2",
"prisma": "^5.6.0",
"rimraf": "^3.0.2",
"tsconfig": "workspace:*",
"tsup": "^5.11.13",
Expand Down
3 changes: 2 additions & 1 deletion packages/database/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-1.1.x", "linux-musl-openssl-3.0.x"]
}

datasource db {
Expand Down Expand Up @@ -46,6 +45,8 @@ model Project {
id String @id @map("_id")
userId String
name String
repositoryId String @unique
repository Repository @relation(fields: [repositoryId], references: [id])
branch String
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./dialog";
export * from "./dropdown-menu";
export * from "./popover";
export * from "./skeleton";
export * from "./table";
export * from "./tabs";
export * from "./toast";
export * from "./toaster";
Expand Down
117 changes: 117 additions & 0 deletions packages/ui/src/components/ui/table.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import * as React from "react"

import { cn } from "@ui/lib/utils"

const Table = React.forwardRef<
HTMLTableElement,
React.HTMLAttributes<HTMLTableElement>
>(({ className, ...props }, ref) => (
<div className="relative w-full overflow-auto">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
))
Table.displayName = "Table"

const TableHeader = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
))
TableHeader.displayName = "TableHeader"

const TableBody = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tbody
ref={ref}
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
))
TableBody.displayName = "TableBody"

const TableFooter = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tfoot
ref={ref}
className={cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
))
TableFooter.displayName = "TableFooter"

const TableRow = React.forwardRef<
HTMLTableRowElement,
React.HTMLAttributes<HTMLTableRowElement>
>(({ className, ...props }, ref) => (
<tr
ref={ref}
className={cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
/>
))
TableRow.displayName = "TableRow"

const TableHead = React.forwardRef<
HTMLTableCellElement,
React.ThHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<th
ref={ref}
className={cn(
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
))
TableHead.displayName = "TableHead"

const TableCell = React.forwardRef<
HTMLTableCellElement,
React.TdHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<td
ref={ref}
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
{...props}
/>
))
TableCell.displayName = "TableCell"

const TableCaption = React.forwardRef<
HTMLTableCaptionElement,
React.HTMLAttributes<HTMLTableCaptionElement>
>(({ className, ...props }, ref) => (
<caption
ref={ref}
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
))
TableCaption.displayName = "TableCaption"

export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}
Loading

0 comments on commit c2fcc29

Please sign in to comment.