diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx index 847d1d2..ceee629 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx @@ -161,6 +161,7 @@ export default function TTBAndamentoServico() { onClose={handleCloseForm} onSave={handleSave} /> + ); 4 } \ No newline at end of file diff --git a/src/app/_components/buttonLoading/LoadingButton.tsx b/src/app/_components/buttonLoading/LoadingButton.tsx new file mode 100644 index 0000000..6e110e5 --- /dev/null +++ b/src/app/_components/buttonLoading/LoadingButton.tsx @@ -0,0 +1,37 @@ +// components/LoadingButton.tsx +"use client"; + +import { Button } from "@/components/ui/button"; +import { Loader2 } from "lucide-react"; +import { ButtonProps } from "@/components/ui/button"; + +interface LoadingButtonProps extends ButtonProps { + isLoading?: boolean; + loadingText?: string; +} + +export function LoadingButton({ + children, + isLoading = false, + loadingText = "Salvando...", + disabled, + type = "submit", // padrão para funcionar com forms + ...props +}: LoadingButtonProps) { + return ( + + ); +} diff --git a/src/app/_components/buttonLoading/useAsyncAction.ts b/src/app/_components/buttonLoading/useAsyncAction.ts new file mode 100644 index 0000000..a4c2d10 --- /dev/null +++ b/src/app/_components/buttonLoading/useAsyncAction.ts @@ -0,0 +1,22 @@ +// hooks/useAsyncAction.ts +import { useState, useCallback } from "react"; + +export function useAsyncAction Promise>(asyncFunction: T) { + const [loading, setLoading] = useState(false); + + const execute = useCallback( + async (...args: Parameters): Promise | void> => { + try { + setLoading(true); + return await asyncFunction(...args); + } catch (error) { + console.error("Erro na ação assíncrona:", error); + } finally { + setLoading(false); + } + }, + [asyncFunction] + ); + + return { execute, loading }; +}