refacto: UI and component for error in loginpage
This commit is contained in:
@@ -4,6 +4,7 @@ import { useState } from "react";
|
|||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { authService } from "@/lib/services/auth.service";
|
import { authService } from "@/lib/services/auth.service";
|
||||||
import { AuthError } from "@/types/auth";
|
import { AuthError } from "@/types/auth";
|
||||||
|
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||||
|
|
||||||
interface LoginFormProps {
|
interface LoginFormProps {
|
||||||
from?: string;
|
from?: string;
|
||||||
@@ -86,11 +87,7 @@ export function LoginForm({ from }: LoginFormProps) {
|
|||||||
Se souvenir de moi
|
Se souvenir de moi
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
{error && (
|
{error && <ErrorMessage message={error.message} variant="form" />}
|
||||||
<div className="rounded-md bg-destructive/15 p-3 text-sm text-destructive">
|
|
||||||
{error.message}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { authService } from "@/lib/services/auth.service";
|
|||||||
import { AuthError } from "@/types/auth";
|
import { AuthError } from "@/types/auth";
|
||||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||||
|
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||||
|
|
||||||
interface RegisterFormProps {
|
interface RegisterFormProps {
|
||||||
from?: string;
|
from?: string;
|
||||||
@@ -96,11 +97,7 @@ export function RegisterForm({ from }: RegisterFormProps) {
|
|||||||
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{error && (
|
{error && <ErrorMessage message={error.message} variant="form" />}
|
||||||
<div className="rounded-md bg-destructive/15 p-3 text-sm text-destructive">
|
|
||||||
{error.message}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
import { AlertCircle } from "lucide-react";
|
import { AlertCircle } from "lucide-react";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
interface ErrorMessageProps {
|
interface ErrorMessageProps {
|
||||||
message: string;
|
message: string;
|
||||||
|
variant?: "default" | "form";
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ErrorMessage = ({ message }: ErrorMessageProps) => {
|
export const ErrorMessage = ({ message, variant = "default" }: ErrorMessageProps) => {
|
||||||
|
if (variant === "form") {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="alert"
|
||||||
|
aria-live="assertive"
|
||||||
|
className="flex items-center gap-2 rounded-md bg-destructive/15 p-2.5 text-sm text-destructive"
|
||||||
|
>
|
||||||
|
<AlertCircle className="h-4 w-4" />
|
||||||
|
<p>{message}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
role="alert"
|
role="alert"
|
||||||
|
|||||||
Reference in New Issue
Block a user