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

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-03-28 13:13:29 +08:00
import { useState } from 'react';
2025-01-02 15:33:37 +11:00
import { msg } from '@lingui/core/macro';
2024-08-27 20:34:39 +09:00
import { useLingui } from '@lingui/react';
2025-01-02 15:33:37 +11:00
import { Trans } from '@lingui/react/macro';
2024-03-28 13:13:29 +08:00
2025-01-02 15:33:37 +11:00
import { authClient } from '@documenso/auth/client';
2024-03-28 13:13:29 +08:00
import { Button } from '@documenso/ui/primitives/button';
import { useToast } from '@documenso/ui/primitives/use-toast';
2025-01-02 15:33:37 +11:00
export type DocumentSigningAuthPageViewProps = {
2024-03-28 13:13:29 +08:00
email: string;
emailHasAccount?: boolean;
2024-03-28 13:13:29 +08:00
};
2025-01-02 15:33:37 +11:00
export const DocumentSigningAuthPageView = ({
email,
emailHasAccount,
}: DocumentSigningAuthPageViewProps) => {
2024-08-27 20:34:39 +09:00
const { _ } = useLingui();
2024-03-28 13:13:29 +08:00
const { toast } = useToast();
2024-09-19 13:45:08 +10:00
const [isSigningOut, setIsSigningOut] = useState(false);
2024-03-28 13:13:29 +08:00
const handleChangeAccount = async (email: string) => {
try {
setIsSigningOut(true);
2025-01-02 15:33:37 +11:00
await authClient.signOut({
redirectPath: emailHasAccount ? `/signin#email=${email}` : `/signup#email=${email}`,
2024-03-28 13:13:29 +08:00
});
} catch {
toast({
2024-08-27 20:34:39 +09:00
title: _(msg`Something went wrong`),
description: _(msg`We were unable to log you out at this time.`),
2024-03-28 13:13:29 +08:00
duration: 10000,
variant: 'destructive',
});
}
setIsSigningOut(false);
};
return (
<div className="mx-auto flex h-[70vh] w-full max-w-md flex-col items-center justify-center">
<div>
2024-08-27 20:34:39 +09:00
<h1 className="text-3xl font-semibold">
<Trans>Authentication required</Trans>
</h1>
2024-03-28 13:13:29 +08:00
<p className="text-muted-foreground mt-2 text-sm">
2024-08-27 20:34:39 +09:00
<Trans>
You need to be logged in as <strong>{email}</strong> to view this page.
</Trans>
2024-03-28 13:13:29 +08:00
</p>
<Button
className="mt-4 w-full"
type="submit"
onClick={async () => handleChangeAccount(email)}
loading={isSigningOut}
>
2024-08-27 20:34:39 +09:00
{emailHasAccount ? <Trans>Login</Trans> : <Trans>Sign up</Trans>}
2024-03-28 13:13:29 +08:00
</Button>
</div>
</div>
);
};