Skip to content

Commit

Permalink
feat: add auto redirect for single organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhenry committed Mar 18, 2024
1 parent 8020282 commit bad0d38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/pages/organizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { ActionList, Avatar, Box, Octicon } from '@primer/react'
import { personalOctokit } from 'bot/octokit'
import { getAuthServerSideProps } from 'components/auth-guard'
import { useSession } from 'next-auth/react'
import { useRouter } from 'next/router'
import { FC, useEffect, useState } from 'react'

interface OrganizationsProps {}

const Organizations: FC<OrganizationsProps> = () => {
const router = useRouter()
const { data: session } = useSession()
const [organizations, setOrganizations] = useState<
Awaited<ReturnType<typeof getAllOrganizations>>
Expand All @@ -28,9 +30,14 @@ const Organizations: FC<OrganizationsProps> = () => {
}

getAllOrganizations(accessToken).then((orgs) => {
// When only one organization, redirect to that organization
if (orgs.length === 1) {
router.push(`/orgs/${orgs[0].login}`)
}

setOrganizations(orgs)
})
}, [session])
}, [session, router])

return (
<Box
Expand Down
18 changes: 17 additions & 1 deletion src/pages/orgs/[organizationId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,23 @@ const SingleOrganization = (
</Flash>
)}
</Box>
<h3>{orgData.login}</h3>
<Box
sx={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
}}
>
<Avatar src={orgData.avatar_url} size={24} />
<Box
as="h3"
sx={{
ml: 2,
}}
>
{orgData.login}
</Box>
</Box>
<Box>
{forks && (
<ActionList showDividers>
Expand Down

0 comments on commit bad0d38

Please sign in to comment.