mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
chore: remove unused error toast
This commit is contained in:
committed by
Mythie
parent
b3a312df98
commit
3544e44c31
@ -1,27 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { Loader } from 'lucide-react';
|
import { Loader } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { ErrorCode, isErrorCode } from '@documenso/lib/next-auth/error-codes';
|
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
const ERROR_MESSAGES = {
|
|
||||||
[ErrorCode.CREDENTIALS_NOT_FOUND]: 'No account found with that email address.',
|
|
||||||
[ErrorCode.INCORRECT_EMAIL_PASSWORD]: 'No account found with that email address.',
|
|
||||||
[ErrorCode.USER_MISSING_PASSWORD]:
|
|
||||||
'This account appears to be using a social login method, please sign in using that method',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ZForgotPasswordFormSchema = z.object({
|
export const ZForgotPasswordFormSchema = z.object({
|
||||||
email: z.string().email().min(1),
|
email: z.string().email().min(1),
|
||||||
@ -34,11 +23,8 @@ export type ForgotPasswordFormProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ForgotPasswordForm = ({ className }: ForgotPasswordFormProps) => {
|
export const ForgotPasswordForm = ({ className }: ForgotPasswordFormProps) => {
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -50,27 +36,6 @@ export const ForgotPasswordForm = ({ className }: ForgotPasswordFormProps) => {
|
|||||||
resolver: zodResolver(ZForgotPasswordFormSchema),
|
resolver: zodResolver(ZForgotPasswordFormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
const errorCode = searchParams?.get('error');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let timeout: NodeJS.Timeout | null = null;
|
|
||||||
|
|
||||||
if (isErrorCode(errorCode)) {
|
|
||||||
timeout = setTimeout(() => {
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
description: ERROR_MESSAGES[errorCode] ?? 'An unknown error occurred',
|
|
||||||
});
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (timeout) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [errorCode, toast]);
|
|
||||||
|
|
||||||
const onFormSubmit = ({ email }: TForgotPasswordFormSchema) => {
|
const onFormSubmit = ({ email }: TForgotPasswordFormSchema) => {
|
||||||
// check if the email is available
|
// check if the email is available
|
||||||
// if not, throw an error
|
// if not, throw an error
|
||||||
|
|||||||
@ -1,27 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { Loader } from 'lucide-react';
|
import { Loader } from 'lucide-react';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { ErrorCode, isErrorCode } from '@documenso/lib/next-auth/error-codes';
|
|
||||||
import { cn } from '@documenso/ui/lib/utils';
|
import { cn } from '@documenso/ui/lib/utils';
|
||||||
import { Button } from '@documenso/ui/primitives/button';
|
import { Button } from '@documenso/ui/primitives/button';
|
||||||
import { Input } from '@documenso/ui/primitives/input';
|
import { Input } from '@documenso/ui/primitives/input';
|
||||||
import { Label } from '@documenso/ui/primitives/label';
|
import { Label } from '@documenso/ui/primitives/label';
|
||||||
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
||||||
|
|
||||||
const ERROR_MESSAGES = {
|
|
||||||
[ErrorCode.CREDENTIALS_NOT_FOUND]: 'No account found with that email address.',
|
|
||||||
[ErrorCode.INCORRECT_EMAIL_PASSWORD]: 'No account found with that email address.',
|
|
||||||
[ErrorCode.USER_MISSING_PASSWORD]:
|
|
||||||
'This account appears to be using a social login method, please sign in using that method',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ZResetPasswordFormSchema = z
|
export const ZResetPasswordFormSchema = z
|
||||||
.object({
|
.object({
|
||||||
@ -40,11 +29,8 @@ export type ResetPasswordFormProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ResetPasswordForm = ({ className }: ResetPasswordFormProps) => {
|
export const ResetPasswordForm = ({ className }: ResetPasswordFormProps) => {
|
||||||
const searchParams = useSearchParams();
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const { toast } = useToast();
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@ -57,27 +43,6 @@ export const ResetPasswordForm = ({ className }: ResetPasswordFormProps) => {
|
|||||||
resolver: zodResolver(ZResetPasswordFormSchema),
|
resolver: zodResolver(ZResetPasswordFormSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
const errorCode = searchParams?.get('error');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let timeout: NodeJS.Timeout | null = null;
|
|
||||||
|
|
||||||
if (isErrorCode(errorCode)) {
|
|
||||||
timeout = setTimeout(() => {
|
|
||||||
toast({
|
|
||||||
variant: 'destructive',
|
|
||||||
description: ERROR_MESSAGES[errorCode] ?? 'An unknown error occurred',
|
|
||||||
});
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
if (timeout) {
|
|
||||||
clearTimeout(timeout);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [errorCode, toast]);
|
|
||||||
|
|
||||||
const onFormSubmit = ({ password, repeatedPassword }: TResetPasswordFormSchema) => {
|
const onFormSubmit = ({ password, repeatedPassword }: TResetPasswordFormSchema) => {
|
||||||
console.log(password, repeatedPassword);
|
console.log(password, repeatedPassword);
|
||||||
|
|
||||||
@ -111,7 +76,7 @@ export const ResetPasswordForm = ({ className }: ResetPasswordFormProps) => {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Label htmlFor="repeatedPassword" className="flex justify-between text-slate-500">
|
<Label htmlFor="repeatedPassword" className="flex justify-between text-slate-500">
|
||||||
<span>Confirm Password</span>
|
<span>Repeat Password</span>
|
||||||
</Label>
|
</Label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
Reference in New Issue
Block a user