'use client'; import { Button } from '@/components/ui/button'; import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger } from '@/components/ui/sheet'; import { Plus, Link as LinkIcon } from 'lucide-react'; import { useEffect, useState } from 'react'; import { Progress } from '@/components/ui/progress'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { cn } from '@/lib/utils'; import Link from 'next/link'; import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { getRepositoryBranches, getUserRepository, GithubRepository } from '@/actions/github/repository'; import { signOut, useSession } from 'next-auth/react'; import { Input } from '@/components/ui/input'; import { Checkbox } from '@/components/ui/checkbox'; import { createApplication, NewApplication } from '@/actions/deploy/application'; import { useParams, useRouter } from 'next/navigation'; 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 [steps, setSteps] = useState(1); const [open, setOpen] = useState(false); const params = useParams(); const [repositories, setRepositories] = useState([]); const [branches, setBranches] = useState([]); const [newApplication, setNewApplication] = useState({ serviceProvider: 'github', git: { repositoryId: 0, repositoryName: '', branch: '', path: '', }, autodeploy: true, env: {}, name: '', }); const { data: session } = useSession(); useEffect(() => { async function fetchRepositories() { if (newApplication.serviceProvider == 'github') { const repos = await getUserRepository(session?.user.id as string, session?.user.username as string); setRepositories(repos); } } fetchRepositories(); }, [newApplication.serviceProvider, session]); useEffect(() => { async function fetchBranches() { if (newApplication.serviceProvider == 'github' && newApplication.git.repositoryId != 0) { const branches = await getRepositoryBranches(session?.user.id as string, session?.user.username as string, newApplication.git.repositoryName); setBranches(branches); } } fetchBranches(); }, [newApplication.serviceProvider, newApplication.git.repositoryId, newApplication.git.repositoryName, session]); return ( setOpen((open) => !open)}> New Application Deploy a new application from source

Step: {(steps == 1 && 'Select Provider') || (steps == 2 && 'Resources') || (steps == 3 && 'Environment Variables') || (steps == 4 && 'Information') || (steps == 5 && 'Review')}

{steps} / 5

{steps == 1 && (
setNewApplication((prev) => ({ ...prev, serviceProvider: e }))}> {ServiceProviderList.map((provider) => (
))}
{newApplication.serviceProvider == 'github' && !!repositories && (

Repository

)} {newApplication.serviceProvider == 'github' && newApplication.git.repositoryId != 0 && ( <>

Branch

Path

setNewApplication((prev) => ({ ...prev, git: { ...prev.git, path: e.target.value } }))} />
setNewApplication((prev) => ({ ...prev, autodeploy: !prev.autodeploy }))}> { console.log(e); }} id={'autodeploy'} color="bg-[#3A7BFE]" />

Every time an update is made to this branch, your application will be re-deployed.

)}
{newApplication.serviceProvider == 'github' && (!repositories ? (

We don't have access to your repositories. s.value == newApplication.serviceProvider)?.permission || ''}>Link your GitHub account

) : (

Not seeing the repositories you expected here? s.value == newApplication.serviceProvider)?.permission || ''}>Edit Your GitHub Permissions

))}
)} {steps == 2 && (

Resources WIP

For now 1 vCPU & 1024Mb RAM

)} {steps == 3 && (

Environment Variables WIP

)} {steps == 4 && (

Application Name

setNewApplication((prev) => ({ ...prev, name: e.target.value }))} />
)} {steps == 5 && (

Service Provider

{newApplication.serviceProvider}

Repository

{newApplication.git.repositoryName}

Branch

{newApplication.git.branch}

Path

{newApplication.git.path}

Auto Deploy

{newApplication.autodeploy ? 'Enabled' : 'Disabled'}

Application Name

{newApplication.name}

)}
{steps == 5 ? ( ) : ( )}
); }