import { useTRPC } from '@/integrations/trpc/react'; import { zodResolver } from '@hookform/resolvers/zod'; import { type ISignInShare, zSignInShare } from '@openpanel/validation'; import { useMutation } from '@tanstack/react-query'; import { useForm } from 'react-hook-form'; import { toast } from 'sonner'; import { LogoSquare } from '../logo'; import { Button } from '../ui/button'; import { Input } from '../ui/input'; export function ShareEnterPassword({ shareId, shareType = 'overview', }: { shareId: string; shareType?: 'overview' | 'dashboard' | 'report'; }) { const trpc = useTRPC(); const mutation = useMutation( trpc.auth.signInShare.mutationOptions({ onSuccess() { window.location.reload(); }, onError() { toast.error('Incorrect password'); }, }), ); const form = useForm({ resolver: zodResolver(zSignInShare), defaultValues: { password: '', shareId, shareType, }, }); const onSubmit = form.handleSubmit((data) => { mutation.mutate({ password: data.password, shareId, shareType, }); }); return (
{shareType === 'dashboard' ? 'Dashboard is locked' : shareType === 'report' ? 'Report is locked' : 'Overview is locked'}
Please enter correct password to access this{' '} {shareType === 'dashboard' ? 'dashboard' : shareType === 'report' ? 'report' : 'overview'}

Powered by{' '} OpenPanel.dev

The best web and product analytics tool out there (our honest opinion).

Try it for free today!

); }