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,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>
);
}