## Description Add support for teams which will allow users to collaborate on documents. Teams features allows users to: - Create, manage and transfer teams - Manage team members - Manage team emails - Manage a shared team inbox and documents These changes do NOT include the following, which are planned for a future release: - Team templates - Team API - Search menu integration ## Testing Performed - Added E2E tests for general team management - Added E2E tests to validate document counts ## Checklist - [X] I have tested these changes locally and they work as expected. - [X] I have added/updated tests that prove the effectiveness of these changes. - [ ] I have updated the documentation to reflect these changes, if applicable. - [X] I have followed the project's coding style guidelines.
99 lines
2.8 KiB
TypeScript
99 lines
2.8 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { TEAM_MEMBER_ROLE_MAP } from '@documenso/lib/constants/teams';
|
|
import type { TeamMemberRole } from '@documenso/prisma/client';
|
|
import { trpc } from '@documenso/trpc/react';
|
|
import { Alert } from '@documenso/ui/primitives/alert';
|
|
import { AvatarWithText } from '@documenso/ui/primitives/avatar';
|
|
import { Button } from '@documenso/ui/primitives/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@documenso/ui/primitives/dialog';
|
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
|
|
export type LeaveTeamDialogProps = {
|
|
teamId: number;
|
|
teamName: string;
|
|
role: TeamMemberRole;
|
|
trigger?: React.ReactNode;
|
|
};
|
|
|
|
export const LeaveTeamDialog = ({ trigger, teamId, teamName, role }: LeaveTeamDialogProps) => {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const { toast } = useToast();
|
|
|
|
const { mutateAsync: leaveTeam, isLoading: isLeavingTeam } = trpc.team.leaveTeam.useMutation({
|
|
onSuccess: () => {
|
|
toast({
|
|
title: 'Success',
|
|
description: 'You have successfully left this team.',
|
|
duration: 5000,
|
|
});
|
|
|
|
setOpen(false);
|
|
},
|
|
onError: () => {
|
|
toast({
|
|
title: 'An unknown error occurred',
|
|
variant: 'destructive',
|
|
duration: 10000,
|
|
description:
|
|
'We encountered an unknown error while attempting to leave this team. Please try again later.',
|
|
});
|
|
},
|
|
});
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={(value) => !isLeavingTeam && setOpen(value)}>
|
|
<DialogTrigger asChild>
|
|
{trigger ?? <Button variant="destructive">Leave team</Button>}
|
|
</DialogTrigger>
|
|
|
|
<DialogContent position="center">
|
|
<DialogHeader>
|
|
<DialogTitle>Are you sure?</DialogTitle>
|
|
|
|
<DialogDescription className="mt-4">
|
|
You are about to leave the following team.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<Alert variant="neutral" padding="tight">
|
|
<AvatarWithText
|
|
avatarClass="h-12 w-12"
|
|
avatarFallback={teamName.slice(0, 1).toUpperCase()}
|
|
primaryText={teamName}
|
|
secondaryText={TEAM_MEMBER_ROLE_MAP[role]}
|
|
/>
|
|
</Alert>
|
|
|
|
<fieldset disabled={isLeavingTeam}>
|
|
<DialogFooter>
|
|
<Button type="button" variant="secondary" onClick={() => setOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
|
|
<Button
|
|
type="submit"
|
|
variant="destructive"
|
|
loading={isLeavingTeam}
|
|
onClick={async () => leaveTeam({ teamId })}
|
|
>
|
|
Leave
|
|
</Button>
|
|
</DialogFooter>
|
|
</fieldset>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|