This commit is contained in:
2024-03-23 22:00:26 +01:00
parent 77f7b60697
commit 957d49c976
23 changed files with 1853 additions and 296 deletions

View File

@@ -0,0 +1,72 @@
'use client';
import { Button } from '@/components/ui/button';
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from '@/components/ui/command';
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
import { cn } from '@/lib/utils';
import { Workspace } from '@prisma/client';
import { CommandList } from 'cmdk';
import { Check, ChevronsUpDown } from 'lucide-react';
import { usePathname, useRouter } from 'next/navigation';
import React from 'react';
export default function WorkspaceNavigation({ workspaces }: { workspaces: Pick<Workspace, 'id' | 'name' | 'slug'>[] }) {
const pathname = usePathname();
const [open, setOpen] = React.useState<boolean>(false);
const [value, setValue] = React.useState<Pick<Workspace, 'id'> | null>(findSelectedWorkspace());
const router = useRouter();
function onWorkspaceSelectionChange(workspace: Pick<Workspace, 'id'>) {
router.push(`/${workspaces.find((w) => w.id === workspace.id)?.slug}`);
}
function findSelectedWorkspace(): Pick<Workspace, 'id'> | null {
const workspace = pathname.split('/')[1];
if (!workspace) return null;
const w = workspaces.find((w) => w.slug === workspace);
if (!w) return null;
return { id: w.id };
}
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button variant="outline" role="combobox" aria-expanded={open} className="w-[200px] justify-between">
{value ? workspaces.find((workspace) => workspace.id === value.id)?.name : 'Select workspace...'}
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<Command>
<CommandInput placeholder="Search workspace..." />
<CommandList>
<CommandEmpty>
<Button variant="ghost" className="">
Create a Workspace
</Button>
</CommandEmpty>
<CommandGroup>
{workspaces.map((workspace) => (
<CommandItem
key={workspace.id}
value={workspace.id}
keywords={[workspace.name, workspace.slug]}
onSelect={(currentValue) => {
setValue({ id: currentValue });
onWorkspaceSelectionChange({ id: currentValue });
setOpen(false);
}}
>
<Check className={cn('mr-2 h-4 w-4', value?.id === workspace.id ? 'opacity-100' : 'opacity-0')} />
{workspace.name}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
);
}

View File

@@ -0,0 +1,68 @@
'use client';
import { Button } from '@/components/ui/button';
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { Plus } from 'lucide-react';
import { useEffect, useState } from 'react';
import { cn } from '@/lib/utils';
import Link from 'next/link';
export const ServiceProviderList = [
{
name: 'GitHub',
value: 'github',
image: 'https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png',
permission: 'https://github.com/apps/stalin-deploy/installations/new',
},
{
name: 'Registry',
value: 'registry',
image: '',
},
{
name: 'Github Registry',
value: 'github-registry',
image: 'https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png',
},
];
export default function CreateApplicationForm() {
const [serviceProvider, setServiceProvider] = useState<string>('github');
return (
<Sheet>
<SheetTrigger asChild>
<Button className="flex gap-1 justify-center items-center bg-[#3A7BFE]">
<Plus />
New Application
</Button>
</SheetTrigger>
<SheetContent className="min-w-[500px]">
<SheetHeader>
<SheetTitle>New Application</SheetTitle>
<SheetDescription>Deploy a new application from source</SheetDescription>
</SheetHeader>
<div>
<h3>Select Provider</h3>
<RadioGroup defaultValue="github" className="flex flex-col gap-4" onValueChange={setServiceProvider}>
{ServiceProviderList.map((provider) => (
<div key={provider.value} className={cn('flex flex-row items-center gap-4 border-[1px] rounded-lg py-2 px-4', provider.value == serviceProvider ? 'border-[#3A7BFE]' : 'border-gray-300')}>
<RadioGroupItem value={provider.value} id={provider.value} />
<label htmlFor={provider.value} className="flex flex-row items-center gap-4">
<img src={provider.image} alt={provider.name} className="w-8 h-8 rounded-full" />
{provider.name}
</label>
</div>
))}
</RadioGroup>
{(serviceProvider == 'github' || serviceProvider == 'github-registry') && (
<p>
Not seeing the repositories you expected here? <Link href={ServiceProviderList.find((s) => s.value == serviceProvider)?.permission || ''}>Edit Your GitHub Permissions</Link>
</p>
)}
</div>
</SheetContent>
</Sheet>
);
}

View File

@@ -0,0 +1,41 @@
'use client';
import { cn } from '@/lib/utils';
import { usePathname } from 'next/navigation';
let links = [
{ href: '', label: 'Applications' },
{ href: 'databases', label: 'Databases' },
{ href: 'registry', label: 'Registry' },
{ href: 'settings', label: 'Settings' },
];
export default function Navigation() {
let pathname = usePathname();
return (
<nav>
<ul className="flex flex-row justify-start mt-4 mb-2 gap-8">
{links.map(({ href, label }) => (
<li key={label}>
<a className={cn('px-3 py-2 rounded-md text-black font-medium text-sm', checkPathname(pathname, href) && 'bg-[#3A7BFE] text-white')} href={setHref(pathname, href)}>
{label}
</a>
</li>
))}
</ul>
</nav>
);
}
function checkPathname(pathname: string, href: string): boolean {
const route = pathname.split('/')[2] || '';
if (route === href) return true;
return false;
}
function setHref(pathname: string, href: string): string {
const route = pathname.split('/')[1];
if (!route) return '';
return `/${route}/${href}`;
}

View File

@@ -0,0 +1,21 @@
import { Button } from '@/components/ui/button';
import { Database, Plus } from 'lucide-react';
export default async function Databases() {
return (
<div className="mt-12">
<h1 className="text-3xl font-semibold">Databases</h1>
<div className="bg-white py-6 flex flex-col items-center rounded-lg mt-6 gap-4">
<Database size={64} className="text-gray-300" />
<div className="text-center">
<h3 className="font-semibold">No database</h3>
<p className="text-gray-700">Get started by creating a new database.</p>
</div>
<Button className="flex gap-1 justify-center items-center bg-[#3A7BFE]">
<Plus />
New Database
</Button>
</div>
</div>
);
}

View File

@@ -0,0 +1,18 @@
import Navigation from './Navigation';
export default async function WorkspaceLayout({ children }: Readonly<{ children: React.ReactNode }>) {
return (
<>
<div className="bg-white flex justify-center py-2 pt-4 border-b-2 border-b-gray-200">
<div className="container">
<div className="border-t-[1px] border-t-gray-200">
<Navigation />
</div>
</div>
</div>
<div className="bg-[#ECEFF1] overflow-y-auto flex-grow">
<div className="container">{children}</div>
</div>
</>
);
}

View File

@@ -0,0 +1,59 @@
import { Button } from '@/components/ui/button';
import prisma from '@/lib/prisma';
import { PackagePlus, Plus } from 'lucide-react';
import CreateApplicationForm from './CreateApplicationForm';
import { getSession } from 'next-auth/react';
export default async function Workspace({ params }: { params: { workspace: string } }) {
const applications = await prisma.application.findMany({
where: {
Workspace: {
name: params.workspace,
},
},
});
const session = await getSession();
const account = await prisma.account.findFirst({
where: {
userId: session?.user.id as string,
},
});
fetch('https://api.github.com/users/fayorg/repos', {
headers: {
Authorization: `Bearer ${account?.access_token}`,
},
})
.then((res) => res.json())
.then(console.log);
if (applications.length == 0) {
return (
<div className="mt-12">
<h1 className="text-3xl font-semibold">Applications</h1>
<div className="bg-white py-6 flex flex-col items-center rounded-lg mt-6 gap-4">
<PackagePlus size={64} className="text-gray-300" />
<div className="text-center">
<h3 className="font-semibold">No applications</h3>
<p className="text-gray-700">Get started by creating a new app.</p>
</div>
<CreateApplicationForm />
</div>
</div>
);
}
return (
<div className="mt-12">
<div className="flex flex-row justify-between">
<h1 className="text-3xl font-semibold">Applications</h1>
<Button className="flex gap-1 justify-center items-center bg-[#3A7BFE]">
<Plus />
New Application
</Button>
</div>
<div className="bg-white py-6 flex flex-col items-center rounded-lg mt-6 gap-4"></div>
</div>
);
}

43
app/(deploy)/layout.tsx Normal file
View File

@@ -0,0 +1,43 @@
import Image from 'next/image';
import '../globals.css';
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
import { redirect } from 'next/navigation';
import { getServerSession } from 'next-auth';
import prisma from '@/lib/prisma';
import WorkspaceNavigation from './WorkspaceNavigation';
export default async function DashboardLayout({ children }: Readonly<{ children: React.ReactNode }>) {
const session = await getServerSession();
if (!session) {
redirect('/sign-in');
}
const workspaces = await prisma.workspace.findMany({
where: {
ownerId: session.user.id as string,
},
});
return (
<>
<div className="bg-white flex justify-center pt-4">
<div className="container">
<div className="flex flex-row justify-between items-center">
<div>
<Image src="/stalin-deploy.png" alt="AkeTechnology" width={200} height={35} />
</div>
<div className="flex gap-2">
<WorkspaceNavigation workspaces={workspaces} />
<Avatar>
<AvatarImage src={session.user.image as string} alt={session.user.name as string} />
<AvatarFallback>{session.user.name.at(0) as string}</AvatarFallback>
</Avatar>
</div>
</div>
</div>
</div>
{children}
</>
);
}

19
app/(deploy)/page.tsx Normal file
View File

@@ -0,0 +1,19 @@
import prisma from '@/lib/prisma';
import { getServerSession } from 'next-auth';
import { redirect } from 'next/navigation';
// This component should never render
export default async function NoWorkspace() {
const session = await getServerSession();
const workspace = await prisma.workspace.findFirst({
where: {
ownerId: session?.user.id as string,
},
});
if (workspace) {
redirect(`/${workspace.slug}`);
}
return <div>You don't </div>;
}