diff --git a/packages/frontend/src/pages/org-slug/projects/create/index.tsx b/packages/frontend/src/pages/org-slug/projects/create/index.tsx
index 5c6aaf51..b80731d0 100644
--- a/packages/frontend/src/pages/org-slug/projects/create/index.tsx
+++ b/packages/frontend/src/pages/org-slug/projects/create/index.tsx
@@ -13,12 +13,12 @@ const NewProject = () => {
<>
- {templateDetails.map((framework, key) => {
+ {templateDetails.map((template) => {
return (
);
})}
diff --git a/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx b/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx
index 1d0e0f5c..50006ede 100644
--- a/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx
+++ b/packages/frontend/src/pages/org-slug/projects/create/template/index.tsx
@@ -1,31 +1,104 @@
-import React from 'react';
-import { useForm, Controller } from 'react-hook-form';
-import { Link } from 'react-router-dom';
+import React, { useCallback, useEffect, useState } from 'react';
+import { useForm, Controller, SubmitHandler } from 'react-hook-form';
+import { useNavigate, useParams } from 'react-router-dom';
+import toast from 'react-hot-toast';
+import assert from 'assert';
-import { Typography } from '@material-tailwind/react';
+import { Option, Typography } from '@material-tailwind/react';
-import Dropdown from '../../../../../components/Dropdown';
+import { useOctokit } from '../../../../../context/OctokitContext';
+import { useGQLClient } from '../../../../../context/GQLClientContext';
+import AsyncSelect from '../../../../../components/shared/AsyncSelect';
-const USER_OPTIONS = [
- { value: 'saugatyadav1', label: 'saugatyadav1' },
- { value: 'brad102', label: 'brad102' },
- { value: 'erin20', label: 'erin20' },
-];
+type SubmitRepoValues = {
+ framework: string;
+ repoName: string;
+ isPrivate: boolean;
+ account: string;
+};
const CreateRepo = () => {
- const { register, handleSubmit, control } = useForm({
+ const { octokit } = useOctokit();
+
+ const client = useGQLClient();
+
+ const { orgSlug } = useParams();
+
+ const navigate = useNavigate();
+
+ const [gitAccounts, setGitAccounts] = useState
([]);
+
+ const submitRepoHandler: SubmitHandler = useCallback(
+ async (data) => {
+ assert(data.account);
+
+ try {
+ // TODO: Handle this functionality in backend
+ const gitRepo = await octokit?.rest.repos.createUsingTemplate({
+ template_owner: 'github-rest',
+ template_repo: 'test-progressive-web-app',
+ owner: data.account,
+ name: data.repoName,
+ description: 'This is your first repository',
+ include_all_branches: false,
+ private: data.isPrivate,
+ });
+
+ if (!gitRepo) {
+ return;
+ }
+
+ const { addProject } = await client.addProject(orgSlug!, {
+ name: `${gitRepo.data.owner!.login}-${gitRepo.data.name}`,
+ // TODO: Get organization id from context or URL
+ prodBranch: gitRepo.data.default_branch ?? 'main',
+ repository: gitRepo.data.full_name,
+ });
+
+ navigate(
+ `/${orgSlug}/projects/create/template/deploy?projectId=${addProject.id}`,
+ );
+ } catch (err) {
+ toast.error('Error deploying project');
+ }
+ },
+ [octokit],
+ );
+
+ useEffect(() => {
+ const fetchUserAndOrgs = async () => {
+ const user = await octokit?.rest.users.getAuthenticated();
+ const orgs = await octokit?.rest.orgs.listForAuthenticatedUser();
+
+ if (user && orgs) {
+ const orgsLoginArr = orgs.data.map((org) => org.login);
+
+ setGitAccounts([user.data.login, ...orgsLoginArr]);
+ }
+ };
+
+ fetchUserAndOrgs();
+ }, [octokit]);
+
+ const { register, handleSubmit, control, reset } = useForm({
defaultValues: {
- framework: 'reactNative',
+ framework: 'React',
repoName: '',
isPrivate: false,
- account: { value: 'saugatyadav1', label: 'saugatyadav1' },
+ account: gitAccounts[0],
},
});
+ useEffect(() => {
+ if (gitAccounts.length > 0) {
+ reset({ account: gitAccounts[0] });
+ }
+ }, [gitAccounts]);
+
// TODO: Get users and orgs from GitHub
return (
-