diff --git a/app/(deploy)/[workspace]/CreateApplicationForm.tsx b/app/(deploy)/[workspace]/CreateApplicationForm.tsx index c9c9781..37da1db 100644 --- a/app/(deploy)/[workspace]/CreateApplicationForm.tsx +++ b/app/(deploy)/[workspace]/CreateApplicationForm.tsx @@ -9,8 +9,12 @@ 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 { getUserRepository, GithubRepository } from '@/actions/github/repository'; +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 = [ { @@ -31,47 +35,53 @@ export const ServiceProviderList = [ }, ]; -export type NewApplication = { - serviceProvider: string; - git: { - repositoryId: number; - repositoryName: string; - }; - env: { - [key: string]: string; - }; -}; - export default function CreateApplicationForm() { const [steps, setSteps] = useState(1); + const [open, setOpen] = useState(false); + + const params = useParams(); - const [serviceProvider, setServiceProvider] = useState('github'); const [repositories, setRepositories] = useState([]); + const [branches, setBranches] = useState([]); const [newApplication, setNewApplication] = useState({ - serviceProvider: '', + serviceProvider: 'github', git: { repositoryId: 0, repositoryName: '', + branch: '', + path: '', }, + autodeploy: true, env: {}, + name: '', }); const { data: session } = useSession(); useEffect(() => { async function fetchRepositories() { - if (serviceProvider == 'github') { + if (newApplication.serviceProvider == 'github') { const repos = await getUserRepository(session?.user.id as string, session?.user.username as string); setRepositories(repos); } } fetchRepositories(); - }, [serviceProvider, session]); + }, [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)}> - + {steps == 5 ? ( + + ) : ( + + )} diff --git a/components/ui/checkbox.tsx b/components/ui/checkbox.tsx new file mode 100644 index 0000000..1936b01 --- /dev/null +++ b/components/ui/checkbox.tsx @@ -0,0 +1,18 @@ +'use client'; + +import * as React from 'react'; +import * as CheckboxPrimitive from '@radix-ui/react-checkbox'; +import { Check } from 'lucide-react'; + +import { cn } from '@/lib/utils'; + +const Checkbox = React.forwardRef, React.ComponentPropsWithoutRef>(({ className, ...props }, ref) => ( + + + + + +)); +Checkbox.displayName = CheckboxPrimitive.Root.displayName; + +export { Checkbox }; diff --git a/components/ui/input.tsx b/components/ui/input.tsx new file mode 100644 index 0000000..677d05f --- /dev/null +++ b/components/ui/input.tsx @@ -0,0 +1,25 @@ +import * as React from "react" + +import { cn } from "@/lib/utils" + +export interface InputProps + extends React.InputHTMLAttributes {} + +const Input = React.forwardRef( + ({ className, type, ...props }, ref) => { + return ( + + ) + } +) +Input.displayName = "Input" + +export { Input }