mirror of
https://github.com/hanzoai/sign.git
synced 2026-10-21 01:21:51 +00:00
The product is branded Hanzo eSign (esign.hanzo.ai, repo hanzoai/esign). Rename all workspace packages @hanzo/sign-* → @hanzo/esign-* (1052 files) and align docker/Dockerfile turbo --scope/--filter to the actual remix package name @hanzo/esign (was a pre-existing mismatch with -remix that broke the build). Protected deps (@hanzo/insights, @hanzo/logo) untouched.
139 lines
4.1 KiB
TypeScript
139 lines
4.1 KiB
TypeScript
import { useState } from 'react';
|
|
|
|
import { msg } from '@lingui/core/macro';
|
|
import { useLingui } from '@lingui/react';
|
|
import { Trans } from '@lingui/react/macro';
|
|
import { z } from 'zod';
|
|
|
|
import type { ZDeleteTeamMemberRequestSchema } from '@hanzo/esign-trpc/server/team-router/delete-team-member.types';
|
|
import { useZapMutation } from '@hanzo/esign-trpc/zap/react';
|
|
import { Alert, AlertDescription } from '@hanzo/esign-ui/primitives/alert';
|
|
import { AvatarWithText } from '@hanzo/esign-ui/primitives/avatar';
|
|
import { Button } from '@hanzo/esign-ui/primitives/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from '@hanzo/esign-ui/primitives/dialog';
|
|
import { useToast } from '@hanzo/esign-ui/primitives/use-toast';
|
|
|
|
export type TeamMemberDeleteDialogProps = {
|
|
teamId: number;
|
|
teamName: string;
|
|
memberId: string;
|
|
memberName: string;
|
|
memberEmail: string;
|
|
isInheritMemberEnabled: boolean | null;
|
|
trigger?: React.ReactNode;
|
|
};
|
|
|
|
export const TeamMemberDeleteDialog = ({
|
|
trigger,
|
|
teamId,
|
|
teamName,
|
|
memberId,
|
|
memberName,
|
|
memberEmail,
|
|
isInheritMemberEnabled,
|
|
}: TeamMemberDeleteDialogProps) => {
|
|
const [open, setOpen] = useState(false);
|
|
|
|
const { _ } = useLingui();
|
|
const { toast } = useToast();
|
|
|
|
const { mutateAsync: deleteTeamMember, isPending: isDeletingTeamMember } = useZapMutation<
|
|
void,
|
|
z.infer<typeof ZDeleteTeamMemberRequestSchema>
|
|
>('team.member.delete', {
|
|
onSuccess: () => {
|
|
toast({
|
|
title: _(msg`Success`),
|
|
description: _(msg`You have successfully removed this user from the team.`),
|
|
duration: 5000,
|
|
});
|
|
|
|
setOpen(false);
|
|
},
|
|
onError: () => {
|
|
toast({
|
|
title: _(msg`An unknown error occurred`),
|
|
description: _(
|
|
msg`We encountered an unknown error while attempting to remove this user. Please try again later.`,
|
|
),
|
|
variant: 'destructive',
|
|
duration: 10000,
|
|
});
|
|
},
|
|
});
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={(value) => !isDeletingTeamMember && setOpen(value)}>
|
|
<DialogTrigger asChild>
|
|
{trigger ?? (
|
|
<Button variant="secondary">
|
|
<Trans>Remove team member</Trans>
|
|
</Button>
|
|
)}
|
|
</DialogTrigger>
|
|
|
|
<DialogContent position="center">
|
|
<DialogHeader>
|
|
<DialogTitle>
|
|
<Trans>Are you sure?</Trans>
|
|
</DialogTitle>
|
|
|
|
<DialogDescription className="mt-4">
|
|
<Trans>
|
|
You are about to remove the following user from{' '}
|
|
<span className="font-semibold">{teamName}</span>.
|
|
</Trans>
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
{isInheritMemberEnabled ? (
|
|
<Alert variant="neutral">
|
|
<AlertDescription>
|
|
<Trans>
|
|
You cannot remove members from this team if the inherit member feature is enabled.
|
|
</Trans>
|
|
</AlertDescription>
|
|
</Alert>
|
|
) : (
|
|
<Alert variant="neutral" padding="tight">
|
|
<AvatarWithText
|
|
avatarClass="h-12 w-12"
|
|
avatarFallback={memberName.slice(0, 1).toUpperCase()}
|
|
primaryText={<span className="font-semibold">{memberName}</span>}
|
|
secondaryText={memberEmail}
|
|
/>
|
|
</Alert>
|
|
)}
|
|
|
|
<fieldset disabled={isDeletingTeamMember}>
|
|
<DialogFooter>
|
|
<Button type="button" variant="secondary" onClick={() => setOpen(false)}>
|
|
<Trans>Close</Trans>
|
|
</Button>
|
|
|
|
{!isInheritMemberEnabled && (
|
|
<Button
|
|
type="submit"
|
|
variant="destructive"
|
|
disabled={Boolean(isInheritMemberEnabled)}
|
|
loading={isDeletingTeamMember}
|
|
onClick={async () => deleteTeamMember({ teamId, memberId })}
|
|
>
|
|
<Trans>Remove</Trans>
|
|
</Button>
|
|
)}
|
|
</DialogFooter>
|
|
</fieldset>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|