Skip to content

Commit 09eaad2

Browse files
minor fixes
1 parent 5cb8491 commit 09eaad2

File tree

10 files changed

+104
-48
lines changed

10 files changed

+104
-48
lines changed

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/projects/page.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default async function Page({
3030
<PageHeading
3131
title="Projects"
3232
subTitle="You can create projects within teams, or within your organization."
33+
3334
/>
3435
<div className="flex justify-between gap-2">
3536
<div className="md:w-1/3">

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/settings/DeleteOrganization.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const DeleteOrganization = ({
8484
animate={{ opacity: 1, y: 0 }}
8585
transition={{ duration: 0.3 }}
8686
>
87-
<Card className="w-full max-w-4xl border-destructive/50 bg-destructive/5">
87+
<Card className="w-full max-w-5xl border-destructive/50 bg-destructive/5">
8888
<CardHeader>
8989
<CardTitle>
9090
Danger Zone

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/settings/EditOrganizationForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function EditOrganizationForm({
7575
animate={{ opacity: 1, y: 0 }}
7676
transition={{ duration: 0.3 }}
7777
>
78-
<Card className="w-full max-w-4xl">
78+
<Card className="w-full max-w-5xl">
7979
<CardHeader>
8080
<CardTitle>Edit Organization</CardTitle>
8181
<CardDescription>Update your organization's title and slug</CardDescription>

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/settings/SetDefaultOrganizationPreference.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SetDefaultOrganizationButton } from './SetDefaultOrganizationButton';
88

99
function Wrapper({ children }: { children: React.ReactNode }) {
1010
return (
11-
<Card className="w-full max-w-4xl ">
11+
<Card className="w-full max-w-5xl ">
1212
<CardHeader className="space-y-1">
1313
<CardTitle className="flex items-center space-x-2">
1414
Default Organization

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/settings/members/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async function TeamMembers({ organizationId }: { organizationId: string }) {
5252
);
5353

5454
return (
55-
<Card className="max-w-4xl">
55+
<Card className="max-w-5xl">
5656
<div className="flex flex-row justify-between items-center pr-6 w-full">
5757
<CardHeader>
5858
<CardTitle>Organization Members</CardTitle>
@@ -120,7 +120,7 @@ async function TeamInvitations({ organizationId }: { organizationId: string }) {
120120
}
121121

122122
return (
123-
<Card className=" max-w-4xl">
123+
<Card className=" max-w-5xl">
124124
<CardHeader>
125125
<CardTitle>Invitations</CardTitle>
126126
<CardDescription>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Pagination } from "@/components/Pagination";
2-
import { getTeamAdminUserNameByTeamId, getTeams, getTeamsTotalCount } from "@/data/user/teams";
2+
import { T } from "@/components/ui/Typography";
3+
import { getTeamOwnerNameByTeamId, getTeams, getTeamsTotalCount } from "@/data/user/teams";
34
import { projectsfilterSchema } from "@/utils/zod-schemas/params";
45
import { OrganizationTeamsTable } from "./OrganizationTeamsTable";
56

@@ -8,25 +9,36 @@ export async function TeamsTableWithPagination({
89
searchParams,
910
}: { organizationId: string; searchParams: unknown }) {
1011
const filters = projectsfilterSchema.parse(searchParams);
11-
const [teams, totalPages, adminNames] = await Promise.all([
12-
getTeams({ ...filters, organizationId }),
13-
getTeamsTotalCount({ ...filters, organizationId }),
14-
Promise.all(
15-
(await getTeams({ ...filters, organizationId })).map(team =>
16-
getTeamAdminUserNameByTeamId(team.id)
17-
)
18-
)
19-
]);
2012

21-
const teamsWithAdminNames = teams.map((team, index) => ({
22-
...team,
23-
adminName: adminNames[index]
24-
}));
13+
try {
14+
const [teams, totalPages] = await Promise.all([
15+
getTeams({ ...filters, organizationId }),
16+
getTeamsTotalCount({ ...filters, organizationId }),
17+
]);
2518

26-
return (
27-
<>
28-
<OrganizationTeamsTable teams={teamsWithAdminNames} />
29-
<Pagination totalPages={totalPages} />
30-
</>
31-
);
19+
console.log('teams', teams);
20+
21+
const adminNames = await Promise.all(
22+
teams.map(team => getTeamOwnerNameByTeamId(team.id))
23+
);
24+
25+
const teamsWithAdminNames = teams.map((team, index) => ({
26+
...team,
27+
adminName: adminNames[index] || 'Unknown'
28+
}));
29+
30+
if (teamsWithAdminNames.length === 0) {
31+
return <T.P className="text-muted-foreground my-6">No teams found.</T.P>;
32+
}
33+
34+
return (
35+
<>
36+
<OrganizationTeamsTable teams={teamsWithAdminNames} />
37+
<Pagination totalPages={totalPages} />
38+
</>
39+
);
40+
} catch (error) {
41+
console.error('Error fetching teams data:', error);
42+
return <T.P className="text-muted-foreground my-6">Error loading teams. Please try again later.</T.P>;
43+
}
3244
}

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/(specific-organization-pages)/teams/page.tsx

+13-15
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,18 @@ export default async function Page({
4141

4242
<CreateTeamDialog organizationId={organizationId} />
4343
</div>
44-
{
45-
<Suspense
46-
fallback={
47-
<T.P className="text-muted-foreground my-6">
48-
Loading teams...
49-
</T.P>
50-
}
51-
>
52-
<TeamsTableWithPagination
53-
organizationId={organizationId}
54-
searchParams={searchParams}
55-
/>
56-
</Suspense>
57-
}
44+
<Suspense
45+
fallback={
46+
<T.P className="text-muted-foreground my-6">
47+
Loading teams...
48+
</T.P>
49+
}
50+
>
51+
<TeamsTableWithPagination
52+
organizationId={organizationId}
53+
searchParams={searchParams}
54+
/>
55+
</Suspense>
5856
</div>
5957
);
60-
}
58+
}

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/team/[teamId]/(specific-team-pages)/page.tsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Button } from '@/components/ui/button';
55
import { T } from '@/components/ui/Typography';
66
import { getSlimTeamById } from '@/data/user/teams';
77
import { projectsfilterSchema } from '@/utils/zod-schemas/params';
8-
import { Plus } from 'lucide-react';
8+
import { Plus, Settings } from 'lucide-react';
99
import Link from 'next/link';
1010
import { Suspense } from 'react';
1111
import { z } from 'zod';
@@ -34,6 +34,14 @@ export default async function TeamPage({
3434
<PageHeading
3535
title={slimteam?.name ?? 'Team'}
3636
subTitle="You can create projects within team"
37+
actions={
38+
<Link href={`/org/${organizationId}/team/${teamId}/settings`}>
39+
<Button variant="outline" size="sm">
40+
<Settings className="mr-2 h-4 w-4" />
41+
Team Settings
42+
</Button>
43+
</Link>
44+
}
3745
/>
3846
<div className="flex justify-between gap-2">
3947
<div className="md:w-1/3">

src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/org/[organizationId]/team/[teamId]/(specific-team-pages)/settings/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default async function TeamSettingsPage({
1818
const { teamId, organizationId } = parsedParams;
1919

2020
return (
21-
<div className="space-y-8 max-w-4xl mt-2">
21+
<div className="space-y-8 max-w-5xl mt-2">
2222
<PageHeading
2323
title="Team Settings"
2424
subTitle="Manage team members and settings here"

src/data/user/teams.ts

+43-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const getTeamsInOrganization = async (
3737
.order('created_at', { ascending: true });
3838

3939
if (error) {
40-
throw error;
40+
console.error('Error fetching projects:', error);
41+
return [];
4142
}
4243

4344
if (!data) {
@@ -74,12 +75,12 @@ export const getTeams = async ({
7475
});
7576

7677
if (error) {
78+
console.error('Error fetching teams:', error);
7779
throw error;
7880
}
7981

80-
return data;
82+
return data || [];
8183
};
82-
8384
export const getTeamsTotalCount = async ({
8485
organizationId,
8586
query = '',
@@ -254,6 +255,35 @@ export const getTeamMembersByTeamId = async (teamId: number) => {
254255
};
255256

256257
export const getTeamAdminUserNameByTeamId = async (teamId: number) => {
258+
const supabase = createSupabaseUserServerComponentClient();
259+
const { data, error } = await supabase
260+
.from('team_members')
261+
.select(
262+
`
263+
user_profiles (
264+
full_name
265+
)
266+
`,
267+
)
268+
.eq('team_id', teamId)
269+
.eq('role', 'admin');
270+
271+
if (error) {
272+
console.error('Error fetching team admin names:', error);
273+
return null;
274+
}
275+
276+
if (!data || data.length === 0) {
277+
return null;
278+
}
279+
280+
// If there are multiple admins, join their names
281+
const adminNames = data
282+
.map((item) => item.user_profiles?.full_name)
283+
.filter(Boolean);
284+
return adminNames.join(', ') || null;
285+
};
286+
export const getTeamOwnerNameByTeamId = async (teamId: number) => {
257287
const supabase = createSupabaseUserServerComponentClient();
258288
const { data, error } = await supabase
259289
.from('team_members')
@@ -266,13 +296,20 @@ export const getTeamAdminUserNameByTeamId = async (teamId: number) => {
266296
)
267297
.eq('team_id', teamId)
268298
.eq('role', 'admin')
269-
.single();
299+
.order('created_at', { ascending: true })
300+
.limit(1);
270301

271302
if (error) {
272-
throw error;
303+
console.error('Error fetching team owner name:', error);
304+
return null;
305+
}
306+
307+
if (!data || data.length === 0) {
308+
return null;
273309
}
274310

275-
return data?.user_profiles?.full_name ?? null;
311+
const ownerName = data[0].user_profiles?.full_name;
312+
return ownerName || null;
276313
};
277314

278315
export const getCanLoggedInUserManageTeam = async (

0 commit comments

Comments
 (0)