diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx new file mode 100644 index 0000000..740f76c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx @@ -0,0 +1,166 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; + +import Loading from "@/app/_components/loading/loading"; +import GTBRegimeComunhaoTable from "../../_components/g_tb_regimecomunhao/GTBRegimeComunhaoTable"; +import GTBRegimeComunhaoForm from "../../_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm"; + +import { useGTBRegimeComunhaoReadHook } from "../../_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook"; +import { useGTBRegimeComunhaoSaveHook } from "../../_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook"; +import { useGTBRegimeComunhaoRemoveHook } from "../../_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoRemoveHook"; + +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import Header from "@/app/_components/structure/Header"; + +export default function TTBAndamentoServico() { + // Hooks para leitura e salvamento + const { gTBRegimeComunhao, fetchGTBRegimeComunhao } = useGTBRegimeComunhaoReadHook(); + const { saveGTBRegimeComunhao } = useGTBRegimeComunhaoSaveHook(); + const { removeGTBRegimeComunhao } = useGTBRegimeComunhaoRemoveHook(); + + // Estados + const [selectedAndamento, setSelectedAndamento] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + + // Estado para saber qual item será deletado + const [itemToDelete, setItemToDelete] = useState(null); + + /** + * Hook do modal de confirmação + */ + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); + + /** + * Abre o formulário no modo de edição ou criação + */ + const handleOpenForm = useCallback((data: GTBRegimeComunhaoInterface | null) => { + setSelectedAndamento(data); + setIsFormOpen(true); + }, []); + + /** + * Fecha o formulário e limpa o andamento selecionado + */ + const handleCloseForm = useCallback(() => { + setSelectedAndamento(null); + setIsFormOpen(false); + }, []); + + /** + * Salva os dados do formulário + */ + const handleSave = useCallback(async (formData: GTBRegimeComunhaoInterface) => { + + // Aguarda salvar o registro + await saveGTBRegimeComunhao(formData); + + // Encerra o fomulário + handleCloseForm(); + + // Atualiza a lista de dados + fetchGTBRegimeComunhao(); + + }, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao, handleCloseForm]); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: GTBRegimeComunhaoInterface) => { + + // Define o item atual para remoção + setItemToDelete(item); + + // Abre o modal de confirmação + openConfirmDialog(); + + }, [openConfirmDialog]); + + /** + * Executa a exclusão de fato quando o usuário confirma + */ + const handleDelete = useCallback(async () => { + + // Protege contra null + if (!itemToDelete) return; + + // Executa o Hook de remoção + await removeGTBRegimeComunhao(itemToDelete); + + // Atualiza a lista + await fetchGTBRegimeComunhao(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchGTBRegimeComunhao, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchGTBRegimeComunhao(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!gTBRegimeComunhao) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
{ handleOpenForm(null) }} + /> + + {/* Tabela de andamentos */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} + +
+ ); 4 +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx new file mode 100644 index 0000000..7691325 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx @@ -0,0 +1,143 @@ +'use client'; + +import z from "zod"; +import { useEffect } from "react"; +import { useForm, Controller } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; + +import { Button } from "@/components/ui/button"; +import { Checkbox } from "@/components/ui/checkbox"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; + +import { GTBRegimeComunhaoSchema } from "../../_schemas/GTBRegimeComunhaoSchema"; + +type FormValues = z.infer; + +interface Props { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: Props) { + // Inicializa o react-hook-form com schema zod + const form = useForm({ + resolver: zodResolver(GTBRegimeComunhaoSchema), + defaultValues: { + tb_regimecomunhao_id: 0, + tb_regimebens_id: 0, + descricao: "", + texto: "", + situacao: "", + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Regimes de Comunhão + + + Controle de Regimes de Comunhão + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Texto */} + ( + + Texto + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoTable.tsx new file mode 100644 index 0000000..704c6d1 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoTable.tsx @@ -0,0 +1,126 @@ +'use client'; + +import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger +} from "@/components/ui/dropdown-menu"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow +} from "@/components/ui/table"; + +import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +interface GTBRegimeComunhaoTableProps { + data: GTBRegimeComunhaoInterface[]; + onEdit: (item: GTBRegimeComunhaoInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBRegimeComunhaoInterface, isEditingFormStatus: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: string }) { + const isActive = situacao === "A"; + + const baseClasses = + "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2"; + + const activeClasses = + "bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300"; + + const inactiveClasses = + "bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300"; + + return ( + + {isActive ? "Ativo" : "Inativo"} + + ); +} + +export default function GTBRegimeComunhaoTable({ + data, + onEdit, + onDelete +}: GTBRegimeComunhaoTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_regimecomunhao_id} + + + + + + + + {item.descricao} + + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts new file mode 100644 index 0000000..f9fd91a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBRegimeComunhaoIndexData(): Promise { + + const api = new API(); + + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_regimecomunhao/` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts new file mode 100644 index 0000000..c92cb66 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +export default async function GTBRegimeComunhaoRemoveData(data: GTBRegimeComunhaoInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts new file mode 100644 index 0000000..51cf575 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts @@ -0,0 +1,16 @@ +import API from "@/services/api/Api"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBRegimeComunhaoSaveData(data: GTBRegimeComunhaoInterface) { + + const isUpdate = Boolean(data.tb_regimecomunhao_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id || ''}`, + body: data + }); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts new file mode 100644 index 0000000..73de8d0 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts @@ -0,0 +1,23 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeComunhaoIndexService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoIndexService"; + +export const useGTBRegimeComunhaoReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + + const fetchGTBRegimeComunhao = async () => { + + const response = await GTBRegimeComunhaoIndexService(); + + setGTBRegimeComunhao(response.data); + + setResponse(response); + + } + + return { gTBRegimeComunhao, fetchGTBRegimeComunhao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoRemoveHook.ts new file mode 100644 index 0000000..658231a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeComunhaoRemoveService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService"; + +export const useGTBRegimeComunhaoRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + + const response = await GTBRegimeComunhaoRemoveService(data); + + setResponse(response); + + } + + return { removeGTBRegimeComunhao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts new file mode 100644 index 0000000..f0d336e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts @@ -0,0 +1,23 @@ +import { useState } from "react"; +import { useResponse } from "@/app/_response/ResponseContext" +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeComunhaoSaveService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService"; + +export const useGTBRegimeComunhaoSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + + const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + + const response = await GTBRegimeComunhaoSaveService(data); + + setGTBRegimeComunhao(response.data); + + setResponse(response); + + } + + return { gTBRegimeComunhao, saveGTBRegimeComunhao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeComunhaoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeComunhaoInterface.ts new file mode 100644 index 0000000..5d4a9be --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeComunhaoInterface.ts @@ -0,0 +1,7 @@ +export default interface GTBRegimeComunhaoInterface { + tb_regimecomunhao_id?: number, + tb_regimebens_id: number, + descricao: string, + texto: string, + situacao: string, +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts new file mode 100644 index 0000000..e47c098 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts @@ -0,0 +1,9 @@ +import z from "zod"; + +export const GTBRegimeComunhaoSchema = z.object({ + tb_regimecomunhao_id: z.number().optional(), + tb_regimebens_id: z.number(), + descricao: z.string(), + texto: z.string(), + situacao: z.string(), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoIndexService.ts new file mode 100644 index 0000000..f23ded7 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoIndexService.ts @@ -0,0 +1,9 @@ +import GTBRegimeComunhaoIndexData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData"; + +export default async function GTBRegimeComunhaoIndexService() { + + const response = await GTBRegimeComunhaoIndexData(); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService.ts new file mode 100644 index 0000000..06bec9b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService.ts @@ -0,0 +1,10 @@ +import GTBRegimeComunhaoRemoveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +export default async function GTBRegimeComunhaoRemoveService(data: GTBRegimeComunhaoInterface) { + + const response = await GTBRegimeComunhaoRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts new file mode 100644 index 0000000..f81e5c9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts @@ -0,0 +1,10 @@ +import GTBRegimeComunhaoSaveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +export default async function GTBRegimeComunhaoSaveService(data: GTBRegimeComunhaoInterface) { + + const response = await GTBRegimeComunhaoSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index cd55946..def5a8f 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -91,8 +91,12 @@ const data = { }, { title: "Profissões", - url: "/cadastros/profissoes/", + url: "/cadastros/profissao/", }, + { + title: "Regimes", + url: "/cadastros/regimes/", + } ], }, {