import { useCallback, useEffect, useMemo, useState } from 'react'; import { Link, Outlet, useLocation, useNavigate, useParams, } from 'react-router-dom'; import { Project as ProjectType } from 'gql-client'; import { useMediaQuery } from 'usehooks-ts'; import { useGQLClient } from '../../../context/GQLClientContext'; import { useOctokit } from '../../../context/OctokitContext'; import { Button } from 'components/shared/Button'; import { ChevronLeft } from 'components/shared/CustomIcon'; import { WavyBorder } from 'components/shared/WavyBorder'; import { Heading } from 'components/shared/Heading'; import { Tabs } from 'components/shared/Tabs'; const Id = () => { const { id } = useParams(); const { octokit } = useOctokit(); const navigate = useNavigate(); const client = useGQLClient(); const location = useLocation(); const isTabletView = useMediaQuery('(min-width: 720px)'); // md: const buttonSize = isTabletView ? {} : { size: 'sm' as const }; const [project, setProject] = useState(null); const [repoUrl, setRepoUrl] = useState(''); const fetchProject = useCallback(async (id: string | undefined) => { if (id) { const { project } = await client.getProject(id); setProject(project); if (project) { const [owner, repo] = project.repository.split('/'); const { data: repoDetails } = await octokit.rest.repos.get({ owner, repo, }); setRepoUrl(repoDetails.html_url); } } }, []); const currentTab = useMemo(() => { if (id) { const regex = /projects\/[^/]+\/([^/]+)/; const match = location.pathname.match(regex); return match ? match[1] : ''; } else { return ''; } }, [location, id]); useEffect(() => { fetchProject(id); }, [id]); const onUpdate = useCallback(async () => { await fetchProject(id); }, [fetchProject, id]); return (
{project ? ( <>
{project.deployments.length > 0 && ( )}
Overview Deployments {/* Integrations */} Settings {/* Not wrapping in Tab.Content because we are using Outlet */}
) : (
Project not found.
)}
); }; export default Id;