Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Aug 2, 2024
1 parent 5cb8491 commit 09eaad2
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default async function Page({
<PageHeading
title="Projects"
subTitle="You can create projects within teams, or within your organization."

/>
<div className="flex justify-between gap-2">
<div className="md:w-1/3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const DeleteOrganization = ({
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
>
<Card className="w-full max-w-4xl border-destructive/50 bg-destructive/5">
<Card className="w-full max-w-5xl border-destructive/50 bg-destructive/5">
<CardHeader>
<CardTitle>
Danger Zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function EditOrganizationForm({
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.3 }}
>
<Card className="w-full max-w-4xl">
<Card className="w-full max-w-5xl">
<CardHeader>
<CardTitle>Edit Organization</CardTitle>
<CardDescription>Update your organization's title and slug</CardDescription>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SetDefaultOrganizationButton } from './SetDefaultOrganizationButton';

function Wrapper({ children }: { children: React.ReactNode }) {
return (
<Card className="w-full max-w-4xl ">
<Card className="w-full max-w-5xl ">
<CardHeader className="space-y-1">
<CardTitle className="flex items-center space-x-2">
Default Organization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function TeamMembers({ organizationId }: { organizationId: string }) {
);

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

return (
<Card className=" max-w-4xl">
<Card className=" max-w-5xl">
<CardHeader>
<CardTitle>Invitations</CardTitle>
<CardDescription>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Pagination } from "@/components/Pagination";
import { getTeamAdminUserNameByTeamId, getTeams, getTeamsTotalCount } from "@/data/user/teams";
import { T } from "@/components/ui/Typography";
import { getTeamOwnerNameByTeamId, getTeams, getTeamsTotalCount } from "@/data/user/teams";
import { projectsfilterSchema } from "@/utils/zod-schemas/params";
import { OrganizationTeamsTable } from "./OrganizationTeamsTable";

Expand All @@ -8,25 +9,36 @@ export async function TeamsTableWithPagination({
searchParams,
}: { organizationId: string; searchParams: unknown }) {
const filters = projectsfilterSchema.parse(searchParams);
const [teams, totalPages, adminNames] = await Promise.all([
getTeams({ ...filters, organizationId }),
getTeamsTotalCount({ ...filters, organizationId }),
Promise.all(
(await getTeams({ ...filters, organizationId })).map(team =>
getTeamAdminUserNameByTeamId(team.id)
)
)
]);

const teamsWithAdminNames = teams.map((team, index) => ({
...team,
adminName: adminNames[index]
}));
try {
const [teams, totalPages] = await Promise.all([
getTeams({ ...filters, organizationId }),
getTeamsTotalCount({ ...filters, organizationId }),
]);

return (
<>
<OrganizationTeamsTable teams={teamsWithAdminNames} />
<Pagination totalPages={totalPages} />
</>
);
console.log('teams', teams);

const adminNames = await Promise.all(
teams.map(team => getTeamOwnerNameByTeamId(team.id))
);

const teamsWithAdminNames = teams.map((team, index) => ({
...team,
adminName: adminNames[index] || 'Unknown'
}));

if (teamsWithAdminNames.length === 0) {
return <T.P className="text-muted-foreground my-6">No teams found.</T.P>;
}

return (
<>
<OrganizationTeamsTable teams={teamsWithAdminNames} />
<Pagination totalPages={totalPages} />
</>
);
} catch (error) {
console.error('Error fetching teams data:', error);
return <T.P className="text-muted-foreground my-6">Error loading teams. Please try again later.</T.P>;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,18 @@ export default async function Page({

<CreateTeamDialog organizationId={organizationId} />
</div>
{
<Suspense
fallback={
<T.P className="text-muted-foreground my-6">
Loading teams...
</T.P>
}
>
<TeamsTableWithPagination
organizationId={organizationId}
searchParams={searchParams}
/>
</Suspense>
}
<Suspense
fallback={
<T.P className="text-muted-foreground my-6">
Loading teams...
</T.P>
}
>
<TeamsTableWithPagination
organizationId={organizationId}
searchParams={searchParams}
/>
</Suspense>
</div>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Button } from '@/components/ui/button';
import { T } from '@/components/ui/Typography';
import { getSlimTeamById } from '@/data/user/teams';
import { projectsfilterSchema } from '@/utils/zod-schemas/params';
import { Plus } from 'lucide-react';
import { Plus, Settings } from 'lucide-react';
import Link from 'next/link';
import { Suspense } from 'react';
import { z } from 'zod';
Expand Down Expand Up @@ -34,6 +34,14 @@ export default async function TeamPage({
<PageHeading
title={slimteam?.name ?? 'Team'}
subTitle="You can create projects within team"
actions={
<Link href={`/org/${organizationId}/team/${teamId}/settings`}>
<Button variant="outline" size="sm">
<Settings className="mr-2 h-4 w-4" />
Team Settings
</Button>
</Link>
}
/>
<div className="flex justify-between gap-2">
<div className="md:w-1/3">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function TeamSettingsPage({
const { teamId, organizationId } = parsedParams;

return (
<div className="space-y-8 max-w-4xl mt-2">
<div className="space-y-8 max-w-5xl mt-2">
<PageHeading
title="Team Settings"
subTitle="Manage team members and settings here"
Expand Down
49 changes: 43 additions & 6 deletions src/data/user/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export const getTeamsInOrganization = async (
.order('created_at', { ascending: true });

if (error) {
throw error;
console.error('Error fetching projects:', error);
return [];
}

if (!data) {
Expand Down Expand Up @@ -74,12 +75,12 @@ export const getTeams = async ({
});

if (error) {
console.error('Error fetching teams:', error);
throw error;
}

return data;
return data || [];
};

export const getTeamsTotalCount = async ({
organizationId,
query = '',
Expand Down Expand Up @@ -254,6 +255,35 @@ export const getTeamMembersByTeamId = async (teamId: number) => {
};

export const getTeamAdminUserNameByTeamId = async (teamId: number) => {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('team_members')
.select(
`
user_profiles (
full_name
)
`,
)
.eq('team_id', teamId)
.eq('role', 'admin');

if (error) {
console.error('Error fetching team admin names:', error);
return null;
}

if (!data || data.length === 0) {
return null;
}

// If there are multiple admins, join their names
const adminNames = data
.map((item) => item.user_profiles?.full_name)
.filter(Boolean);
return adminNames.join(', ') || null;
};
export const getTeamOwnerNameByTeamId = async (teamId: number) => {
const supabase = createSupabaseUserServerComponentClient();
const { data, error } = await supabase
.from('team_members')
Expand All @@ -266,13 +296,20 @@ export const getTeamAdminUserNameByTeamId = async (teamId: number) => {
)
.eq('team_id', teamId)
.eq('role', 'admin')
.single();
.order('created_at', { ascending: true })
.limit(1);

if (error) {
throw error;
console.error('Error fetching team owner name:', error);
return null;
}

if (!data || data.length === 0) {
return null;
}

return data?.user_profiles?.full_name ?? null;
const ownerName = data[0].user_profiles?.full_name;
return ownerName || null;
};

export const getCanLoggedInUserManageTeam = async (
Expand Down

0 comments on commit 09eaad2

Please sign in to comment.