Files
sign/apps/remix/app/components/general/document-signing/document-signing-auth-account.tsx

85 lines
2.5 KiB
TypeScript
Raw Normal View History

import { useState } from 'react';
2025-01-02 15:33:37 +11:00
import { Trans, useLingui } from '@lingui/react/macro';
import { RecipientRole } from '@prisma/client';
2024-09-19 13:45:08 +10:00
2025-01-02 15:33:37 +11:00
import { authClient } from '@documenso/auth/client';
import { Alert, AlertDescription } from '@documenso/ui/primitives/alert';
import { Button } from '@documenso/ui/primitives/button';
import { DialogFooter } from '@documenso/ui/primitives/dialog';
2025-01-02 15:33:37 +11:00
import { useToast } from '@documenso/ui/primitives/use-toast';
2025-01-02 15:33:37 +11:00
import { useRequiredDocumentSigningAuthContext } from './document-signing-auth-provider';
2025-01-02 15:33:37 +11:00
export type DocumentSigningAuthAccountProps = {
actionTarget?: 'FIELD' | 'DOCUMENT';
actionVerb?: string;
onOpenChange: (value: boolean) => void;
};
2025-01-02 15:33:37 +11:00
export const DocumentSigningAuthAccount = ({
actionTarget = 'FIELD',
actionVerb = 'sign',
onOpenChange,
2025-01-02 15:33:37 +11:00
}: DocumentSigningAuthAccountProps) => {
const { recipient } = useRequiredDocumentSigningAuthContext();
const { t } = useLingui();
2025-01-02 15:33:37 +11:00
const { toast } = useToast();
2024-09-19 13:45:08 +10:00
const [isSigningOut, setIsSigningOut] = useState(false);
const handleChangeAccount = async (email: string) => {
try {
setIsSigningOut(true);
2025-01-02 15:33:37 +11:00
await authClient.signOut({
redirectPath: `/signin#email=${email}`,
});
} catch {
setIsSigningOut(false);
2025-01-02 15:33:37 +11:00
toast({
title: t`Something went wrong`,
description: t`We were unable to log you out at this time.`,
duration: 10000,
variant: 'destructive',
});
}
};
return (
<fieldset disabled={isSigningOut} className="space-y-4">
<Alert variant="warning">
<AlertDescription>
{actionTarget === 'DOCUMENT' && recipient.role === RecipientRole.VIEWER ? (
<span>
2024-08-27 20:34:39 +09:00
<Trans>
To mark this document as viewed, you need to be logged in as{' '}
<strong>{recipient.email}</strong>
</Trans>
</span>
) : (
<span>
2024-08-27 20:34:39 +09:00
{/* Todo: Translate */}
To {actionVerb.toLowerCase()} this {actionTarget.toLowerCase()}, you need to be logged
in as <strong>{recipient.email}</strong>
</span>
)}
</AlertDescription>
</Alert>
<DialogFooter>
<Button type="button" variant="secondary" onClick={() => onOpenChange(false)}>
2024-08-27 20:34:39 +09:00
<Trans>Cancel</Trans>
</Button>
<Button onClick={async () => handleChangeAccount(recipient.email)} loading={isSigningOut}>
2024-08-27 20:34:39 +09:00
<Trans>Login</Trans>
</Button>
</DialogFooter>
</fieldset>
);
};