[[...routeSlug]].tsx80 lines · main
| 1 | import { NextPage } from 'next' |
| 2 | import Head from 'next/head' |
| 3 | import { useRouter } from 'next/router' |
| 4 | import { cn } from 'ui' |
| 5 | |
| 6 | import { |
| 7 | Header, |
| 8 | LoadingCardView, |
| 9 | NoOrganizationsState, |
| 10 | } from '@/components/interfaces/Home/ProjectList/EmptyStates' |
| 11 | import { buildOrgUrl } from '@/components/interfaces/Organization/Organization.utils' |
| 12 | import { OrganizationCard } from '@/components/interfaces/Organization/OrganizationCard' |
| 13 | import { PageLayout } from '@/components/layouts/PageLayout/PageLayout' |
| 14 | import { ScaffoldContainer, ScaffoldSection } from '@/components/layouts/Scaffold' |
| 15 | import { useOrganizationsQuery } from '@/data/organizations/organizations-query' |
| 16 | import { useCustomContent } from '@/hooks/custom-content/useCustomContent' |
| 17 | import { withAuth } from '@/hooks/misc/withAuth' |
| 18 | import { buildStudioPageTitle } from '@/lib/page-title' |
| 19 | |
| 20 | const GenericOrganizationPage: NextPage = () => { |
| 21 | const router = useRouter() |
| 22 | const { appTitle } = useCustomContent(['app:title']) |
| 23 | const { routeSlug, ...queryParams } = router.query |
| 24 | const queryString = |
| 25 | Object.keys(queryParams).length > 0 |
| 26 | ? new URLSearchParams(queryParams as Record<string, string>).toString() |
| 27 | : '' |
| 28 | |
| 29 | const { data: organizations, isPending: isLoading } = useOrganizationsQuery() |
| 30 | const pageTitle = buildStudioPageTitle({ |
| 31 | section: 'Select an organization', |
| 32 | surface: 'Organizations', |
| 33 | brand: appTitle || 'Briven', |
| 34 | }) |
| 35 | |
| 36 | return ( |
| 37 | <> |
| 38 | <Head> |
| 39 | <title>{pageTitle}</title> |
| 40 | <meta name="description" content="Briven Studio" /> |
| 41 | </Head> |
| 42 | <Header /> |
| 43 | <PageLayout className="grow min-h-0" title="Select an organization to continue"> |
| 44 | <ScaffoldContainer> |
| 45 | <ScaffoldSection isFullWidth> |
| 46 | <div |
| 47 | className="grow overflow-y-auto" |
| 48 | style={{ maxHeight: 'calc(100vh - 49px - 64px)' }} |
| 49 | > |
| 50 | <div className="w-full mx-auto flex flex-col gap-y-8"> |
| 51 | {isLoading ? ( |
| 52 | <LoadingCardView /> |
| 53 | ) : organizations?.length === 0 ? ( |
| 54 | <NoOrganizationsState /> |
| 55 | ) : ( |
| 56 | <ul |
| 57 | className={cn( |
| 58 | 'w-full mx-auto grid grid-cols-1 gap-4', |
| 59 | 'sm:grid-cols-1 md:grid-cols-1 lg:grid-cols-2 xl:grid-cols-3' |
| 60 | )} |
| 61 | > |
| 62 | {organizations?.map((org) => ( |
| 63 | <OrganizationCard |
| 64 | key={org.id} |
| 65 | organization={org} |
| 66 | href={buildOrgUrl({ slug: routeSlug, orgSlug: org.slug, queryString })} |
| 67 | /> |
| 68 | ))} |
| 69 | </ul> |
| 70 | )} |
| 71 | </div> |
| 72 | </div> |
| 73 | </ScaffoldSection> |
| 74 | </ScaffoldContainer> |
| 75 | </PageLayout> |
| 76 | </> |
| 77 | ) |
| 78 | } |
| 79 | |
| 80 | export default withAuth(GenericOrganizationPage) |