From f46c05ab9748a4762b130d21e89933d1f67e2598 Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 22 Sep 2025 11:23:30 -0300 Subject: [PATCH] =?UTF-8?q?[DSAAS-11]=20feat(LoadingButton):=20Cria=20comp?= =?UTF-8?q?onente=20de=20bot=C3=A3o=20que=20controla=20o=20estado=20de=20l?= =?UTF-8?q?oading=20de=20requisi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../loadingButton/LoadingButton.tsx | 34 ++++ .../loadingButton/LoadingButtonProps.ts | 7 + src/components/login-form.tsx | 180 ++++++------------ 3 files changed, 101 insertions(+), 120 deletions(-) create mode 100644 src/app/_components/loadingButton/LoadingButton.tsx create mode 100644 src/app/_components/loadingButton/LoadingButtonProps.ts diff --git a/src/app/_components/loadingButton/LoadingButton.tsx b/src/app/_components/loadingButton/LoadingButton.tsx new file mode 100644 index 0000000..e334b8b --- /dev/null +++ b/src/app/_components/loadingButton/LoadingButton.tsx @@ -0,0 +1,34 @@ +'use client'; + +import { forwardRef } from "react"; +import { Button } from "@/components/ui/button"; +import { Loader2 } from "lucide-react"; +import clsx from "clsx"; +import LoadingButtonProps from "./LoadingButtonProps"; + +const LoadingButton = forwardRef( + ({ text, textLoading, loading = false, className, disabled, ...props }, ref) => { + return ( + + ); + } +); + +LoadingButton.displayName = "LoadingButton"; + +export default LoadingButton; \ No newline at end of file diff --git a/src/app/_components/loadingButton/LoadingButtonProps.ts b/src/app/_components/loadingButton/LoadingButtonProps.ts new file mode 100644 index 0000000..195f683 --- /dev/null +++ b/src/app/_components/loadingButton/LoadingButtonProps.ts @@ -0,0 +1,7 @@ +import { Button } from "@/components/ui/button"; + +export default interface LoadingButtonProps extends React.ComponentProps { + text: string; + textLoading: string; + loading?: boolean; +} \ No newline at end of file diff --git a/src/components/login-form.tsx b/src/components/login-form.tsx index 888204b..0a78c5a 100644 --- a/src/components/login-form.tsx +++ b/src/components/login-form.tsx @@ -2,167 +2,113 @@ 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 { UsuarioFormSchema } from "@/app/(protected)/(administrativo)/_schemas/GUsuarioSchema" +import { GUsuarioSchema } from "@/app/(protected)/(administrativo)/_schemas/GUsuarioSchema" 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 +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(UsuarioFormSchema), + resolver: zodResolver(GUsuarioSchema), defaultValues: { login: '', senha_api: '' }, }); - 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 +120,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.
-
- ) }