From 957bb86be1de52c0a949f37fb2def2541127c8de Mon Sep 17 00:00:00 2001 From: keven Date: Fri, 19 Sep 2025 17:08:35 -0300 Subject: [PATCH] =?UTF-8?q?feat(LoadingButton):=20Implementa=20parcialment?= =?UTF-8?q?e=20bot=C3=A3o=20de=20loading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../loadingButton/LoadingButton.tsx | 30 +++ src/components/login-form.tsx | 177 ++++++------------ 2 files changed, 86 insertions(+), 121 deletions(-) create mode 100644 src/app/_components/loadingButton/LoadingButton.tsx diff --git a/src/app/_components/loadingButton/LoadingButton.tsx b/src/app/_components/loadingButton/LoadingButton.tsx new file mode 100644 index 0000000..051c4eb --- /dev/null +++ b/src/app/_components/loadingButton/LoadingButton.tsx @@ -0,0 +1,30 @@ +'use client'; + +import { Button } from "@/components/ui/button"; +import { Loader2 } from "lucide-react"; + +interface LoadingButtonProps { + text: string; + loading?: boolean; // recebe loading do form + type?: "button" | "submit" | "reset"; + variant?: "default" | "outline" | "secondary" | "ghost" | "destructive"; +} + +export default function LoadingButton({ + text, + loading = false, + type = "button", + variant = "default", +}: LoadingButtonProps) { + return ( + + ); +} diff --git a/src/components/login-form.tsx b/src/components/login-form.tsx index 602127c..28d1d2b 100644 --- a/src/components/login-form.tsx +++ b/src/components/login-form.tsx @@ -2,7 +2,6 @@ import Image from "next/image"; import { cn } from "@/lib/utils" -import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { GUsuarioSchema } from "@/app/(protected)/(administrativo)/_schemas/GUsuarioSchema" @@ -10,22 +9,22 @@ import z from "zod" import { zodResolver } from "@hookform/resolvers/zod" import GUsuarioLoginService from "@/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin" import { useForm } from "react-hook-form" +import { useState } from "react" import { Form, FormControl, - FormDescription, FormField, FormItem, FormLabel, FormMessage } from "./ui/form" +import LoadingButton from "@/app/_components/loadingButton/LoadingButton"; +import { Button } from "./ui/button"; type FormValues = z.infer -export function LoginForm({ - className, - ...props -}: React.ComponentProps<"div">) { +export function LoginForm({ className, ...props }: React.ComponentProps<"div">) { + const [loading, setLoading] = useState(false); const form = useForm({ resolver: zodResolver(GUsuarioSchema), @@ -35,134 +34,76 @@ export function LoginForm({ }, }); - async function onSubmit(values: FormValues) { - const data = await GUsuarioLoginService(values); + // onSubmit agora recebe o evento do form através do handleSubmit + const onSubmit = async (values: FormValues) => { + setLoading(true); + try { + await GUsuarioLoginService(values); + // aqui você pode redirecionar ou mostrar mensagem de sucesso + } catch (error) { + console.error("Erro ao fazer login:", error); + } finally { + setLoading(false); + } } return ( -
- - -
+ - - -
- -
- -

- - Bem vindo de volta! - -

- -

- - Entre na sua conta Orius Tecnologia. - -

- -
- -
- - ( - - - - Login - - - - - - - - )} - /> - -
- -
- - ( - - - - Senha - - - - - - - - )} - /> - -
- +
+

Bem vindo de volta!

+

+ Entre na sua conta Orius Tecnologia. +

- + ( + + Login + + + + + + )} + /> -
+ ( + + Senha + + + + + + )} + /> + {/* Botão de loading */} + + +
- Ou entre em contato - -
- - - - - + +
-
@@ -174,18 +115,12 @@ export function LoginForm({ className="object-contain dark:brightness-[0.2] dark:grayscale" />
- - -
- - Ao clicar você concordar com Nossos termos de serviços{" "}e Políticas de Privacidade. - +
+ Ao clicar você concorda com Nossos termos de serviços e Políticas de Privacidade.
-
- ) }