- {/* TODO: Fix selection of Git user at start */}
-
+
Promise;
}
@@ -44,7 +43,7 @@ const DOMAIN_RECORD = {
const DomainCard = ({
domains,
domain,
- repo,
+ branches,
project,
onUpdate,
}: DomainCardProps) => {
@@ -188,7 +187,7 @@ const DomainCard = ({
domains={domains}
open={editDialogOpen}
domain={domain}
- repo={repo}
+ branches={branches}
onUpdate={onUpdate}
/>
>
diff --git a/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx b/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx
index 78e4aceb..b9d2866c 100644
--- a/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx
+++ b/packages/frontend/src/components/projects/project/settings/EditDomainDialog.tsx
@@ -15,7 +15,6 @@ import {
Option,
} from '@material-tailwind/react';
-import { RepositoryDetails } from '../../../../types';
import { useGQLClient } from '../../../../context/GQLClientContext';
const DEFAULT_REDIRECT_OPTIONS = ['none'];
@@ -25,7 +24,7 @@ interface EditDomainDialogProp {
open: boolean;
handleOpen: () => void;
domain: Domain;
- repo: RepositoryDetails;
+ branches: string[];
onUpdate: () => Promise;
}
@@ -40,7 +39,7 @@ const EditDomainDialog = ({
open,
handleOpen,
domain,
- repo,
+ branches,
onUpdate,
}: EditDomainDialogProp) => {
const client = useGQLClient();
@@ -120,7 +119,7 @@ const EditDomainDialog = ({
branch: domain.branch,
redirectedTo: getRedirectUrl(domain),
});
- }, [domain, repo]);
+ }, [domain]);
return (
Import a repository
-
+
>
) : (
diff --git a/packages/frontend/src/pages/org-slug/projects/id/Overview.tsx b/packages/frontend/src/pages/org-slug/projects/id/Overview.tsx
index c5db5c34..a5f1ad73 100644
--- a/packages/frontend/src/pages/org-slug/projects/id/Overview.tsx
+++ b/packages/frontend/src/pages/org-slug/projects/id/Overview.tsx
@@ -24,10 +24,6 @@ const OverviewTabPanel = () => {
const { project } = useOutletContext
();
useEffect(() => {
- if (!octokit) {
- return;
- }
-
// TODO: Save repo commits in DB and avoid using GitHub API in frontend
// TODO: Figure out fetching latest commits for all branches
const fetchRepoActivity = async () => {
diff --git a/packages/frontend/src/pages/org-slug/projects/id/settings/Domains.tsx b/packages/frontend/src/pages/org-slug/projects/id/settings/Domains.tsx
index f912e8fa..24457b1a 100644
--- a/packages/frontend/src/pages/org-slug/projects/id/settings/Domains.tsx
+++ b/packages/frontend/src/pages/org-slug/projects/id/settings/Domains.tsx
@@ -1,4 +1,5 @@
-import React, { useEffect, useState } from 'react';
+import { RequestError } from 'octokit';
+import React, { useCallback, useEffect, useState } from 'react';
import { Link, useOutletContext } from 'react-router-dom';
import { Domain } from 'gql-client';
@@ -6,14 +7,41 @@ import { Button, Typography } from '@material-tailwind/react';
import DomainCard from '../../../../../components/projects/project/settings/DomainCard';
import { useGQLClient } from '../../../../../context/GQLClientContext';
-import repositories from '../../../../../assets/repositories.json';
import { OutletContextType } from '../../../../../types';
+import { useOctokit } from '../../../../../context/OctokitContext';
const Domains = () => {
const client = useGQLClient();
+ const { octokit } = useOctokit();
const { project } = useOutletContext();
const [domains, setDomains] = useState([]);
+ const [branches, setBranches] = useState([]);
+
+ const fetchBranches = useCallback(async () => {
+ const [owner, repo] = project.repository.split('/');
+
+ try {
+ const result = await octokit.rest.repos.listBranches({
+ owner,
+ repo,
+ });
+
+ const branches = result.data.map((repo) => repo.name);
+
+ setBranches(branches);
+ } catch (err) {
+ if (!(err instanceof RequestError && err.status === 404)) {
+ throw err;
+ }
+
+ console.error(err);
+ }
+ }, []);
+
+ useEffect(() => {
+ fetchBranches();
+ }, []);
const fetchDomains = async () => {
if (project === undefined) {
@@ -46,7 +74,7 @@ const Domains = () => {
domain={domain}
key={domain.id}
// TODO: Use github API for getting linked repository
- repo={repositories[0]!}
+ branches={branches}
project={project}
onUpdate={fetchDomains}
/>
diff --git a/packages/frontend/src/types.ts b/packages/frontend/src/types.ts
index 1ece61d3..2ca22da6 100644
--- a/packages/frontend/src/types.ts
+++ b/packages/frontend/src/types.ts
@@ -6,15 +6,6 @@ export interface GitOrgDetails {
avatar_url: string;
}
-// TODO: Use GitRepositoryDetails
-export interface RepositoryDetails {
- title: string;
- updatedAt: string;
- user: string;
- private: boolean;
- branch: string[];
-}
-
export interface GitRepositoryDetails {
id: number;
name: string;