This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
docs/src/frontend/apps/impress/src/pages/teams/[id].tsx
Anthony LC 8fda0bc9b9 🚀(app-impress) create the base app impress
Create the base app impress, based on the
people app.
2024-04-02 16:39:17 +02:00

68 lines
1.5 KiB
TypeScript

import { Loader } from '@openfun/cunningham-react';
import { useRouter as useNavigate } from 'next/navigation';
import { useRouter } from 'next/router';
import { ReactElement } from 'react';
import { Box } from '@/components';
import { TextErrors } from '@/components/TextErrors';
import { MemberGrid } from '@/features/members';
import { Role, TeamInfo, TeamLayout, useTeam } from '@/features/teams/';
import { NextPageWithLayout } from '@/types/next';
const Page: NextPageWithLayout = () => {
const {
query: { id },
} = useRouter();
if (typeof id !== 'string') {
throw new Error('Invalid team id');
}
return <Team id={id} />;
};
interface TeamProps {
id: string;
}
const Team = ({ id }: TeamProps) => {
const { data: team, isLoading, isError, error } = useTeam({ id });
const navigate = useNavigate();
if (isError && error) {
if (error.status === 404) {
navigate.replace(`/404`);
return null;
}
return <TextErrors causes={error.cause} />;
}
if (isLoading || !team) {
return (
<Box $align="center" $justify="center" $height="100%">
<Loader />
</Box>
);
}
const currentRole = team.abilities.delete
? Role.OWNER
: team.abilities.manage_accesses
? Role.ADMIN
: Role.MEMBER;
return (
<>
<TeamInfo team={team} currentRole={currentRole} />
<MemberGrid team={team} currentRole={currentRole} />
</>
);
};
Page.getLayout = function getLayout(page: ReactElement) {
return <TeamLayout>{page}</TeamLayout>;
};
export default Page;