import { useState } from 'react'; import { msg } from '@lingui/core/macro'; import { useLingui } from '@lingui/react'; import { Trans } from '@lingui/react/macro'; import { match } from 'ts-pattern'; import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error'; import { trpc } from '@documenso/trpc/react'; import type { TGetUserResponse } from '@documenso/trpc/server/admin-router/get-user.types'; import { Alert, AlertDescription, AlertTitle } from '@documenso/ui/primitives/alert'; import { Button } from '@documenso/ui/primitives/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@documenso/ui/primitives/dialog'; import { Input } from '@documenso/ui/primitives/input'; import { useToast } from '@documenso/ui/primitives/use-toast'; export type AdminUserEnableDialogProps = { className?: string; userToEnable: TGetUserResponse; }; export const AdminUserEnableDialog = ({ className, userToEnable }: AdminUserEnableDialogProps) => { const { toast } = useToast(); const { _ } = useLingui(); const [email, setEmail] = useState(''); const { mutateAsync: enableUser, isPending: isEnablingUser } = trpc.admin.user.enable.useMutation(); const onEnableAccount = async () => { try { await enableUser({ id: userToEnable.id, }); toast({ title: _(msg`Account enabled`), description: _(msg`The account has been enabled successfully.`), duration: 5000, }); } catch (err) { const error = AppError.parseError(err); const errorMessage = match(error.code) .with(AppErrorCode.NOT_FOUND, () => msg`User not found.`) .with(AppErrorCode.UNAUTHORIZED, () => msg`You are not authorized to enable this user.`) .otherwise(() => msg`An error occurred while enabling the user.`); toast({ title: _(msg`Error`), description: _(errorMessage), variant: 'destructive', duration: 7500, }); } }; return (
Enable Account Enabling the account results in the user being able to use the account again, and all the related features such as webhooks, teams, and API keys for example.
Enable Account
To confirm, please enter the accounts email address
({userToEnable.email} ).
setEmail(e.target.value)} />
); };