import { useMemo } from 'react'; import { Plural, Trans, useLingui } from '@lingui/react/macro'; import { Building2Icon, InboxIcon, SettingsIcon, UsersIcon } from 'lucide-react'; import { DateTime } from 'luxon'; import { Link, redirect } from 'react-router'; import { useSession } from '@documenso/lib/client-only/providers/session'; import { ORGANISATION_MEMBER_ROLE_MAP } from '@documenso/lib/constants/organisations-translations'; import { TEAM_MEMBER_ROLE_MAP } from '@documenso/lib/constants/teams-translations'; import { formatAvatarUrl } from '@documenso/lib/utils/avatars'; import { canExecuteOrganisationAction } from '@documenso/lib/utils/organisations'; import { canExecuteTeamAction } from '@documenso/lib/utils/teams'; import { Avatar, AvatarFallback, AvatarImage } from '@documenso/ui/primitives/avatar'; import { Button } from '@documenso/ui/primitives/button'; import { Card, CardContent } from '@documenso/ui/primitives/card'; import { ScrollArea, ScrollBar } from '@documenso/ui/primitives/scroll-area'; import { OrganisationInvitations } from '~/components/general/organisations/organisation-invitations'; import { InboxTable } from '~/components/tables/inbox-table'; import { appMetaTags } from '~/utils/meta'; export function loader() { throw redirect('/'); } export function meta() { return appMetaTags('Dashboard'); } export default function DashboardPage() { const { t } = useLingui(); const { user, organisations } = useSession(); // Todo: Sort by recent access (TBD by cookies) // Teams, flattened with the organisation data still attached. const teams = useMemo(() => { return organisations.flatMap((org) => org.teams.map((team) => ({ ...team, organisation: { ...org, teams: undefined, }, })), ); }, [organisations]); return (

Dashboard

Welcome back! Here's an overview of your account.

{organisations.length === 0 && (

No organisations found

Create an organisation to get started.

)} {/* Organisations Section */} {organisations.length > 1 && (

Organisations

{/* Right hand side action if required. */} {/* */}
{organisations.map((org) => (
{org.avatarImageId && ( )} {org.name.slice(0, 1).toUpperCase()}

{org.name}

{org.ownerUserId === user.id ? t`Owner` : t(ORGANISATION_MEMBER_ROLE_MAP[org.currentOrganisationRole])}
# team} other={# teams} />
{canExecuteOrganisationAction( 'MANAGE_ORGANISATION', org.currentOrganisationRole, ) && (
)}
))}
)} {/* Teams Section */} {teams.length >= 1 && (

Teams

{/* */}
{teams.map((team) => (
{team.avatarImageId && ( )} {team.name.slice(0, 1).toUpperCase()}

{team.name}

{team.organisation.ownerUserId === user.id ? t`Owner` : t(TEAM_MEMBER_ROLE_MAP[team.currentTeamRole])}
{team.organisation.name}
Joined{' '} {DateTime.fromJSDate(team.createdAt).toRelative({ style: 'short' })}
{canExecuteTeamAction('MANAGE_TEAM', team.currentTeamRole) && (
)}
))}
)} {/* Inbox Section */}

Personal Inbox

{/* */}
); }