Skip to content

Commit

Permalink
Fixes Members Page Routing bug (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzelei authored Dec 16, 2023
1 parent 4129b00 commit c2df7e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 4 additions & 1 deletion frontend/apps/web/app/[account]/settings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PageHeader from '@/components/headers/PageHeader';
import { useAccount } from '@/components/providers/account-provider';
import { useGetSystemAppConfig } from '@/libs/hooks/useGetSystemAppConfig';
import { cn } from '@/libs/utils';
import { UserAccountType } from '@neosync/sdk';
import Link from 'next/link';
import { usePathname } from 'next/navigation';

Expand Down Expand Up @@ -45,7 +46,9 @@ export default function SettingsLayout({
const items = getNavSettings(account?.name ?? '');

const filteredItems =
!isSystemConfigLoading && systemAppConfigData?.isAuthEnabled
!isSystemConfigLoading &&
systemAppConfigData?.isAuthEnabled &&
account?.type === UserAccountType.TEAM
? items
: items.filter((item) => item.title !== 'Members');

Expand Down
14 changes: 11 additions & 3 deletions frontend/apps/web/app/[account]/settings/members/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use client';
import { useAccount } from '@/components/providers/account-provider';
import { Alert, AlertTitle } from '@/components/ui/alert';
import { Skeleton } from '@/components/ui/skeleton';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { UserAccountType } from '@neosync/sdk';
import { ReactElement } from 'react';
import { InvitesTable } from './components/InviteTable';
import MembersTable from './components/MemberTable';
Expand All @@ -16,13 +18,19 @@ export default function MemberManagementSettings(_: Props): ReactElement {
return <Skeleton className="w-full h-12" />;
}

const isTeamAccount = account?.type.toString() == 'USER_ACCOUNT_TYPE_TEAM';
const isTeamAccount = account?.type === UserAccountType.TEAM;
if (!isTeamAccount) {
return <div></div>;
return (
<div>
<Alert variant="destructive">
<AlertTitle>Members can only be added to team accounts</AlertTitle>
</Alert>
</div>
);
}

return (
<div className="mt-10">
<div className="flex flex-col gap-3">
<h1 className="text-xl font-bold tracking-tight">Member Managment</h1>
<Tabs defaultValue="members">
<TabsList>
Expand Down
7 changes: 6 additions & 1 deletion frontend/apps/web/app/[account]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import OverviewContainer from '@/components/containers/OverviewContainer';
import PageHeader from '@/components/headers/PageHeader';
import { useAccount } from '@/components/providers/account-provider';
import { useGetSystemAppConfig } from '@/libs/hooks/useGetSystemAppConfig';
import { UserAccountType } from '@neosync/sdk';
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';

Expand All @@ -17,7 +18,11 @@ export default function Settings() {
if (isSystemAppConfigDataLoading || isAccountLoading) {
return;
}
if (systemAppConfigData?.isAuthEnabled && account?.name) {
if (
systemAppConfigData?.isAuthEnabled &&
account?.name &&
account.type === UserAccountType.TEAM
) {
return router.push(`/${account?.name}/settings/members`);
} else {
return router.push('/personal/settings/temporal');
Expand Down
3 changes: 2 additions & 1 deletion frontend/apps/web/libs/hooks/useGetSystemAppConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { SystemAppConfig } from '@/app/config/app-config';
import useSWR, { KeyedMutator } from 'swr';
import { fetcher } from '../fetcher';
import type { HookReply } from './types';
import { useGenericErrorToast } from './useGenericErrorToast';

export function useGetSystemAppConfig(): HookReply<SystemAppConfig> {
const { data, error, mutate, isLoading, isValidating } =
useSWR(`/api/config`);
useSWR<SystemAppConfig>(`/api/config`, fetcher);
useGenericErrorToast(error);

if (isLoading) {
Expand Down

0 comments on commit c2df7e8

Please sign in to comment.