From 12a2c62af859a88bab55fc61a3ac03e9ebb14261 Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 9 Sep 2025 15:15:23 -0300 Subject: [PATCH 01/56] [MVPTN-1] feat(Listagem): implementa a listagem de tipos de reconhecimento, atualmente usando dados 'mockados' --- .../reconhecimentos/page.tsx | 91 +++++++++++++++++++ .../TTBReconhecimentoTipoIndexData.ts | 25 +++++ .../useTTBReconhecimentoTipoReadHooks.ts | 26 ++++++ .../_interfaces/ITTTBReconhecimentoTipo.ts | 5 + .../_schemas/TTTBReconhecimentoTipo.ts | 7 ++ src/components/app-sidebar.tsx | 14 +-- 6 files changed, 157 insertions(+), 11 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx new file mode 100644 index 0000000..1147a6b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -0,0 +1,91 @@ +'use client' + +import { Card, CardContent } from "@/components/ui/card"; +import { + Table, + TableBody, + TableCaption, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/useTTBReconhecimentoTipoReadHooks"; +import { useEffect } from "react"; +import ITTTBReconhecimentoTipo from '../../_interfaces/ITTTBReconhecimentoTipo' +import Loading from "@/app/_components/loading/loading"; +import { Button } from "@/components/ui/button"; +import Link from "next/link"; + +export default function TTBReconhecimentoTipoPage() { + + const { reconhecimentosTipos, fetchReconhecimentosTipos } = useTTBReconhecimentoTipoReadHooks(); + + useEffect(() => { + fetchReconhecimentosTipos(); + }, []); + + if (!reconhecimentosTipos) return + + return ( + +
+ +
+
+
+ Tipos de Reconhecimentos +
+
+ Gerenciamento de tipos de reconhecimentos +
+
+
+ +
+
+ + + + + + + # + + + Descrição + + + Situação + + Amount + + + + {reconhecimentosTipos.map((reconhecimentosTipos: ITTTBReconhecimentoTipo) => ( + + + {reconhecimentosTipos.tb_reconhecimentotipo_id} + + + {reconhecimentosTipos.descricao} + + + {reconhecimentosTipos.tb_reconhecimentotipo_id} + + $250.00 + + ))} + +
+
+
+
+ + ); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts new file mode 100644 index 0000000..869a90a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts @@ -0,0 +1,25 @@ +'use server' + +import API from "@/services/api/Api" +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TTBReconhecimentoTipoIndexData() { + + // const api = new API(); + + // const response = await api.send({ + // 'method': Methods.GET, + // 'endpoint': `cadastros/reconhecimentos` + // }); + + // return response; + + return Promise.resolve({ + data: [ + { tb_reconhecimentotipo_id: 1, descricao: 'SEMELHANÇA', situacao: 'A' }, + { tb_reconhecimentotipo_id: 2, descricao: 'VERDADEIRO', situacao: 'A' }, + { tb_reconhecimentotipo_id: 3, descricao: 'ABONO', situacao: 'A' } + ] + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts new file mode 100644 index 0000000..e626769 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts @@ -0,0 +1,26 @@ +'use client' + +import ITTTBReconhecimentoTipo from '../_interfaces/ITTTBReconhecimentoTipo' +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import TTBReconhecimentoTipoIndexData from '../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData'; + +export const useTTBReconhecimentoTipoReadHooks = () => { + + const { setResponse } = useResponse(); + + const [reconhecimentosTipos, setReconhecimenntosTipos] = useState(); + + const fetchReconhecimentosTipos = async () => { + + const response = await TTBReconhecimentoTipoIndexData(); + + setReconhecimenntosTipos(response.data); + + setResponse(response); + + } + + return { reconhecimentosTipos, fetchReconhecimentosTipos } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts new file mode 100644 index 0000000..d0f4dda --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts @@ -0,0 +1,5 @@ +export default interface ITTTBReconhecimentoTipo{ + tb_reconhecimentotipo_id: number, + descricao: string, + situacao: string, +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts new file mode 100644 index 0000000..18d493e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts @@ -0,0 +1,7 @@ +import { z } from 'zod'; + +export const TTBReconhecimentoTipoSchema = z.object({ + tb_reconhecimentotipo_id: z.number(), + descricao: z.string().min(1), + situacao: z.string().min(1), +}); \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 0e30057..0f56829 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -64,21 +64,13 @@ const data = { ], }, { - title: "Models", + title: "Cadastros", url: "#", icon: Bot, items: [ { - title: "Genesis", - url: "#", - }, - { - title: "Explorer", - url: "#", - }, - { - title: "Quantum", - url: "#", + title: "Reconhecimentos", + url: "/cadastros/reconhecimentos/", }, ], }, From 02ae936c879c49c8f1334765db35d345c2f27ab3 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 10 Sep 2025 16:59:00 -0300 Subject: [PATCH 02/56] =?UTF-8?q?[MVPTN]=20feat(dialog):=20Implementado=20?= =?UTF-8?q?formul=C3=A1rio=20em=20dialog=20e=20confirma=C3=A7=C3=A3o=20de?= =?UTF-8?q?=20exclus=C3=A3o=20de=20registro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 75 +++++ package.json | 2 + .../reconhecimentos/page.tsx | 276 +++++++++++++++--- .../TTBReconhecimentoTipoSaveData.ts | 14 + .../useTTBReconhecimentoTipoReadHooks.ts | 8 +- .../useTTBReconhecimentoTipoSaveHooks.ts | 29 ++ .../_schemas/TTTBReconhecimentoTipo.ts | 4 +- src/components/ui/alert-dialog.tsx | 157 ++++++++++ src/components/ui/checkbox.tsx | 32 ++ src/components/ui/dialog.tsx | 143 +++++++++ 10 files changed, 699 insertions(+), 41 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts create mode 100644 src/components/ui/alert-dialog.tsx create mode 100644 src/components/ui/checkbox.tsx create mode 100644 src/components/ui/dialog.tsx diff --git a/package-lock.json b/package-lock.json index 0f7ae39..10555ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,9 @@ "version": "0.1.0", "dependencies": { "@hookform/resolvers": "^5.2.1", + "@radix-ui/react-alert-dialog": "^1.1.15", "@radix-ui/react-avatar": "^1.1.10", + "@radix-ui/react-checkbox": "^1.3.3", "@radix-ui/react-collapsible": "^1.1.12", "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", @@ -736,6 +738,34 @@ "integrity": "sha512-JTF99U/6XIjCBo0wqkU5sK10glYe27MRRsfwoiq5zzOEZLHU3A3KCMa5X/azekYRCJ0HlwI0crAXS/5dEHTzDg==", "license": "MIT" }, + "node_modules/@radix-ui/react-alert-dialog": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/@radix-ui/react-alert-dialog/-/react-alert-dialog-1.1.15.tgz", + "integrity": "sha512-oTVLkEw5GpdRe29BqJ0LSDFWI3qu0vR1M0mUkOQWDIUnY/QIkLpgDMWuKxP94c2NAC2LGcgVhG1ImF3jkZ5wXw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-dialog": "1.1.15", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-slot": "1.2.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-arrow": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@radix-ui/react-arrow/-/react-arrow-1.1.7.tgz", @@ -786,6 +816,36 @@ } } }, + "node_modules/@radix-ui/react-checkbox": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.3.3.tgz", + "integrity": "sha512-wBbpv+NQftHDdG86Qc0pIyXk5IR3tM8Vd0nWLKDcX8nNn4nXFOFwsKuqw2okA/1D/mpaAkmuyndrPJTYDNZtFw==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-presence": "1.1.5", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-use-size": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-collapsible": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/@radix-ui/react-collapsible/-/react-collapsible-1.1.12.tgz", @@ -1412,6 +1472,21 @@ } } }, + "node_modules/@radix-ui/react-use-previous": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.1.tgz", + "integrity": "sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-use-rect": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.1.tgz", diff --git a/package.json b/package.json index 9ab3d66..22ea23d 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,9 @@ }, "dependencies": { "@hookform/resolvers": "^5.2.1", + "@radix-ui/react-alert-dialog": "^1.1.15", "@radix-ui/react-avatar": "^1.1.10", + "@radix-ui/react-checkbox": "^1.3.3", "@radix-ui/react-collapsible": "^1.1.12", "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index 1147a6b..c944264 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -1,37 +1,123 @@ 'use client' -import { Card, CardContent } from "@/components/ui/card"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger, +} from "@/components/ui/alert-dialog" + +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" + +import { Input } from "@/components/ui/input" +import { Card, CardContent } from "@/components/ui/card" import { Table, TableBody, - TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" -import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/useTTBReconhecimentoTipoReadHooks"; -import { useEffect } from "react"; -import ITTTBReconhecimentoTipo from '../../_interfaces/ITTTBReconhecimentoTipo' -import Loading from "@/app/_components/loading/loading"; -import { Button } from "@/components/ui/button"; -import Link from "next/link"; +import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/useTTBReconhecimentoTipoReadHooks" +import { useEffect, useState } from "react" +import ITTTBReconhecimentoTipo from "../../_interfaces/ITTTBReconhecimentoTipo" +import Loading from "@/app/_components/loading/loading" +import { Button } from "@/components/ui/button" +import { useTTBReconhecimentoTipoSaveHooks } from "../../_hooks/useTTBReconhecimentoTipoSaveHooks" +import { Controller, useForm } from "react-hook-form" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { zodResolver } from "@hookform/resolvers/zod" +import { TTBReconhecimentoTipoSchema } from "../../_schemas/TTTBReconhecimentoTipo" +import z from "zod" +import { Label } from "@/components/ui/label" +import { Checkbox } from "@/components/ui/checkbox" +import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" +import { DropdownMenuLabel } from "@radix-ui/react-dropdown-menu" +import { EllipsisIcon, PencilIcon, PlusIcon, Trash2 } from "lucide-react" + +type FormValues = z.infer export default function TTBReconhecimentoTipoPage() { + const { reconhecimentosTipos, fetchReconhecimentosTipos, addReconhecimentoTipo } = useTTBReconhecimentoTipoReadHooks() + const { reconhecimentoTipo, saveReconhecimentoTipo } = useTTBReconhecimentoTipoSaveHooks() - const { reconhecimentosTipos, fetchReconhecimentosTipos } = useTTBReconhecimentoTipoReadHooks(); + const [dialogOpen, setDialogOpen] = useState(false); + const [editingItem, setEditingItem] = useState(null); + + const [alertDialogOpen, setAlertDialogOpen] = useState(false); + const [item, setItem] = useState(null); useEffect(() => { - fetchReconhecimentosTipos(); - }, []); + fetchReconhecimentosTipos() + }, []) + + const form = useForm({ + resolver: zodResolver(TTBReconhecimentoTipoSchema), + defaultValues: { + tb_reconhecimentotipo_id: 0, + descricao: "", + situacao: "I", + }, + }) + + async function onSubmit(values: FormValues) { + const saved = await saveReconhecimentoTipo(values); // aguarda o retorno + addReconhecimentoTipo(saved); // adiciona diretamente na lista + + // reinicia o formulário para o estado original + form.reset(); + } + + async function openForm(values: FormValues) { + setEditingItem(values); // guarda os valores do item + setDialogOpen(true); // abre o Dialog + form.reset({ + tb_reconhecimentotipo_id: values.tb_reconhecimentotipo_id, + descricao: values.descricao, + situacao: values.situacao, + }); + + } + + async function handlingConfirmation(visibility : boolean, item: null|any) { + setAlertDialogOpen(visibility); + setItem(item); + } + + const emptyForm: FormValues = { + tb_reconhecimentotipo_id: 0, + descricao: "", + situacao: "I", // padrão Inativo + }; if (!reconhecimentosTipos) return return (
- -
+
Tipos de Reconhecimentos @@ -40,14 +126,14 @@ export default function TTBReconhecimentoTipoPage() { Gerenciamento de tipos de reconhecimentos
+
-
+ @@ -56,36 +142,148 @@ export default function TTBReconhecimentoTipoPage() { # - - Descrição - Situação - Amount + + Descrição + + + - {reconhecimentosTipos.map((reconhecimentosTipos: ITTTBReconhecimentoTipo) => ( - - - {reconhecimentosTipos.tb_reconhecimentotipo_id} - - - {reconhecimentosTipos.descricao} - - - {reconhecimentosTipos.tb_reconhecimentotipo_id} - - $250.00 - - ))} + {reconhecimentosTipos.map( + (item: ITTTBReconhecimentoTipo) => ( + + + {item.tb_reconhecimentotipo_id} + + + {item.situacao === 'A' ? ( + + Ativo + + ) : ( + + Inativo + + )} + + + {item.descricao} + + + + + + + + + openForm(item)}> + Editar + + + handlingConfirmation(true, item)}> + Remover + + + + + + + ) + )}
+ + + {/* Formulário dentro do Dialog */} +
+ + + + + + Tipos de Reconhecimentos + + Tipos de reconhecimentos são usados na tela de balcão + + + ( + + Descrição + + + + + + )} + /> +
+ ( + field.onChange(checked ? "A" : "I")} + /> + )} + /> + +
+ + + + + + + + + +
+ + +
+ + + + + + #{item?.tb_reconhecimentotipo_id} - {item?.descricao} + + + Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. + + + + handlingConfirmation(false, null)} className="cursor-pointer"> + Cancelar + + + Continuar + + + + +
- - ); - -} \ No newline at end of file + ) +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts new file mode 100644 index 0000000..daf5964 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts @@ -0,0 +1,14 @@ +import { faker } from "@faker-js/faker" + +export default async function TTBReconhecimentoTipoSaveData(reconhecimentoTipo: any) { + + return Promise.resolve({ + message: 'Dados salvos com sucesso', + data: { + tb_reconhecimentotipo_id: faker.number.int({ min: 1, max: 1000 }), + descricao: reconhecimentoTipo.tb_reconhecimentotipo_id + reconhecimentoTipo.descricao, + situacao: reconhecimentoTipo.situacao + }, + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts index e626769..fb01797 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts @@ -21,6 +21,12 @@ export const useTTBReconhecimentoTipoReadHooks = () => { } - return { reconhecimentosTipos, fetchReconhecimentosTipos } + function addReconhecimentoTipo(reconhecimentoTipo: ITTTBReconhecimentoTipo) { + + setReconhecimenntosTipos(prev => [...(prev || []), reconhecimentoTipo]); + + } + + return { reconhecimentosTipos, fetchReconhecimentosTipos, addReconhecimentoTipo } } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts new file mode 100644 index 0000000..8605a63 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts @@ -0,0 +1,29 @@ +'use client' + +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import ITTTBReconhecimentoTipo from '../_interfaces/ITTTBReconhecimentoTipo' +import TTBReconhecimentoTipoSaveData from "../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; + +export const useTTBReconhecimentoTipoSaveHooks = () => { + + const { setResponse } = useResponse(); + + const [reconhecimentoTipo, setReconhcimentoTipo] = useState(); + + const saveReconhecimentoTipo = async (reconhecimentoTipo: ITTTBReconhecimentoTipo) => { + + const response = await TTBReconhecimentoTipoSaveData(reconhecimentoTipo); + + setReconhcimentoTipo(response.data); + + setResponse(response); + + // Retorna os valores de forma imediata + return response.data; + + } + + return { reconhecimentoTipo, saveReconhecimentoTipo } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts index 18d493e..c8e73dc 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts @@ -3,5 +3,7 @@ import { z } from 'zod'; export const TTBReconhecimentoTipoSchema = z.object({ tb_reconhecimentotipo_id: z.number(), descricao: z.string().min(1), - situacao: z.string().min(1), + situacao: z.enum(["A", "I"], { + errorMap: () => ({ message: "Situação deve ser 'A' ou 'I'" }) + }), }); \ No newline at end of file diff --git a/src/components/ui/alert-dialog.tsx b/src/components/ui/alert-dialog.tsx new file mode 100644 index 0000000..0863e40 --- /dev/null +++ b/src/components/ui/alert-dialog.tsx @@ -0,0 +1,157 @@ +"use client" + +import * as React from "react" +import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" + +import { cn } from "@/lib/utils" +import { buttonVariants } from "@/components/ui/button" + +function AlertDialog({ + ...props +}: React.ComponentProps) { + return +} + +function AlertDialogTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogPortal({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogContent({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + + ) +} + +function AlertDialogHeader({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function AlertDialogFooter({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function AlertDialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogAction({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogCancel({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + AlertDialog, + AlertDialogPortal, + AlertDialogOverlay, + AlertDialogTrigger, + AlertDialogContent, + AlertDialogHeader, + AlertDialogFooter, + AlertDialogTitle, + AlertDialogDescription, + AlertDialogAction, + AlertDialogCancel, +} diff --git a/src/components/ui/checkbox.tsx b/src/components/ui/checkbox.tsx new file mode 100644 index 0000000..fa0e4b5 --- /dev/null +++ b/src/components/ui/checkbox.tsx @@ -0,0 +1,32 @@ +"use client" + +import * as React from "react" +import * as CheckboxPrimitive from "@radix-ui/react-checkbox" +import { CheckIcon } from "lucide-react" + +import { cn } from "@/lib/utils" + +function Checkbox({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + + + ) +} + +export { Checkbox } diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx new file mode 100644 index 0000000..d9ccec9 --- /dev/null +++ b/src/components/ui/dialog.tsx @@ -0,0 +1,143 @@ +"use client" + +import * as React from "react" +import * as DialogPrimitive from "@radix-ui/react-dialog" +import { XIcon } from "lucide-react" + +import { cn } from "@/lib/utils" + +function Dialog({ + ...props +}: React.ComponentProps) { + return +} + +function DialogTrigger({ + ...props +}: React.ComponentProps) { + return +} + +function DialogPortal({ + ...props +}: React.ComponentProps) { + return +} + +function DialogClose({ + ...props +}: React.ComponentProps) { + return +} + +function DialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogContent({ + className, + children, + showCloseButton = true, + ...props +}: React.ComponentProps & { + showCloseButton?: boolean +}) { + return ( + + + + {children} + {showCloseButton && ( + + + Close + + )} + + + ) +} + +function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function DialogFooter({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function DialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function DialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +export { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogOverlay, + DialogPortal, + DialogTitle, + DialogTrigger, +} From 11aff8e15a3155f190a0913af518243bacf51658 Mon Sep 17 00:00:00 2001 From: keven Date: Thu, 11 Sep 2025 17:13:55 -0300 Subject: [PATCH 03/56] [MVPTN-2] feat(CRUD): CRUD com Mock para gerenciar a tabela t_tb_andamentoservico --- package-lock.json | 88 ++++++++ package.json | 2 + .../andamentos/page.tsx | 93 ++++++++ .../TTBAndamentoServicoAlert.tsx | 38 ++++ .../TTBAndamentoServicoForm.tsx | 150 +++++++++++++ .../TTBAndamentoServicoTable.tsx | 79 +++++++ .../TTBAndamentoServicoIndexData.ts | 132 ++++++++++++ .../TTBAndamentoServicoSaveData.ts | 16 ++ .../useTTBAndamentoServicoReadHook.ts | 33 +++ .../useTTBAndamentoServicoSaveHook.ts | 29 +++ .../TTBAndamentoServicoInterface.ts | 15 ++ .../cadastros/_schemas/TTBAndamentoServico.ts | 11 + src/app/globals.css | 200 ++++++++++++------ src/components/app-sidebar.tsx | 4 + src/components/ui/popover.tsx | 48 +++++ src/components/ui/select.tsx | 185 ++++++++++++++++ 16 files changed, 1057 insertions(+), 66 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts create mode 100644 src/components/ui/popover.tsx create mode 100644 src/components/ui/select.tsx diff --git a/package-lock.json b/package-lock.json index 10555ab..db55039 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,8 @@ "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-label": "^2.1.7", + "@radix-ui/react-popover": "^1.1.15", + "@radix-ui/react-select": "^2.2.6", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-tooltip": "^1.2.8", @@ -732,6 +734,12 @@ "node": ">= 10" } }, + "node_modules/@radix-ui/number": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@radix-ui/number/-/number-1.1.1.tgz", + "integrity": "sha512-MkKCwxlXTgz6CFoJx3pCwn07GKp36+aZyu/u2Ln2VrA5DcdyCZkASEDBTd8x5whTQQL5CiYf4prXKLcgQdv29g==", + "license": "MIT" + }, "node_modules/@radix-ui/primitive": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@radix-ui/primitive/-/primitive-1.1.3.tgz", @@ -1160,6 +1168,43 @@ } } }, + "node_modules/@radix-ui/react-popover": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.1.15.tgz", + "integrity": "sha512-kr0X2+6Yy/vJzLYJUPCZEc8SfQcf+1COFoAqauJm74umQhta9M7lNJHP7QQS3vkvcGLQUbWpMzwrXYwrYztHKA==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-dismissable-layer": "1.1.11", + "@radix-ui/react-focus-guards": "1.1.3", + "@radix-ui/react-focus-scope": "1.1.7", + "@radix-ui/react-id": "1.1.1", + "@radix-ui/react-popper": "1.2.8", + "@radix-ui/react-portal": "1.1.9", + "@radix-ui/react-presence": "1.1.5", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-slot": "1.2.3", + "@radix-ui/react-use-controllable-state": "1.2.2", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.6.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-popper": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.8.tgz", @@ -1294,6 +1339,49 @@ } } }, + "node_modules/@radix-ui/react-select": { + "version": "2.2.6", + "resolved": "https://registry.npmjs.org/@radix-ui/react-select/-/react-select-2.2.6.tgz", + "integrity": "sha512-I30RydO+bnn2PQztvo25tswPH+wFBjehVGtmagkU78yMdwTwVf12wnAOF+AeP8S2N8xD+5UPbGhkUfPyvT+mwQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/number": "1.1.1", + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-collection": "1.1.7", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-direction": "1.1.1", + "@radix-ui/react-dismissable-layer": "1.1.11", + "@radix-ui/react-focus-guards": "1.1.3", + "@radix-ui/react-focus-scope": "1.1.7", + "@radix-ui/react-id": "1.1.1", + "@radix-ui/react-popper": "1.2.8", + "@radix-ui/react-portal": "1.1.9", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-slot": "1.2.3", + "@radix-ui/react-use-callback-ref": "1.1.1", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-layout-effect": "1.1.1", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-visually-hidden": "1.2.3", + "aria-hidden": "^1.2.4", + "react-remove-scroll": "^2.6.3" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-separator": { "version": "1.1.7", "resolved": "https://registry.npmjs.org/@radix-ui/react-separator/-/react-separator-1.1.7.tgz", diff --git a/package.json b/package.json index 22ea23d..7d867a7 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-label": "^2.1.7", + "@radix-ui/react-popover": "^1.1.15", + "@radix-ui/react-select": "^2.2.6", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-tooltip": "^1.2.8", diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx new file mode 100644 index 0000000..8249c7b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -0,0 +1,93 @@ +'use client' + +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +import { useEffect, useState } from "react"; +import { useTTBAndamentoServicoReadHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook"; +import Loading from "@/app/_components/loading/loading"; +import TTBAndamentoServicoInteface, { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; +import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServico"; +import z from "zod"; +import { useTTBAndamentoServicoSaveHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook"; +import TTBAndamentoServicoTable from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoTable"; +import TTBAndamentoServicoForm from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoForm"; +import TTBAndamentoServicoAlert from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoAlert"; +import { PlusIcon } from "lucide-react"; + +type FormValues = z.infer + +export default function TTBAndamentoServico() { + + const { tTBAndamentosServicos, fetchTTBAndamentoServico, addTTBAndamentoServico } = useTTBAndamentoServicoReadHook(); + const { tTBAndamentoServico, saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook(); + + const [dialogOpen, setDialogOpen] = useState(false); + const [alertDialogOpen, setAlertDialogOpen] = useState(false); + const [item, setItem] = useState(null); + + const [formOpen, setFormOpen] = useState(false); + const [editingItem, setEditingItem] = useState(null); + + const [deleteOpen, setDeleteOpen] = useState(false) + const [deleteItem, setDeleteItem] = useState(null) + + const emptyForm: FormValues = { + tb_andamentoservico_id: 0, + descricao: "", + situacao: "I", + tipo: "", + usa_email: "", + }; + + useEffect(() => { + fetchTTBAndamentoServico(); + }, []); + + const handleSave = async (values: FormValues) => { + const saved = await saveTTBAndamentoServico(values); + addTTBAndamentoServico(saved); + setFormOpen(false); + } + + if (!tTBAndamentosServicos) return ; + return ( +
+
+
+
+ Andamentos +
+
+ Gerenciamento de tipos de reconhecimentos +
+
+
+ +
+
+ + + { setEditingItem(item); setFormOpen(true) }} + onDelete={(item) => { setDeleteItem(item); setDeleteOpen(true) }} + /> + + + setFormOpen(false)} + initialData={editingItem || emptyForm} + onSave={handleSave} + /> + < TTBAndamentoServicoAlert + isOpen={deleteOpen} + item={deleteItem} + onClose={() => setDeleteOpen(false)} + onConfirm={() => { setDeleteOpen(false) }} + /> +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx new file mode 100644 index 0000000..1fc1667 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx @@ -0,0 +1,38 @@ +'use client' + +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; + +interface Props { + isOpen: boolean, + item?: TTBAndamentoServicoInteface | null, + onClose: () => void + onConfirm: () => void +} + +export default function TTBAndamentoServicoAlert({ isOpen, item, onClose, onConfirm }: Props) { + return ( +
+ + + + + #{item?.tb_andamentoservico_id} - {item?.descricao} + + + Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. + + + + + Cancelar + + + Continuar + + + + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx new file mode 100644 index 0000000..e2599d5 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx @@ -0,0 +1,150 @@ +'use client' + +import z from "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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { Controller, useForm } from "react-hook-form"; +import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServico"; +import { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; + +type FormValues = z.infer + +interface Props { + isOpen: boolean + onClose: () => void + initialData?: FormValues + onSave: (data: FormValues) => void +} + +export default function TTBAndamentoServicoForm({ isOpen, onClose, initialData, onSave }: Props) { + + const form = useForm({ + resolver: undefined, + defaultValues: initialData || { tb_andamentoservico_id: 0, descricao: "", situacao: "I" } + }) + + const tipoOptions = Object.values(tipoEnum).map((value) => ({ + value, + // Aqui você pode personalizar o label como quiser + label: + value === "C" ? "Cancelado" : + value === "E" ? "Estornado" : + value === "PT" ? "Protocolado" : + value === "PD" ? "Pedido" : + value === "NC" ? "Não Consta" : + "Outros" + })); + + return ( +
+ +
+ + + + + + Andamentos + + Controle de andamentos de atos + + + ( + + + Descrição + + + + + + + )} + /> + ( + + + Tipo + + + + + )} + /> +
+ ( + field.onChange(checked ? "A" : "I")} + /> + )} + /> + +
+
+ ( + field.onChange(checked ? "A" : "I")} + /> + )} + /> + +
+ + + + + + + + + +
+ + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx new file mode 100644 index 0000000..9183f05 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx @@ -0,0 +1,79 @@ +'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 TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; + +interface Props { + data: TTBAndamentoServicoInteface[] + onEdit: (item: TTBAndamentoServicoInteface) => void + onDelete: (item: TTBAndamentoServicoInteface) => void +} + +export default function TTBAndamentoServicoTable({ data, onEdit, onDelete }: Props) { + return ( + + + + + # + + + Situação + + + Descrição + + + + + + {data.map( + (item: TTBAndamentoServicoInteface) => ( + + + {item.tb_andamentoservico_id} + + + {item.situacao === 'A' ? ( + + Ativo + + ) : ( + + Inativo + + )} + + + {item.descricao} + + + + + + + + + onEdit(item)}> + Editar + + + onDelete(item)}> + Remover + + + + + + + ) + )} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts new file mode 100644 index 0000000..b91bb11 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts @@ -0,0 +1,132 @@ +export default async function TTBAndamentoServicoIndexData() { + return Promise.resolve({ + data: [ + { + tb_andamentoservico_id: 1, + descricao: "Recepção 1", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 2, + descricao: "Aguardando assinatura da Imobiliária", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 3, + descricao: "Esc. Impugnada (Falta Itbi, cert. ou documentos)", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 4, + descricao: "Aguardando Certtb_andamentoservico_idão de Registro", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 5, + descricao: "Conferencia", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 16, + descricao: "Mapa", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 6, + descricao: "Entregue", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 18, + descricao: "PROTOCOLADO", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 7, + descricao: "Protocolo", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 8, + descricao: "Cadastro", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 9, + descricao: "Registro/Espelho", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 10, + descricao: "Corrigtb_andamentoservico_ido Pronto", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 11, + descricao: "Aguardando Cliente", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 12, + descricao: "Cancelado a pedtb_andamentoservico_ido da parte", + status: "A", + tipo: "C" + }, + { + tb_andamentoservico_id: 13, + descricao: "Cancelado por determinação judicial", + status: "A", + tipo: "C" + }, + { + tb_andamentoservico_id: 14, + descricao: "Capas e Indicador", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 15, + descricao: "Falta assinatura", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 17, + descricao: "Impugnado", + status: "A", + tipo: "G" + }, + { + tb_andamentoservico_id: 19, + descricao: "Entregre/sem registro", + status: "A", + tipo: "C" + }, + { + tb_andamentoservico_id: 20, + descricao: "Corrigtb_andamentoservico_ido sem Registro", + status: "A", + tipo: "C" + }, + { + tb_andamentoservico_id: 21, + descricao: "Cancelamento de ofício", + status: "A", + tipo: "C" + } + ] + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts new file mode 100644 index 0000000..ab8035d --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts @@ -0,0 +1,16 @@ +import { faker } from "@faker-js/faker"; + +export default async function name(andamentoServico: any) { + + return Promise.resolve({ + message: 'Dados salvos com sucesso', + data: { + tb_reconhecimentotipo_id: faker.number.int({ min: 1, max: 1000 }), + descricao: andamentoServico.tb_reconhecimentotipo_id + andamentoServico.descricao, + situacao: andamentoServico.situacao, + tipo: andamentoServico.tipo, + usa_email: andamentoServico.usa_email, + }, + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts new file mode 100644 index 0000000..df69730 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts @@ -0,0 +1,33 @@ +'use client' + +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; +import TTBAndamentoServicoIndexData from "../../_data/TTBAndamentoServico/TTBAndamentoServicoIndexData"; + +export const useTTBAndamentoServicoReadHook = () => { + + const { setResponse } = useResponse(); + + const [tTBAndamentosServicos, setTTBAndamentosServicos] = useState(null); + + const fetchTTBAndamentoServico = async () => { + + const response = await TTBAndamentoServicoIndexData(); + + setTTBAndamentosServicos(response.data); + + // Define os dados do componente de resposta (toast, modal, etc) + setResponse(response); + + } + + function addTTBAndamentoServico(tTTBAndamentoServico: TTBAndamentoServicoInteface) { + + setTTBAndamentosServicos(prev => [...(prev || []), tTTBAndamentoServico]); + + } + + return { tTBAndamentosServicos, fetchTTBAndamentoServico, addTTBAndamentoServico } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts new file mode 100644 index 0000000..b854b0a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -0,0 +1,29 @@ +'use client' + +import { useResponse } from "@/app/_response/ResponseContext" +import { use, useState } from "react"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; +import TTBReconhecimentoTipoSaveData from "../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; + +export const useTTBAndamentoServicoSaveHook = () => { + + const { setResponse } = useResponse(); + + const [tTBAndamentoServico, setTTBAndamentoServico] = useState(); + + const saveTTBAndamentoServico = async (form: TTBAndamentoServicoInteface) => { + + const response = await TTBReconhecimentoTipoSaveData(form); + + setTTBAndamentoServico(response.data); + + setResponse(response); + + // Retorna os valores de forma imediata + return response.data; + + } + + return { tTBAndamentoServico, saveTTBAndamentoServico } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts new file mode 100644 index 0000000..5322010 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts @@ -0,0 +1,15 @@ +export default interface TTBAndamentoServicoInteface { + tb_andamentoservico_id: number, + descricao: null | string, + situacao: null | string, + tipo: null | tipoEnum, +} + +export enum tipoEnum { + CANCELADO = "C", + ESTORNADO = "E", + PROTOCOLADO = "PT", + PEDIDO = "PD", + NAO_CONSTA = "NC", + OUTROS = "O", +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts new file mode 100644 index 0000000..af713ff --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts @@ -0,0 +1,11 @@ +import { z } from 'zod'; + +export const TTBAndamentoServicoSchema = z.object({ + + tb_andamentoservico_id: z.number(), + descricao: z.string(), + situacao: z.string(), + tipo: z.string(), + usa_email: z.string() + +}); \ No newline at end of file diff --git a/src/app/globals.css b/src/app/globals.css index 7be488e..2b6326b 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -6,8 +6,8 @@ @theme inline { --color-background: var(--background); --color-foreground: var(--foreground); - --font-sans: var(--font-geist-sans); - --font-mono: var(--font-geist-mono); + --font-sans: Inter, sans-serif; + --font-mono: JetBrains Mono, monospace; --color-sidebar-ring: var(--sidebar-ring); --color-sidebar-border: var(--sidebar-border); --color-sidebar-accent-foreground: var(--sidebar-accent-foreground); @@ -41,75 +41,142 @@ --radius-md: calc(var(--radius) - 2px); --radius-lg: var(--radius); --radius-xl: calc(var(--radius) + 4px); + --font-serif: Source Serif 4, serif; + --radius: 0.375rem; + --tracking-tighter: calc(var(--tracking-normal) - 0.05em); + --tracking-tight: calc(var(--tracking-normal) - 0.025em); + --tracking-wide: calc(var(--tracking-normal) + 0.025em); + --tracking-wider: calc(var(--tracking-normal) + 0.05em); + --tracking-widest: calc(var(--tracking-normal) + 0.1em); + --tracking-normal: var(--tracking-normal); + --shadow-2xl: var(--shadow-2xl); + --shadow-xl: var(--shadow-xl); + --shadow-lg: var(--shadow-lg); + --shadow-md: var(--shadow-md); + --shadow: var(--shadow); + --shadow-sm: var(--shadow-sm); + --shadow-xs: var(--shadow-xs); + --shadow-2xs: var(--shadow-2xs); + --spacing: var(--spacing); + --letter-spacing: var(--letter-spacing); + --shadow-offset-y: var(--shadow-offset-y); + --shadow-offset-x: var(--shadow-offset-x); + --shadow-spread: var(--shadow-spread); + --shadow-blur: var(--shadow-blur); + --shadow-opacity: var(--shadow-opacity); + --color-shadow-color: var(--shadow-color); + --color-destructive-foreground: var(--destructive-foreground); } :root { - --radius: 0.625rem; - --background: oklch(1 0 0); - --foreground: oklch(0.145 0 0); - --card: oklch(1 0 0); - --card-foreground: oklch(0.145 0 0); - --popover: oklch(1 0 0); - --popover-foreground: oklch(0.145 0 0); - --primary: oklch(0.205 0 0); - --primary-foreground: oklch(0.985 0 0); - --secondary: oklch(0.97 0 0); - --secondary-foreground: oklch(0.205 0 0); - --muted: oklch(0.97 0 0); - --muted-foreground: oklch(0.556 0 0); - --accent: oklch(0.97 0 0); - --accent-foreground: oklch(0.205 0 0); - --destructive: oklch(0.577 0.245 27.325); - --border: oklch(0.922 0 0); - --input: oklch(0.922 0 0); - --ring: oklch(0.708 0 0); - --chart-1: oklch(0.646 0.222 41.116); - --chart-2: oklch(0.6 0.118 184.704); - --chart-3: oklch(0.398 0.07 227.392); - --chart-4: oklch(0.828 0.189 84.429); - --chart-5: oklch(0.769 0.188 70.08); - --sidebar: oklch(0.985 0 0); - --sidebar-foreground: oklch(0.145 0 0); - --sidebar-primary: oklch(0.205 0 0); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.97 0 0); - --sidebar-accent-foreground: oklch(0.205 0 0); - --sidebar-border: oklch(0.922 0 0); - --sidebar-ring: oklch(0.708 0 0); + --radius: 0.375rem; + --background: oklch(1.0000 0 0); + --foreground: oklch(0.2686 0 0); + --card: oklch(1.0000 0 0); + --card-foreground: oklch(0.2686 0 0); + --popover: oklch(1.0000 0 0); + --popover-foreground: oklch(0.2686 0 0); + --primary: oklch(0.7686 0.1647 70.0804); + --primary-foreground: oklch(0 0 0); + --secondary: oklch(0.9670 0.0029 264.5419); + --secondary-foreground: oklch(0.4461 0.0263 256.8018); + --muted: oklch(0.9846 0.0017 247.8389); + --muted-foreground: oklch(0.5510 0.0234 264.3637); + --accent: oklch(0.9869 0.0214 95.2774); + --accent-foreground: oklch(0.4732 0.1247 46.2007); + --destructive: oklch(0.6368 0.2078 25.3313); + --border: oklch(0.9276 0.0058 264.5313); + --input: oklch(0.9276 0.0058 264.5313); + --ring: oklch(0.7686 0.1647 70.0804); + --chart-1: oklch(0.7686 0.1647 70.0804); + --chart-2: oklch(0.6658 0.1574 58.3183); + --chart-3: oklch(0.5553 0.1455 48.9975); + --chart-4: oklch(0.4732 0.1247 46.2007); + --chart-5: oklch(0.4137 0.1054 45.9038); + --sidebar: oklch(0.9846 0.0017 247.8389); + --sidebar-foreground: oklch(0.2686 0 0); + --sidebar-primary: oklch(0.7686 0.1647 70.0804); + --sidebar-primary-foreground: oklch(1.0000 0 0); + --sidebar-accent: oklch(0.9869 0.0214 95.2774); + --sidebar-accent-foreground: oklch(0.4732 0.1247 46.2007); + --sidebar-border: oklch(0.9276 0.0058 264.5313); + --sidebar-ring: oklch(0.7686 0.1647 70.0804); + --destructive-foreground: oklch(1.0000 0 0); + --font-sans: Inter, sans-serif; + --font-serif: Source Serif 4, serif; + --font-mono: JetBrains Mono, monospace; + --shadow-color: hsl(0 0% 0%); + --shadow-opacity: 0.1; + --shadow-blur: 8px; + --shadow-spread: -1px; + --shadow-offset-x: 0px; + --shadow-offset-y: 4px; + --letter-spacing: 0em; + --spacing: 0.25rem; + --shadow-2xs: 0px 4px 8px -1px hsl(0 0% 0% / 0.05); + --shadow-xs: 0px 4px 8px -1px hsl(0 0% 0% / 0.05); + --shadow-sm: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 1px 2px -2px hsl(0 0% 0% / 0.10); + --shadow: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 1px 2px -2px hsl(0 0% 0% / 0.10); + --shadow-md: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 2px 4px -2px hsl(0 0% 0% / 0.10); + --shadow-lg: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 4px 6px -2px hsl(0 0% 0% / 0.10); + --shadow-xl: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 8px 10px -2px hsl(0 0% 0% / 0.10); + --shadow-2xl: 0px 4px 8px -1px hsl(0 0% 0% / 0.25); + --tracking-normal: 0em; } .dark { - --background: oklch(0.145 0 0); - --foreground: oklch(0.985 0 0); - --card: oklch(0.205 0 0); - --card-foreground: oklch(0.985 0 0); - --popover: oklch(0.205 0 0); - --popover-foreground: oklch(0.985 0 0); - --primary: oklch(0.922 0 0); - --primary-foreground: oklch(0.205 0 0); - --secondary: oklch(0.269 0 0); - --secondary-foreground: oklch(0.985 0 0); - --muted: oklch(0.269 0 0); - --muted-foreground: oklch(0.708 0 0); - --accent: oklch(0.269 0 0); - --accent-foreground: oklch(0.985 0 0); - --destructive: oklch(0.704 0.191 22.216); - --border: oklch(1 0 0 / 10%); - --input: oklch(1 0 0 / 15%); - --ring: oklch(0.556 0 0); - --chart-1: oklch(0.488 0.243 264.376); - --chart-2: oklch(0.696 0.17 162.48); - --chart-3: oklch(0.769 0.188 70.08); - --chart-4: oklch(0.627 0.265 303.9); - --chart-5: oklch(0.645 0.246 16.439); - --sidebar: oklch(0.205 0 0); - --sidebar-foreground: oklch(0.985 0 0); - --sidebar-primary: oklch(0.488 0.243 264.376); - --sidebar-primary-foreground: oklch(0.985 0 0); - --sidebar-accent: oklch(0.269 0 0); - --sidebar-accent-foreground: oklch(0.985 0 0); - --sidebar-border: oklch(1 0 0 / 10%); - --sidebar-ring: oklch(0.556 0 0); + --background: oklch(0.2046 0 0); + --foreground: oklch(0.9219 0 0); + --card: oklch(0.2686 0 0); + --card-foreground: oklch(0.9219 0 0); + --popover: oklch(0.2686 0 0); + --popover-foreground: oklch(0.9219 0 0); + --primary: oklch(0.7686 0.1647 70.0804); + --primary-foreground: oklch(0 0 0); + --secondary: oklch(0.2686 0 0); + --secondary-foreground: oklch(0.9219 0 0); + --muted: oklch(0.2686 0 0); + --muted-foreground: oklch(0.7155 0 0); + --accent: oklch(0.4732 0.1247 46.2007); + --accent-foreground: oklch(0.9243 0.1151 95.7459); + --destructive: oklch(0.6368 0.2078 25.3313); + --border: oklch(0.3715 0 0); + --input: oklch(0.3715 0 0); + --ring: oklch(0.7686 0.1647 70.0804); + --chart-1: oklch(0.8369 0.1644 84.4286); + --chart-2: oklch(0.6658 0.1574 58.3183); + --chart-3: oklch(0.4732 0.1247 46.2007); + --chart-4: oklch(0.5553 0.1455 48.9975); + --chart-5: oklch(0.4732 0.1247 46.2007); + --sidebar: oklch(0.1684 0 0); + --sidebar-foreground: oklch(0.9219 0 0); + --sidebar-primary: oklch(0.7686 0.1647 70.0804); + --sidebar-primary-foreground: oklch(1.0000 0 0); + --sidebar-accent: oklch(0.4732 0.1247 46.2007); + --sidebar-accent-foreground: oklch(0.9243 0.1151 95.7459); + --sidebar-border: oklch(0.3715 0 0); + --sidebar-ring: oklch(0.7686 0.1647 70.0804); + --destructive-foreground: oklch(1.0000 0 0); + --radius: 0.375rem; + --font-sans: Inter, sans-serif; + --font-serif: Source Serif 4, serif; + --font-mono: JetBrains Mono, monospace; + --shadow-color: hsl(0 0% 0%); + --shadow-opacity: 0.1; + --shadow-blur: 8px; + --shadow-spread: -1px; + --shadow-offset-x: 0px; + --shadow-offset-y: 4px; + --letter-spacing: 0em; + --spacing: 0.25rem; + --shadow-2xs: 0px 4px 8px -1px hsl(0 0% 0% / 0.05); + --shadow-xs: 0px 4px 8px -1px hsl(0 0% 0% / 0.05); + --shadow-sm: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 1px 2px -2px hsl(0 0% 0% / 0.10); + --shadow: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 1px 2px -2px hsl(0 0% 0% / 0.10); + --shadow-md: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 2px 4px -2px hsl(0 0% 0% / 0.10); + --shadow-lg: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 4px 6px -2px hsl(0 0% 0% / 0.10); + --shadow-xl: 0px 4px 8px -1px hsl(0 0% 0% / 0.10), 0px 8px 10px -2px hsl(0 0% 0% / 0.10); + --shadow-2xl: 0px 4px 8px -1px hsl(0 0% 0% / 0.25); } @layer base { @@ -118,8 +185,9 @@ } body { @apply bg-background text-foreground; + letter-spacing: var(--tracking-normal); } .bg-brand{ background-color: #1A292F; } -} +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 0f56829..0460464 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -72,6 +72,10 @@ const data = { title: "Reconhecimentos", url: "/cadastros/reconhecimentos/", }, + { + title: "Andamentos", + url: "/cadastros/andamentos/", + }, ], }, { diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx new file mode 100644 index 0000000..01e468b --- /dev/null +++ b/src/components/ui/popover.tsx @@ -0,0 +1,48 @@ +"use client" + +import * as React from "react" +import * as PopoverPrimitive from "@radix-ui/react-popover" + +import { cn } from "@/lib/utils" + +function Popover({ + ...props +}: React.ComponentProps) { + return +} + +function PopoverTrigger({ + ...props +}: React.ComponentProps) { + return +} + +function PopoverContent({ + className, + align = "center", + sideOffset = 4, + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +function PopoverAnchor({ + ...props +}: React.ComponentProps) { + return +} + +export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor } diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx new file mode 100644 index 0000000..dcbbc0c --- /dev/null +++ b/src/components/ui/select.tsx @@ -0,0 +1,185 @@ +"use client" + +import * as React from "react" +import * as SelectPrimitive from "@radix-ui/react-select" +import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react" + +import { cn } from "@/lib/utils" + +function Select({ + ...props +}: React.ComponentProps) { + return +} + +function SelectGroup({ + ...props +}: React.ComponentProps) { + return +} + +function SelectValue({ + ...props +}: React.ComponentProps) { + return +} + +function SelectTrigger({ + className, + size = "default", + children, + ...props +}: React.ComponentProps & { + size?: "sm" | "default" +}) { + return ( + + {children} + + + + + ) +} + +function SelectContent({ + className, + children, + position = "popper", + ...props +}: React.ComponentProps) { + return ( + + + + + {children} + + + + + ) +} + +function SelectLabel({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function SelectItem({ + className, + children, + ...props +}: React.ComponentProps) { + return ( + + + + + + + {children} + + ) +} + +function SelectSeparator({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function SelectScrollUpButton({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +function SelectScrollDownButton({ + className, + ...props +}: React.ComponentProps) { + return ( + + + + ) +} + +export { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectScrollDownButton, + SelectScrollUpButton, + SelectSeparator, + SelectTrigger, + SelectValue, +} From 3355c98164cb427b5aebf460cf11a1c9ac96e837 Mon Sep 17 00:00:00 2001 From: keven Date: Fri, 12 Sep 2025 10:31:16 -0300 Subject: [PATCH 04/56] =?UTF-8?q?[MVPTN-2]=20feat(CRUD):=20Atualiza=C3=A7?= =?UTF-8?q?=C3=A3o=20no=20crud=20de=20gerenciamento=20de=20andamentos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cadastros/(t_tb_andamentoservico)/andamentos/page.tsx | 2 +- .../(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx | 8 ++++---- .../t_tb_andamentoservico/TTBAndamentoServicoForm.tsx | 6 ++++-- .../useTTBReconhecimentoTipoReadHooks.ts | 4 ++-- .../useTTBReconhecimentoTipoSaveHooks.ts | 4 ++-- ...hecimentoTipo.ts => TTBReconhecimentoTipoInterface.ts} | 2 +- ...TBAndamentoServico.ts => TTBAndamentoServicoSchema.ts} | 0 ...conhecimentoTipo.ts => TTBReconhecimentoTipoSchema.ts} | 0 8 files changed, 14 insertions(+), 12 deletions(-) rename src/app/(protected)/(cadastros)/cadastros/_hooks/{ => t_tb_reocnhecimentotipo}/useTTBReconhecimentoTipoReadHooks.ts (79%) rename src/app/(protected)/(cadastros)/cadastros/_hooks/{ => t_tb_reocnhecimentotipo}/useTTBReconhecimentoTipoSaveHooks.ts (78%) rename src/app/(protected)/(cadastros)/cadastros/_interfaces/{ITTTBReconhecimentoTipo.ts => TTBReconhecimentoTipoInterface.ts} (59%) rename src/app/(protected)/(cadastros)/cadastros/_schemas/{TTBAndamentoServico.ts => TTBAndamentoServicoSchema.ts} (100%) rename src/app/(protected)/(cadastros)/cadastros/_schemas/{TTTBReconhecimentoTipo.ts => TTBReconhecimentoTipoSchema.ts} (100%) diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 8249c7b..0338ae2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -6,7 +6,7 @@ import { useEffect, useState } from "react"; import { useTTBAndamentoServicoReadHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook"; import Loading from "@/app/_components/loading/loading"; import TTBAndamentoServicoInteface, { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; -import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServico"; +import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema"; import z from "zod"; import { useTTBAndamentoServicoSaveHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook"; import TTBAndamentoServicoTable from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoTable"; diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index c944264..ac533b6 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -33,12 +33,12 @@ import { TableHeader, TableRow, } from "@/components/ui/table" -import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/useTTBReconhecimentoTipoReadHooks" +import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks" import { useEffect, useState } from "react" -import ITTTBReconhecimentoTipo from "../../_interfaces/ITTTBReconhecimentoTipo" +import ITTTBReconhecimentoTipo from "../../_interfaces/TTBReconhecimentoTipoInterface" import Loading from "@/app/_components/loading/loading" import { Button } from "@/components/ui/button" -import { useTTBReconhecimentoTipoSaveHooks } from "../../_hooks/useTTBReconhecimentoTipoSaveHooks" +import { useTTBReconhecimentoTipoSaveHooks } from "../../_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks" import { Controller, useForm } from "react-hook-form" import { Form, @@ -49,7 +49,7 @@ import { FormMessage, } from "@/components/ui/form" import { zodResolver } from "@hookform/resolvers/zod" -import { TTBReconhecimentoTipoSchema } from "../../_schemas/TTTBReconhecimentoTipo" +import { TTBReconhecimentoTipoSchema } from "../../_schemas/TTBReconhecimentoTipoSchema" import z from "zod" import { Label } from "@/components/ui/label" import { Checkbox } from "@/components/ui/checkbox" diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx index e2599d5..dbb519f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx @@ -9,7 +9,7 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Controller, useForm } from "react-hook-form"; -import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServico"; +import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema"; import { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; type FormValues = z.infer @@ -52,7 +52,9 @@ export default function TTBAndamentoServicoForm({ isOpen, onClose, initialData,
- Andamentos + + Andamentos + Controle de andamentos de atos diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts similarity index 79% rename from src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts rename to src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts index fb01797..39c2686 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoReadHooks.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts @@ -1,9 +1,9 @@ 'use client' -import ITTTBReconhecimentoTipo from '../_interfaces/ITTTBReconhecimentoTipo' +import ITTTBReconhecimentoTipo from '../../_interfaces/TTBReconhecimentoTipoInterface' import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; -import TTBReconhecimentoTipoIndexData from '../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData'; +import TTBReconhecimentoTipoIndexData from '../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData'; export const useTTBReconhecimentoTipoReadHooks = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts similarity index 78% rename from src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts rename to src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts index 8605a63..820b846 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/useTTBReconhecimentoTipoSaveHooks.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts @@ -2,8 +2,8 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; -import ITTTBReconhecimentoTipo from '../_interfaces/ITTTBReconhecimentoTipo' -import TTBReconhecimentoTipoSaveData from "../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; +import ITTTBReconhecimentoTipo from '../../_interfaces/TTBReconhecimentoTipoInterface' +import TTBReconhecimentoTipoSaveData from "../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; export const useTTBReconhecimentoTipoSaveHooks = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts similarity index 59% rename from src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts rename to src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts index d0f4dda..8eef0fe 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/ITTTBReconhecimentoTipo.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts @@ -1,4 +1,4 @@ -export default interface ITTTBReconhecimentoTipo{ +export default interface TTBReconhecimentoTipoInterface{ tb_reconhecimentotipo_id: number, descricao: string, situacao: string, diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts similarity index 100% rename from src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServico.ts rename to src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts similarity index 100% rename from src/app/(protected)/(cadastros)/cadastros/_schemas/TTTBReconhecimentoTipo.ts rename to src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts From 46918249a20e3cf150e889aee9cee702c2548789 Mon Sep 17 00:00:00 2001 From: keven Date: Fri, 12 Sep 2025 11:32:34 -0300 Subject: [PATCH 05/56] =?UTF-8?q?[MVPTN-1]=20feat(Componentes):=20Separado?= =?UTF-8?q?=20a=20p=C3=A1gina=20em=20componentes=20que=20compo=C3=AAm=20a?= =?UTF-8?q?=20p=C3=A1gina?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reconhecimentos/page.tsx | 150 ------------------ .../TTBReconhecimentoTipoAlert.tsx | 28 ++++ .../TTBReconhecimentoTipoForm.tsx | 74 +++++++++ .../TTBReconhecimentoTipoTable.tsx | 85 ++++++++++ 4 files changed, 187 insertions(+), 150 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index ac533b6..4bab9e4 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -134,156 +134,6 @@ export default function TTBReconhecimentoTipoPage() {
- - - - - - - # - - - Situação - - - Descrição - - - - - - - {reconhecimentosTipos.map( - (item: ITTTBReconhecimentoTipo) => ( - - - {item.tb_reconhecimentotipo_id} - - - {item.situacao === 'A' ? ( - - Ativo - - ) : ( - - Inativo - - )} - - - {item.descricao} - - - - - - - - - openForm(item)}> - Editar - - - handlingConfirmation(true, item)}> - Remover - - - - - - - ) - )} - -
-
-
- - - {/* Formulário dentro do Dialog */} - - - - - - - Tipos de Reconhecimentos - - Tipos de reconhecimentos são usados na tela de balcão - - - ( - - Descrição - - - - - - )} - /> -
- ( - field.onChange(checked ? "A" : "I")} - /> - )} - /> - -
- - - - - - - - - -
- - -
- - - - - - #{item?.tb_reconhecimentotipo_id} - {item?.descricao} - - - Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. - - - - handlingConfirmation(false, null)} className="cursor-pointer"> - Cancelar - - - Continuar - - - - -
) } diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx new file mode 100644 index 0000000..a95e312 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx @@ -0,0 +1,28 @@ +import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; + +export default function TTBReconhecimentoTipoAlert() { + + return ( + + + + + #{item?.tb_reconhecimentotipo_id} - {item?.descricao} + + + Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. + + + + handlingConfirmation(false, null)} className="cursor-pointer"> + Cancelar + + + Continuar + + + + + ); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx new file mode 100644 index 0000000..ffa8e5e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx @@ -0,0 +1,74 @@ +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 { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; +import { Label } from "@/components/ui/label"; +import { Controller, Form } from "react-hook-form"; + +export default function TTBReconhecimentoTipoForm() { + + return ( + + {/* Formulário dentro do Dialog */} +
+ + + + + + Tipos de Reconhecimentos + + Tipos de reconhecimentos são usados na tela de balcão + + + ( + + Descrição + + + + + + )} + /> +
+ ( + field.onChange(checked ? "A" : "I")} + /> + )} + /> + +
+ + + + + + + + + +
+ + +
+ ); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx new file mode 100644 index 0000000..72ce875 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx @@ -0,0 +1,85 @@ +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +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, Trash2 } from "lucide-react"; +import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; + +interface Props { + data: TTBReconhecimentoTipoInterface, + onEdit: (item: TTBReconhecimentoTipoInterface) => void, + onDelete: (item: TTBReconhecimentoTipoInterface) => void, +} + +export default function TTBReconhecimentoTipoTable() { + + return ( + + + + + + + # + + + Situação + + + Descrição + + + + + + + {reconhecimentosTipos.map( + (item: ITTTBReconhecimentoTipo) => ( + + + {item.tb_reconhecimentotipo_id} + + + {item.situacao === 'A' ? ( + + Ativo + + ) : ( + + Inativo + + )} + + + {item.descricao} + + + + + + + + + openForm(item)}> + Editar + + + handlingConfirmation(true, item)}> + Remover + + + + + + + ) + )} + +
+
+
+ ); + +} \ No newline at end of file From 60af379e4f2f0519d693d8282390bba0a6d7f964 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 12:34:59 -0300 Subject: [PATCH 06/56] fix(Config): Ajuste ao acesso ao banco de dados via conteiner --- src/config/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/app.json b/src/config/app.json index 64ba493..0743536 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "http://localhost:3000/", + "url": "http://api_saas_api_homologacao:8000/", "prefix": "api/v1/", "content_type": "application/json" } From affa2bc2139f3213b16b2a44ed212f7082d88050 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 12:44:28 -0300 Subject: [PATCH 07/56] =?UTF-8?q?feat(Dockerfile):=20Cria=C3=A7=C3=A3o=20d?= =?UTF-8?q?o=20arquivo=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bbaca32 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Etapa 1: Construir a aplicação Next.js +# Use uma imagem Node.js leve como base +FROM node:20-alpine AS builder + +# Defina o diretório de trabalho +WORKDIR /app + +# Copie o package.json e o package-lock.json (ou yarn.lock) +COPY package*.json ./ + +# Instale as dependências do projeto +RUN npm install + +# Copie o restante do código fonte da aplicação +COPY . . + +# Construa a aplicação Next.js para produção +RUN npm run build + +# Etapa 2: Executar a aplicação Next.js +# Use uma imagem Node.js mais leve para a execução +FROM node:20-alpine AS runner + +# Defina o diretório de trabalho +WORKDIR /app + +# Copie os artefatos de build da etapa anterior +COPY --from=builder /app/.next ./.next +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/public ./public +COPY --from=builder /app/.env ./.env # Copie variáveis de ambiente, se necessário + +# Expõe a porta em que a aplicação Next.js será executada (padrão é 3000) +EXPOSE 3000 + +# Comando para iniciar a aplicação em modo de produção +CMD ["npm", "start"] \ No newline at end of file From cb066a514bdb16e0e108d1649fd7e890bf3ffb60 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 13:23:12 -0300 Subject: [PATCH 08/56] =?UTF-8?q?feat(Dockerfile):=20Nova=20cria=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20Dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index bbaca32..2525d04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,42 @@ -# Etapa 1: Construir a aplicação Next.js -# Use uma imagem Node.js leve como base +# Etapa 1: Construir a aplicação FROM node:20-alpine AS builder -# Defina o diretório de trabalho +# Define o diretório de trabalho WORKDIR /app -# Copie o package.json e o package-lock.json (ou yarn.lock) -COPY package*.json ./ +# Copia os arquivos de configuração do pacote +COPY package.json package-lock.json ./ -# Instale as dependências do projeto +# Instala as dependências, incluindo as de desenvolvimento RUN npm install -# Copie o restante do código fonte da aplicação +# Copia o restante do código da aplicação COPY . . -# Construa a aplicação Next.js para produção +# Constrói a aplicação com o output 'standalone' RUN npm run build -# Etapa 2: Executar a aplicação Next.js -# Use uma imagem Node.js mais leve para a execução +# Etapa 2: Executar a aplicação +# Usa uma imagem Node.js leve FROM node:20-alpine AS runner -# Defina o diretório de trabalho +# Define o diretório de trabalho WORKDIR /app -# Copie os artefatos de build da etapa anterior -COPY --from=builder /app/.next ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json -COPY --from=builder /app/public ./public -COPY --from=builder /app/.env ./.env # Copie variáveis de ambiente, se necessário +# Copia o diretório 'standalone' da etapa de build, que já contém o servidor e as dependências +# O diretório 'standalone' é a pasta .next/standalone gerada pela configuração 'output: standalone' +COPY --from=builder /app/.next/standalone ./ -# Expõe a porta em que a aplicação Next.js será executada (padrão é 3000) +# Copia os arquivos públicos +COPY --from=builder /app/public ./public + +# Define variáveis de ambiente, se necessário. +# Por exemplo, se precisar de uma variável NEXT_PUBLIC_API_URL +# ENV NEXT_PUBLIC_API_URL=https://api.meuapp.com + +# Expõe a porta padrão do Next.js EXPOSE 3000 -# Comando para iniciar a aplicação em modo de produção -CMD ["npm", "start"] \ No newline at end of file +# Define o comando para iniciar a aplicação +# O 'start' do package.json não é necessário, o próprio servidor standalone já está no container +CMD ["node", "server.js"] \ No newline at end of file From 3c033c2c4411cfc2ee93daa3b37b7014c57ab76f Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 13:34:23 -0300 Subject: [PATCH 09/56] feat(DockerFileNextConfig): Ajustando Dockerfile + next.config.ts --- Dockerfile | 32 +++++++++++++++----------------- next.config.ts | 3 ++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2525d04..a87dcbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,42 +1,40 @@ -# Etapa 1: Construir a aplicação +# Etapa 1: Construção da aplicação +# Use uma imagem Node.js completa para instalar as dependências e construir a aplicação FROM node:20-alpine AS builder -# Define o diretório de trabalho +# Define o diretório de trabalho dentro do container WORKDIR /app # Copia os arquivos de configuração do pacote COPY package.json package-lock.json ./ -# Instala as dependências, incluindo as de desenvolvimento +# Instala as dependências do projeto RUN npm install -# Copia o restante do código da aplicação +# Copia todo o código da sua aplicação para o container COPY . . -# Constrói a aplicação com o output 'standalone' +# Executa o comando de build do Next.js. O "output: 'standalone'" garante que os arquivos +# necessários para o servidor de produção sejam gerados em um diretório específico. RUN npm run build -# Etapa 2: Executar a aplicação -# Usa uma imagem Node.js leve +# Etapa 2: Execução da aplicação +# Use uma imagem Node.js minimalista para o ambiente de produção FROM node:20-alpine AS runner # Define o diretório de trabalho WORKDIR /app -# Copia o diretório 'standalone' da etapa de build, que já contém o servidor e as dependências -# O diretório 'standalone' é a pasta .next/standalone gerada pela configuração 'output: standalone' +# Copia a pasta "standalone" gerada na etapa de build, +# que contém o servidor, as dependências e os arquivos compilados COPY --from=builder /app/.next/standalone ./ -# Copia os arquivos públicos +# Copia a pasta 'public' que contém assets estáticos COPY --from=builder /app/public ./public -# Define variáveis de ambiente, se necessário. -# Por exemplo, se precisar de uma variável NEXT_PUBLIC_API_URL -# ENV NEXT_PUBLIC_API_URL=https://api.meuapp.com - -# Expõe a porta padrão do Next.js +# Define a porta que a aplicação irá expor EXPOSE 3000 -# Define o comando para iniciar a aplicação -# O 'start' do package.json não é necessário, o próprio servidor standalone já está no container +# Comando para iniciar o servidor Next.js em produção +# O "server.js" é o servidor otimizado gerado no modo 'standalone' CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index e9ffa30..0a838ef 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,7 +1,8 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { - /* config options here */ + // Isso gera um diretório otimizado que inclui tudo o que a aplicação precisa para rodar + output: 'standalone', }; export default nextConfig; From 3abde1e7cd52170010bf85157904fe5f6c939c5a Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 13:51:27 -0300 Subject: [PATCH 10/56] feat(Dockerfile): Ajustando Dockerfile --- Dockerfile | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index a87dcbb..2f707e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ -# Etapa 1: Construção da aplicação -# Use uma imagem Node.js completa para instalar as dependências e construir a aplicação +# Etapa 1: Construir a aplicação FROM node:20-alpine AS builder -# Define o diretório de trabalho dentro do container +# Define o diretório de trabalho WORKDIR /app # Copia os arquivos de configuração do pacote @@ -11,30 +10,33 @@ COPY package.json package-lock.json ./ # Instala as dependências do projeto RUN npm install -# Copia todo o código da sua aplicação para o container +# Copia todo o código da aplicação para o container COPY . . -# Executa o comando de build do Next.js. O "output: 'standalone'" garante que os arquivos -# necessários para o servidor de produção sejam gerados em um diretório específico. +# Constrói a aplicação com o output 'standalone' RUN npm run build -# Etapa 2: Execução da aplicação -# Use uma imagem Node.js minimalista para o ambiente de produção +# Etapa 2: Executar a aplicação +# Usa uma imagem Node.js leve FROM node:20-alpine AS runner # Define o diretório de trabalho WORKDIR /app -# Copia a pasta "standalone" gerada na etapa de build, -# que contém o servidor, as dependências e os arquivos compilados +# Copia o diretório 'standalone' da etapa de build, que já contém o servidor e as dependências +# O diretório 'standalone' é a pasta .next/standalone gerada pela configuração 'output: standalone' COPY --from=builder /app/.next/standalone ./ -# Copia a pasta 'public' que contém assets estáticos +# Copia os arquivos públicos COPY --from=builder /app/public ./public -# Define a porta que a aplicação irá expor +# Define variáveis de ambiente, se necessário. +# Por exemplo, se precisar de uma variável NEXT_PUBLIC_API_URL +# ENV NEXT_PUBLIC_API_URL=https://api.meuapp.com + +# Expõe a porta padrão do Next.js EXPOSE 3000 -# Comando para iniciar o servidor Next.js em produção -# O "server.js" é o servidor otimizado gerado no modo 'standalone' +# Define o comando para iniciar a aplicação +# O 'start' do package.json não é necessário, o próprio servidor standalone já está no container CMD ["node", "server.js"] \ No newline at end of file From e1993272343a56078213bbe30f6b1a4c2db9b20c Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 14:38:02 -0300 Subject: [PATCH 11/56] feat(Dockerfile): Ajustando Dockerfile --- Dockerfile | 7 ++--- package-lock.json | 80 +++++++++++++++++++++++------------------------ package.json | 2 +- 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f707e2..42d7e81 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,13 +30,12 @@ COPY --from=builder /app/.next/standalone ./ # Copia os arquivos públicos COPY --from=builder /app/public ./public -# Define variáveis de ambiente, se necessário. -# Por exemplo, se precisar de uma variável NEXT_PUBLIC_API_URL -# ENV NEXT_PUBLIC_API_URL=https://api.meuapp.com +# Copia os arquivos estáticos gerados pelo build. É aqui que os arquivos CSS e JS ficam. +COPY --from=builder /app/.next/static ./.next/static # Expõe a porta padrão do Next.js EXPOSE 3000 # Define o comando para iniciar a aplicação # O 'start' do package.json não é necessário, o próprio servidor standalone já está no container -CMD ["node", "server.js"] \ No newline at end of file +CMD ["node", "server.js"] diff --git a/package-lock.json b/package-lock.json index 0f7ae39..150fb4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "cookies-next": "^6.1.0", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.540.0", - "next": "15.4.6", + "next": "^15.5.3", "next-themes": "^0.4.6", "react": "19.1.0", "react-dom": "19.1.0", @@ -597,15 +597,15 @@ } }, "node_modules/@next/env": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/env/-/env-15.4.6.tgz", - "integrity": "sha512-yHDKVTcHrZy/8TWhj0B23ylKv5ypocuCwey9ZqPyv4rPdUdRzpGCkSi03t04KBPyU96kxVtUqx6O3nE1kpxASQ==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/env/-/env-15.5.3.tgz", + "integrity": "sha512-RSEDTRqyihYXygx/OJXwvVupfr9m04+0vH8vyy0HfZ7keRto6VX9BbEk0J2PUk0VGy6YhklJUSrgForov5F9pw==", "license": "MIT" }, "node_modules/@next/swc-darwin-arm64": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.4.6.tgz", - "integrity": "sha512-667R0RTP4DwxzmrqTs4Lr5dcEda9OxuZsVFsjVtxVMVhzSpo6nLclXejJVfQo2/g7/Z9qF3ETDmN3h65mTjpTQ==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-15.5.3.tgz", + "integrity": "sha512-nzbHQo69+au9wJkGKTU9lP7PXv0d1J5ljFpvb+LnEomLtSbJkbZyEs6sbF3plQmiOB2l9OBtN2tNSvCH1nQ9Jg==", "cpu": [ "arm64" ], @@ -619,9 +619,9 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.4.6.tgz", - "integrity": "sha512-KMSFoistFkaiQYVQQnaU9MPWtp/3m0kn2Xed1Ces5ll+ag1+rlac20sxG+MqhH2qYWX1O2GFOATQXEyxKiIscg==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-15.5.3.tgz", + "integrity": "sha512-w83w4SkOOhekJOcA5HBvHyGzgV1W/XvOfpkrxIse4uPWhYTTRwtGEM4v/jiXwNSJvfRvah0H8/uTLBKRXlef8g==", "cpu": [ "x64" ], @@ -635,9 +635,9 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.4.6.tgz", - "integrity": "sha512-PnOx1YdO0W7m/HWFeYd2A6JtBO8O8Eb9h6nfJia2Dw1sRHoHpNf6lN1U4GKFRzRDBi9Nq2GrHk9PF3Vmwf7XVw==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-15.5.3.tgz", + "integrity": "sha512-+m7pfIs0/yvgVu26ieaKrifV8C8yiLe7jVp9SpcIzg7XmyyNE7toC1fy5IOQozmr6kWl/JONC51osih2RyoXRw==", "cpu": [ "arm64" ], @@ -651,9 +651,9 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.4.6.tgz", - "integrity": "sha512-XBbuQddtY1p5FGPc2naMO0kqs4YYtLYK/8aPausI5lyOjr4J77KTG9mtlU4P3NwkLI1+OjsPzKVvSJdMs3cFaw==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-15.5.3.tgz", + "integrity": "sha512-u3PEIzuguSenoZviZJahNLgCexGFhso5mxWCrrIMdvpZn6lkME5vc/ADZG8UUk5K1uWRy4hqSFECrON6UKQBbQ==", "cpu": [ "arm64" ], @@ -667,9 +667,9 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.4.6.tgz", - "integrity": "sha512-+WTeK7Qdw82ez3U9JgD+igBAP75gqZ1vbK6R8PlEEuY0OIe5FuYXA4aTjL811kWPf7hNeslD4hHK2WoM9W0IgA==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-15.5.3.tgz", + "integrity": "sha512-lDtOOScYDZxI2BENN9m0pfVPJDSuUkAD1YXSvlJF0DKwZt0WlA7T7o3wrcEr4Q+iHYGzEaVuZcsIbCps4K27sA==", "cpu": [ "x64" ], @@ -683,9 +683,9 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.4.6.tgz", - "integrity": "sha512-XP824mCbgQsK20jlXKrUpZoh/iO3vUWhMpxCz8oYeagoiZ4V0TQiKy0ASji1KK6IAe3DYGfj5RfKP6+L2020OQ==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-15.5.3.tgz", + "integrity": "sha512-9vWVUnsx9PrY2NwdVRJ4dUURAQ8Su0sLRPqcCCxtX5zIQUBES12eRVHq6b70bbfaVaxIDGJN2afHui0eDm+cLg==", "cpu": [ "x64" ], @@ -699,9 +699,9 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.4.6.tgz", - "integrity": "sha512-FxrsenhUz0LbgRkNWx6FRRJIPe/MI1JRA4W4EPd5leXO00AZ6YU8v5vfx4MDXTvN77lM/EqsE3+6d2CIeF5NYg==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-15.5.3.tgz", + "integrity": "sha512-1CU20FZzY9LFQigRi6jM45oJMU3KziA5/sSG+dXeVaTm661snQP6xu3ykGxxwU5sLG3sh14teO/IOEPVsQMRfA==", "cpu": [ "arm64" ], @@ -715,9 +715,9 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.4.6.tgz", - "integrity": "sha512-T4ufqnZ4u88ZheczkBTtOF+eKaM14V8kbjud/XrAakoM5DKQWjW09vD6B9fsdsWS2T7D5EY31hRHdta7QKWOng==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-15.5.3.tgz", + "integrity": "sha512-JMoLAq3n3y5tKXPQwCK5c+6tmwkuFDa2XAxz8Wm4+IVthdBZdZGh+lmiLUHg9f9IDwIQpUjp+ysd6OkYTyZRZw==", "cpu": [ "x64" ], @@ -2444,12 +2444,12 @@ } }, "node_modules/next": { - "version": "15.4.6", - "resolved": "https://registry.npmjs.org/next/-/next-15.4.6.tgz", - "integrity": "sha512-us++E/Q80/8+UekzB3SAGs71AlLDsadpFMXVNM/uQ0BMwsh9m3mr0UNQIfjKed8vpWXsASe+Qifrnu1oLIcKEQ==", + "version": "15.5.3", + "resolved": "https://registry.npmjs.org/next/-/next-15.5.3.tgz", + "integrity": "sha512-r/liNAx16SQj4D+XH/oI1dlpv9tdKJ6cONYPwwcCC46f2NjpaRWY+EKCzULfgQYV6YKXjHBchff2IZBSlZmJNw==", "license": "MIT", "dependencies": { - "@next/env": "15.4.6", + "@next/env": "15.5.3", "@swc/helpers": "0.5.15", "caniuse-lite": "^1.0.30001579", "postcss": "8.4.31", @@ -2462,14 +2462,14 @@ "node": "^18.18.0 || ^19.8.0 || >= 20.0.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "15.4.6", - "@next/swc-darwin-x64": "15.4.6", - "@next/swc-linux-arm64-gnu": "15.4.6", - "@next/swc-linux-arm64-musl": "15.4.6", - "@next/swc-linux-x64-gnu": "15.4.6", - "@next/swc-linux-x64-musl": "15.4.6", - "@next/swc-win32-arm64-msvc": "15.4.6", - "@next/swc-win32-x64-msvc": "15.4.6", + "@next/swc-darwin-arm64": "15.5.3", + "@next/swc-darwin-x64": "15.5.3", + "@next/swc-linux-arm64-gnu": "15.5.3", + "@next/swc-linux-arm64-musl": "15.5.3", + "@next/swc-linux-x64-gnu": "15.5.3", + "@next/swc-linux-x64-musl": "15.5.3", + "@next/swc-win32-arm64-msvc": "15.5.3", + "@next/swc-win32-x64-msvc": "15.5.3", "sharp": "^0.34.3" }, "peerDependencies": { diff --git a/package.json b/package.json index 9ab3d66..fa2939c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "cookies-next": "^6.1.0", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.540.0", - "next": "15.4.6", + "next": "^15.5.3", "next-themes": "^0.4.6", "react": "19.1.0", "react-dom": "19.1.0", From 261144e45f73b3403bcf8c23a3df63abef81ae5d Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 15:02:48 -0300 Subject: [PATCH 12/56] =?UTF-8?q?feat(Dockerfile):=20Ajustando=20Dockerfil?= =?UTF-8?q?e=20para=20depura=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 41 +++++++++++------------------------------ Dockerfile-homologacao | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 30 deletions(-) create mode 100644 Dockerfile-homologacao diff --git a/Dockerfile b/Dockerfile index 42d7e81..6edcd97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,22 @@ -# Etapa 1: Construir a aplicação -FROM node:20-alpine AS builder +# Use uma imagem Node.js completa para o desenvolvimento +FROM node:20-alpine -# Define o diretório de trabalho +# Define o diretório de trabalho no container WORKDIR /app -# Copia os arquivos de configuração do pacote +# Copia os arquivos de configuração do projeto COPY package.json package-lock.json ./ -# Instala as dependências do projeto +# Instala todas as dependências do projeto +# Isso é necessário para o modo de desenvolvimento, pois o build não pré-compila os arquivos. RUN npm install -# Copia todo o código da aplicação para o container +# Copia o restante do código da sua aplicação COPY . . -# Constrói a aplicação com o output 'standalone' -RUN npm run build - -# Etapa 2: Executar a aplicação -# Usa uma imagem Node.js leve -FROM node:20-alpine AS runner - -# Define o diretório de trabalho -WORKDIR /app - -# Copia o diretório 'standalone' da etapa de build, que já contém o servidor e as dependências -# O diretório 'standalone' é a pasta .next/standalone gerada pela configuração 'output: standalone' -COPY --from=builder /app/.next/standalone ./ - -# Copia os arquivos públicos -COPY --from=builder /app/public ./public - -# Copia os arquivos estáticos gerados pelo build. É aqui que os arquivos CSS e JS ficam. -COPY --from=builder /app/.next/static ./.next/static - -# Expõe a porta padrão do Next.js +# Expõe a porta de desenvolvimento padrão do Next.js EXPOSE 3000 -# Define o comando para iniciar a aplicação -# O 'start' do package.json não é necessário, o próprio servidor standalone já está no container -CMD ["node", "server.js"] +# Define o comando para iniciar a aplicação em modo de desenvolvimento +# Isso ativará o servidor de desenvolvimento e a recarga automática +CMD ["npm", "run", "dev"] diff --git a/Dockerfile-homologacao b/Dockerfile-homologacao new file mode 100644 index 0000000..42d7e81 --- /dev/null +++ b/Dockerfile-homologacao @@ -0,0 +1,41 @@ +# Etapa 1: Construir a aplicação +FROM node:20-alpine AS builder + +# Define o diretório de trabalho +WORKDIR /app + +# Copia os arquivos de configuração do pacote +COPY package.json package-lock.json ./ + +# Instala as dependências do projeto +RUN npm install + +# Copia todo o código da aplicação para o container +COPY . . + +# Constrói a aplicação com o output 'standalone' +RUN npm run build + +# Etapa 2: Executar a aplicação +# Usa uma imagem Node.js leve +FROM node:20-alpine AS runner + +# Define o diretório de trabalho +WORKDIR /app + +# Copia o diretório 'standalone' da etapa de build, que já contém o servidor e as dependências +# O diretório 'standalone' é a pasta .next/standalone gerada pela configuração 'output: standalone' +COPY --from=builder /app/.next/standalone ./ + +# Copia os arquivos públicos +COPY --from=builder /app/public ./public + +# Copia os arquivos estáticos gerados pelo build. É aqui que os arquivos CSS e JS ficam. +COPY --from=builder /app/.next/static ./.next/static + +# Expõe a porta padrão do Next.js +EXPOSE 3000 + +# Define o comando para iniciar a aplicação +# O 'start' do package.json não é necessário, o próprio servidor standalone já está no container +CMD ["node", "server.js"] From e3a29dd5d0ed548bbe1088b4e768a34c2ccb4944 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 15:59:56 -0300 Subject: [PATCH 13/56] feat(app.json): Ajustando arquivo app.json --- src/config/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/app.json b/src/config/app.json index 0743536..d2883ec 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "http://api_saas_api_homologacao:8000/", + "url": "https://saas_api_homologacao.oriustecnologia.com", "prefix": "api/v1/", "content_type": "application/json" } From b6274f1cf3ad9d3d2f0bc9d2cbb2264765bed53c Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 16:25:22 -0300 Subject: [PATCH 14/56] feat(app.json): Ajustando arquivo app.json --- src/config/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/app.json b/src/config/app.json index d2883ec..0743536 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "https://saas_api_homologacao.oriustecnologia.com", + "url": "http://api_saas_api_homologacao:8000/", "prefix": "api/v1/", "content_type": "application/json" } From f0f02634b506d45ebc1a334b0b0fad481aa21993 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 16:33:05 -0300 Subject: [PATCH 15/56] feat(app.json): Ajustando arquivo app.json --- src/config/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/app.json b/src/config/app.json index 0743536..9a82c08 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "http://api_saas_api_homologacao:8000/", + "url": "http://api-saas-api-homologacao:8000/", "prefix": "api/v1/", "content_type": "application/json" } From 06678901d402698350247f4721ff4525bd8455c7 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 16:47:21 -0300 Subject: [PATCH 16/56] feat(app.json): Ajustando arquivo app.json --- src/config/app.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/app.json b/src/config/app.json index 9a82c08..fda4fd5 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "http://api-saas-api-homologacao:8000/", + "url": "api-saas-api-homologacao:8000/", "prefix": "api/v1/", "content_type": "application/json" } From e782085ed09265b80bcbb0fbea2995267e0e3bc0 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:15:51 -0300 Subject: [PATCH 17/56] feat(app.json): Ajustando arquivo app.json --- src/config/app.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/app.json b/src/config/app.json index fda4fd5..fb7f42d 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,8 +1,8 @@ { "state": "go", "api": { - "url": "api-saas-api-homologacao:8000/", - "prefix": "api/v1/", + "url": "http://api-saas-api-homologacao:8000/", + "prefix": "api/v1", "content_type": "application/json" } } \ No newline at end of file From c95380c9321bc8a7e331c2488287b8cc5dd57d43 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:22:34 -0300 Subject: [PATCH 18/56] feat(Debug) Debugando url do fetch --- src/services/api/Api.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 75e6173..53e0321 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -45,6 +45,8 @@ export default class API { // Verifica se existe body para envio const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; + console.log(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`) + // Realiza a requisição const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`, { method: _data.method, From b936df520a86da72e5ae48415f7f376b1ae847ff Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:26:33 -0300 Subject: [PATCH 19/56] feat(Debug) Debugando url do fetch --- src/services/api/Api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 53e0321..65c9d75 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -45,7 +45,7 @@ export default class API { // Verifica se existe body para envio const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; - console.log(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`) + console.log("URL:: " + `${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`) // Realiza a requisição const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`, { From 025dd6a0c233075bc5771fb6b55316c8f8482e73 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:29:59 -0300 Subject: [PATCH 20/56] feat(Debug): Removendo debug --- src/services/api/Api.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 65c9d75..75e6173 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -45,8 +45,6 @@ export default class API { // Verifica se existe body para envio const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; - console.log("URL:: " + `${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`) - // Realiza a requisição const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`, { method: _data.method, From 557ad241d15b7836a1963811c38772c5168cf36e Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:32:03 -0300 Subject: [PATCH 21/56] feat(Debug): DEbug de url --- src/services/api/Api.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 75e6173..20f9919 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -45,8 +45,11 @@ export default class API { // Verifica se existe body para envio const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; + + console.log("URL:: " + `${this.ApiSchema.url}${this.ApiSchema.prefix}/administrativo/g_usuario/authenticate`) + // Realiza a requisição - const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`, { + const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/administrativo/g_usuario/authenticate`, { method: _data.method, headers: { "Accept": `${this.ApiSchema.contentType}`, From c6cb1368c44e706d18923eee430f841ee3e547b0 Mon Sep 17 00:00:00 2001 From: Kenio de Souza Date: Fri, 12 Sep 2025 17:53:28 -0300 Subject: [PATCH 22/56] feat(Debug): DEbug de url --- src/services/api/Api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 20f9919..1597c5f 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -46,10 +46,10 @@ export default class API { const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; - console.log("URL:: " + `${this.ApiSchema.url}${this.ApiSchema.prefix}/administrativo/g_usuario/authenticate`) + console.log("URL:: " + `http://api-saas-api-homologacao:8000/administrativo/g_usuario/authenticate`) // Realiza a requisição - const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/administrativo/g_usuario/authenticate`, { + const response = await fetch(`http://api-saas-api-homologacao:8000/administrativo/g_usuario/authenticate`, { method: _data.method, headers: { "Accept": `${this.ApiSchema.contentType}`, From 0407483d2300523ff2fec06568ec4e75e6d12e2b Mon Sep 17 00:00:00 2001 From: keven Date: Sat, 13 Sep 2025 13:14:00 -0300 Subject: [PATCH 23/56] =?UTF-8?q?[MVPTN-2]=20refacto(AndamentoServico):=20?= =?UTF-8?q?Refaz=20o=20CRUD=20de=20AndamentoServico=20implementando=20comp?= =?UTF-8?q?oneiza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 24 ++ package.json | 2 + src/actions/json/Json.ts | 16 +- .../andamentos/page.tsx | 174 +++++++---- .../TTBAndamentoServicoAlert.tsx | 38 --- .../TTBAndamentoServicoForm.tsx | 273 ++++++++++-------- .../TTBAndamentoServicoTable.tsx | 169 +++++++---- .../TTBAndamentoServicoIndexData.ts | 145 +--------- .../TTBAndamentoServicoSaveData.ts | 25 +- .../useTTBAndamentoServicoReadHook.ts | 1 + .../useTTBAndamentoServicoSaveHook.ts | 8 +- .../confirm_dialog/ConfirmDialog.tsx | 83 ++++++ .../confirm_dialog/useConfirmDialog.ts | 51 ++++ src/config/app.json | 2 +- src/services/api/Api.ts | 5 +- 15 files changed, 580 insertions(+), 436 deletions(-) delete mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx create mode 100644 src/app/_components/confirm_dialog/ConfirmDialog.tsx create mode 100644 src/app/_components/confirm_dialog/useConfirmDialog.ts diff --git a/package-lock.json b/package-lock.json index db55039..9e77c45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "app", "version": "0.1.0", "dependencies": { + "@faker-js/faker": "^10.0.0", "@hookform/resolvers": "^5.2.1", "@radix-ui/react-alert-dialog": "^1.1.15", "@radix-ui/react-avatar": "^1.1.10", @@ -24,6 +25,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cookies-next": "^6.1.0", + "faker-js": "^1.0.0", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.540.0", "next": "15.4.6", @@ -69,6 +71,22 @@ "tslib": "^2.4.0" } }, + "node_modules/@faker-js/faker": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@faker-js/faker/-/faker-10.0.0.tgz", + "integrity": "sha512-UollFEUkVXutsaP+Vndjxar40Gs5JL2HeLcl8xO1QAjJgOdhc3OmBFWyEylS+RddWaaBiAzH+5/17PLQJwDiLw==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/fakerjs" + } + ], + "license": "MIT", + "engines": { + "node": "^20.19.0 || ^22.13.0 || ^23.5.0 || >=24.0.0", + "npm": ">=10" + } + }, "node_modules/@floating-ui/core": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/@floating-ui/core/-/core-1.7.3.tgz", @@ -2167,6 +2185,12 @@ "node": ">=10.13.0" } }, + "node_modules/faker-js": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/faker-js/-/faker-js-1.0.0.tgz", + "integrity": "sha512-kaToadbN63LWhHjl69pqG+YHlxAK0aZAPhQDUpVP7v7+RG//ZpK0OzXjCwaAQq98awOii0WSHxtJmIz0X7/UqQ==", + "license": "ISC" + }, "node_modules/get-nonce": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-nonce/-/get-nonce-1.0.1.tgz", diff --git a/package.json b/package.json index 7d867a7..0111c7f 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "lint": "next lint" }, "dependencies": { + "@faker-js/faker": "^10.0.0", "@hookform/resolvers": "^5.2.1", "@radix-ui/react-alert-dialog": "^1.1.15", "@radix-ui/react-avatar": "^1.1.10", @@ -25,6 +26,7 @@ "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cookies-next": "^6.1.0", + "faker-js": "^1.0.0", "jsonwebtoken": "^9.0.2", "lucide-react": "^0.540.0", "next": "15.4.6", diff --git a/src/actions/json/Json.ts b/src/actions/json/Json.ts index 92a1a18..b075b64 100644 --- a/src/actions/json/Json.ts +++ b/src/actions/json/Json.ts @@ -1,16 +1,6 @@ +import appConfig from '../../config/app.json'; export default class Json { - - static execute(path: string) { - - return { - "state": "go", - "api": { - "url": "http://localhost:8000/", - "prefix": "api/v1", - "content_type": "application/json" - } - } - + static execute() { + return appConfig; } - } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 0338ae2..7fe708a 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -1,92 +1,154 @@ -'use client' +'use client'; +import { useEffect, useState, useCallback } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; -import { useEffect, useState } from "react"; -import { useTTBAndamentoServicoReadHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook"; -import Loading from "@/app/_components/loading/loading"; -import TTBAndamentoServicoInteface, { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; -import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema"; -import z from "zod"; -import { useTTBAndamentoServicoSaveHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook"; -import TTBAndamentoServicoTable from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoTable"; -import TTBAndamentoServicoForm from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoForm"; -import TTBAndamentoServicoAlert from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoAlert"; import { PlusIcon } from "lucide-react"; -type FormValues = z.infer +import Loading from "@/app/_components/loading/loading"; +import TTBAndamentoServicoTable from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoTable"; +import TTBAndamentoServicoForm from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoForm"; + +import { useTTBAndamentoServicoReadHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook"; +import { useTTBAndamentoServicoSaveHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook"; + +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import TTBAndamentoServicoInterface from "../../_interfaces/TTBAndamentoServicoInterface"; export default function TTBAndamentoServico() { + // Hooks para leitura e salvamento + const { tTBAndamentosServicos, fetchTTBAndamentoServico } = useTTBAndamentoServicoReadHook(); + const { saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook(); - const { tTBAndamentosServicos, fetchTTBAndamentoServico, addTTBAndamentoServico } = useTTBAndamentoServicoReadHook(); - const { tTBAndamentoServico, saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook(); + // Estados + const [selectedAndamento, setSelectedAndamento] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); - const [dialogOpen, setDialogOpen] = useState(false); - const [alertDialogOpen, setAlertDialogOpen] = useState(false); - const [item, setItem] = useState(null); + // Estado para saber qual item será deletado + const [itemToDelete, setItemToDelete] = useState(null); - const [formOpen, setFormOpen] = useState(false); - const [editingItem, setEditingItem] = useState(null); + /** + * Hook do modal de confirmação + */ + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); - const [deleteOpen, setDeleteOpen] = useState(false) - const [deleteItem, setDeleteItem] = useState(null) + /** + * Abre o formulário no modo de edição ou criação + */ + const handleOpenForm = useCallback((data: TTBAndamentoServicoInterface | null) => { + setSelectedAndamento(data); + setIsFormOpen(true); + }, []); - const emptyForm: FormValues = { - tb_andamentoservico_id: 0, - descricao: "", - situacao: "I", - tipo: "", - usa_email: "", - }; + /** + * 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: TTBAndamentoServicoInterface) => { + await saveTTBAndamentoServico(formData); + handleCloseForm(); + fetchTTBAndamentoServico(); // Atualiza a lista após salvar + }, + [saveTTBAndamentoServico, fetchTTBAndamentoServico, handleCloseForm] + ); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: TTBAndamentoServicoInterface) => { + setItemToDelete(item); + openConfirmDialog(); // Abre o modal de confirmação + }, [openConfirmDialog]); + + /** + * Executa a exclusão de fato quando o usuário confirma + */ + const handleDelete = useCallback(() => { + if (!itemToDelete) return; + console.log("Deletando andamento:", itemToDelete); + + // TODO: Implementar lógica de exclusão na API + fetchTTBAndamentoServico(); // Atualiza a lista + setItemToDelete(null); // Limpa o item selecionado + handleCancel(); // Fecha o modal + }, [itemToDelete, fetchTTBAndamentoServico, handleCancel]); + + /** + * Busca inicial dos dados + */ useEffect(() => { fetchTTBAndamentoServico(); }, []); - const handleSave = async (values: FormValues) => { - const saved = await saveTTBAndamentoServico(values); - addTTBAndamentoServico(saved); - setFormOpen(false); + /** + * Tela de loading enquanto carrega os dados + */ + if (!tTBAndamentosServicos) { + return ; } - if (!tTBAndamentosServicos) return ; return (
-
-
-
+ {/* Cabeçalho */} +
+
+

Andamentos -

-
+ +

Gerenciamento de tipos de reconhecimentos -

-
-
- +

+
+ + {/* Tabela de andamentos */} { setEditingItem(item); setFormOpen(true) }} - onDelete={(item) => { setDeleteItem(item); setDeleteOpen(true) }} + onEdit={handleOpenForm} + onDelete={handleConfirmDelete} /> - setFormOpen(false)} - initialData={editingItem || emptyForm} - onSave={handleSave} + + {/* Modal de confirmação */} + - < TTBAndamentoServicoAlert - isOpen={deleteOpen} - item={deleteItem} - onClose={() => setDeleteOpen(false)} - onConfirm={() => { setDeleteOpen(false) }} + + {/* Formulário de criação/edição */} +
); diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx deleted file mode 100644 index 1fc1667..0000000 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoAlert.tsx +++ /dev/null @@ -1,38 +0,0 @@ -'use client' - -import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; -import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; - -interface Props { - isOpen: boolean, - item?: TTBAndamentoServicoInteface | null, - onClose: () => void - onConfirm: () => void -} - -export default function TTBAndamentoServicoAlert({ isOpen, item, onClose, onConfirm }: Props) { - return ( -
- - - - - #{item?.tb_andamentoservico_id} - {item?.descricao} - - - Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. - - - - - Cancelar - - - Continuar - - - - -
- ); -} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx index dbb519f..bd85c25 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx @@ -1,36 +1,67 @@ -'use client' +'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 { + 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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; -import { Controller, useForm } from "react-hook-form"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from "@/components/ui/select"; + import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema"; import { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface"; -type FormValues = z.infer +type FormValues = z.infer; interface Props { - isOpen: boolean - onClose: () => void - initialData?: FormValues - onSave: (data: FormValues) => void + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; } -export default function TTBAndamentoServicoForm({ isOpen, onClose, initialData, onSave }: Props) { - +export default function TTBAndamentoServicoForm({ isOpen, data, onClose, onSave }: Props) { + // Inicializa o react-hook-form com schema zod const form = useForm({ - resolver: undefined, - defaultValues: initialData || { tb_andamentoservico_id: 0, descricao: "", situacao: "I" } - }) + resolver: zodResolver(TTBAndamentoServicoSchema), + defaultValues: { + descricao: "", + tipo: "", + situacao: "A", + usa_email: "I", + tb_andamentoservico_id: undefined, + }, + }); + // Opções do Select mapeadas a partir do enum const tipoOptions = Object.values(tipoEnum).map((value) => ({ value, - // Aqui você pode personalizar o label como quiser label: value === "C" ? "Cancelado" : value === "E" ? "Estornado" : @@ -40,113 +71,117 @@ export default function TTBAndamentoServicoForm({ isOpen, onClose, initialData, "Outros" })); + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + return ( -
- + { + if (!open) onClose(null, false); + }} + > + + + + Andamentos + + + Controle de andamentos de atos + + +
- - - - - - - Andamentos - - - Controle de andamentos de atos - - - ( - - - Descrição - - - - - - - )} + + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Tipo */} + ( + + Tipo + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} /> - ( - - - Tipo - - - - - )} + +
+ )} + /> + + {/* Usar e-mail */} + ( +
+ field.onChange(checked ? "A" : "I")} /> -
- ( - field.onChange(checked ? "A" : "I")} - /> - )} - /> - -
-
- ( - field.onChange(checked ? "A" : "I")} - /> - )} - /> - -
- - - - - - - - - - + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + -
-
+ + ); -} \ No newline at end of file +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx index 9183f05..1eada8f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoTable.tsx @@ -1,79 +1,124 @@ -'use client' +'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 { + 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 TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; -interface Props { - data: TTBAndamentoServicoInteface[] - onEdit: (item: TTBAndamentoServicoInteface) => void - onDelete: (item: TTBAndamentoServicoInteface) => void +interface TTBAndamentoServicoTableProps { + data: TTBAndamentoServicoInteface[]; + onEdit: (item: TTBAndamentoServicoInteface, isEditingFormStatus: boolean) => void; + onDelete: (item: TTBAndamentoServicoInteface, isEditingFormStatus: boolean) => void; } -export default function TTBAndamentoServicoTable({ data, onEdit, onDelete }: Props) { +/** + * 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 TTBAndamentoServicoTable({ + data, + onEdit, + onDelete +}: TTBAndamentoServicoTableProps) { return ( - - # - - - Situação - - - Descrição - - + # + Situação + Descrição + Ações + - {data.map( - (item: TTBAndamentoServicoInteface) => ( - - - {item.tb_andamentoservico_id} - - - {item.situacao === 'A' ? ( - - Ativo - - ) : ( - - Inativo - - )} - - - {item.descricao} - - - - - - - - - onEdit(item)}> - Editar - - - onDelete(item)}> - Remover - - - - - - - ) - )} + {data.map((item) => ( + + + {item.tb_andamentoservico_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))}
); -} \ No newline at end of file +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts index b91bb11..3865338 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoIndexData.ts @@ -1,132 +1,17 @@ +'use server' + +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + export default async function TTBAndamentoServicoIndexData() { - return Promise.resolve({ - data: [ - { - tb_andamentoservico_id: 1, - descricao: "Recepção 1", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 2, - descricao: "Aguardando assinatura da Imobiliária", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 3, - descricao: "Esc. Impugnada (Falta Itbi, cert. ou documentos)", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 4, - descricao: "Aguardando Certtb_andamentoservico_idão de Registro", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 5, - descricao: "Conferencia", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 16, - descricao: "Mapa", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 6, - descricao: "Entregue", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 18, - descricao: "PROTOCOLADO", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 7, - descricao: "Protocolo", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 8, - descricao: "Cadastro", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 9, - descricao: "Registro/Espelho", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 10, - descricao: "Corrigtb_andamentoservico_ido Pronto", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 11, - descricao: "Aguardando Cliente", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 12, - descricao: "Cancelado a pedtb_andamentoservico_ido da parte", - status: "A", - tipo: "C" - }, - { - tb_andamentoservico_id: 13, - descricao: "Cancelado por determinação judicial", - status: "A", - tipo: "C" - }, - { - tb_andamentoservico_id: 14, - descricao: "Capas e Indicador", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 15, - descricao: "Falta assinatura", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 17, - descricao: "Impugnado", - status: "A", - tipo: "G" - }, - { - tb_andamentoservico_id: 19, - descricao: "Entregre/sem registro", - status: "A", - tipo: "C" - }, - { - tb_andamentoservico_id: 20, - descricao: "Corrigtb_andamentoservico_ido sem Registro", - status: "A", - tipo: "C" - }, - { - tb_andamentoservico_id: 21, - descricao: "Cancelamento de ofício", - status: "A", - tipo: "C" - } - ] + + const api = new API(); + + const response = await api.send({ + 'method': Methods.GET, + 'endpoint': `administrativo/t_tb_andamentoservico/` }); -} + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts index ab8035d..fdc5943 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts @@ -1,16 +1,19 @@ -import { faker } from "@faker-js/faker"; +'use server' -export default async function name(andamentoServico: any) { +import API from "@/services/api/Api"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; - return Promise.resolve({ - message: 'Dados salvos com sucesso', - data: { - tb_reconhecimentotipo_id: faker.number.int({ min: 1, max: 1000 }), - descricao: andamentoServico.tb_reconhecimentotipo_id + andamentoServico.descricao, - situacao: andamentoServico.situacao, - tipo: andamentoServico.tipo, - usa_email: andamentoServico.usa_email, - }, +export default async function TTBAndamentoServicoSaveData(andamentoServico: TTBAndamentoServicoInteface) { + + const api = new API(); + + const response = await api.send({ + method: Methods.POST, + endpoint: `administrativo/t_tb_andamentoservico/`, + body: andamentoServico }); + return response; + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts index df69730..a1b0ac1 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts @@ -15,6 +15,7 @@ export const useTTBAndamentoServicoReadHook = () => { const response = await TTBAndamentoServicoIndexData(); + // Armazena os dados consultados setTTBAndamentosServicos(response.data); // Define os dados do componente de resposta (toast, modal, etc) diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts index b854b0a..18f6c0d 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -1,9 +1,9 @@ 'use client' import { useResponse } from "@/app/_response/ResponseContext" -import { use, useState } from "react"; +import { useState } from "react"; import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; -import TTBReconhecimentoTipoSaveData from "../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; +import TTBAndamentoServicoSaveData from "../../_data/TTBAndamentoServico/TTBAndamentoServicoSaveData"; export const useTTBAndamentoServicoSaveHook = () => { @@ -13,10 +13,12 @@ export const useTTBAndamentoServicoSaveHook = () => { const saveTTBAndamentoServico = async (form: TTBAndamentoServicoInteface) => { - const response = await TTBReconhecimentoTipoSaveData(form); + const response = await TTBAndamentoServicoSaveData(form); + // Armazena os dados da repsota setTTBAndamentoServico(response.data); + // Define os dados da respota(toast, modal, etc) setResponse(response); // Retorna os valores de forma imediata diff --git a/src/app/_components/confirm_dialog/ConfirmDialog.tsx b/src/app/_components/confirm_dialog/ConfirmDialog.tsx new file mode 100644 index 0000000..f72a3eb --- /dev/null +++ b/src/app/_components/confirm_dialog/ConfirmDialog.tsx @@ -0,0 +1,83 @@ +'use client'; + +import React from 'react'; + +// Shadcn UI components +import { + AlertDialog, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogAction, +} from '@/components/ui/alert-dialog'; + +interface AlertProps { + /** Controla a abertura do modal */ + isOpen: boolean; + + /** Título principal do alerta */ + title: string; + + /** Descrição adicional do alerta */ + description?: string; + + /** Mensagem do corpo do alerta */ + message: string; + + /** Texto do botão de confirmação */ + confirmText?: string; + + /** Texto do botão de cancelamento */ + cancelText?: string; + + /** Função executada ao confirmar */ + onConfirm: () => void; + + /** Função executada ao cancelar */ + onCancel: () => void; +} + +/** + * Componente de alerta genérico e reutilizável. + * Baseado no Radix e Shadcn UI, com suporte a título, descrição, + * mensagem e botões de ação customizáveis. + */ +export default function ConfirmDialog({ + isOpen, + title, + description, + message, + confirmText = 'Confirmar', + cancelText = 'Cancelar', + onConfirm, + onCancel, +}: AlertProps) { + return ( + + + + {title} + {description && ( + {description} + )} + + +
+ {message} +
+ + + + {cancelText} + + + {confirmText} + + +
+
+ ); +} diff --git a/src/app/_components/confirm_dialog/useConfirmDialog.ts b/src/app/_components/confirm_dialog/useConfirmDialog.ts new file mode 100644 index 0000000..55afbc6 --- /dev/null +++ b/src/app/_components/confirm_dialog/useConfirmDialog.ts @@ -0,0 +1,51 @@ +// Importa os hooks useCallback e useState do React +import { useCallback, useState } from "react"; + +// Define a interface para opções do hook +// Permite que o usuário passe callbacks opcionais para confirmação e cancelamento +interface UseConfirmDialogOptions { + onConfirm?: () => void; // Função chamada quando o usuário confirma a ação + onCancel?: () => void; // Função chamada quando o usuário cancela a ação +} + +// Declara o hook customizado useConfirmDialog +// Recebe um objeto de opções que contém os callbacks onConfirm e onCancel +export function useConfirmDialog({ onConfirm, onCancel }: UseConfirmDialogOptions = {}) { + // Estado interno que controla se o diálogo de confirmação está aberto + const [isOpen, setIsOpen] = useState(false); + + // Função para abrir o diálogo + // useCallback memoriza a função para que não seja recriada em cada renderização + const openDialog = useCallback(() => setIsOpen(true), []); + + // Função para fechar o diálogo + const closeDialog = useCallback(() => setIsOpen(false), []); + + // Função chamada quando o usuário confirma a ação + // Executa o callback onConfirm, se fornecido, e fecha o diálogo + const handleConfirm = useCallback(() => { + onConfirm?.(); // Chama onConfirm somente se ele existir + closeDialog(); // Fecha o diálogo após a confirmação + }, [onConfirm, closeDialog]); + + // Função chamada quando o usuário cancela a ação + // Executa o callback onCancel, se fornecido, e fecha o diálogo + const handleCancel = useCallback(() => { + onCancel?.(); // Chama onCancel somente se ele existir + closeDialog(); // Fecha o diálogo após o cancelamento + }, [onCancel, closeDialog]); + + // Retorna os valores e funções que serão usados pelo componente + // isOpen -> estado do modal + // openDialog -> função para abrir o modal + // closeDialog -> função para fechar o modal + // handleConfirm -> função para confirmar a ação + // handleCancel -> função para cancelar a ação + return { + isOpen, + openDialog, + closeDialog, + handleConfirm, + handleCancel, + }; +} diff --git a/src/config/app.json b/src/config/app.json index 64ba493..d38e8d3 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,7 +1,7 @@ { "state": "go", "api": { - "url": "http://localhost:3000/", + "url": "http://localhost:8000/", "prefix": "api/v1/", "content_type": "application/json" } diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index 75e6173..dfa75f1 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -1,6 +1,5 @@ import Json from '@/actions/json/Json'; import ApiInterface from './interfaces/ApiInterface'; -import Response from '@/services/response/Response'; import TokenGet from '@/actions/token/TokenGet'; import ApiSchema from '@/services/api/schemas/ApiSchema'; @@ -17,7 +16,7 @@ export default class API { this.ApiSchema = new ApiSchema(); // Obtem as configurações da aplicação - this.config = Json.execute('config/app.json'); + this.config = Json.execute(); } @@ -46,7 +45,7 @@ export default class API { const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; // Realiza a requisição - const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}/${this.ApiSchema.endpoint}`, { + const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}${this.ApiSchema.endpoint}`, { method: _data.method, headers: { "Accept": `${this.ApiSchema.contentType}`, From 44d20d6f81c08d93f1063113471b9e231609d4ce Mon Sep 17 00:00:00 2001 From: keven Date: Sun, 14 Sep 2025 10:49:05 -0300 Subject: [PATCH 24/56] =?UTF-8?q?[MVPTN-2]=20feat(CRUD):=20Finaliza=C3=A7?= =?UTF-8?q?=C3=A3o=20de=20a=C3=A7=C3=B5es=20do=20CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../andamentos/page.tsx | 49 +++++++++++++------ .../TTBAndamentoServicoForm.tsx | 8 +-- .../TTBAndamentoServicoRemoveData.ts | 18 +++++++ .../TTBAndamentoServicoSaveData.ts | 8 +-- .../useTTBAndamentoServicoDeleteHook.ts | 24 +++++++++ .../useTTBAndamentoServicoSaveHook.ts | 4 +- .../_schemas/TTBAndamentoServicoSchema.ts | 10 ++-- 7 files changed, 91 insertions(+), 30 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 7fe708a..2f9fb14 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -16,11 +16,13 @@ import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; import TTBAndamentoServicoInterface from "../../_interfaces/TTBAndamentoServicoInterface"; +import { useTTBAndamentoServicoDeleteHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook"; export default function TTBAndamentoServico() { // Hooks para leitura e salvamento const { tTBAndamentosServicos, fetchTTBAndamentoServico } = useTTBAndamentoServicoReadHook(); const { saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook(); + const { deleteTTBAndamentoServico } = useTTBAndamentoServicoDeleteHook(); // Estados const [selectedAndamento, setSelectedAndamento] = useState(null); @@ -58,34 +60,49 @@ export default function TTBAndamentoServico() { /** * Salva os dados do formulário */ - const handleSave = useCallback( - async (formData: TTBAndamentoServicoInterface) => { - await saveTTBAndamentoServico(formData); - handleCloseForm(); - fetchTTBAndamentoServico(); // Atualiza a lista após salvar - }, - [saveTTBAndamentoServico, fetchTTBAndamentoServico, handleCloseForm] - ); + const handleSave = useCallback(async (formData: TTBAndamentoServicoInterface) => { + + // Aguarda salvar o registro + await saveTTBAndamentoServico(formData); + + // Encerra o fomulário + handleCloseForm(); + + // Atualiza a lista de dados + fetchTTBAndamentoServico(); + + }, [saveTTBAndamentoServico, fetchTTBAndamentoServico, handleCloseForm]); /** * Quando o usuário clica em "remover" na tabela */ const handleConfirmDelete = useCallback((item: TTBAndamentoServicoInterface) => { + + // Define o item atual para remoção setItemToDelete(item); - openConfirmDialog(); // Abre o modal de confirmação + + // Abre o modal de confirmação + openConfirmDialog(); + }, [openConfirmDialog]); /** * Executa a exclusão de fato quando o usuário confirma */ - const handleDelete = useCallback(() => { - if (!itemToDelete) return; - console.log("Deletando andamento:", itemToDelete); + const handleDelete = useCallback(async () => { + + // Executa o Hook de remoção + await deleteTTBAndamentoServico(itemToDelete); + + // Atualiza a lista + await fetchTTBAndamentoServico(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); - // TODO: Implementar lógica de exclusão na API - fetchTTBAndamentoServico(); // Atualiza a lista - setItemToDelete(null); // Limpa o item selecionado - handleCancel(); // Fecha o modal }, [itemToDelete, fetchTTBAndamentoServico, handleCancel]); /** diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx index bd85c25..f93cd52 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_andamentoservico/TTBAndamentoServicoForm.tsx @@ -55,7 +55,7 @@ export default function TTBAndamentoServicoForm({ isOpen, data, onClose, onSave tipo: "", situacao: "A", usa_email: "I", - tb_andamentoservico_id: undefined, + tb_andamentoservico_id: 0, }, }); @@ -170,11 +170,13 @@ export default function TTBAndamentoServicoForm({ isOpen, data, onClose, onSave {/* Rodapé do Dialog */} - - + {/* Campo oculto */} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoRemoveData.ts new file mode 100644 index 0000000..5ad8fc9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoRemoveData.ts @@ -0,0 +1,18 @@ +'use server' + +import API from "@/services/api/Api"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TTBAndamentoServicoRemoveData(tTBAndamentoServico: TTBAndamentoServicoInteface) { + + const api = new API(); + + const response = await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_tb_andamentoservico/${tTBAndamentoServico.tb_andamentoservico_id}` + }); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts index fdc5943..c8ebd33 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts @@ -4,14 +4,14 @@ import API from "@/services/api/Api"; import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -export default async function TTBAndamentoServicoSaveData(andamentoServico: TTBAndamentoServicoInteface) { +export default async function TTBAndamentoServicoSaveData(data: TTBAndamentoServicoInteface) { const api = new API(); const response = await api.send({ - method: Methods.POST, - endpoint: `administrativo/t_tb_andamentoservico/`, - body: andamentoServico + method: data.tb_andamentoservico_id ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_tb_andamentoservico/${data.tb_andamentoservico_id ? data.tb_andamentoservico_id : ''}`, + body: data }); return response; diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook.ts new file mode 100644 index 0000000..c3407ee --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook.ts @@ -0,0 +1,24 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; +import TTBAndamentoServicoRemoveData from "../../_data/TTBAndamentoServico/TTBAndamentoServicoRemoveData"; + +export const useTTBAndamentoServicoDeleteHook = () => { + + const { setResponse } = useResponse(); + + const [tTBAndamentoServico, setTTBAndamentoServico] = useState(); + + const deleteTTBAndamentoServico = async (data: TTBAndamentoServicoInteface) => { + + const response = await TTBAndamentoServicoRemoveData(data); + + setTTBAndamentoServico(data); + + setResponse(response); + + } + + return { tTBAndamentoServico, deleteTTBAndamentoServico } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts index 18f6c0d..c5c1c37 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -11,9 +11,9 @@ export const useTTBAndamentoServicoSaveHook = () => { const [tTBAndamentoServico, setTTBAndamentoServico] = useState(); - const saveTTBAndamentoServico = async (form: TTBAndamentoServicoInteface) => { + const saveTTBAndamentoServico = async (data: TTBAndamentoServicoInteface) => { - const response = await TTBAndamentoServicoSaveData(form); + const response = await TTBAndamentoServicoSaveData(data); // Armazena os dados da repsota setTTBAndamentoServico(response.data); diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts index af713ff..7a326bc 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts @@ -2,10 +2,10 @@ import { z } from 'zod'; export const TTBAndamentoServicoSchema = z.object({ - tb_andamentoservico_id: z.number(), - descricao: z.string(), - situacao: z.string(), - tipo: z.string(), - usa_email: z.string() + tb_andamentoservico_id: z.number().optional(), + descricao: z.string().min(1, "Descrição Obrigatória"), + situacao: z.string().min(1, "Situação Obrigatória"), + tipo: z.string().min(1, "Tipo Obrigatória"), + usa_email: z.string().min(1, "Email Obrigatória"), }); \ No newline at end of file From bdf982fe38efbbc77c29a324ee81304dd143dcc9 Mon Sep 17 00:00:00 2001 From: keven Date: Sun, 14 Sep 2025 11:33:44 -0300 Subject: [PATCH 25/56] =?UTF-8?q?[MVPTN-1]=20feat(CRUD):=20Finaliza=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20CRUD=20de=20cadastro=20de=20Tipos=20de=20Reconhe?= =?UTF-8?q?cimentos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reconhecimentos/page.tsx | 275 ++++++++++-------- .../TTBReconhecimentoTipoAlert.tsx | 28 -- .../TTBReconhecimentoTipoForm.tsx | 178 ++++++++---- .../TTBReconhecimentoTipoTable.tsx | 191 +++++++----- .../TTBReconhecimentoTipoDeleteData.ts | 16 + .../TTBReconhecimentoTipoIndexData.ts | 20 +- .../TTBReconhecimentoTipoSaveData.ts | 21 +- .../useTTBReconhecimentoTipoDeleteHook.ts | 19 ++ .../useTTBReconhecimentoTipoReadHook.ts} | 14 +- .../useTTBReconhecimentoTipoSaveHook.ts} | 10 +- 10 files changed, 447 insertions(+), 325 deletions(-) delete mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoDeleteData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoDeleteHook.ts rename src/app/(protected)/(cadastros)/cadastros/_hooks/{t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts => t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts} (52%) rename src/app/(protected)/(cadastros)/cadastros/_hooks/{t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts => t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts} (60%) diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index 4bab9e4..d24425b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -1,139 +1,174 @@ -'use client' +'use client'; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from "@/components/ui/alert-dialog" +import { useEffect, useState, useCallback } from "react"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent } from "@/components/ui/card"; +import { PlusIcon } from "lucide-react"; -import { - Dialog, - DialogClose, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog" +import Loading from "@/app/_components/loading/loading"; +import TTBAndamentoServicoTable from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable"; +import TTBAndamentoServicoForm from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; -import { Input } from "@/components/ui/input" -import { Card, CardContent } from "@/components/ui/card" -import { - Table, - TableBody, - TableCell, - TableHead, - TableHeader, - TableRow, -} from "@/components/ui/table" -import { useTTBReconhecimentoTipoReadHooks } from "../../_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks" -import { useEffect, useState } from "react" -import ITTTBReconhecimentoTipo from "../../_interfaces/TTBReconhecimentoTipoInterface" -import Loading from "@/app/_components/loading/loading" -import { Button } from "@/components/ui/button" -import { useTTBReconhecimentoTipoSaveHooks } from "../../_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks" -import { Controller, useForm } from "react-hook-form" -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form" -import { zodResolver } from "@hookform/resolvers/zod" -import { TTBReconhecimentoTipoSchema } from "../../_schemas/TTBReconhecimentoTipoSchema" -import z from "zod" -import { Label } from "@/components/ui/label" -import { Checkbox } from "@/components/ui/checkbox" -import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" -import { DropdownMenuLabel } from "@radix-ui/react-dropdown-menu" -import { EllipsisIcon, PencilIcon, PlusIcon, Trash2 } from "lucide-react" +import { useTTBReconhecimentoTipoReadHook } from "../../_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook"; +import { useTTBReconhecimentoTipoSaveHook } from "../../_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook"; +import { useTTBReconhecimentoTipoDeleteHook } from "../../_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoDeleteHook"; -type FormValues = z.infer +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; -export default function TTBReconhecimentoTipoPage() { - const { reconhecimentosTipos, fetchReconhecimentosTipos, addReconhecimentoTipo } = useTTBReconhecimentoTipoReadHooks() - const { reconhecimentoTipo, saveReconhecimentoTipo } = useTTBReconhecimentoTipoSaveHooks() +import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; +import TTBReconhecimentoTipoFormProps from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; - const [dialogOpen, setDialogOpen] = useState(false); - const [editingItem, setEditingItem] = useState(null); +export default function TTBAndamentoServico() { - const [alertDialogOpen, setAlertDialogOpen] = useState(false); - const [item, setItem] = useState(null); + // Hooks para leitura e salvamento + const { tTBReconhecimentosTipos, fetchTTBReconhecimentosTipos } = useTTBReconhecimentoTipoReadHook(); + const { saveTTBReconhecimentoTipo } = useTTBReconhecimentoTipoSaveHook(); + const { deleteTTBReconhecimentoTipo } = useTTBReconhecimentoTipoDeleteHook(); + // Estados + const [selectedReconhecimentoTipo, setReconhecimentoTipo] = 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: TTBReconhecimentoTipoInterface | null) => { + setReconhecimentoTipo(data); + setIsFormOpen(true); + }, []); + + /** + * Fecha o formulário e limpa o andamento selecionado + */ + const handleCloseForm = useCallback(() => { + setReconhecimentoTipo(null); + setIsFormOpen(false); + }, []); + + /** + * Salva os dados do formulário + */ + const handleSave = useCallback(async (formData: TTBReconhecimentoTipoInterface) => { + + // Aguarda salvar o registro + await saveTTBReconhecimentoTipo(formData); + + // Encerra o fomulário + handleCloseForm(); + + // Atualiza a lista de dados + fetchTTBReconhecimentosTipos(); + + }, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos, handleCloseForm]); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: TTBReconhecimentoTipoInterface) => { + + // 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 () => { + + // Executa o Hook de remoção + await deleteTTBReconhecimentoTipo(itemToDelete); + + // Atualiza a lista + await fetchTTBReconhecimentosTipos(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchTTBReconhecimentosTipos, handleCancel]); + + /** + * Busca inicial dos dados + */ useEffect(() => { - fetchReconhecimentosTipos() - }, []) + fetchTTBReconhecimentosTipos(); + }, []); - const form = useForm({ - resolver: zodResolver(TTBReconhecimentoTipoSchema), - defaultValues: { - tb_reconhecimentotipo_id: 0, - descricao: "", - situacao: "I", - }, - }) - - async function onSubmit(values: FormValues) { - const saved = await saveReconhecimentoTipo(values); // aguarda o retorno - addReconhecimentoTipo(saved); // adiciona diretamente na lista - - // reinicia o formulário para o estado original - form.reset(); + /** + * Tela de loading enquanto carrega os dados + */ + if (!tTBReconhecimentosTipos) { + return ; } - async function openForm(values: FormValues) { - setEditingItem(values); // guarda os valores do item - setDialogOpen(true); // abre o Dialog - form.reset({ - tb_reconhecimentotipo_id: values.tb_reconhecimentotipo_id, - descricao: values.descricao, - situacao: values.situacao, - }); - - } - - async function handlingConfirmation(visibility : boolean, item: null|any) { - setAlertDialogOpen(visibility); - setItem(item); - } - - const emptyForm: FormValues = { - tb_reconhecimentotipo_id: 0, - descricao: "", - situacao: "I", // padrão Inativo - }; - - if (!reconhecimentosTipos) return - return ( -
-
-
-
- Tipos de Reconhecimentos -
-
+ {/* Cabeçalho */} +
+
+

+ Reconhecimentos +

+

Gerenciamento de tipos de reconhecimentos -

-
- -
- +

+
+ {/* Tabela de andamentos */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} +
- ) -} + ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx deleted file mode 100644 index a95e312..0000000 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoAlert.tsx +++ /dev/null @@ -1,28 +0,0 @@ -import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; - -export default function TTBReconhecimentoTipoAlert() { - - return ( - - - - - #{item?.tb_reconhecimentotipo_id} - {item?.descricao} - - - Esta ação não pode ser desfeita. Isso excluirá permanentemente o registro e seus dados dos nossos servidores. - - - - handlingConfirmation(false, null)} className="cursor-pointer"> - Cancelar - - - Continuar - - - - - ); - -} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx index ffa8e5e..3eb8bf6 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm.tsx @@ -1,74 +1,126 @@ +'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 { FormControl, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; +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 { Controller, Form } from "react-hook-form"; -export default function TTBReconhecimentoTipoForm() { +import { TTBReconhecimentoTipoSchema } from "../../_schemas/TTBReconhecimentoTipoSchema"; + +type FormValues = z.infer; + +interface TTBReconhecimentoTipoFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function TTBReconhecimentoTipoFormProps({ isOpen, data, onClose, onSave }: TTBReconhecimentoTipoFormProps) { + // Inicializa o react-hook-form com schema zod + const form = useForm({ + resolver: zodResolver(TTBReconhecimentoTipoSchema), + defaultValues: { + tb_reconhecimentotipo_id: 0, + descricao: "", + situacao: "A", + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); return ( - - {/* Formulário dentro do Dialog */} -
- - - - - - Tipos de Reconhecimentos - - Tipos de reconhecimentos são usados na tela de balcão - - - ( - - Descrição - - - - - - )} - /> + { + if (!open) onClose(null, false); + }} + > + + + + Reconhecimentos + + + Tipos de Reconhecimentos + + + + + + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + (
- ( - field.onChange(checked ? "A" : "I")} - /> - )} + field.onChange(checked ? "A" : "I")} /> - +
- - - - - - - - - -
- - + )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
); - -} \ No newline at end of file +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx index 72ce875..d8e1087 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable.tsx @@ -1,85 +1,124 @@ +'use client'; + import { Button } from "@/components/ui/button"; -import { Card, CardContent } from "@/components/ui/card"; -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, Trash2 } from "lucide-react"; +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 TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; -interface Props { - data: TTBReconhecimentoTipoInterface, - onEdit: (item: TTBReconhecimentoTipoInterface) => void, - onDelete: (item: TTBReconhecimentoTipoInterface) => void, +interface TTBReconhecimentoTipoTableProps { + data: TTBReconhecimentoTipoInterface[]; + onEdit: (item: TTBReconhecimentoTipoInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: TTBReconhecimentoTipoInterface, isEditingFormStatus: boolean) => void; } -export default function TTBReconhecimentoTipoTable() { +/** + * 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 ( - - - - - - - # - - - Situação - - - Descrição - - - - - - - {reconhecimentosTipos.map( - (item: ITTTBReconhecimentoTipo) => ( - - - {item.tb_reconhecimentotipo_id} - - - {item.situacao === 'A' ? ( - - Ativo - - ) : ( - - Inativo - - )} - - - {item.descricao} - - - - - - - - - openForm(item)}> - Editar - - - handlingConfirmation(true, item)}> - Remover - - - - - - - ) - )} - -
-
-
+ + {isActive ? "Ativo" : "Inativo"} + ); +} -} \ No newline at end of file +export default function TTBReconhecimentoTipoTable({ + data, + onEdit, + onDelete +}: TTBReconhecimentoTipoTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_reconhecimentotipo_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoDeleteData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoDeleteData.ts new file mode 100644 index 0000000..5f279f9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoDeleteData.ts @@ -0,0 +1,16 @@ +import API from "@/services/api/Api"; +import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TTBReconhecimentoTipoDeleteData(data: TTBReconhecimentoTipoInterface) { + + const api = new API(); + + const response = await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_tb_reconhecimentotipo/${data.tb_reconhecimentotipo_id}` + }); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts index 869a90a..7d7995e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData.ts @@ -5,21 +5,13 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum"; export default async function TTBReconhecimentoTipoIndexData() { - // const api = new API(); + const api = new API(); - // const response = await api.send({ - // 'method': Methods.GET, - // 'endpoint': `cadastros/reconhecimentos` - // }); - - // return response; - - return Promise.resolve({ - data: [ - { tb_reconhecimentotipo_id: 1, descricao: 'SEMELHANÇA', situacao: 'A' }, - { tb_reconhecimentotipo_id: 2, descricao: 'VERDADEIRO', situacao: 'A' }, - { tb_reconhecimentotipo_id: 3, descricao: 'ABONO', situacao: 'A' } - ] + const response = await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_tb_reconhecimentotipo` }); + return response; + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts index daf5964..e045e65 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData.ts @@ -1,14 +1,17 @@ -import { faker } from "@faker-js/faker" +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; -export default async function TTBReconhecimentoTipoSaveData(reconhecimentoTipo: any) { +export default async function TTBReconhecimentoTipoSaveData(data: TTBReconhecimentoTipoInterface) { - return Promise.resolve({ - message: 'Dados salvos com sucesso', - data: { - tb_reconhecimentotipo_id: faker.number.int({ min: 1, max: 1000 }), - descricao: reconhecimentoTipo.tb_reconhecimentotipo_id + reconhecimentoTipo.descricao, - situacao: reconhecimentoTipo.situacao - }, + const api = new API(); + + const response = await api.send({ + method: data.tb_reconhecimentotipo_id ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_tb_reconhecimentotipo/${data.tb_reconhecimentotipo_id ? data.tb_reconhecimentotipo_id : ''}`, + body: data }); + return response; + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoDeleteHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoDeleteHook.ts new file mode 100644 index 0000000..eb926e7 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoDeleteHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; +import TTBReconhecimentoTipoDeleteData from "../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoDeleteData"; + +export const useTTBReconhecimentoTipoDeleteHook = () => { + + const { setResponse } = useResponse(); + + const deleteTTBReconhecimentoTipo = async (data: TTBReconhecimentoTipoInterface) => { + + const response = await TTBReconhecimentoTipoDeleteData(data); + + setResponse(response); + + } + + return { deleteTTBReconhecimentoTipo } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts similarity index 52% rename from src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts rename to src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts index 39c2686..3f62408 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoReadHooks.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts @@ -5,13 +5,13 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; import TTBReconhecimentoTipoIndexData from '../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoIndexData'; -export const useTTBReconhecimentoTipoReadHooks = () => { +export const useTTBReconhecimentoTipoReadHook = () => { const { setResponse } = useResponse(); - const [reconhecimentosTipos, setReconhecimenntosTipos] = useState(); + const [tTBReconhecimentosTipos, setReconhecimenntosTipos] = useState(); - const fetchReconhecimentosTipos = async () => { + const fetchTTBReconhecimentosTipos = async () => { const response = await TTBReconhecimentoTipoIndexData(); @@ -21,12 +21,6 @@ export const useTTBReconhecimentoTipoReadHooks = () => { } - function addReconhecimentoTipo(reconhecimentoTipo: ITTTBReconhecimentoTipo) { - - setReconhecimenntosTipos(prev => [...(prev || []), reconhecimentoTipo]); - - } - - return { reconhecimentosTipos, fetchReconhecimentosTipos, addReconhecimentoTipo } + return { tTBReconhecimentosTipos, fetchTTBReconhecimentosTipos } } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts similarity index 60% rename from src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts rename to src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts index 820b846..48c60dd 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reocnhecimentotipo/useTTBReconhecimentoTipoSaveHooks.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts @@ -5,17 +5,17 @@ import { useState } from "react"; import ITTTBReconhecimentoTipo from '../../_interfaces/TTBReconhecimentoTipoInterface' import TTBReconhecimentoTipoSaveData from "../../_data/TTBReconhecimentoTipo/TTBReconhecimentoTipoSaveData"; -export const useTTBReconhecimentoTipoSaveHooks = () => { +export const useTTBReconhecimentoTipoSaveHook = () => { const { setResponse } = useResponse(); - const [reconhecimentoTipo, setReconhcimentoTipo] = useState(); + const [tTBReconhecimentoTipo, setTTBReconhcimentoTipo] = useState(); - const saveReconhecimentoTipo = async (reconhecimentoTipo: ITTTBReconhecimentoTipo) => { + const saveTTBReconhecimentoTipo = async (reconhecimentoTipo: ITTTBReconhecimentoTipo) => { const response = await TTBReconhecimentoTipoSaveData(reconhecimentoTipo); - setReconhcimentoTipo(response.data); + saveTTBReconhecimentoTipo(response.data); setResponse(response); @@ -24,6 +24,6 @@ export const useTTBReconhecimentoTipoSaveHooks = () => { } - return { reconhecimentoTipo, saveReconhecimentoTipo } + return { tTBReconhecimentoTipo, saveTTBReconhecimentoTipo } } \ No newline at end of file From 477c1cd22a568e9db214b48102cbe12ef2004d06 Mon Sep 17 00:00:00 2001 From: keven Date: Sun, 14 Sep 2025 12:29:19 -0300 Subject: [PATCH 26/56] =?UTF-8?q?fix(Build):=20ajuste=20nos=20crud=20de=20?= =?UTF-8?q?andamento=20e=20tipo=20de=20reconhecimento=20para=20realizar=20?= =?UTF-8?q?a=20build=20da=20vers=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(t_tb_andamentoservico)/andamentos/page.tsx | 5 ++++- .../reconhecimentos/page.tsx | 12 +++++++----- .../TTBAndamentoServicoForm.tsx | 2 +- .../TTBReconhecimentoTipoForm.tsx | 5 +++-- .../useTTBReconhecimentoTipoReadHook.ts | 2 +- .../_interfaces/TTBAndamentoServicoInterface.ts | 9 +++++---- .../_interfaces/TTBReconhecimentoTipoInterface.ts | 13 ++++++++++--- .../cadastros/_schemas/TTBAndamentoServicoSchema.ts | 3 ++- .../_schemas/TTBReconhecimentoTipoSchema.ts | 9 ++++----- 9 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 2f9fb14..a11eecb 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -91,6 +91,9 @@ export default function TTBAndamentoServico() { */ const handleDelete = useCallback(async () => { + // Protege contra null + if (!itemToDelete) return; + // Executa o Hook de remoção await deleteTTBAndamentoServico(itemToDelete); @@ -168,5 +171,5 @@ export default function TTBAndamentoServico() { onSave={handleSave} />
- ); + );4 } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index d24425b..2372e32 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -6,8 +6,8 @@ import { Card, CardContent } from "@/components/ui/card"; import { PlusIcon } from "lucide-react"; import Loading from "@/app/_components/loading/loading"; -import TTBAndamentoServicoTable from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable"; -import TTBAndamentoServicoForm from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; +import TTBReconhecimentoTipoTable from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable"; +import TTBReconhecimentoTipoForm from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; import { useTTBReconhecimentoTipoReadHook } from "../../_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook"; import { useTTBReconhecimentoTipoSaveHook } from "../../_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook"; @@ -17,7 +17,6 @@ import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface"; -import TTBReconhecimentoTipoFormProps from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; export default function TTBAndamentoServico() { @@ -93,6 +92,9 @@ export default function TTBAndamentoServico() { */ const handleDelete = useCallback(async () => { + // Protege contra null + if (!itemToDelete) return; + // Executa o Hook de remoção await deleteTTBReconhecimentoTipo(itemToDelete); @@ -142,7 +144,7 @@ export default function TTBAndamentoServico() { {/* Tabela de andamentos */} - {/* Formulário de criação/edição */} - ; @@ -38,14 +39,14 @@ interface TTBReconhecimentoTipoFormProps { onSave: (data: FormValues) => void; } -export default function TTBReconhecimentoTipoFormProps({ isOpen, data, onClose, onSave }: TTBReconhecimentoTipoFormProps) { +export default function TTBReconhecimentoTipoForm({ isOpen, data, onClose, onSave }: TTBReconhecimentoTipoFormProps) { // Inicializa o react-hook-form com schema zod const form = useForm({ resolver: zodResolver(TTBReconhecimentoTipoSchema), defaultValues: { tb_reconhecimentotipo_id: 0, descricao: "", - situacao: "A", + situacao: situacaoEnum.ATIVO, }, }); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts index 3f62408..5817953 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoReadHook.ts @@ -9,7 +9,7 @@ export const useTTBReconhecimentoTipoReadHook = () => { const { setResponse } = useResponse(); - const [tTBReconhecimentosTipos, setReconhecimenntosTipos] = useState(); + const [tTBReconhecimentosTipos, setReconhecimenntosTipos] = useState([]); const fetchTTBReconhecimentosTipos = async () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts index 5322010..26ad9e2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBAndamentoServicoInterface.ts @@ -1,8 +1,9 @@ export default interface TTBAndamentoServicoInteface { - tb_andamentoservico_id: number, - descricao: null | string, - situacao: null | string, - tipo: null | tipoEnum, + tb_andamentoservico_id?: number, + descricao: string, + situacao: string, + tipo: tipoEnum, + usa_email: string } export enum tipoEnum { diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts index 8eef0fe..46daae9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TTBReconhecimentoTipoInterface.ts @@ -1,5 +1,12 @@ -export default interface TTBReconhecimentoTipoInterface{ - tb_reconhecimentotipo_id: number, +export default interface TTBReconhecimentoTipoInterface { + tb_reconhecimentotipo_id?: number, descricao: string, - situacao: string, + situacao: situacaoEnum, +} + +export enum situacaoEnum { + + ATIVO = 'A', + INATIVO = 'I', + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts index 7a326bc..4677fdf 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBAndamentoServicoSchema.ts @@ -1,11 +1,12 @@ import { z } from 'zod'; +import { tipoEnum } from '../_interfaces/TTBAndamentoServicoInterface'; export const TTBAndamentoServicoSchema = z.object({ tb_andamentoservico_id: z.number().optional(), descricao: z.string().min(1, "Descrição Obrigatória"), situacao: z.string().min(1, "Situação Obrigatória"), - tipo: z.string().min(1, "Tipo Obrigatória"), + tipo: z.nativeEnum(tipoEnum, { message: "Tipo inválido" }), usa_email: z.string().min(1, "Email Obrigatória"), }); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts index c8e73dc..f9c8f27 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TTBReconhecimentoTipoSchema.ts @@ -1,9 +1,8 @@ import { z } from 'zod'; +import { situacaoEnum } from '../_interfaces/TTBReconhecimentoTipoInterface'; export const TTBReconhecimentoTipoSchema = z.object({ - tb_reconhecimentotipo_id: z.number(), - descricao: z.string().min(1), - situacao: z.enum(["A", "I"], { - errorMap: () => ({ message: "Situação deve ser 'A' ou 'I'" }) - }), + tb_reconhecimentotipo_id: z.number().optional(), + descricao: z.string().min(1, "Campo descrição deve ser preenchido"), + situacao: z.nativeEnum(situacaoEnum, { message: "Tipo inválido" }), }); \ No newline at end of file From 2256dd367fc8284fa868029c8f725ff54bb08fd4 Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 08:55:42 -0300 Subject: [PATCH 27/56] =?UTF-8?q?refactor(API):=20Ajusta=20os=20endpoints?= =?UTF-8?q?=20para=20consultar=20o=20usu=C3=A1rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usuarios/[id]/detalhes/page.tsx | 2 +- .../(g_usuario)/usuarios/formulario/page.tsx | 6 +- .../(g_usuario)/usuarios/page.tsx | 2 +- .../_data/g_usuario/GUsuarioDeleteData.ts | 2 +- .../_data/g_usuario/GUsuarioIndexData.ts | 2 +- .../_data/g_usuario/GUsuarioLoginData.ts | 2 +- .../_data/g_usuario/GUsuarioReadData.ts | 2 +- .../_data/g_usuario/GUsuarioSaveData.ts | 2 +- .../_hooks/g_usuario/useGUsuarioIndexHook.ts | 2 +- .../_hooks/g_usuario/useGUsuarioReadHooks.ts | 2 +- .../_hooks/g_usuario/useGUsuarioSaveHook.ts | 2 +- .../{IGUsuario.ts => GUsuarioInterface.ts} | 2 +- .../_schemas/GUsuarioSchema.ts | 2 +- .../_services/g_usuario/GUsuarioIndex.ts | 2 +- .../_services/g_usuario/GUsuarioLogin.ts | 1 - .../andamentos/page.tsx | 25 ++---- .../reconhecimentos/page.tsx | 23 ++--- .../(protected)/(servicos)/servicos/page.tsx | 88 +++++++++++++++++++ .../confirm_dialog/ConfirmDialog.tsx | 2 - src/app/_components/structure/Header.tsx | 33 +++++++ src/components/app-sidebar.tsx | 13 +++ 21 files changed, 165 insertions(+), 52 deletions(-) rename src/app/(protected)/(administrativo)/_interfaces/{IGUsuario.ts => GUsuarioInterface.ts} (96%) create mode 100644 src/app/(protected)/(servicos)/servicos/page.tsx create mode 100644 src/app/_components/structure/Header.tsx diff --git a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx index f48c529..42f4757 100644 --- a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx +++ b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx @@ -8,7 +8,7 @@ import { CardContent } from "@/components/ui/card"; import { useGUsuarioReadHooks } from "@/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks"; -import Usuario from "@/app/(protected)/(administrativo)/_interfaces/IGUsuario"; +import Usuario from "@/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface"; import Loading from "@/app/_components/loading/loading"; export default function UsuarioDetalhes() { diff --git a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/formulario/page.tsx b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/formulario/page.tsx index f4d153a..16c0a87 100644 --- a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/formulario/page.tsx +++ b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/formulario/page.tsx @@ -4,7 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { z } from "zod" import { Input } from "@/components/ui/input" -import { UsuarioFormSchema } from "../../../_schemas/GUsuarioSchema" +import { GUsuarioSchema } from "../../../_schemas/GUsuarioSchema" import { Button @@ -26,14 +26,14 @@ import { import { useGUsuarioSaveHook } from "../../../_hooks/g_usuario/useGUsuarioSaveHook" -type FormValues = z.infer +type FormValues = z.infer export default function UsuarioFormularioPage() { const { usuario, saveUsuario } = useGUsuarioSaveHook(); const form = useForm({ - resolver: zodResolver(UsuarioFormSchema), + resolver: zodResolver(GUsuarioSchema), defaultValues: { login: '', nome_completo: '', diff --git a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/page.tsx b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/page.tsx index 77e4dc5..37344b1 100644 --- a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/page.tsx +++ b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/page.tsx @@ -14,7 +14,7 @@ import { TableRow, } from "@/components/ui/table" -import Usuario from "../../_interfaces/IGUsuario"; +import Usuario from "../../_interfaces/GUsuarioInterface"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import { useGUsuarioIndexHook } from "../../_hooks/g_usuario/useGUsuarioIndexHook"; diff --git a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioDeleteData.ts b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioDeleteData.ts index 3313c91..1d1d6ba 100644 --- a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioDeleteData.ts +++ b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioDeleteData.ts @@ -9,7 +9,7 @@ export default async function GUsuarioDeleteData(usuarioId: number) { const response = await api.send({ 'method': Methods.DELETE, - 'endpoint': `administrativo/usuarios/${usuarioId}` + 'endpoint': `administrativo/g_usuario/${usuarioId}` }); return response; diff --git a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioIndexData.ts b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioIndexData.ts index 8b6f66f..aaf6075 100644 --- a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioIndexData.ts +++ b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioIndexData.ts @@ -9,7 +9,7 @@ export default async function GUsuarioIndexData() { const response = await api.send({ 'method': Methods.GET, - 'endpoint': `administrativo/usuarios/` + 'endpoint': `administrativo/g_usuario/` }); return response; diff --git a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioLoginData.ts b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioLoginData.ts index 5602616..c6f7c46 100644 --- a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioLoginData.ts +++ b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioLoginData.ts @@ -10,7 +10,7 @@ export default async function GUsuarioLoginData(form: any) { // Realiza o envio dos dados const response = await api.send({ method: Methods.POST, - endpoint: `administrativo/usuarios/login`, + endpoint: `administrativo/g_usuario/authenticate`, body: form }); diff --git a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioReadData.ts b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioReadData.ts index 872c948..afe73b3 100644 --- a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioReadData.ts +++ b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioReadData.ts @@ -9,7 +9,7 @@ export default async function GUsuarioReadData(usuarioId: number) { const response = await api.send({ 'method': Methods.GET, - 'endpoint': `administrativo/usuarios/${usuarioId}` + 'endpoint': `administrativo/g_usuario/${usuarioId}` }); return response diff --git a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioSaveData.ts b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioSaveData.ts index 2ee92e2..e6ce62c 100644 --- a/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioSaveData.ts +++ b/src/app/(protected)/(administrativo)/_data/g_usuario/GUsuarioSaveData.ts @@ -9,7 +9,7 @@ export default async function GUsuarioSaveData(form: any) { const response = await api.send({ 'method': Methods.POST, - 'endpoint': `administrativo/usuarios/`, + 'endpoint': `administrativo/g_usuario/`, 'body': form }); diff --git a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioIndexHook.ts b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioIndexHook.ts index ce65a48..93ca26d 100644 --- a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioIndexHook.ts +++ b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioIndexHook.ts @@ -1,7 +1,7 @@ 'use client' import { useState } from "react" -import Usuario from "../../_interfaces/IGUsuario" +import Usuario from "../../_interfaces/GUsuarioInterface" import GUsuarioIndex from "../../_services/g_usuario/GUsuarioIndex"; import { useResponse } from "@/app/_response/ResponseContext"; diff --git a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts index 3283fa1..da75695 100644 --- a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts +++ b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts @@ -1,7 +1,7 @@ 'use client' import { useState } from "react" -import Usuario from "../../_interfaces/IGUsuario" +import Usuario from "../../_interfaces/GUsuarioInterface" import GUsuarioRead from "../../_services/g_usuario/GUsuarioRead"; import { useResponse } from "@/app/_response/ResponseContext"; diff --git a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioSaveHook.ts b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioSaveHook.ts index c6d1144..6519021 100644 --- a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioSaveHook.ts +++ b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioSaveHook.ts @@ -1,7 +1,7 @@ 'use client' import { useState } from "react" -import Usuario from "../../_interfaces/IGUsuario" +import Usuario from "../../_interfaces/GUsuarioInterface" import GUsuarioSave from "../../_services/g_usuario/GUsuarioSave"; import { useResponse } from "@/app/_response/ResponseContext"; diff --git a/src/app/(protected)/(administrativo)/_interfaces/IGUsuario.ts b/src/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface.ts similarity index 96% rename from src/app/(protected)/(administrativo)/_interfaces/IGUsuario.ts rename to src/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface.ts index bb299b4..13af8c1 100644 --- a/src/app/(protected)/(administrativo)/_interfaces/IGUsuario.ts +++ b/src/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface.ts @@ -1,4 +1,4 @@ -export default interface Usuario { +export default interface GUsuario { usuario_id: number, trocarsenha: string, login: string, diff --git a/src/app/(protected)/(administrativo)/_schemas/GUsuarioSchema.ts b/src/app/(protected)/(administrativo)/_schemas/GUsuarioSchema.ts index c6b8831..c3942c2 100644 --- a/src/app/(protected)/(administrativo)/_schemas/GUsuarioSchema.ts +++ b/src/app/(protected)/(administrativo)/_schemas/GUsuarioSchema.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const UsuarioFormSchema = z.object({ +export const GUsuarioSchema = z.object({ trocarsenha: z.string().optional(), login: z.string().optional(), senha: z.string().optional(), diff --git a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioIndex.ts b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioIndex.ts index 7447a94..b105740 100644 --- a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioIndex.ts +++ b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioIndex.ts @@ -8,4 +8,4 @@ export default async function GUsuarioIndex() { return response; -} \ No newline at end of file +} \ No newline at end of file diff --git a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts index b2f5926..2699a22 100644 --- a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts +++ b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts @@ -6,7 +6,6 @@ import { import GUsuarioLoginData from "../../_data/g_usuario/GUsuarioLoginData" import { redirect } from "next/navigation"; -import empty from "@/actions/validations/empty"; export default async function GUsuarioLoginService(form: any) { diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index a11eecb..9d80a98 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -1,9 +1,7 @@ 'use client'; import { useEffect, useState, useCallback } from "react"; -import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; -import { PlusIcon } from "lucide-react"; import Loading from "@/app/_components/loading/loading"; import TTBAndamentoServicoTable from "../../_components/t_tb_andamentoservico/TTBAndamentoServicoTable"; @@ -17,6 +15,7 @@ import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDia import TTBAndamentoServicoInterface from "../../_interfaces/TTBAndamentoServicoInterface"; import { useTTBAndamentoServicoDeleteHook } from "../../_hooks/t_tb_andamentoservico/useTTBAndamentoServicoDeleteHook"; +import Header from "@/app/_components/structure/Header"; export default function TTBAndamentoServico() { // Hooks para leitura e salvamento @@ -125,20 +124,12 @@ export default function TTBAndamentoServico() { return (
{/* Cabeçalho */} -
-
-

- Andamentos -

-

- Gerenciamento de tipos de reconhecimentos -

-
- -
+
{ handleOpenForm(null) }} + /> {/* Tabela de andamentos */} @@ -171,5 +162,5 @@ export default function TTBAndamentoServico() { onSave={handleSave} />
- );4 + ); 4 } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index 2372e32..6f66b36 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -1,11 +1,10 @@ 'use client'; import { useEffect, useState, useCallback } from "react"; -import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; -import { PlusIcon } from "lucide-react"; import Loading from "@/app/_components/loading/loading"; +import Header from "@/app/_components/structure/Header"; import TTBReconhecimentoTipoTable from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoTable"; import TTBReconhecimentoTipoForm from "../../_components/t_tb_reconhecimentotipo/TTBReconhecimentoTipoForm"; @@ -126,20 +125,12 @@ export default function TTBAndamentoServico() { return (
{/* Cabeçalho */} -
-
-

- Reconhecimentos -

-

- Gerenciamento de tipos de reconhecimentos -

-
- -
+
{ handleOpenForm(null) }} + /> {/* Tabela de andamentos */} diff --git a/src/app/(protected)/(servicos)/servicos/page.tsx b/src/app/(protected)/(servicos)/servicos/page.tsx new file mode 100644 index 0000000..ebfcd9d --- /dev/null +++ b/src/app/(protected)/(servicos)/servicos/page.tsx @@ -0,0 +1,88 @@ +'use client' + +import { Card, CardAction, CardContent, CardDescription, CardTitle } from "@/components/ui/card" +import { BabyIcon, CrossIcon, FileCheckIcon, FileTextIcon, GavelIcon, GlobeIcon, HeartIcon, PenIcon, ScrollIcon, UsersIcon } from "lucide-react"; + +const services = [ + { + title: 'Registro de Nascimento', + description: 'Emissão e registro de certidões de nascimento, garantindo a cidadania e identidade legal do recém-nascido.', + icon: BabyIcon + }, + { + title: 'Registro de Casamento', + description: 'Processo completo para habilitação, registro e emissão da certidão de casamento.', + icon: HeartIcon + }, + { + title: 'Registro de Óbito', + description: 'Lavratura do registro de óbito e emissão da certidão correspondente para fins legais.', + icon: CrossIcon + }, + { + title: 'Reconhecimento de Firma', + description: 'Autenticação da assinatura de documentos, garantindo sua validade jurídica.', + icon: PenIcon + }, + { + title: 'Autenticação de Documentos', + description: 'Confirmação de que cópias estão de acordo com o documento original apresentado.', + icon: FileCheckIcon + }, + { + title: 'Procurações', + description: 'Elaboração e registro de procurações públicas para representação legal de pessoas físicas ou jurídicas.', + icon: ScrollIcon + }, + { + title: 'Testamentos', + description: 'Lavratura e registro de testamentos públicos com segurança jurídica.', + icon: GavelIcon + }, + { + title: 'Divórcio Extrajudicial', + description: 'Formalização do divórcio por via administrativa, de forma rápida e sem processo judicial.', + icon: UsersIcon + }, + { + title: 'Apostilamento de Documentos', + description: 'Apostilamento conforme a Convenção da Haia para validade internacional de documentos.', + icon: GlobeIcon + }, + { + title: 'Certidões e Segunda Via', + description: 'Emissão de segundas vias e certidões de nascimento, casamento e óbito.', + icon: FileTextIcon + } +]; + +export default function ServicosPage() { + return ( +
+
+

Bem-vindo(a)!

+

+ Olá, Keven! É um prazer ter você conosco. +

+
+
+ {services.map((item: any, index) => ( + + +
+ +
+ + + {item.title} + + + {item.description} + +
+
+ ))} +
+
+ ) +} \ No newline at end of file diff --git a/src/app/_components/confirm_dialog/ConfirmDialog.tsx b/src/app/_components/confirm_dialog/ConfirmDialog.tsx index f72a3eb..e24cfd3 100644 --- a/src/app/_components/confirm_dialog/ConfirmDialog.tsx +++ b/src/app/_components/confirm_dialog/ConfirmDialog.tsx @@ -64,11 +64,9 @@ export default function ConfirmDialog({ {description} )} -
{message}
- {cancelText} diff --git a/src/app/_components/structure/Header.tsx b/src/app/_components/structure/Header.tsx new file mode 100644 index 0000000..c8c02e6 --- /dev/null +++ b/src/app/_components/structure/Header.tsx @@ -0,0 +1,33 @@ +import { Button } from "@/components/ui/button"; +import { PlusIcon } from "lucide-react"; + +interface HeaderProps { + + title: string, + description: string, + buttonText: string, + buttonAction: (...args: any[]) => void; +}; + +export default function Header({ title, description, buttonText, buttonAction }: HeaderProps) { + + return ( +
+
+
+

+ {title} +

+

+ {description} +

+
+ +
+
+ ); + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 0460464..a037aff 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -8,6 +8,7 @@ import { Command, Frame, GalleryVerticalEnd, + House, Map, PieChart, Settings2, @@ -51,6 +52,18 @@ const data = { }, ], navMain: [ + { + title: "Início", + url: "#", + icon: House, + isActive: false, + items: [ + { + title: "Serviços", + url: "/servicos/", + }, + ], + }, { title: "Administrativo", url: "#", From 43116214fffc0ea1c5e74213d7661ce5685d36c2 Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 09:16:02 -0300 Subject: [PATCH 28/56] fix(Diversos): Ajustes no config e gitignore --- .gitignore | 2 ++ src/services/api/Api.ts | 3 --- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5ef6a52..ad6413d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,5 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +src/config/app.json diff --git a/src/services/api/Api.ts b/src/services/api/Api.ts index d1ff30b..dfa75f1 100644 --- a/src/services/api/Api.ts +++ b/src/services/api/Api.ts @@ -44,9 +44,6 @@ export default class API { // Verifica se existe body para envio const filteredBody = _data.body ? Object.fromEntries(Object.entries(_data.body).filter(([_, v]) => v != null && v !== "")) : null; - - console.log("URL:: " + `http://api-saas-api-homologacao:8000/administrativo/g_usuario/authenticate`) - // Realiza a requisição const response = await fetch(`${this.ApiSchema.url}${this.ApiSchema.prefix}${this.ApiSchema.endpoint}`, { method: _data.method, From 7ecf79e8a3a0dd7a24de6bfee378e70a874595fc Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 10:23:59 -0300 Subject: [PATCH 29/56] =?UTF-8?q?[MVPTN-62]=20feat(CRUD):=20Cria=20CRUD=20?= =?UTF-8?q?para=20Profiss=C3=B5es=20trabalhando=20com=20dados=20em=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(g_tb_profissao)/profissao/page.tsx | 166 ++++++++++++++++++ .../g_tb_profissao/GTBProfissaoForm.tsx | 142 +++++++++++++++ .../g_tb_profissao/GTBProfissaoTable.tsx | 129 ++++++++++++++ .../GTBProfissao/GTBProfissaoIndexData.ts | 49 ++++++ .../GTBProfissao/GTBProfissaoRemoveData.ts | 11 ++ .../GTBProfissao/GTBProfissaoSaveData.ts | 10 ++ .../g_tb_profissao/useGTBProfissaoReadHook.ts | 23 +++ .../useGTBProfissaoRemoveHook.ts | 19 ++ .../g_tb_profissao/useGTBProfissaoSaveHook.ts | 23 +++ .../_interfaces/GTBProfissaoInterface.ts | 9 + .../cadastros/_schemas/GTBProfissaoSchema.ts | 8 + .../GTBProfissaoIndexService.ts | 9 + .../GTBProfissaoRemoveService.ts | 12 ++ .../g_tb_profissao/GTBProfissaoSaveService.ts | 10 ++ src/components/app-sidebar.tsx | 4 + 15 files changed, 624 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/page.tsx new file mode 100644 index 0000000..847d1d2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/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 GTBProfissaoTable from "../../_components/g_tb_profissao/GTBProfissaoTable"; +import GTBProfissaoForm from "../../_components/g_tb_profissao/GTBProfissaoForm"; + +import { useGTBProfissaoReadHook } from "../../_hooks/g_tb_profissao/useGTBProfissaoReadHook"; +import { useGTBProfissaoSaveHook } from "../../_hooks/g_tb_profissao/useGTBProfissaoSaveHook"; +import { useGTBProfissaoRemoveHook } from "../../_hooks/g_tb_profissao/useGTBProfissaoRemoveHook"; + +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import Header from "@/app/_components/structure/Header"; + +export default function TTBAndamentoServico() { + // Hooks para leitura e salvamento + const { gTBProfissao, fetchGTBProfissao } = useGTBProfissaoReadHook(); + const { saveGTBProfissao } = useGTBProfissaoSaveHook(); + const { removeGTBProfissao } = useGTBProfissaoRemoveHook(); + + // 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: GTBProfissaoInterface | 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: GTBProfissaoInterface) => { + + // Aguarda salvar o registro + await saveGTBProfissao(formData); + + // Encerra o fomulário + handleCloseForm(); + + // Atualiza a lista de dados + fetchGTBProfissao(); + + }, [saveGTBProfissao, fetchGTBProfissao, handleCloseForm]); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: GTBProfissaoInterface) => { + + // 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 removeGTBProfissao(itemToDelete); + + // Atualiza a lista + await fetchGTBProfissao(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchGTBProfissao, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchGTBProfissao(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!gTBProfissao) { + 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_profissao/GTBProfissaoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx new file mode 100644 index 0000000..37aaf6a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx @@ -0,0 +1,142 @@ +'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 { GTBProfissaoSchema } from "../../_schemas/GTBProfissaoSchema"; + +type FormValues = z.infer; + +interface Props { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Props) { + // Inicializa o react-hook-form com schema zod + const form = useForm({ + resolver: zodResolver(GTBProfissaoSchema), + defaultValues: { + descricao: "", + cod_cbo: "", + situacao: "A", + tb_profissao_id: 0, + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Profissões + + + Controle de profissões + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* CBO */} + ( + + CBO + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoTable.tsx new file mode 100644 index 0000000..295a003 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoTable.tsx @@ -0,0 +1,129 @@ +'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 GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +interface GTBProfissaoTableProps { + data: GTBProfissaoInterface[]; + onEdit: (item: GTBProfissaoInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBProfissaoInterface, 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 GTBProfissaoTable({ + data, + onEdit, + onDelete +}: GTBProfissaoTableProps) { + return ( + + + + # + Situação + CBO + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_profissao_id} + + + + + + + + {item.cod_cbo} + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts new file mode 100644 index 0000000..d6a5a97 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts @@ -0,0 +1,49 @@ + +export default async function GTBProfissoesIndexData() { + + return Promise.resolve([ + { "tb_profissao_id": 2, "descricao": "gestora comercial", "situacao": "A", "cod_cbo": "" }, + { "tb_profissao_id": 3, "descricao": "OPERADOR DE SUBSTAÇÃO", "situacao": "A", "cod_cbo": "123456" }, + { "tb_profissao_id": 4, "descricao": "funcionária pública federal", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 5, "descricao": "Estudante", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 6, "descricao": "Fazendeiro", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 7, "descricao": "Gerente de Fazenda", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 8, "descricao": "Lavrador", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 9, "descricao": "motorista", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 11, "descricao": "2º Tenente", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 12, "descricao": "agricultor", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 13, "descricao": "Aposentada", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 14, "descricao": "Arquiteto", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 15, "descricao": "Artesã", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 16, "descricao": "Autônomo", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 17, "descricao": "Auxiliar de Escritório", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 19, "descricao": "Administrador Rural", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 20, "descricao": "Administrador de fazenda", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 21, "descricao": "Advogada", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 22, "descricao": "Designer de Sobrancelhas", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 23, "descricao": "Agente Administrativo Educacional", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 24, "descricao": "Agricultora", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 25, "descricao": "Agrimensor", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 26, "descricao": "Agropecuarista", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 27, "descricao": "Agrônoma", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 28, "descricao": "Ambulante", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 29, "descricao": "Analista de Sistemas", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 30, "descricao": "Arquiteta", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 31, "descricao": "Artesão", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 32, "descricao": "Assessora Parlamentar", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 33, "descricao": "Assistente de Gestão", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 34, "descricao": "Auxiliar Técnico", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 35, "descricao": "Auxiliar Administrativo", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 36, "descricao": "Auxiliar de Cartório", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 37, "descricao": "Auxiliar de Enfermagem", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 38, "descricao": "Auxiliar de Limpeza", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 39, "descricao": "Auxiliar de Produção II", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 40, "descricao": "Auxiliar de Serviços gerais", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 41, "descricao": "Auxiliar de Sondagem", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 42, "descricao": "Balconista", "situacao": "A", "cod_cbo": "-2" }, + { "tb_profissao_id": 43, "descricao": "Bancário Aposentado", "situacao": "A", "cod_cbo": null }, + { "tb_profissao_id": 44, "descricao": "Bioquímico", "situacao": "A", "cod_cbo": "-2" } + ] + ); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts new file mode 100644 index 0000000..952b392 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts @@ -0,0 +1,11 @@ +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +export default async function GTBProfissaoRemoveData(data: GTBProfissaoInterface) { + + console.log(data) + + return Promise.resolve({ + message: 'Dados removidos com sucesso' + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts new file mode 100644 index 0000000..91c21e6 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts @@ -0,0 +1,10 @@ +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +export default async function GTBProfissaoSaveData(data: GTBProfissaoInterface) { + + return Promise.resolve({ + message: 'Profissao salva com sucesso', + data: { "tb_profissao_id": 2, "descricao": "gestora comercial", "situacao": "A", "cod_cbo": "" }, + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts new file mode 100644 index 0000000..958da81 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts @@ -0,0 +1,23 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import GTBProfissaoIndexService from "../../_services/g_tb_profissao/GTBProfissaoIndexService"; + +export const useGTBProfissaoReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBProfissao, setGTBProfissao] = useState(null); + + const fetchGTBProfissao = async () => { + + const response = await GTBProfissaoIndexService(); + + setGTBProfissao(response); + + setResponse(response); + + } + + return { gTBProfissao, fetchGTBProfissao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoRemoveHook.ts new file mode 100644 index 0000000..421c186 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import GTBProfissaoRemoveService from "../../_services/g_tb_profissao/GTBProfissaoRemoveService"; + +export const useGTBProfissaoRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBProfissao = async (data: GTBProfissaoInterface) => { + + const response = await GTBProfissaoRemoveService(data); + + setResponse(response); + + } + + return { removeGTBProfissao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts new file mode 100644 index 0000000..b259478 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts @@ -0,0 +1,23 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import GTBProfissaoSaveService from "../../_services/g_tb_profissao/GTBProfissaoSaveService"; + +export const useGTBProfissaoSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBProfissao, setGTBProfissao] = useState(null); + + const saveGTBProfissao = async (data: GTBProfissaoInterface) => { + + const response = await GTBProfissaoSaveService(data); + + setGTBProfissao(response); + + setResponse(response); + + } + + return { gTBProfissao, saveGTBProfissao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts new file mode 100644 index 0000000..13f7312 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts @@ -0,0 +1,9 @@ + +export default interface GTBProfissaoInterface { + + tb_profissao_id?: number, + descricao: string, + situacao: string, + cod_cbo: string + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts new file mode 100644 index 0000000..b7823ff --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts @@ -0,0 +1,8 @@ +import z from "zod"; + +export const GTBProfissaoSchema = z.object({ + tb_profissao_id: z.number().optional, + descricao: z.string().optional, + situacao: z.string().optional, + cod_cbo: z.string().optional +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoIndexService.ts new file mode 100644 index 0000000..8170fd7 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoIndexService.ts @@ -0,0 +1,9 @@ +import GTBProfissoesIndexData from "../../_data/GTBProfissao/GTBProfissaoIndexData"; + +export default async function GTBProfissaoIndexService() { + + const response = await GTBProfissoesIndexData(); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts new file mode 100644 index 0000000..9a1dcef --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts @@ -0,0 +1,12 @@ +import GTBProfissaoRemoveData from "../../_data/GTBProfissao/GTBProfissaoRemoveData"; +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +export default async function GTBProfissaoRemoveService(data: GTBProfissaoInterface) { + + console.log(data); + + const response = await GTBProfissaoRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts new file mode 100644 index 0000000..034c23d --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts @@ -0,0 +1,10 @@ +import GTBProfissaoSaveData from "../../_data/GTBProfissao/GTBProfissaoSaveData"; +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +export default async function GTProfissaoSaveService(data: GTBProfissaoInterface) { + + const response = await GTBProfissaoSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index a037aff..cd55946 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -89,6 +89,10 @@ const data = { title: "Andamentos", url: "/cadastros/andamentos/", }, + { + title: "Profissões", + url: "/cadastros/profissoes/", + }, ], }, { From 611f00b5d0c312d759df2638cfc640111ade7baa Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 12:00:14 -0300 Subject: [PATCH 30/56] =?UTF-8?q?[MVPTN-64]=20feat(CRUD):=20Cria=20o=20CRU?= =?UTF-8?q?D=20de=20Regime=20de=20Comunh=C3=A3o=20com=20dados=20mocados?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../regime_comunhao/page.tsx | 166 ++++++++++++++++++ .../GTBRegimeComunhaoForm.tsx | 143 +++++++++++++++ .../GTBRegimeComunhaoTable.tsx | 126 +++++++++++++ .../GTBRegimeComunhaoIndexData.ts | 51 ++++++ .../GTBRegimeComunhaoRemoveData.ts | 9 + .../GTBRegimeComunhaoSaveData.ts | 16 ++ .../useGTBRegimeComunhaoReadHook.ts | 23 +++ .../useGTBRegimeComunhaoRemoveHook.ts | 19 ++ .../useGTBRegimeComunhaoSaveHook.ts | 23 +++ .../_interfaces/GTBRegimeComunhaoInterface.ts | 7 + .../_schemas/GTBRegimeComunhaoSchema.ts | 9 + .../GTBRegimeComunhaoIndexService.ts | 9 + .../GTBRegimeComunhaoRemoveService.ts | 10 ++ .../GTBRegimeComunhaoSaveService.ts | 10 ++ src/components/app-sidebar.tsx | 6 +- 15 files changed, 626 insertions(+), 1 deletion(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeComunhaoInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts 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..d7aac8f --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts @@ -0,0 +1,51 @@ +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +export default async function GTBRegimeComunhaoIndexData(): Promise { + + return Promise.resolve([ + { + "tb_regimecomunhao_id": 1, + "descricao": "comunhão parcial de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 1 + }, + { + "tb_regimecomunhao_id": 2, + "descricao": "comunhão universal de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 2 + }, + { + "tb_regimecomunhao_id": 33, + "descricao": "Comunhão parcial de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 1 + }, + { + "tb_regimecomunhao_id": 3, + "descricao": "separacão total de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 4 + }, + { + "tb_regimecomunhao_id": 4, + "descricao": "Não Informado", + "texto": null, + "situacao": "A", + "tb_regimebens_id": null + }, + { + "tb_regimecomunhao_id": 35, + "descricao": "Comunhão de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 2 + } + ] + ); + +} \ 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..53c60c5 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts @@ -0,0 +1,9 @@ +import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; + +export default async function GTBRegimeComunhaoRemoveData(data: GTBProfissaoInterface) { + + return Promise.resolve({ + message: 'Dados removidos com sucesso' + }); + +} \ 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..04a87c9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts @@ -0,0 +1,16 @@ +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; + +export default async function GTBRegimeComunhaoSaveData(data: GTBRegimeComunhaoInterface) { + + return Promise.resolve({ + message: 'Profissao salva com sucesso', + data: { + "tb_regimecomunhao_id": 1, + "descricao": "comunhão parcial de bens", + "texto": null, + "situacao": "A", + "tb_regimebens_id": 1 + } + }); + +} \ 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..efe31dd --- /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); + + 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..65e0c2f --- /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 GTBRegimeComunhaoSaveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData"; + +export const useGTBRegimeComunhaoSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + + const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + + const response = await GTBRegimeComunhaoSaveData(data); + + setGTBRegimeComunhao(response); + + 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..4608727 --- /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..db998a4 --- /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 GTProfissaoSaveService(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/", + } ], }, { From b7c5f670df80431a2555ea90c5d9cd2fdcdcc37b Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 15:08:19 -0300 Subject: [PATCH 31/56] =?UTF-8?q?[MVPTN-62]=20feat(CRUD):=20Integra=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20crud=20com=20os=20endpoints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{profissao => profissoes}/page.tsx | 0 .../g_tb_profissao/GTBProfissaoForm.tsx | 4 +- .../GTBProfissao/GTBProfissaoIndexData.ts | 51 +++---------------- .../GTBProfissao/GTBProfissaoRemoveData.ts | 9 ++-- .../GTBProfissao/GTBProfissaoSaveData.ts | 13 +++-- .../g_tb_profissao/useGTBProfissaoReadHook.ts | 2 +- .../g_tb_profissao/useGTBProfissaoSaveHook.ts | 2 +- .../_interfaces/GTBProfissaoInterface.ts | 2 +- .../cadastros/_schemas/GTBProfissaoSchema.ts | 10 ++-- .../GTBProfissaoRemoveService.ts | 2 - src/config/app.json | 4 +- 11 files changed, 35 insertions(+), 64 deletions(-) rename src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/{profissao => profissoes}/page.tsx (100%) diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx similarity index 100% rename from src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissao/page.tsx rename to src/app/(protected)/(cadastros)/cadastros/(g_tb_profissao)/profissoes/page.tsx diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx index 37aaf6a..96f5104 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx @@ -83,7 +83,7 @@ export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Prop Descrição - + @@ -98,7 +98,7 @@ export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Prop CBO - + diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts index d6a5a97..b1fa9f0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoIndexData.ts @@ -1,49 +1,12 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; export default async function GTBProfissoesIndexData() { - return Promise.resolve([ - { "tb_profissao_id": 2, "descricao": "gestora comercial", "situacao": "A", "cod_cbo": "" }, - { "tb_profissao_id": 3, "descricao": "OPERADOR DE SUBSTAÇÃO", "situacao": "A", "cod_cbo": "123456" }, - { "tb_profissao_id": 4, "descricao": "funcionária pública federal", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 5, "descricao": "Estudante", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 6, "descricao": "Fazendeiro", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 7, "descricao": "Gerente de Fazenda", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 8, "descricao": "Lavrador", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 9, "descricao": "motorista", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 11, "descricao": "2º Tenente", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 12, "descricao": "agricultor", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 13, "descricao": "Aposentada", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 14, "descricao": "Arquiteto", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 15, "descricao": "Artesã", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 16, "descricao": "Autônomo", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 17, "descricao": "Auxiliar de Escritório", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 19, "descricao": "Administrador Rural", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 20, "descricao": "Administrador de fazenda", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 21, "descricao": "Advogada", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 22, "descricao": "Designer de Sobrancelhas", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 23, "descricao": "Agente Administrativo Educacional", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 24, "descricao": "Agricultora", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 25, "descricao": "Agrimensor", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 26, "descricao": "Agropecuarista", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 27, "descricao": "Agrônoma", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 28, "descricao": "Ambulante", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 29, "descricao": "Analista de Sistemas", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 30, "descricao": "Arquiteta", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 31, "descricao": "Artesão", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 32, "descricao": "Assessora Parlamentar", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 33, "descricao": "Assistente de Gestão", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 34, "descricao": "Auxiliar Técnico", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 35, "descricao": "Auxiliar Administrativo", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 36, "descricao": "Auxiliar de Cartório", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 37, "descricao": "Auxiliar de Enfermagem", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 38, "descricao": "Auxiliar de Limpeza", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 39, "descricao": "Auxiliar de Produção II", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 40, "descricao": "Auxiliar de Serviços gerais", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 41, "descricao": "Auxiliar de Sondagem", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 42, "descricao": "Balconista", "situacao": "A", "cod_cbo": "-2" }, - { "tb_profissao_id": 43, "descricao": "Bancário Aposentado", "situacao": "A", "cod_cbo": null }, - { "tb_profissao_id": 44, "descricao": "Bioquímico", "situacao": "A", "cod_cbo": "-2" } - ] - ); + const api = new API(); + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_profissao/` + }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts index 952b392..61f3064 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoRemoveData.ts @@ -1,11 +1,14 @@ +import API from "@/services/api/Api"; import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; export default async function GTBProfissaoRemoveData(data: GTBProfissaoInterface) { - console.log(data) + const api = new API(); - return Promise.resolve({ - message: 'Dados removidos com sucesso' + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id}` }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts index 91c21e6..de65818 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBProfissao/GTBProfissaoSaveData.ts @@ -1,10 +1,17 @@ +import API from "@/services/api/Api"; import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; export default async function GTBProfissaoSaveData(data: GTBProfissaoInterface) { - return Promise.resolve({ - message: 'Profissao salva com sucesso', - data: { "tb_profissao_id": 2, "descricao": "gestora comercial", "situacao": "A", "cod_cbo": "" }, + const isUpdate = Boolean(data.tb_profissao_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id || ''}`, + body: data }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts index 958da81..6033859 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts @@ -12,7 +12,7 @@ export const useGTBProfissaoReadHook = () => { const response = await GTBProfissaoIndexService(); - setGTBProfissao(response); + setGTBProfissao(response.data); setResponse(response); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts index b259478..d93edb3 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts @@ -12,7 +12,7 @@ export const useGTBProfissaoSaveHook = () => { const response = await GTBProfissaoSaveService(data); - setGTBProfissao(response); + setGTBProfissao(response.data); setResponse(response); diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts index 13f7312..0d86edf 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBProfissaoInterface.ts @@ -4,6 +4,6 @@ export default interface GTBProfissaoInterface { tb_profissao_id?: number, descricao: string, situacao: string, - cod_cbo: string + cod_cbo?: string } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts index b7823ff..9d11ff2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBProfissaoSchema.ts @@ -1,8 +1,8 @@ -import z from "zod"; +import { z } from "zod"; export const GTBProfissaoSchema = z.object({ - tb_profissao_id: z.number().optional, - descricao: z.string().optional, - situacao: z.string().optional, - cod_cbo: z.string().optional + tb_profissao_id: z.number().optional(), + descricao: z.string(), + situacao: z.string(), + cod_cbo: z.string().optional() }); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts index 9a1dcef..8e2ebb0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts @@ -3,8 +3,6 @@ import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; export default async function GTBProfissaoRemoveService(data: GTBProfissaoInterface) { - console.log(data); - const response = await GTBProfissaoRemoveData(data); return response; diff --git a/src/config/app.json b/src/config/app.json index fb7f42d..d38e8d3 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,8 +1,8 @@ { "state": "go", "api": { - "url": "http://api-saas-api-homologacao:8000/", - "prefix": "api/v1", + "url": "http://localhost:8000/", + "prefix": "api/v1/", "content_type": "application/json" } } \ No newline at end of file From b1e39a15183488029c5d331a77c878db55c8c424 Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 15:20:38 -0300 Subject: [PATCH 32/56] =?UTF-8?q?[MVPTN-62]=20fix(Schema):=20Ajusta=20o=20?= =?UTF-8?q?schema=20do=20formul=C3=A1rio=20para=20abrir=20corretamente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts | 2 +- src/components/login-form.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts index 6033859..6bd2c60 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoReadHook.ts @@ -6,7 +6,7 @@ import GTBProfissaoIndexService from "../../_services/g_tb_profissao/GTBProfissa export const useGTBProfissaoReadHook = () => { const { setResponse } = useResponse(); - const [gTBProfissao, setGTBProfissao] = useState(null); + const [gTBProfissao, setGTBProfissao] = useState([]); const fetchGTBProfissao = async () => { diff --git a/src/components/login-form.tsx b/src/components/login-form.tsx index 888204b..602127c 100644 --- a/src/components/login-form.tsx +++ b/src/components/login-form.tsx @@ -5,7 +5,7 @@ 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" @@ -20,7 +20,7 @@ import { FormMessage } from "./ui/form" -type FormValues = z.infer +type FormValues = z.infer export function LoginForm({ className, @@ -28,7 +28,7 @@ export function LoginForm({ }: React.ComponentProps<"div">) { const form = useForm({ - resolver: zodResolver(UsuarioFormSchema), + resolver: zodResolver(GUsuarioSchema), defaultValues: { login: '', senha_api: '' From 5e899442a2285d38b8fe884e5832cd96503fa72b Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 15 Sep 2025 17:09:28 -0300 Subject: [PATCH 33/56] =?UTF-8?q?[MVPTN-64]=20feat(CRUD):=20Adiciona=20os?= =?UTF-8?q?=20endpoints=20ao=20crud=20de=20Regime=20Comunh=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GTBRegimeComunhaoIndexData.ts | 53 +++---------------- .../GTBRegimeComunhaoRemoveData.ts | 13 +++-- .../GTBRegimeComunhaoSaveData.ts | 20 +++---- .../useGTBRegimeComunhaoReadHook.ts | 2 +- .../useGTBRegimeComunhaoSaveHook.ts | 6 +-- .../_schemas/GTBRegimeComunhaoSchema.ts | 2 +- .../GTBProfissaoRemoveService.ts | 2 - .../GTBRegimeComunhaoSaveService.ts | 2 +- src/config/app.json | 4 +- 9 files changed, 35 insertions(+), 69 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts index d7aac8f..f9fd91a 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts @@ -1,51 +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 { - return Promise.resolve([ - { - "tb_regimecomunhao_id": 1, - "descricao": "comunhão parcial de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 1 - }, - { - "tb_regimecomunhao_id": 2, - "descricao": "comunhão universal de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 2 - }, - { - "tb_regimecomunhao_id": 33, - "descricao": "Comunhão parcial de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 1 - }, - { - "tb_regimecomunhao_id": 3, - "descricao": "separacão total de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 4 - }, - { - "tb_regimecomunhao_id": 4, - "descricao": "Não Informado", - "texto": null, - "situacao": "A", - "tb_regimebens_id": null - }, - { - "tb_regimecomunhao_id": 35, - "descricao": "Comunhão de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 2 - } - ] - ); + 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 index 53c60c5..c92cb66 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData.ts @@ -1,9 +1,14 @@ -import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; -export default async function GTBRegimeComunhaoRemoveData(data: GTBProfissaoInterface) { +export default async function GTBRegimeComunhaoRemoveData(data: GTBRegimeComunhaoInterface) { - return Promise.resolve({ - message: 'Dados removidos com sucesso' + 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 index 04a87c9..51cf575 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData.ts @@ -1,16 +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) { - return Promise.resolve({ - message: 'Profissao salva com sucesso', - data: { - "tb_regimecomunhao_id": 1, - "descricao": "comunhão parcial de bens", - "texto": null, - "situacao": "A", - "tb_regimebens_id": 1 - } - }); + 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 index efe31dd..73de8d0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts @@ -12,7 +12,7 @@ export const useGTBRegimeComunhaoReadHook = () => { const response = await GTBRegimeComunhaoIndexService(); - setGTBRegimeComunhao(response); + setGTBRegimeComunhao(response.data); setResponse(response); 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 index 65e0c2f..f0d336e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts @@ -1,7 +1,7 @@ import { useState } from "react"; import { useResponse } from "@/app/_response/ResponseContext" import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; -import GTBRegimeComunhaoSaveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData"; +import GTBRegimeComunhaoSaveService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService"; export const useGTBRegimeComunhaoSaveHook = () => { @@ -10,9 +10,9 @@ export const useGTBRegimeComunhaoSaveHook = () => { const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { - const response = await GTBRegimeComunhaoSaveData(data); + const response = await GTBRegimeComunhaoSaveService(data); - setGTBRegimeComunhao(response); + setGTBRegimeComunhao(response.data); setResponse(response); diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts index 4608727..e47c098 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeComunhaoSchema.ts @@ -1,7 +1,7 @@ import z from "zod"; export const GTBRegimeComunhaoSchema = z.object({ - tb_regimecomunhao_id: z.number().optional, + tb_regimecomunhao_id: z.number().optional(), tb_regimebens_id: z.number(), descricao: z.string(), texto: z.string(), diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts index 9a1dcef..8e2ebb0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoRemoveService.ts @@ -3,8 +3,6 @@ import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface"; export default async function GTBProfissaoRemoveService(data: GTBProfissaoInterface) { - console.log(data); - const response = await GTBProfissaoRemoveData(data); return response; 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 index db998a4..f81e5c9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService.ts @@ -1,7 +1,7 @@ import GTBRegimeComunhaoSaveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData"; import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; -export default async function GTProfissaoSaveService(data: GTBRegimeComunhaoInterface) { +export default async function GTBRegimeComunhaoSaveService(data: GTBRegimeComunhaoInterface) { const response = await GTBRegimeComunhaoSaveData(data); diff --git a/src/config/app.json b/src/config/app.json index fb7f42d..d38e8d3 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1,8 +1,8 @@ { "state": "go", "api": { - "url": "http://api-saas-api-homologacao:8000/", - "prefix": "api/v1", + "url": "http://localhost:8000/", + "prefix": "api/v1/", "content_type": "application/json" } } \ No newline at end of file From debe30dc714c81541ded60f6389c12465d431e0b Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 16 Sep 2025 11:19:36 -0300 Subject: [PATCH 34/56] fix(Response): Ajuste do controle de resposta inesperadas vindas do servidor --- .gitignore | 2 +- .../(g_tb_profissao)/profissoes/page.tsx | 3 -- .../regime_comunhao/page.tsx | 5 +-- .../andamentos/page.tsx | 7 ++-- .../reconhecimentos/page.tsx | 5 +-- .../g_tb_profissao/GTBProfissaoForm.tsx | 1 + .../g_tb_profissao/useGTBProfissaoSaveHook.ts | 8 +++++ .../useGTBRegimeComunhaoSaveHook.ts | 10 ++++++ .../useTTBAndamentoServicoSaveHook.ts | 6 ++++ .../useTTBReconhecimentoTipoSaveHook.ts | 6 ++++ .../g_tb_profissao/GTBProfissaoSaveService.ts | 2 ++ src/app/(protected)/layout.tsx | 2 +- src/app/_response/ResponseContext.tsx | 4 +-- src/app/_response/response.tsx | 35 +++++++++++++++---- 14 files changed, 69 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index ad6413d..674c347 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,4 @@ yarn-error.log* *.tsbuildinfo next-env.d.ts -src/config/app.json +/src/config/app.json 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..cce2544 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 @@ -64,9 +64,6 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveGTBProfissao(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchGTBProfissao(); 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 index 740f76c..55af3da 100644 --- 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 @@ -64,13 +64,10 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveGTBRegimeComunhao(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchGTBRegimeComunhao(); - }, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao, handleCloseForm]); + }, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 9d80a98..823afb8 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -63,14 +63,11 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveTTBAndamentoServico(formData); - - // Encerra o fomulário - handleCloseForm(); - + // Atualiza a lista de dados fetchTTBAndamentoServico(); - }, [saveTTBAndamentoServico, fetchTTBAndamentoServico, handleCloseForm]); + }, [saveTTBAndamentoServico, fetchTTBAndamentoServico]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx index 6f66b36..8501ce9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_reconhecimentotipo)/reconhecimentos/page.tsx @@ -65,13 +65,10 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveTTBReconhecimentoTipo(formData); - // Encerra o fomulário - handleCloseForm(); - // Atualiza a lista de dados fetchTTBReconhecimentosTipos(); - }, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos, handleCloseForm]); + }, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos]); /** * Quando o usuário clica em "remover" na tabela diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx index 96f5104..ec7d5d1 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_profissao/GTBProfissaoForm.tsx @@ -63,6 +63,7 @@ export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Prop }} > + Profissões diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts index d93edb3..74b9dd5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_profissao/useGTBProfissaoSaveHook.ts @@ -7,6 +7,8 @@ export const useGTBProfissaoSaveHook = () => { const { setResponse } = useResponse(); const [gTBProfissao, setGTBProfissao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); const saveGTBProfissao = async (data: GTBProfissaoInterface) => { @@ -16,6 +18,12 @@ export const useGTBProfissaoSaveHook = () => { setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + } return { gTBProfissao, saveGTBProfissao } 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 index f0d336e..b67690e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoSaveHook.ts @@ -7,15 +7,25 @@ export const useGTBRegimeComunhaoSaveHook = () => { const { setResponse } = useResponse(); const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { const response = await GTBRegimeComunhaoSaveService(data); + // Guardar os dados localizados setGTBRegimeComunhao(response.data); + // Manda a resposta para o verificador de resposta setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + } return { gTBRegimeComunhao, saveGTBRegimeComunhao } diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts index c5c1c37..43586da 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -11,6 +11,9 @@ export const useTTBAndamentoServicoSaveHook = () => { const [tTBAndamentoServico, setTTBAndamentoServico] = useState(); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + const saveTTBAndamentoServico = async (data: TTBAndamentoServicoInteface) => { const response = await TTBAndamentoServicoSaveData(data); @@ -21,6 +24,9 @@ export const useTTBAndamentoServicoSaveHook = () => { // Define os dados da respota(toast, modal, etc) setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + // Retorna os valores de forma imediata return response.data; diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts index 48c60dd..88a88df 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_reconhecimentotipo/useTTBReconhecimentoTipoSaveHook.ts @@ -11,6 +11,9 @@ export const useTTBReconhecimentoTipoSaveHook = () => { const [tTBReconhecimentoTipo, setTTBReconhcimentoTipo] = useState(); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + const saveTTBReconhecimentoTipo = async (reconhecimentoTipo: ITTTBReconhecimentoTipo) => { const response = await TTBReconhecimentoTipoSaveData(reconhecimentoTipo); @@ -19,6 +22,9 @@ export const useTTBReconhecimentoTipoSaveHook = () => { setResponse(response); + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + // Retorna os valores de forma imediata return response.data; diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts index 034c23d..4d9e9b9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_profissao/GTBProfissaoSaveService.ts @@ -5,6 +5,8 @@ export default async function GTProfissaoSaveService(data: GTBProfissaoInterface const response = await GTBProfissaoSaveData(data); + console.log('GTBRegimeComunhaoSaveData', response) + return response; } \ No newline at end of file diff --git a/src/app/(protected)/layout.tsx b/src/app/(protected)/layout.tsx index 0ca9fb4..1ab8b42 100644 --- a/src/app/(protected)/layout.tsx +++ b/src/app/(protected)/layout.tsx @@ -74,7 +74,7 @@ export default function RootLayout({
{children} - +
diff --git a/src/app/_response/ResponseContext.tsx b/src/app/_response/ResponseContext.tsx index f356b31..e4bb515 100644 --- a/src/app/_response/ResponseContext.tsx +++ b/src/app/_response/ResponseContext.tsx @@ -17,10 +17,10 @@ interface ResponseContextProps { const ResponseContext = createContext(undefined); export const ResponseProvider: React.FC<{ children: ReactNode }> = ({ children }) => { - const [response, setResponseState] = useState({ message: '', type: null, status : 0}); + const [response, setResponseState] = useState({ message: '', type: null, status: 0 }); const setResponse = (value: ResponseState) => setResponseState(value); - const clearResponse = () => setResponseState({ message: '', type: null, status : 0}); + const clearResponse = () => setResponseState({ message: '', type: null, status: 0 }); return ( diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 4a6e245..4b62195 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -1,20 +1,41 @@ // app/src/app/_response/response.tsx "use client"; -import { useResponse } from "./ResponseContext"; -import { useEffect } from "react"; -import { toast } from "sonner"; +import { + useResponse +} from "./ResponseContext"; +import { + useEffect +} from "react"; +import { + toast +} from "sonner"; export default function Response() { - const { response, clearResponse } = useResponse(); + const { + response, + clearResponse + } = useResponse(); useEffect(() => { switch (Number(response?.status)) { - case 200: - toast(response.message); + case 201: + toast.success(response.message); + break; + + case 422: + toast.danger(response.error, { + description: response.detail + }); + break; + + default: + if (response.status !== 0 && response.status !== 200 && response.status !== 201) { + toast.warning(JSON.stringify(response)); + } break; } }, [response, clearResponse]); return
; -} +} \ No newline at end of file From 639fc5e9fd74b5d027180fb71ed1429456c876ff Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 16 Sep 2025 14:58:34 -0300 Subject: [PATCH 35/56] =?UTF-8?q?[MVPTN-68]=20feat(CRUD):=20Finaliza=C3=A7?= =?UTF-8?q?=C3=A3o=20do=20crud=20com=20os=20ednpoints=20reais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page.tsx | 0 .../GTBRegimeComunhaoForm.tsx | 48 ++++++++++++++++++- .../GTBRegimeBens/GTBRegimeBensIndexData.ts | 14 ++++++ .../GTBRegimeBens/GTBRegimeBensRemoveData.ts | 14 ++++++ .../GTBRegimeBens/GTBRegimeBensSaveData.ts | 16 +++++++ .../useGTBRegimeBensReadHook.ts | 25 ++++++++++ .../useGTBRegimeBensRemoveHook.ts | 19 ++++++++ .../useGTBRegimeBensSaveHook.ts | 33 +++++++++++++ .../useGTBRegimeComunhaoReadHook.ts | 2 +- .../_interfaces/GTBRegimeBensInterface.ts | 6 +++ .../_schemas/GTBRegimeBensSchemas.ts | 7 +++ .../GTBRegimeBensIndexService.ts | 10 ++++ .../GTBRegimeBensRemoveService.ts | 10 ++++ .../GTBRegimeBensSaveService.ts | 10 ++++ src/components/app-sidebar.tsx | 4 +- 15 files changed, 214 insertions(+), 4 deletions(-) rename src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/{regime_comunhao => regime-comunhao}/page.tsx (100%) create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts 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 similarity index 100% rename from src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx rename to src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime-comunhao/page.tsx 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 index 7691325..9a8dc1f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx @@ -28,6 +28,8 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { GTBRegimeComunhaoSchema } from "../../_schemas/GTBRegimeComunhaoSchema"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook"; type FormValues = z.infer; @@ -39,6 +41,9 @@ interface Props { } export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: Props) { + + const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook(); + // Inicializa o react-hook-form com schema zod const form = useForm({ resolver: zodResolver(GTBRegimeComunhaoSchema), @@ -53,7 +58,18 @@ export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: // Atualiza o formulário quando recebe dados para edição useEffect(() => { - if (data) form.reset(data); + + const loadData = async () => { + // Se existir dados, reseta o formulário com os dados informados + if (data) form.reset(data); + + // Aguarda a busca terminar + await fetchGTBRegimeBens(); + }; + + // Dispara a função + loadData(); + }, [data, form]); return ( @@ -106,6 +122,36 @@ export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: )} /> + {/* Tipo */} + ( + + Tipo + + + + )} + /> + {/* Situação */} { + + const api = new API(); + + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_regimebens/` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts new file mode 100644 index 0000000..4437ff2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.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 GTBRegimeBensRemoveData(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/GTBRegimeBens/GTBRegimeBensSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts new file mode 100644 index 0000000..c76f733 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.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 GTBRegimeBensSaveData(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_regimebens/useGTBRegimeBensReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts new file mode 100644 index 0000000..e72811a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts @@ -0,0 +1,25 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import GTBRegimeBensIndexService from "../../_services/g_tb_regimebens/GTBRegimeBensIndexService"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export const useGTBRegimeBensReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeBens, setGTBRegimeBens] = useState(null); + + const fetchGTBRegimeBens = async () => { + + const response = await GTBRegimeBensIndexService(); + + setGTBRegimeBens(response.data); + + setResponse(response); + + return response; + + } + + return { gTBRegimeBens, fetchGTBRegimeBens } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts new file mode 100644 index 0000000..7c4ac98 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.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 useGTBRegimeBensRemoveHook = () => { + + 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_regimebens/useGTBRegimeBensSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts new file mode 100644 index 0000000..bd63963 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts @@ -0,0 +1,33 @@ +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 useGTBRegimeBensSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + + const response = await GTBRegimeComunhaoSaveService(data); + + // Guardar os dados localizados + setGTBRegimeComunhao(response.data); + + // Manda a resposta para o verificador de resposta + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gTBRegimeComunhao, saveGTBRegimeComunhao } + +} \ 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 index 73de8d0..fbf483b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts @@ -6,7 +6,7 @@ import GTBRegimeComunhaoIndexService from "../../_services/g_tb_regimecomunhao/G export const useGTBRegimeComunhaoReadHook = () => { const { setResponse } = useResponse(); - const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); const fetchGTBRegimeComunhao = async () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts new file mode 100644 index 0000000..767bc50 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts @@ -0,0 +1,6 @@ + +export default interface GTBRegimeBensInterface { + tb_regimebens_id?: number, + descricao: string, + situacao: string, +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts new file mode 100644 index 0000000..7356f03 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts @@ -0,0 +1,7 @@ +import z from "zod"; + +export const GTBRegimeBensSchemas = z.object({ + tb_regimebens_id: z.number().optional(), + descricao: z.string(), + situacao: z.string(), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts new file mode 100644 index 0000000..b642bcf --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts @@ -0,0 +1,10 @@ +import GTBRegimeBensIndexData from "../../_data/GTBRegimeBens/GTBRegimeBensIndexData"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export default async function GTBRegimeBensIndexService(): Promise { + + const response = await GTBRegimeBensIndexData(); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts new file mode 100644 index 0000000..06bec9b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.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_regimebens/GTBRegimeBensSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts new file mode 100644 index 0000000..f81e5c9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.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 def5a8f..86bb6d8 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -94,8 +94,8 @@ const data = { url: "/cadastros/profissao/", }, { - title: "Regimes", - url: "/cadastros/regimes/", + title: "Regimes/Comunhão", + url: "/cadastros/regime-comunhao/", } ], }, From c20f3ee64a27ad2f5264542bb35731bbe225da8f Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 09:57:38 -0300 Subject: [PATCH 36/56] =?UTF-8?q?[MVPTN-68]=20fix(Tipagem):=20Remove=20as?= =?UTF-8?q?=20tipagem=20de=20sa=C3=ADda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts | 3 +-- .../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts | 2 +- .../_services/g_tb_regimebens/GTBRegimeBensIndexService.ts | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts index ade4ede..c7dda24 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts @@ -1,8 +1,7 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -export default async function GTBRegimeBensIndexData(): Promise { +export default async function GTBRegimeBensIndexData() { const api = new API(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts index e72811a..9294db5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts @@ -6,7 +6,7 @@ import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; export const useGTBRegimeBensReadHook = () => { const { setResponse } = useResponse(); - const [gTBRegimeBens, setGTBRegimeBens] = useState(null); + const [gTBRegimeBens, setGTBRegimeBens] = useState([]); const fetchGTBRegimeBens = async () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts index b642bcf..b57f1f1 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts @@ -1,7 +1,6 @@ import GTBRegimeBensIndexData from "../../_data/GTBRegimeBens/GTBRegimeBensIndexData"; -import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -export default async function GTBRegimeBensIndexService(): Promise { +export default async function GTBRegimeBensIndexService() { const response = await GTBRegimeBensIndexData(); From 409b61a86ec637005afd61cb95d6067b28308575 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 10:01:28 -0300 Subject: [PATCH 37/56] =?UTF-8?q?[MVPTN-64]=20fix(Tipagem):=20Remo=C3=A7?= =?UTF-8?q?=C3=A3o=20das=20tipagem=20de=20sa=C3=ADda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts | 2 +- .../_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts index f9fd91a..4dd3d24 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts @@ -2,7 +2,7 @@ import API from "@/services/api/Api"; import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -export default async function GTBRegimeComunhaoIndexData(): Promise { +export default async function GTBRegimeComunhaoIndexData() { const api = new API(); 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 index 73de8d0..1d1ff3a 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts @@ -6,7 +6,7 @@ import GTBRegimeComunhaoIndexService from "../../_services/g_tb_regimecomunhao/G export const useGTBRegimeComunhaoReadHook = () => { const { setResponse } = useResponse(); - const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState([]); const fetchGTBRegimeComunhao = async () => { From 0f0121d543729e320285f1e0804e3d2c6c3e03a6 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 10:13:55 -0300 Subject: [PATCH 38/56] fix(Response): Ajuste de tipagem no componente de resposta --- src/app/_response/ResponseContext.tsx | 8 +++++--- src/app/_response/response.tsx | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/_response/ResponseContext.tsx b/src/app/_response/ResponseContext.tsx index e4bb515..b387176 100644 --- a/src/app/_response/ResponseContext.tsx +++ b/src/app/_response/ResponseContext.tsx @@ -3,9 +3,11 @@ import React, { createContext, useContext, useState, ReactNode } from 'react'; interface ResponseState { - message: string; - type: 'toast' | 'modal' | 'alert' | null; - status: number; + message?: string; + type?: 'toast' | 'modal' | 'alert' | null; + status?: number; + error?: string; + detail?: string; } interface ResponseContextProps { diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 4b62195..033c585 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -24,7 +24,7 @@ export default function Response() { break; case 422: - toast.danger(response.error, { + toast.error(response.error, { description: response.detail }); break; From 5e82d47c6a13e7212e74b6dc39e3fc05129cece2 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 11:51:31 -0300 Subject: [PATCH 39/56] =?UTF-8?q?fix(Menu):=20ajuste=20na=20url=20de=20nav?= =?UTF-8?q?ega=C3=A7=C3=A3o=20do=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/app-sidebar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 86bb6d8..ed96420 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -91,7 +91,7 @@ const data = { }, { title: "Profissões", - url: "/cadastros/profissao/", + url: "/cadastros/profissoes/", }, { title: "Regimes/Comunhão", From d61e0ad75bf6a4023861758986e629f5dec21d0e Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 11:55:47 -0300 Subject: [PATCH 40/56] fix(Config): Remove o config do versionamento --- src/config/app.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/config/app.json diff --git a/src/config/app.json b/src/config/app.json deleted file mode 100644 index d38e8d3..0000000 --- a/src/config/app.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "state": "go", - "api": { - "url": "http://localhost:8000/", - "prefix": "api/v1/", - "content_type": "application/json" - } -} \ No newline at end of file From bbc5cd74106a6c68fd99867217cbce95317df799 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 11:57:29 -0300 Subject: [PATCH 41/56] feat(Config): Adiciona o config de exemplo --- src/config/app_example.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/config/app_example.json diff --git a/src/config/app_example.json b/src/config/app_example.json new file mode 100644 index 0000000..d38e8d3 --- /dev/null +++ b/src/config/app_example.json @@ -0,0 +1,8 @@ +{ + "state": "go", + "api": { + "url": "http://localhost:8000/", + "prefix": "api/v1/", + "content_type": "application/json" + } +} \ No newline at end of file From 01b61781b3524615ab0e6533d25bc5ab5c58899e Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 12:52:15 -0300 Subject: [PATCH 42/56] =?UTF-8?q?fix(Menu):=20Ajusta=20o=20menu=20para=20q?= =?UTF-8?q?ue=20as=20p=C3=A1ginas=20sejam=20carregadas=20de=20forma=20assi?= =?UTF-8?q?ncrona?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/nav-main.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/nav-main.tsx b/src/components/nav-main.tsx index 1d71af1..c7d45b5 100644 --- a/src/components/nav-main.tsx +++ b/src/components/nav-main.tsx @@ -1,6 +1,7 @@ "use client" import { ChevronRight, type LucideIcon } from "lucide-react" +import Link from "next/link"; import { Collapsible, @@ -56,9 +57,9 @@ export function NavMain({ {item.items?.map((subItem) => ( - + {subItem.title} - + ))} From 7eafc9439b97b1d37e0a7d2fc76f83793ff8c141 Mon Sep 17 00:00:00 2001 From: keven Date: Wed, 17 Sep 2025 15:57:26 -0300 Subject: [PATCH 43/56] [MVPTN-72] feat(CRUD): Cria CRUD para manipular as centrais do CENSEC --- .../cadastros/(t_censec)/censec/page.tsx | 163 ++++++++++++++++++ .../_components/t_censec/TCensecForm.tsx | 127 ++++++++++++++ .../_components/t_censec/TCensecTable.tsx | 125 ++++++++++++++ .../_data/TCensec/TCensecDeleteData.ts | 10 ++ .../_data/TCensec/TCensecIndexData.ts | 30 ++++ .../_data/TCensec/TCensecSaveData.ts | 15 ++ .../_hooks/t_censec/useTCensecDeleteHook.ts | 19 ++ .../_hooks/t_censec/useTCensecReadHook.ts | 26 +++ .../_hooks/t_censec/useTCensecSaveHook.ts | 37 ++++ .../cadastros/_interfaces/TCensecInterface.ts | 6 + .../cadastros/_schemas/TCensecSchema.ts | 7 + .../t_censec/TCensecDeleteService.ts | 10 ++ .../_services/t_censec/TCensecIndexService.ts | 9 + .../_services/t_censec/TCensecSaveService.ts | 10 ++ src/components/app-sidebar.tsx | 4 + 15 files changed, 598 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx new file mode 100644 index 0000000..e4050c9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx @@ -0,0 +1,163 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; + +import Loading from "@/app/_components/loading/loading"; +import TCensecTable from "../../_components/t_censec/TCensecTable"; +import TCensecForm from "../../_components/t_censec/TCensecForm"; + +import { useTCensecReadHook } from "../../_hooks/t_censec/useTCensecReadHook"; +import { useTCensecSaveHook } from "../../_hooks/t_censec/useTCensecSaveHook"; +import { useTCensecDeleteHook } from "../../_hooks/t_censec/useTCensecDeleteHook"; + +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import TCensecInterface from "../../_interfaces/TCensecInterface"; +import Header from "@/app/_components/structure/Header"; + +export default function TTBAndamentoServico() { + // Hooks para leitura e salvamento + const { tCensec, fetchTCensec } = useTCensecReadHook(); + const { saveTCensec } = useTCensecSaveHook(); + const { deleteTCensec } = useTCensecDeleteHook(); + + // 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: TCensecInterface | 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: TCensecInterface) => { + + // Aguarda salvar o registro + await saveTCensec(formData); + + // Atualiza a lista de dados + fetchTCensec(); + + }, [saveTCensec, fetchTCensec, handleCloseForm]); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: TCensecInterface) => { + + // 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 deleteTCensec(itemToDelete); + + // Atualiza a lista + await fetchTCensec(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchTCensec, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchTCensec(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!tCensec) { + 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/t_censec/TCensecForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx new file mode 100644 index 0000000..93576d7 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx @@ -0,0 +1,127 @@ +'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 { TCensecSchema } from "../../_schemas/TCensecSchema"; + +type FormValues = z.infer; + +interface Props { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function TCensecForm({ isOpen, data, onClose, onSave }: Props) { + // Inicializa o react-hook-form com schema zod + const form = useForm({ + resolver: zodResolver(TCensecSchema), + defaultValues: { + descricao: "", + situacao: "A", + censec_id: 0, + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + + Censec + + + Tipos de Centrais + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecTable.tsx new file mode 100644 index 0000000..37df466 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecTable.tsx @@ -0,0 +1,125 @@ +'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 TCensecInterface from "../../_interfaces/TCensecInterface"; + +interface TCensecTableProps { + data: TCensecInterface[]; + onEdit: (item: TCensecInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: TCensecInterface, 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 TCensecTable({ + data, + onEdit, + onDelete +}: TCensecTableProps) { + return ( + + + + # + Situação + CBO + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.censec_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts new file mode 100644 index 0000000..f3f367a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts @@ -0,0 +1,10 @@ +import TCensecInterface from "../../_interfaces/TCensecInterface"; + +export default async function TCensecDeleteData(data: TCensecInterface) { + + return Promise.resolve({ + message: 'Dados removidos', + status: 200 + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts new file mode 100644 index 0000000..d1747cf --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts @@ -0,0 +1,30 @@ +export default async function TCensecIndexData() { + + return Promise.resolve({ + message: 'Dados localizados', + status: 200, + data: [ + { + censec_id: 1.00, + descricao: 'CEP - Escritura e Procurações Diversas', + situacao: 'A' + }, + { + censec_id: 2.00, + descricao: 'CESDI - Escrituras Lei 11.441', + situacao: 'A' + }, + { + censec_id: 3.00, + descricao: 'RCTO - Testamentos', + situacao: 'A' + }, + { + censec_id: 9.00, + descricao: 'Não Possui', + situacao: 'A' + } + ] + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts new file mode 100644 index 0000000..eefb0f8 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts @@ -0,0 +1,15 @@ +import TCensecInterface from "../../_interfaces/TCensecInterface"; + +export default async function TCensecSaveData(data: TCensecInterface) { + + return Promise.resolve({ + message: 'Dados salvos', + status: 201, + data: { + censec_id: 9.00, + descricao: 'Não Possui', + situacao: 'A' + } + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts new file mode 100644 index 0000000..6542033 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import TCensecInterface from "../../_interfaces/TCensecInterface"; +import TCensecDeleteService from "../../_services/t_censec/TCensecDeleteService"; + +export const useTCensecDeleteHook = () => { + + const { setResponse } = useResponse(); + + const deleteTCensec = async (data: TCensecInterface) => { + + const response = await TCensecDeleteService(data); + + setResponse(response); + + } + + return { deleteTCensec } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts new file mode 100644 index 0000000..b71e8c3 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts @@ -0,0 +1,26 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import TCensecIndexService from "../../_services/t_censec/TCensecIndexService"; +import { useState } from "react"; +import TCensecInterface from "../../_interfaces/TCensecInterface"; + +export const useTCensecReadHook = () => { + + const { setResponse } = useResponse(); + + const [tCensec, setTCensec] = useState([]); + + const fetchTCensec = async () => { + + const response = await TCensecIndexService(); + + setTCensec(response.data); + + setResponse(response); + + return response + + } + + return { tCensec, fetchTCensec } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts new file mode 100644 index 0000000..a1412b7 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts @@ -0,0 +1,37 @@ +'use client' + +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import TCensecInterface from "../../_interfaces/TCensecInterface"; +import TCensecSaveService from "../../_services/t_censec/TCensecSaveService"; + +export const useTCensecSaveHook = () => { + + const { setResponse } = useResponse(); + + const [tCensec, setTCensec] = useState(); + + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveTCensec = async (data: TCensecInterface) => { + + const response = await TCensecSaveService(data); + + // Armazena os dados da repsota + setTCensec(response.data); + + // Define os dados da respota(toast, modal, etc) + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os valores de forma imediata + return response.data; + + } + + return { tCensec, saveTCensec } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecInterface.ts new file mode 100644 index 0000000..2fbf58a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecInterface.ts @@ -0,0 +1,6 @@ + +export default interface TCensecInterface { + censec_id?: number + descricao: string + situacao: string +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecSchema.ts new file mode 100644 index 0000000..a9d0aa4 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecSchema.ts @@ -0,0 +1,7 @@ +import z from "zod"; + +export const TCensecSchema = z.object({ + censec_id: z.number().optional(), + descricao: z.string().min(1, "O campo deve ser preenchido").max(60, "O campo excedeu o limite de 60 caracteres"), + situacao: z.string().min(1, "O campo deve ser preenchido").max(10, "O campo excedeu o limite de 10 caracteres"), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts new file mode 100644 index 0000000..f70eea2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts @@ -0,0 +1,10 @@ +import TCensecDeleteData from "../../_data/TCensec/TCensecDeleteData"; +import TCensecInterface from "../../_interfaces/TCensecInterface"; + +export default async function TCensecDeleteService(data: TCensecInterface) { + + const response = await TCensecDeleteData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts new file mode 100644 index 0000000..1e37031 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts @@ -0,0 +1,9 @@ +import TCensecIndexData from "../../_data/TCensec/TCensecIndexData"; + +export default async function TCensecIndexService() { + + const response = await TCensecIndexData(); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts new file mode 100644 index 0000000..0240cb8 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts @@ -0,0 +1,10 @@ +import TCensecSaveData from "../../_data/TCensec/TCensecSaveData"; +import TCensecInterface from "../../_interfaces/TCensecInterface"; + +export default async function TCensecSaveService(data: TCensecInterface) { + + const response = await TCensecSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index ed96420..a771867 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -96,6 +96,10 @@ const data = { { title: "Regimes/Comunhão", url: "/cadastros/regime-comunhao/", + }, + { + title: "Censec/Centrais", + url: "/cadastros/censec/", } ], }, From 51dbdad1910a96ed463fe88e2eaf16c3c8c0a586 Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 17 Sep 2025 16:51:09 -0300 Subject: [PATCH 44/56] [MVPTN-9] feat(CRUD): Implementando Cadastro de tipos de logradouro --- .../tipo-logradouro/page.tsx | 163 ++++++++++++++++++ .../GTBTipoLogradouroForm.tsx | 133 ++++++++++++++ .../GTBTipoLogradouroTable.tsx | 123 +++++++++++++ .../GTBTipoLogradouroIndexData.ts | 25 +++ .../GTBTipoLogradouroRemoveData.ts | 14 ++ .../GTBTipoLogradouroSaveData.ts | 17 ++ .../GTBTipoLogradouro/mockTipoLogradouro.ts | 98 +++++++++++ .../useGTBTipoLogradouroReadHook.ts | 27 +++ .../useGTBTipoLogradouroRemoveHook.ts | 19 ++ .../useGTBTipoLogradouroSaveHook.ts | 31 ++++ .../_interfaces/GTBTipoLogradouroInterface.ts | 8 + .../_schemas/GTBTipoLogradouroSchema.ts | 10 ++ .../GTBTipoLogradouroIndexService.ts | 12 ++ .../GTBTipoLogradouroRemoveService.ts | 10 ++ .../GTBTipoLogradouroSaveService.ts | 12 ++ src/components/app-sidebar.tsx | 4 + 16 files changed, 706 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_tipologradouro)/tipo-logradouro/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/mockTipoLogradouro.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBTipoLogradouroInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBTipoLogradouroSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_tipologradouro)/tipo-logradouro/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_tipologradouro)/tipo-logradouro/page.tsx new file mode 100644 index 0000000..aced899 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_tipologradouro)/tipo-logradouro/page.tsx @@ -0,0 +1,163 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; +import GTBTipoLogradouroTable from "../../_components/g_tb_tipologradouro/GTBTipoLogradouroTable"; +import GTBTipoLogradouroForm from "../../_components/g_tb_tipologradouro/GTBTipoLogradouroForm"; + +import { useGTBTipoLogradouroReadHook } from "../../_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook"; +import { useGTBTipoLogradouroSaveHook } from "../../_hooks/g_tb_tipologradouro/useGTBTipoLogradouroSaveHook"; +import { useGTBTipoLogradouroRemoveHook } from "../../_hooks/g_tb_tipologradouro/useGTBTipoLogradouroRemoveHook"; + +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +export default function TTBAndamentoServico() { + + // Hooks para leitura e salvamento + const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook(); + const { saveGTBTipoLogradouro } = useGTBTipoLogradouroSaveHook(); + const { removeGTBTipoLogradouro } = useGTBTipoLogradouroRemoveHook(); + + // Estados + const [selectedTipoLogradouro, setTipoLogradouro] = 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: GTBTipoLogradouroInterface | null) => { + setTipoLogradouro(data); + setIsFormOpen(true); + }, []); + + /** + * Fecha o formulário e limpa o andamento selecionado + */ + const handleCloseForm = useCallback(() => { + setTipoLogradouro(null); + setIsFormOpen(false); + }, []); + + /** + * Salva os dados do formulário + */ + const handleSave = useCallback(async (formData: GTBTipoLogradouroInterface) => { + + // Aguarda salvar o registro + await saveGTBTipoLogradouro(formData); + + // Atualiza a lista de dados + fetchGTBTipoLogradouro(); + + }, [saveGTBTipoLogradouro, fetchGTBTipoLogradouro]); + + /** + * Quando o usuário clica em "remover" na tabela + */ + const handleConfirmDelete = useCallback((item: GTBTipoLogradouroInterface) => { + + // 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 removeGTBTipoLogradouro(itemToDelete); + + // Atualiza a lista + await fetchGTBTipoLogradouro(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchGTBTipoLogradouro, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchGTBTipoLogradouro(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!gTBTipoLogradouro) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
{ handleOpenForm(null) }} + /> + + {/* Tabela de andamentos */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx new file mode 100644 index 0000000..8cc9866 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx @@ -0,0 +1,133 @@ +'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 { GTBTipoLogradouroSchema } from "../../_schemas/GTBTipoLogradouroSchema"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +type FormValues = z.infer; + +interface GTBTipoLogradouroFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GTBTipoLogradouroForm({ isOpen, data, onClose, onSave }: GTBTipoLogradouroFormProps) { + // Inicializa o react-hook-form com schema zod + const form = useForm({ + resolver: zodResolver(GTBTipoLogradouroSchema), + defaultValues: { + sistema_id: null, + tb_tipologradouro_id: 0, + situacao_id: null, + descricao: "", + situacao: "A", + onr_tipo_logradouro_id: 0 + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Tipo de Logradouro + + + Crie ou edite um tipo de logradouro + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campos ocultos */} + + + + + + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroTable.tsx new file mode 100644 index 0000000..acadbdc --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroTable.tsx @@ -0,0 +1,123 @@ +'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 { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +interface GTBTipoLogradouroTableProps { + data: GTBTipoLogradouroInterface[]; + onEdit: (item: GTBTipoLogradouroInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBTipoLogradouroInterface, isEditingFormStatus: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) { + 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 GTBTipoLogradouroTable({ + data, + onEdit, + onDelete +}: GTBTipoLogradouroTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_tipologradouro_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts new file mode 100644 index 0000000..227b30b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts @@ -0,0 +1,25 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import TipoLogradouroMockDeDados from "./mockTipoLogradouro"; + +const useMock = true + +export default async function GTBTipoLogradouroIndexData() { + if (useMock) { + console.log(TipoLogradouroMockDeDados()) + return await TipoLogradouroMockDeDados(); + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_tipologradouro/` + }); + return dados + } catch (error) { + console.log(error) + return error + } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroRemoveData.ts new file mode 100644 index 0000000..9a1799e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBTipoLogradouroRemoveData(data: GTBTipoLogradouroInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroSaveData.ts new file mode 100644 index 0000000..5508890 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroSaveData.ts @@ -0,0 +1,17 @@ +import API from "@/services/api/Api"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBTipoLogradouroSaveData(data: GTBTipoLogradouroInterface) { + + const isUpdate = Boolean(data.tb_tipologradouro_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id || ''}`, + body: data + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/mockTipoLogradouro.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/mockTipoLogradouro.ts new file mode 100644 index 0000000..d0ea84a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/mockTipoLogradouro.ts @@ -0,0 +1,98 @@ +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +export default async function TipoLogradouroMockDeDados(){ + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: [ + { + sistema_id: null, + tb_tipologradouro_id: 1, + situacao_id: null, + descricao: "Rua", + situacao: "A", + onr_tipo_logradouro_id: 250 + }, + { + sistema_id: null, + tb_tipologradouro_id: 2, + situacao_id: null, + descricao: "Avenida", + situacao: "A", + onr_tipo_logradouro_id: 26 + }, + { + sistema_id: null, + tb_tipologradouro_id: 3, + situacao_id: null, + descricao: "Alameda", + situacao: "A", + onr_tipo_logradouro_id: 10 + }, + { + sistema_id: null, + tb_tipologradouro_id: 4, + situacao_id: null, + descricao: "Praça", + situacao: "A", + onr_tipo_logradouro_id: 215 + }, + { + sistema_id: null, + tb_tipologradouro_id: 5, + situacao_id: null, + descricao: "Via", + situacao: "A", + onr_tipo_logradouro_id: 294 + }, + { + sistema_id: null, + tb_tipologradouro_id: 6, + situacao_id: null, + descricao: "Viela", + situacao: "A", + onr_tipo_logradouro_id: 297 + }, + { + sistema_id: null, + tb_tipologradouro_id: 7, + situacao_id: null, + descricao: "Travessa", + situacao: "A", + onr_tipo_logradouro_id: 273 + }, + { + sistema_id: null, + tb_tipologradouro_id: 8, + situacao_id: null, + descricao: "Rodovia", + situacao: "A", + onr_tipo_logradouro_id: 247 + }, + { + sistema_id: null, + tb_tipologradouro_id: 9, + situacao_id: null, + descricao: "Sítios", + situacao: "A", + onr_tipo_logradouro_id: 263 + }, + { + sistema_id: null, + tb_tipologradouro_id: 10, + situacao_id: null, + descricao: "Córrego", + situacao: "A", + onr_tipo_logradouro_id: 86 + }, + { + sistema_id: null, + tb_tipologradouro_id: 11, + situacao_id: null, + descricao: "Estrada", + situacao: "A", + onr_tipo_logradouro_id: 117 + } + ] + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook.ts new file mode 100644 index 0000000..a452e29 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroReadHook.ts @@ -0,0 +1,27 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; +import GTBTipoLogradouroIndexService from "../../_services/g_tb_tipologradouro/GTBTipoLogradouroIndexService"; + +export const useGTBTipoLogradouroReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBTipoLogradouro, setGTBTipoLogradouro] = useState([]); + + const fetchGTBTipoLogradouro = async () => { + + try { + const response = await GTBTipoLogradouroIndexService(); + + setGTBTipoLogradouro(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { gTBTipoLogradouro, fetchGTBTipoLogradouro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroRemoveHook.ts new file mode 100644 index 0000000..529ae61 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; +import GTBTipoLogradouroRemoveService from "../../_services/g_tb_tipologradouro/GTBTipoLogradouroRemoveService"; + +export const useGTBTipoLogradouroRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBTipoLogradouro = async (data: GTBTipoLogradouroInterface) => { + + const response = await GTBTipoLogradouroRemoveService(data); + + setResponse(response); + + } + + return { removeGTBTipoLogradouro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroSaveHook.ts new file mode 100644 index 0000000..668966d --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_tipologradouro/useGTBTipoLogradouroSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; +import GTBTipoLogradouroSaveService from "../../_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService"; + +export const useGTBTipoLogradouroSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBTipoLogradouro, setGTBTipoLogradouro] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGTBTipoLogradouro = async (data: GTBTipoLogradouroInterface) => { + + const response = await GTBTipoLogradouroSaveService(data); + + setGTBTipoLogradouro(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gTBTipoLogradouro, saveGTBTipoLogradouro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBTipoLogradouroInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBTipoLogradouroInterface.ts new file mode 100644 index 0000000..c7c3a80 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBTipoLogradouroInterface.ts @@ -0,0 +1,8 @@ +export interface GTBTipoLogradouroInterface { + sistema_id: number | null; + tb_tipologradouro_id: number; + situacao_id: number | null; + descricao: string; + situacao: 'A' | 'I'; + onr_tipo_logradouro_id: number; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBTipoLogradouroSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBTipoLogradouroSchema.ts new file mode 100644 index 0000000..92204bd --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBTipoLogradouroSchema.ts @@ -0,0 +1,10 @@ +import { z } from 'zod'; + +export const GTBTipoLogradouroSchema = z.object({ + sistema_id: z.number().int().nullable(), + tb_tipologradouro_id: z.number().int(), + situacao_id: z.number().nullable(), + descricao: z.string(), + situacao: z.enum(['A', 'I']), + onr_tipo_logradouro_id: z.number(), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroIndexService.ts new file mode 100644 index 0000000..1eb7666 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroIndexService.ts @@ -0,0 +1,12 @@ +import GTBTipoLogradouroIndexData from "../../_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData"; + +export default async function GTBTipoLogradouroIndexService() { + + try { + const response = await GTBTipoLogradouroIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroRemoveService.ts new file mode 100644 index 0000000..2fca163 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroRemoveService.ts @@ -0,0 +1,10 @@ +import GTBTipoLogradouroRemoveData from "../../_data/GTBTipoLogradouro/GTBTipoLogradouroRemoveData"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +export default async function GTBTipoLogradouroRemoveService(data: GTBTipoLogradouroInterface) { + + const response = await GTBTipoLogradouroRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts new file mode 100644 index 0000000..5f0542d --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts @@ -0,0 +1,12 @@ +import GTBTipoLogradouroSaveData from "../../_data/GTBTipoLogradouro/GTBTipoLogradouroSaveData"; +import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface"; + +export default async function GTBTipoLogradouroSaveService(data: GTBTipoLogradouroInterface) { + + const response = await GTBTipoLogradouroSaveData(data); + + console.log('GTBRegimeComunhaoSaveData', response) + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index def5a8f..926c914 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -96,6 +96,10 @@ const data = { { title: "Regimes", url: "/cadastros/regimes/", + }, + { + title: "Tipos de Logradouros", + url: "/cadastros/tipo-logradouro" } ], }, From aecd665654eb9667a7ad7b143fd9fe9eb6074d9d Mon Sep 17 00:00:00 2001 From: keven Date: Thu, 18 Sep 2025 12:10:56 -0300 Subject: [PATCH 45/56] [MVPTN-68] feat(CRUD): Cria o crud de Regime de Bens --- .../(g_tb_regimebens)/regime-bens/page.tsx | 163 ++++++++++++++++++ .../g_tb_regimebens/GTBRegimeBensForm.tsx | 127 ++++++++++++++ .../g_tb_regimebens/GTBRegimeBensTable.tsx | 126 ++++++++++++++ .../GTBRegimeBens/GTBRegimeBensRemoveData.ts | 6 +- .../GTBRegimeBens/GTBRegimeBensSaveData.ts | 8 +- .../useGTBRegimeBensRemoveHook.ts | 8 +- .../useGTBRegimeBensSaveHook.ts | 10 +- ...eBensSchemas.ts => GTBRegimeBensSchema.ts} | 2 +- .../GTBRegimeBensRemoveService.ts | 8 +- .../GTBRegimeBensSaveService.ts | 8 +- src/components/app-sidebar.tsx | 4 + ...app_example.json => app_example copy.json} | 0 12 files changed, 445 insertions(+), 25 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx rename src/app/(protected)/(cadastros)/cadastros/_schemas/{GTBRegimeBensSchemas.ts => GTBRegimeBensSchema.ts} (72%) rename src/config/{app_example.json => app_example copy.json} (100%) diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx new file mode 100644 index 0000000..a637e10 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx @@ -0,0 +1,163 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; + +import Loading from "@/app/_components/loading/loading"; +import GTBRegimeBensTable from "../../_components/g_tb_regimebens/GTBRegimeBensTable"; +import GTBRegimeBensForm from "../../_components/g_tb_regimebens/GTBRegimeBensForm"; + +import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook"; +import { useGTBRegimeBensSaveHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook"; +import { useGTBRegimeBensRemoveHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook"; + +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 { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook(); + const { saveGTBRegimeComunhao } = useGTBRegimeBensSaveHook(); + const { removeGTBRegimeComunhao } = useGTBRegimeBensRemoveHook(); + + // 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); + + // Atualiza a lista de dados + fetchGTBRegimeBens(); + + }, [saveGTBRegimeComunhao, fetchGTBRegimeBens]); + + /** + * 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 fetchGTBRegimeBens(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchGTBRegimeBens, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchGTBRegimeBens(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!gTBRegimeBens) { + 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_regimebens/GTBRegimeBensForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx new file mode 100644 index 0000000..e535fd8 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx @@ -0,0 +1,127 @@ +'use client'; + +import z from "zod"; +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 { GTBRegimeBensSchema } from "../../_schemas/GTBRegimeBensSchema"; +import { useEffect } from "react"; + +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(GTBRegimeBensSchema), + defaultValues: { + tb_regimebens_id: 0, + descricao: "", + 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 Bens + + + Controle de Regimes de Vens + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx new file mode 100644 index 0000000..364df88 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.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 GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +interface GTBRegimeBensTableProps { + data: GTBRegimeBensInterface[]; + onEdit: (item: GTBRegimeBensInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBRegimeBensInterface, 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 GTBRegimeBensTable({ + data, + onEdit, + onDelete +}: GTBRegimeBensTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_regimebens_id} + + + + + + + + {item.descricao} + + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts index 4437ff2..ebbb985 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts @@ -1,14 +1,14 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -export default async function GTBRegimeBensRemoveData(data: GTBRegimeComunhaoInterface) { +export default async function GTBRegimeBensRemoveData(data: GTBRegimeBensInterface) { const api = new API(); return await api.send({ method: Methods.DELETE, - endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id}` + endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id}` }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts index c76f733..7bf3c83 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts @@ -1,16 +1,16 @@ import API from "@/services/api/Api"; -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -export default async function GTBRegimeBensSaveData(data: GTBRegimeComunhaoInterface) { +export default async function GTBRegimeBensSaveData(data: GTBRegimeBensInterface) { - const isUpdate = Boolean(data.tb_regimecomunhao_id); + const isUpdate = Boolean(data.tb_regimebens_id); const api = new API(); return await api.send({ method: isUpdate ? Methods.PUT : Methods.POST, - endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id || ''}`, + endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id || ''}`, body: data }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts index 7c4ac98..748313e 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts @@ -1,14 +1,14 @@ import { useResponse } from "@/app/_response/ResponseContext" -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; -import GTBRegimeComunhaoRemoveService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoRemoveService"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import GTBRegimeBensRemoveData from "../../_data/GTBRegimeBens/GTBRegimeBensRemoveData"; export const useGTBRegimeBensRemoveHook = () => { const { setResponse } = useResponse(); - const removeGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + const removeGTBRegimeComunhao = async (data: GTBRegimeBensInterface) => { - const response = await GTBRegimeComunhaoRemoveService(data); + const response = await GTBRegimeBensRemoveData(data); setResponse(response); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts index bd63963..fa7b3f9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts @@ -1,18 +1,18 @@ import { useState } from "react"; import { useResponse } from "@/app/_response/ResponseContext" -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; -import GTBRegimeComunhaoSaveService from "../../_services/g_tb_regimecomunhao/GTBRegimeComunhaoSaveService"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import GTBRegimeBensSaveService from "../../_services/g_tb_regimebens/GTBRegimeBensSaveService"; export const useGTBRegimeBensSaveHook = () => { const { setResponse } = useResponse(); - const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); // controla se o formulário está aberto ou fechado const [isOpen, setIsOpen] = useState(false); - const saveGTBRegimeComunhao = async (data: GTBRegimeComunhaoInterface) => { + const saveGTBRegimeComunhao = async (data: GTBRegimeBensInterface) => { - const response = await GTBRegimeComunhaoSaveService(data); + const response = await GTBRegimeBensSaveService(data); // Guardar os dados localizados setGTBRegimeComunhao(response.data); diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts similarity index 72% rename from src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts rename to src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts index 7356f03..49637f0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchemas.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts @@ -1,6 +1,6 @@ import z from "zod"; -export const GTBRegimeBensSchemas = z.object({ +export const GTBRegimeBensSchema = z.object({ tb_regimebens_id: z.number().optional(), descricao: z.string(), situacao: z.string(), diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts index 06bec9b..b194991 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts @@ -1,9 +1,9 @@ -import GTBRegimeComunhaoRemoveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoRemoveData"; -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeBensRemoveData from "../../_data/GTBRegimeBens/GTBRegimeBensRemoveData"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -export default async function GTBRegimeComunhaoRemoveService(data: GTBRegimeComunhaoInterface) { +export default async function GTBRegimeBensRemoveService(data: GTBRegimeBensInterface) { - const response = await GTBRegimeComunhaoRemoveData(data); + const response = await GTBRegimeBensRemoveData(data); return response; diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts index f81e5c9..65e80c0 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts @@ -1,9 +1,9 @@ -import GTBRegimeComunhaoSaveData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoSaveData"; -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeBensSaveData from "../../_data/GTBRegimeBens/GTBRegimeBensSaveData"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -export default async function GTBRegimeComunhaoSaveService(data: GTBRegimeComunhaoInterface) { +export default async function GTBRegimeBensSaveService(data: GTBRegimeBensInterface) { - const response = await GTBRegimeComunhaoSaveData(data); + const response = await GTBRegimeBensSaveData(data); return response; diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index ed96420..5ad8c36 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -93,6 +93,10 @@ const data = { title: "Profissões", url: "/cadastros/profissoes/", }, + { + title: "Regimes/Bens", + url: "/cadastros/regime-bens/", + }, { title: "Regimes/Comunhão", url: "/cadastros/regime-comunhao/", diff --git a/src/config/app_example.json b/src/config/app_example copy.json similarity index 100% rename from src/config/app_example.json rename to src/config/app_example copy.json From 96f591f02f6e2e9e4e82152d8c93e43aeaf2aff4 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 18 Sep 2025 15:32:10 -0300 Subject: [PATCH 46/56] [MVPTN-70] feat(CRUD): Implementando Cadastro de Bairros --- .../cadastros/(g_tb_bairro)/bairro/page.tsx | 130 ++++++++++++++++++ .../_components/g_tb_bairro/GTBBairroForm.tsx | 129 +++++++++++++++++ .../g_tb_bairro/GTBBairroTable.tsx | 123 +++++++++++++++++ .../GTBTipoLogradouroForm.tsx | 15 ++ .../_data/GTBBairro/GTBBairroIndexData.ts | 25 ++++ .../_data/GTBBairro/GTBBairroRemoveData.ts | 14 ++ .../_data/GTBBairro/GTBBairroSaveData.ts | 17 +++ .../cadastros/_data/GTBBairro/mockBairro.ts | 46 +++++++ .../g_tb_bairro/useGTBBairroReadHook.ts | 27 ++++ .../g_tb_bairro/useGTBBairroRemoveHook.ts | 19 +++ .../g_tb_bairro/useGTBBairroSaveHook.ts | 31 +++++ .../_interfaces/GTBBairroInterface.ts | 6 + .../cadastros/_schemas/GTBBairroSchema.ts | 8 ++ .../g_tb_bairro/GTBBairroIndexService.ts | 12 ++ .../g_tb_bairro/GTBBairroRemoveService.ts | 10 ++ .../g_tb_bairro/GTBBairroSaveService.ts | 12 ++ .../GTBTipoLogradouroSaveService.ts | 2 +- src/components/app-sidebar.tsx | 4 + 18 files changed, 629 insertions(+), 1 deletion(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/mockBairro.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx new file mode 100644 index 0000000..841f229 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx @@ -0,0 +1,130 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; +import GTBBairroTable from "../../_components/g_tb_bairro/GTBBairroTable"; +import GTBBairroForm from "../../_components/g_tb_bairro/GTBBairroForm"; + +import { useGTBBairroReadHook } from "../../_hooks/g_tb_bairro/useGTBBairroReadHook"; +import { useGTBBairroSaveHook } from "../../_hooks/g_tb_bairro/useGTBBairroSaveHook"; +import { useGTBBairroRemoveHook } from "../../_hooks/g_tb_bairro/useGTBBairroRemoveHook"; + +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +const initialBairro: GTBBairroInterface = { + sistema_id: null, + tb_bairro_id: 0, + descricao: '', + situacao: 'A' +} + +export default function TTBAndamentoServico() { + + // Hooks para leitura e salvamento + const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook(); + const { saveGTBBairro } = useGTBBairroSaveHook(); + const { removeGTBBairro } = useGTBBairroRemoveHook(); + + // Estado para controlar o formulário e item selecionado + const [selectedBairro, setBairro] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); + + // Hook para o modal de confirmação + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); + + // Ações do formulário + const handleOpenForm = useCallback((data: GTBBairroInterface | null) => { + setBairro(data); + setIsFormOpen(true); + }, []); + + const handleCloseForm = useCallback(() => { + setBairro(null); + setIsFormOpen(false); + }, []); + + const handleSave = useCallback(async (data: GTBBairroInterface) => { + await saveGTBBairro(data); + fetchGTBBairro(); // Atualiza a tabela após salvar + }, [saveGTBBairro, fetchGTBBairro]); + + // Ações de deleção + const handleConfirmDelete = useCallback((item: GTBBairroInterface) => { + setItemToDelete(item); + openConfirmDialog(); + }, [openConfirmDialog]); + + const handleDelete = useCallback(async () => { + if (!itemToDelete) return; + + await removeGTBBairro(itemToDelete); + await fetchGTBBairro(); // Atualiza a tabela após remover + + setItemToDelete(null) + + handleCancel(); + }, [itemToDelete, fetchGTBBairro, handleCancel]); + + // Efeito para carregar os dados na montagem do componente + useEffect(() => { + fetchGTBBairro(); + }, []); + + if (!gTBBairro) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
{ handleOpenForm(data = initialBairro) }} + /> + + {/* Tabela de Bairros */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx new file mode 100644 index 0000000..3cb3cd2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx @@ -0,0 +1,129 @@ +'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 { GTBBairroSchema } from "../../_schemas/GTBBairroSchema"; +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +type FormValues = z.infer; + +interface GTBBairroFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GTBBairroForm({ isOpen, data, onClose, onSave }: GTBBairroFormProps) { + // Inicializa o react-hook-form com o schema Zod + const form = useForm({ + resolver: zodResolver(GTBBairroSchema), + defaultValues: { + sistema_id: null, + tb_bairro_id: 0, + descricao: "", + situacao: "A", + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Bairro + + + Crie ou edite um bairro + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campos ocultos */} + + + + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroTable.tsx new file mode 100644 index 0000000..7aeb15c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroTable.tsx @@ -0,0 +1,123 @@ +'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 { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +interface GTBBairroTableProps { + data: GTBBairroInterface[]; + onEdit: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) { + 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 GTBBairroTable({ + data, + onEdit, + onDelete +}: GTBBairroTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_bairro_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx index 8cc9866..30e26af 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_tipologradouro/GTBTipoLogradouroForm.tsx @@ -93,6 +93,21 @@ export default function GTBTipoLogradouroForm({ isOpen, data, onClose, onSave }: )} /> + {/* ID do tipo logradouro na ONR */} + ( + + ID do tipo logradouro na ONR + + + + + + )} + /> + {/* Situação */} { + + const { setResponse } = useResponse(); + const [gTBBairro, setGTBBairro] = useState([]); + + const fetchGTBBairro = async () => { + + try { + const response = await GTBBairroIndexService(); + + setGTBBairro(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { gTBBairro, fetchGTBBairro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroRemoveHook.ts new file mode 100644 index 0000000..00ed2d0 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; +import GTBBairroRemoveService from "../../_services/g_tb_bairro/GTBBairroRemoveService"; + +export const useGTBBairroRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBBairro = async (data: GTBBairroInterface) => { + + const response = await GTBBairroRemoveService(data); + + setResponse(response); + + } + + return { removeGTBBairro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts new file mode 100644 index 0000000..8873c44 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; +import GTBBairroSaveService from "../../_services/g_tb_bairro/GTBBairroSaveService"; + +export const useGTBBairroSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBBairro, setGTBBairro] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGTBBairro = async (data: GTBBairroInterface) => { + + const response = await GTBBairroSaveService(data); + + setGTBBairro(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gTBBairro, saveGTBBairro } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts new file mode 100644 index 0000000..e3a8c68 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts @@ -0,0 +1,6 @@ +export interface GTBBairroInterface { + sistema_id: number | null; + tb_bairro_id: number; + descricao: string; + situacao: 'A' | 'I'; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts new file mode 100644 index 0000000..50fcf25 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts @@ -0,0 +1,8 @@ +import { z } from 'zod'; + +export const GTBBairroSchema = z.object({ + sistema_id: z.number().nullable(), + tb_bairro_id: z.number(), + descricao: z.string(), + situacao: z.enum(['A', 'I']), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts new file mode 100644 index 0000000..fbc3e01 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts @@ -0,0 +1,12 @@ +import GTBBairroIndexData from "../../_data/GTBBairro/GTBBairroIndexData"; + +export default async function GTBBairroIndexService() { + + try { + const response = await GTBBairroIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroRemoveService.ts new file mode 100644 index 0000000..59bbe42 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroRemoveService.ts @@ -0,0 +1,10 @@ +import GTBBairroRemoveData from "../../_data/GTBBairro/GTBBairroRemoveData"; +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +export default async function GTBBairroRemoveService(data: GTBBairroInterface) { + + const response = await GTBBairroRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts new file mode 100644 index 0000000..f7e8da4 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts @@ -0,0 +1,12 @@ +import GTBBairroSaveData from "../../_data/GTBBairro/GTBBairroSaveData"; +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +export default async function GTBBairroSaveService(data: GTBBairroInterface) { + + const response = await GTBBairroSaveData(data); + + console.log('GTBRegimeComunhaoSaveData', response) + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts index 5f0542d..ce514bc 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_tipologradouro/GTBTipoLogradouroSaveService.ts @@ -5,7 +5,7 @@ export default async function GTBTipoLogradouroSaveService(data: GTBTipoLogradou const response = await GTBTipoLogradouroSaveData(data); - console.log('GTBRegimeComunhaoSaveData', response) + console.log('GTBTipoLogradouroSaveData', response) return response; diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 926c914..b959708 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -100,6 +100,10 @@ const data = { { title: "Tipos de Logradouros", url: "/cadastros/tipo-logradouro" + }, + { + title: "Bairro", + url: "/cadastros/bairro" } ], }, From d4a8488489f6af9993ad617e0e7098889b11dce9 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 18 Sep 2025 16:50:01 -0300 Subject: [PATCH 47/56] [MVPTN-77] feat(CRUD): Implementando Cadastro de Estado Civil --- .../(g_tb_estadocivil)/estado-civil/page.tsx | 129 ++++++++++++++++++ .../g_tb_estadocivil/GTBEstadoCivilForm.tsx | 129 ++++++++++++++++++ .../g_tb_estadocivil/GTBEstadoCivilTable.tsx | 123 +++++++++++++++++ .../GTBEstadoCivil/GTBEstadoCivilIndexData.ts | 25 ++++ .../GTBEstadoCivilRemoveData.ts | 14 ++ .../GTBEstadoCivil/GTBEstadoCivilSaveData.ts | 17 +++ .../_data/GTBEstadoCivil/mockEstadoCivil.ts | 58 ++++++++ .../useGTBEstadoCivilReadHook.ts | 27 ++++ .../useGTBEstadoCivilRemoveHook.ts | 19 +++ .../useGTBEstadoCivilSaveHook.ts | 31 +++++ .../_interfaces/GTBEstadoCivilInterface.ts | 6 + .../_schemas/GTBEstadoCivilSchema.ts | 8 ++ .../GTBEstadoCivilIndexService.ts | 12 ++ .../GTBEstadoCivilRemoveService.ts | 10 ++ .../GTBEstadoCivilSaveService.ts | 12 ++ src/components/app-sidebar.tsx | 4 + 16 files changed, 624 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_estadocivil)/estado-civil/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/mockEstadoCivil.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBEstadoCivilInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBEstadoCivilSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_estadocivil)/estado-civil/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_estadocivil)/estado-civil/page.tsx new file mode 100644 index 0000000..536b2be --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_estadocivil)/estado-civil/page.tsx @@ -0,0 +1,129 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; +import GTBEstadoCivilTable from "../../_components/g_tb_estadocivil/GTBEstadoCivilTable"; +import GTBEstadoCivilForm from "../../_components/g_tb_estadocivil/GTBEstadoCivilForm"; + +import { useGTBEstadoCivilReadHook } from "../../_hooks/g_tb_estadocivil/useGTBEstadoCivilReadHook"; +import { useGTBEstadoCivilSaveHook } from "../../_hooks/g_tb_estadocivil/useGTBEstadoCivilSaveHook"; +import { useGTBEstadoCivilRemoveHook } from "../../_hooks/g_tb_estadocivil/useGTBEstadoCivilRemoveHook"; + +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; + +const initalEstadoCivil: GTBEstadoCivilInterface = { + tb_estadocivil_id: 0, + sistema_id: 0, + descricao: '', + situacao: 'A', +} + +export default function TBEstadoCivilPage() { + + // Hooks para leitura e salvamento + const { gTBEstadoCivil, fetchGTBEstadoCivil } = useGTBEstadoCivilReadHook(); + const { saveGTBEstadoCivil } = useGTBEstadoCivilSaveHook(); + const { removeGTBEstadoCivil } = useGTBEstadoCivilRemoveHook(); + + // Estado para controlar o formulário e item selecionado + const [selectedEstadoCivil, setSelectedEstadoCivil] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); + + // Hook para o modal de confirmação + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); + + // Ações do formulário + const handleOpenForm = useCallback((data: GTBEstadoCivilInterface | null) => { + setSelectedEstadoCivil(data); + setIsFormOpen(true); + }, []); + + const handleCloseForm = useCallback(() => { + setIsFormOpen(false); + setSelectedEstadoCivil(null); + }, []); + + const handleSave = useCallback(async (data: GTBEstadoCivilInterface) => { + await saveGTBEstadoCivil(data); + await fetchGTBEstadoCivil(); // Atualiza a tabela após salvar + handleCloseForm(); + }, [saveGTBEstadoCivil, fetchGTBEstadoCivil]); + + // Ações de deleção + const handleConfirmDelete = useCallback((item: GTBEstadoCivilInterface) => { + setItemToDelete(item); + openConfirmDialog(); + }, [openConfirmDialog]); + + const handleDelete = useCallback(async () => { + if (itemToDelete) { + await removeGTBEstadoCivil(itemToDelete); + await fetchGTBEstadoCivil(); // Atualiza a tabela após remover + } + handleCancel(); + }, [itemToDelete, fetchGTBEstadoCivil, handleCancel]); + + // Efeito para carregar os dados na montagem do componente + useEffect(() => { + fetchGTBEstadoCivil(); + }, []); + + // Mostra tela de loading enquanto os dados não são carregados + if (!gTBEstadoCivil) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
{ handleOpenForm(data = initalEstadoCivil) }} + /> + + {/* Tabela de Estados Civis */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilForm.tsx new file mode 100644 index 0000000..6e94347 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilForm.tsx @@ -0,0 +1,129 @@ +'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 { GTBEstadoCivilSchema } from "../../_schemas/GTBEstadoCivilSchema"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; + +type FormValues = z.infer; + +interface TBEstadoCivilFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GTBEstadoCivilForm({ isOpen, data, onClose, onSave }: TBEstadoCivilFormProps) { + // Inicializa o react-hook-form com o schema Zod + const form = useForm({ + resolver: zodResolver(GTBEstadoCivilSchema), + defaultValues: { + tb_estadocivil_id: 0, + sistema_id: 0, + descricao: "", + situacao: "A", + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Estado Civil + + + Crie ou edite um estado civil + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campos ocultos */} + + + + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilTable.tsx new file mode 100644 index 0000000..1f3ba22 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_estadocivil/GTBEstadoCivilTable.tsx @@ -0,0 +1,123 @@ +'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 { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; + +interface TBEstadoCivilTableProps { + data: GTBEstadoCivilInterface[]; + onEdit: (item: GTBEstadoCivilInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBEstadoCivilInterface, isEditingFormStatus: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) { + 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 GTBEstadoCivilTable({ + data, + onEdit, + onDelete +}: TBEstadoCivilTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_estadocivil_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilIndexData.ts new file mode 100644 index 0000000..efa8787 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilIndexData.ts @@ -0,0 +1,25 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import EstadoCivilMockDeDados from "./mockEstadoCivil"; + +const useMock = true + +export default async function GTBEstadoCivilIndexData() { + if (useMock) { + console.log(EstadoCivilMockDeDados()) + return await EstadoCivilMockDeDados(); + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_estado_civil/` + }); + return dados + } catch (error) { + console.log(error) + return error + } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilRemoveData.ts new file mode 100644 index 0000000..306b3c4 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBEstadoCivilRemoveData(data: GTBEstadoCivilInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilSaveData.ts new file mode 100644 index 0000000..da800a6 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/GTBEstadoCivilSaveData.ts @@ -0,0 +1,17 @@ +import API from "@/services/api/Api"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBEstadoCivilSaveData(data: GTBEstadoCivilInterface) { + + const isUpdate = Boolean(data.tb_estadocivil_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id || ''}`, + body: data + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/mockEstadoCivil.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/mockEstadoCivil.ts new file mode 100644 index 0000000..04e8155 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBEstadoCivil/mockEstadoCivil.ts @@ -0,0 +1,58 @@ +import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; + +export default async function EstadoCivilMockDeDados() { + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: [ + { + tb_estadocivil_id: 26.00, + sistema_id: 2.00, + descricao: "casado", + situacao: "A", + }, + { + tb_estadocivil_id: 27.00, + sistema_id: 2.00, + descricao: "solteiro(a)", + situacao: "A", + }, + { + tb_estadocivil_id: 28.00, + sistema_id: 2.00, + descricao: "desquitado(a)", + situacao: "A", + }, + { + tb_estadocivil_id: 29.00, + sistema_id: 2.00, + descricao: "divorciado(a)", + situacao: "A", + }, + { + tb_estadocivil_id: 30.00, + sistema_id: 2.00, + descricao: "espólio", + situacao: "A", + }, + { + tb_estadocivil_id: 31.00, + sistema_id: 2.00, + descricao: "menor impúbere", + situacao: "A", + }, + { + tb_estadocivil_id: 32.00, + sistema_id: 2.00, + descricao: "menor púbere", + situacao: "A", + }, + { + tb_estadocivil_id: 33.00, + sistema_id: 2.00, + descricao: "não consta", + situacao: "A", + } + ] + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilReadHook.ts new file mode 100644 index 0000000..4a7d31b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilReadHook.ts @@ -0,0 +1,27 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; +import GTBEstadoCivilIndexService from "../../_services/g_tb_estadocivil/GTBEstadoCivilIndexService"; + +export const useGTBEstadoCivilReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBEstadoCivil, setGTBEstadoCivil] = useState([]); + + const fetchGTBEstadoCivil = async () => { + + try { + const response = await GTBEstadoCivilIndexService(); + + setGTBEstadoCivil(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { gTBEstadoCivil, fetchGTBEstadoCivil } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilRemoveHook.ts new file mode 100644 index 0000000..1cc29cf --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; +import GTBEstadoCivilRemoveService from "../../_services/g_tb_estadocivil/GTBEstadoCivilRemoveService"; + +export const useGTBEstadoCivilRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBEstadoCivil = async (data: GTBEstadoCivilInterface) => { + + const response = await GTBEstadoCivilRemoveService(data); + + setResponse(response); + + } + + return { removeGTBEstadoCivil } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilSaveHook.ts new file mode 100644 index 0000000..63a0237 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_estadocivil/useGTBEstadoCivilSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; +import GTBEstadoCivilSaveService from "../../_services/g_tb_estadocivil/GTBEstadoCivilSaveService"; + +export const useGTBEstadoCivilSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBEstadoCivil, setGTBEstadoCivil] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGTBEstadoCivil = async (data: GTBEstadoCivilInterface) => { + + const response = await GTBEstadoCivilSaveService(data); + + setGTBEstadoCivil(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gTBEstadoCivil, saveGTBEstadoCivil } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBEstadoCivilInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBEstadoCivilInterface.ts new file mode 100644 index 0000000..12f1cf5 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBEstadoCivilInterface.ts @@ -0,0 +1,6 @@ +export interface GTBEstadoCivilInterface { + tb_estadocivil_id: number; + sistema_id: number; + descricao: string; + situacao: 'A' | 'I'; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBEstadoCivilSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBEstadoCivilSchema.ts new file mode 100644 index 0000000..88cb617 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBEstadoCivilSchema.ts @@ -0,0 +1,8 @@ +import { z } from 'zod'; + +export const GTBEstadoCivilSchema = z.object({ + tb_estadocivil_id: z.number(), + sistema_id: z.number(), + descricao: z.string(), + situacao: z.enum(['A', 'I']), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilIndexService.ts new file mode 100644 index 0000000..11c0b1d --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilIndexService.ts @@ -0,0 +1,12 @@ +import GTBEstadoCivilIndexData from "../../_data/GTBEstadoCivil/GTBEstadoCivilIndexData"; + +export default async function GTBEstadoCivilIndexService() { + + try { + const response = await GTBEstadoCivilIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilRemoveService.ts new file mode 100644 index 0000000..4c19f10 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilRemoveService.ts @@ -0,0 +1,10 @@ +import GTBEstadoCivilSaveData from "../../_data/GTBEstadoCivil/GTBEstadoCivilSaveData"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; + +export default async function GTBEstadoCivilRemoveService(data: GTBEstadoCivilInterface) { + + const response = await GTBEstadoCivilSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilSaveService.ts new file mode 100644 index 0000000..0567d52 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_estadocivil/GTBEstadoCivilSaveService.ts @@ -0,0 +1,12 @@ +import GTBEstadoCivilSaveData from "../../_data/GTBEstadoCivil/GTBEstadoCivilSaveData"; +import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface"; + +export default async function GTBEstadoCivilSaveService(data: GTBEstadoCivilInterface) { + + const response = await GTBEstadoCivilSaveData(data); + + console.log('GTBRegimeComunhaoSaveData', response) + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index b959708..35c881d 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -104,6 +104,10 @@ const data = { { title: "Bairro", url: "/cadastros/bairro" + }, + { + title: "Estado Civil", + url: "/cadastros/estado-civil" } ], }, From 08889a914ae2a96f5adaad057c1c0322ec0d2dad Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 18 Sep 2025 17:55:01 -0300 Subject: [PATCH 48/56] [MVPTN-74] feat(CRUD): Implementando Tipo de Medida --- .../(g_medidatipo)/medida-tipo/page.tsx | 128 ++++++++++++++++++ .../g_medidatipo/GMedidaTipoForm.tsx | 125 +++++++++++++++++ .../g_medidatipo/GMedidaTipoTable.tsx | 96 +++++++++++++ .../_data/GMedidoTipo/GMedidaTipoIndexData.ts | 25 ++++ .../GMedidoTipo/GMedidaTipoRemoveData.ts | 14 ++ .../_data/GMedidoTipo/GMedidaTipoSaveData.ts | 17 +++ .../_data/GMedidoTipo/mockMedidaTipo.ts | 28 ++++ .../g_medidatipo/useGMedidaTipoReadHook.ts | 27 ++++ .../g_medidatipo/useGMedidaTipoRemoveHook.ts | 19 +++ .../g_medidatipo/useGMedidaTipoSaveHook.ts | 31 +++++ .../_interfaces/GMedidaTipoInterface.ts | 5 + .../cadastros/_schemas/GMedidaTipoSchema.ts | 7 + .../g_medidatipo/GMedidaTipoIndexService.ts | 12 ++ .../g_medidatipo/GMedidaTipoRemoveService.ts | 10 ++ .../g_medidatipo/GMedidaTipoSaveService.ts | 12 ++ src/components/app-sidebar.tsx | 4 + 16 files changed, 560 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_medidatipo)/medida-tipo/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/mockMedidaTipo.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GMedidaTipoInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GMedidaTipoSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_medidatipo)/medida-tipo/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_medidatipo)/medida-tipo/page.tsx new file mode 100644 index 0000000..5b198ea --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_medidatipo)/medida-tipo/page.tsx @@ -0,0 +1,128 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; +import GMedidaTipoTable from "../../_components/g_medidatipo/GMedidaTipoTable"; +import GMedidaTipoForm from "../../_components/g_medidatipo/GMedidaTipoForm"; + +import { useGMedidaTipoReadHook } from "../../_hooks/g_medidatipo/useGMedidaTipoReadHook"; +import { useGMedidaTipoSaveHook } from "../../_hooks/g_medidatipo/useGMedidaTipoSaveHook"; +import { useGMedidaTipoRemoveHook } from "../../_hooks/g_medidatipo/useGMedidaTipoRemoveHook"; + +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; + +const initialMedidaTipo: GMedidaTipoInterface = { + medida_tipo_id: 0, + sigla: '', + descricao: '' +} + +export default function GMedidaTipoPage() { + + // Hooks para leitura, salvamento e remoção + const { gMedidaTipo, fetchGMedidaTipo } = useGMedidaTipoReadHook(); + const { saveGMedidaTipo } = useGMedidaTipoSaveHook(); + const { removeGMedidaTipo } = useGMedidaTipoRemoveHook(); + + // Estado para controlar o formulário e o item selecionado + const [selectedMedidaTipo, setSelectedMedidaTipo] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); + + // Hook para o modal de confirmação + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); + + // Ações do formulário + const handleOpenForm = useCallback((data: GMedidaTipoInterface | null) => { + setSelectedMedidaTipo(data); + setIsFormOpen(true); + }, []); + + const handleCloseForm = useCallback(() => { + setIsFormOpen(false); + setSelectedMedidaTipo(null); + }, []); + + const handleSave = useCallback(async (data: GMedidaTipoInterface) => { + await saveGMedidaTipo(data); + await fetchGMedidaTipo(); // Atualiza a tabela após salvar + handleCloseForm(); + }, [saveGMedidaTipo, fetchGMedidaTipo]); + + // Ações de deleção + const handleConfirmDelete = useCallback((item: GMedidaTipoInterface) => { + setItemToDelete(item); + openConfirmDialog(); + }, [openConfirmDialog]); + + const handleDelete = useCallback(async () => { + if (itemToDelete) { + await removeGMedidaTipo(itemToDelete); + await fetchGMedidaTipo(); // Atualiza a tabela após remover + } + handleCancel(); + }, [itemToDelete, fetchGMedidaTipo, handleCancel]); + + // Efeito para carregar os dados na montagem do componente + useEffect(() => { + fetchGMedidaTipo(); + }, []); + + // Mostra tela de loading enquanto os dados não são carregados + if (!gMedidaTipo) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
{ handleOpenForm(data = initialMedidaTipo) }} + /> + + {/* Tabela de Tipos de Medida */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário de criação/edição */} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoForm.tsx new file mode 100644 index 0000000..46b47a1 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoForm.tsx @@ -0,0 +1,125 @@ +'use client'; + +import z from "zod"; +import { useEffect } from "react"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; + +import { Button } from "@/components/ui/button"; +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 { GMedidaTipoSchema } from "../../_schemas/GMedidaTipoSchema"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; + +type FormValues = z.infer; + +interface GMedidaTipoFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function GMedidaTipoForm({ isOpen, data, onClose, onSave }: GMedidaTipoFormProps) { + // Inicializa o react-hook-form com o schema Zod + const form = useForm({ + resolver: zodResolver(GMedidaTipoSchema), + defaultValues: { + medida_tipo_id: 0, + sigla: "", + descricao: "", + }, + }); + + // Atualiza o formulário quando recebe dados para edição + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + + Tipo de Medida + + + Crie ou edite um tipo de medida + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Sigla */} + ( + + Sigla + + + + + + )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoTable.tsx new file mode 100644 index 0000000..6005b84 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_medidatipo/GMedidaTipoTable.tsx @@ -0,0 +1,96 @@ +'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 { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; + +interface GMedidaTipoTableProps { + data: GMedidaTipoInterface[]; + onEdit: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void; +} + +export default function GMedidaTipoTable({ + data, + onEdit, + onDelete +}: GMedidaTipoTableProps) { + return ( + + + + # + Descrição + Sigla + Ações + + + + + {data.map((item) => ( + + + {item.medida_tipo_id} + + {item.descricao} + {item.sigla} + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts new file mode 100644 index 0000000..7767d4c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoIndexData.ts @@ -0,0 +1,25 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import MedidaTipoMockDeDados from "./mockMedidaTipo"; + +const useMock = true + +export default async function GMedidaTipoIndexData() { + if (useMock) { + console.log(MedidaTipoMockDeDados()) + return await MedidaTipoMockDeDados(); + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_medida_tipo/` + }); + return dados + } catch (error) { + console.log(error) + return error + } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts new file mode 100644 index 0000000..7e7f4d3 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GMedidaTipoRemoveData(data: GMedidaTipoInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts new file mode 100644 index 0000000..deff26e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/GMedidaTipoSaveData.ts @@ -0,0 +1,17 @@ +import API from "@/services/api/Api"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GMedidaTipoSaveData(data: GMedidaTipoInterface) { + + const isUpdate = Boolean(data.medida_tipo_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id || ''}`, + body: data + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/mockMedidaTipo.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/mockMedidaTipo.ts new file mode 100644 index 0000000..ae1eabf --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GMedidoTipo/mockMedidaTipo.ts @@ -0,0 +1,28 @@ +export default async function MedidaTipoMockDeDados() { + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: [ + { + medida_tipo_id: 1.00, + sigla: "Alqueire", + descricao: "Alqueire" + }, + { + medida_tipo_id: 2.00, + sigla: "ha", + descricao: "Hectare" + }, + { + medida_tipo_id: 3.00, + sigla: "m2", + descricao: "Metros Quadrados" + }, + { + medida_tipo_id: 4.00, + sigla: "braça", + descricao: "Braça" + } + ] + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts new file mode 100644 index 0000000..9ac7b2c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoReadHook.ts @@ -0,0 +1,27 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; +import GMedidaTipoIndexService from "../../_services/g_medidatipo/GMedidaTipoIndexService"; + +export const useGMedidaTipoReadHook = () => { + + const { setResponse } = useResponse(); + const [gMedidaTipo, setGMedidaTipo] = useState([]); + + const fetchGMedidaTipo = async () => { + + try { + const response = await GMedidaTipoIndexService(); + + setGMedidaTipo(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { gMedidaTipo, fetchGMedidaTipo } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts new file mode 100644 index 0000000..d19018a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; +import GMedidaTipoRemoveService from "../../_services/g_medidatipo/GMedidaTipoRemoveService"; + +export const useGMedidaTipoRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGMedidaTipo = async (data: GMedidaTipoInterface) => { + + const response = await GMedidaTipoRemoveService(data); + + setResponse(response); + + } + + return { removeGMedidaTipo } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts new file mode 100644 index 0000000..8f70843 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_medidatipo/useGMedidaTipoSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; +import GMedidaTipoSaveService from "../../_services/g_medidatipo/GMedidaTipoSaveService"; + +export const useGMedidaTipoSaveHook = () => { + + const { setResponse } = useResponse(); + const [gMedidaTipo, setGMedidaTipo] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGMedidaTipo = async (data: GMedidaTipoInterface) => { + + const response = await GMedidaTipoSaveService(data); + + setGMedidaTipo(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gMedidaTipo, saveGMedidaTipo } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GMedidaTipoInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GMedidaTipoInterface.ts new file mode 100644 index 0000000..f351f54 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GMedidaTipoInterface.ts @@ -0,0 +1,5 @@ +export interface GMedidaTipoInterface { + medida_tipo_id: number; + sigla: string; + descricao: string; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GMedidaTipoSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GMedidaTipoSchema.ts new file mode 100644 index 0000000..12bc46e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GMedidaTipoSchema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod'; + +export const GMedidaTipoSchema = z.object({ + medida_tipo_id: z.number(), + sigla: z.string(), + descricao: z.string(), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts new file mode 100644 index 0000000..e12ceba --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoIndexService.ts @@ -0,0 +1,12 @@ +import GMedidaTipoIndexData from "../../_data/GMedidoTipo/GMedidaTipoIndexData"; + +export default async function GMedidaTipoIndexService() { + + try { + const response = await GMedidaTipoIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts new file mode 100644 index 0000000..2a98f69 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoRemoveService.ts @@ -0,0 +1,10 @@ +import GMedidaTipoRemoveData from "../../_data/GMedidoTipo/GMedidaTipoRemoveData"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; + +export default async function GMedidaTipoRemoveService(data: GMedidaTipoInterface) { + + const response = await GMedidaTipoRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts new file mode 100644 index 0000000..c6f3460 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_medidatipo/GMedidaTipoSaveService.ts @@ -0,0 +1,12 @@ +import GMedidaTipoSaveData from "../../_data/GMedidoTipo/GMedidaTipoSaveData"; +import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface"; + +export default async function GMedidaTipoSaveService(data: GMedidaTipoInterface) { + + const response = await GMedidaTipoSaveData(data); + + console.log('GTBRegimeComunhaoSaveData', response) + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 35c881d..aa0bd20 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -108,6 +108,10 @@ const data = { { title: "Estado Civil", url: "/cadastros/estado-civil" + }, + { + title: "Tipo de Medida", + url: "/cadastros/medida-tipo" } ], }, From b2d1388da7157ae112986d98d0a1228a49c3ba3c Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 19 Sep 2025 10:10:44 -0300 Subject: [PATCH 49/56] =?UTF-8?q?[MVPTN-75]=20feat(CRUD):=20Implementa?= =?UTF-8?q?=C3=A7=C3=A3o=20cadastro=20de=20Natureza=20Lit=C3=ADgio=20do=20?= =?UTF-8?q?CENSEC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../censec-natureza-litigio/page.tsx | 131 ++++++++++++++++++ .../TCensecNaturezaLitigioForm.tsx | 129 +++++++++++++++++ .../TCensecNaturezaLitigioTable.tsx | 123 ++++++++++++++++ .../TCensecNaturezaLitigioIndexData.ts | 24 ++++ .../TCensecNaturezaLitigioRemoveData.ts | 14 ++ .../TCensecNaturezaLitigioSaveData.ts | 17 +++ .../mockCensecNaturezaLitigio.ts | 113 +++++++++++++++ .../useTCensecNaturezaLitigioReadHook.ts | 27 ++++ .../useTCensecNaturezaLitigioRemoveHook.ts | 19 +++ .../useTCensecNaturezaLitigioSaveHook.ts | 31 +++++ .../TCensecNaturezaLitigioInterface.ts | 5 + .../_schemas/TCensecNaturezaLitigioSchema.ts | 7 + .../TCensecNaturezaLitigioIndexService.ts | 12 ++ .../TCensecNaturezaLitigioRemoveService.ts | 10 ++ .../TCensecNaturezaLitigioSaveService.ts | 10 ++ src/components/app-sidebar.tsx | 4 + 16 files changed, 676 insertions(+) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioSaveService.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx new file mode 100644 index 0000000..f0cf8f2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx @@ -0,0 +1,131 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; + +import TCensecNaturezaLitigioTable from "../../_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable"; +import TCensecNaturezaLitigioForm from "../../_components/t_censecnaturezalitigio/TCensecNaturezaLitigioForm"; + +import { useTCensecNaturezaLitigioReadHook } from "../../_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook"; +import { useTCensecNaturezaLitigioSaveHook } from "../../_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioSaveHook"; +import { useTCensecNaturezaLitigioRemoveHook } from "../../_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook"; + +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; + +const initialCensecNaturezaLitigio: TCensecNaturezaLitigioInterface = { + censec_naturezaltigio_id: 0, + descricao: "", + situacao: 'A' +} + +export default function TCensecNaturezaLitigioPage() { + + // Hooks + const { tCensecNaturezaLitigio, fetchTCensecNaturezaLitigio } = useTCensecNaturezaLitigioReadHook(); + const { saveTCensecNaturezaLitigio } = useTCensecNaturezaLitigioSaveHook(); + const { removeTCensecNaturezaLitigio } = useTCensecNaturezaLitigioRemoveHook(); + + // Estados + const [selectedItem, setSelectedItem] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); + + // Modal de confirmação + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel, + } = useConfirmDialog(); + + // Abrir formulário (criação ou edição) + const handleOpenForm = useCallback((item: TCensecNaturezaLitigioInterface | null) => { + setSelectedItem(item); + setIsFormOpen(true); + }, []); + + // Fechar formulário + const handleCloseForm = useCallback(() => { + setSelectedItem(null); + setIsFormOpen(false); + }, []); + + // Salvar item + const handleSave = useCallback(async (formData: TCensecNaturezaLitigioInterface) => { + await saveTCensecNaturezaLitigio(formData); + await fetchTCensecNaturezaLitigio(); + }, [saveTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio]); + + // Confirmar remoção + const handleConfirmDelete = useCallback((item: TCensecNaturezaLitigioInterface) => { + setItemToDelete(item); + openConfirmDialog(); + }, [openConfirmDialog]); + + // Executar remoção + const handleDelete = useCallback(async () => { + if (!itemToDelete) return; + await removeTCensecNaturezaLitigio(itemToDelete); + await fetchTCensecNaturezaLitigio(); + setItemToDelete(null); + handleCancel(); + }, [itemToDelete, removeTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio, handleCancel]); + + // Fetch inicial + useEffect(() => { + fetchTCensecNaturezaLitigio(); + }, []); + + // Loading enquanto carrega + if (!tCensecNaturezaLitigio) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
handleOpenForm(data = initialCensecNaturezaLitigio)} + /> + + {/* Tabela */} + + + + + + + {/* Modal de confirmação */} + + + {/* Formulário */} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioForm.tsx new file mode 100644 index 0000000..171c27f --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioForm.tsx @@ -0,0 +1,129 @@ +'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 { TCensecNaturezaLitigioSchema } from '../../_schemas/TCensecNaturezaLitigioSchema'; +import { TCensecNaturezaLitigioInterface } from '../../_interfaces/TCensecNaturezaLitigioInterface'; + +type FormValues = z.infer; + +interface TCensecNaturezaLitigioFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function TCensecNaturezaLitigioForm({ + isOpen, + data, + onClose, + onSave +}: TCensecNaturezaLitigioFormProps) { + const form = useForm({ + resolver: zodResolver(TCensecNaturezaLitigioSchema), + defaultValues: { + censec_naturezaltigio_id: 0, + descricao: "", + situacao: "A" + } + }); + + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + + + Natureza do Litígio + + Crie ou edite uma natureza do litígio + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + + {/* Rodapé */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx new file mode 100644 index 0000000..9b6edaf --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx @@ -0,0 +1,123 @@ +'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 { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; + +interface TCensecNaturezaLitigioTableProps { + data: TCensecNaturezaLitigioInterface[]; + onEdit: (item: TCensecNaturezaLitigioInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: TCensecNaturezaLitigioInterface, isEditingFormStatus: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) { + 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 TCensecNaturezaLitigioTable({ + data, + onEdit, + onDelete +}: TCensecNaturezaLitigioTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.censec_naturezaltigio_id} + + + + + + + {item.descricao} + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts new file mode 100644 index 0000000..96d722f --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts @@ -0,0 +1,24 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import CensecNaturezaLitigioMockDeDados from "./mockCensecNaturezaLitigio"; + +const useMock = true + +export default async function TCensecNaturezaLitigioIndexData() { + if (useMock) { + return await CensecNaturezaLitigioMockDeDados(); + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_censec_natureza_litigio/` + }); + return dados + } catch (error) { + console.log(error) + return error + } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts new file mode 100644 index 0000000..b8dfa54 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TCensecNaturezaLitigioRemoveData(data: TCensecNaturezaLitigioInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_censec_natureza_litigio/${data.censec_naturezaltigio_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts new file mode 100644 index 0000000..0f33808 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts @@ -0,0 +1,17 @@ +import API from "@/services/api/Api"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TCensecNaturezaLitigioTipoSaveData(data: TCensecNaturezaLitigioInterface) { + + const isUpdate = Boolean(data.censec_naturezaltigio_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_censec_natureza_litigio/${data.censec_naturezaltigio_id || ''}`, + body: data + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts new file mode 100644 index 0000000..93c6c7c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts @@ -0,0 +1,113 @@ +export default async function CensecNaturezaLitigioMockDeDados() { + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: [ + { + censec_naturezaltigio_id: 1.00, + descricao: "Bancário", + situacao: "A" + }, + { + censec_naturezaltigio_id: 2.00, + descricao: "Concessionária de Água", + situacao: "A" + }, + { + censec_naturezaltigio_id: 3.00, + descricao: "Concessionária de Gás", + situacao: "A" + }, + { + censec_naturezaltigio_id: 4.00, + descricao: "Concessionária de Luz", + situacao: "A" + }, + { + censec_naturezaltigio_id: 5.00, + descricao: "Consumidor", + situacao: "A" + }, + { + censec_naturezaltigio_id: 6.00, + descricao: "Contrato", + situacao: "A" + }, + { + censec_naturezaltigio_id: 7.00, + descricao: "Empresarial", + situacao: "A" + }, + { + censec_naturezaltigio_id: 8.00, + descricao: "Família", + situacao: "A" + }, + { + censec_naturezaltigio_id: 9.00, + descricao: "Locação", + situacao: "A" + }, + { + censec_naturezaltigio_id: 10.00, + descricao: "Mobiliário", + situacao: "A" + }, + { + censec_naturezaltigio_id: 11.00, + descricao: "Previdência", + situacao: "A" + }, + { + censec_naturezaltigio_id: 12.00, + descricao: "Saúde", + situacao: "A" + }, + { + censec_naturezaltigio_id: 13.00, + descricao: "Seguro", + situacao: "A" + }, + { + censec_naturezaltigio_id: 14.00, + descricao: "Serviço Público", + situacao: "A" + }, + { + censec_naturezaltigio_id: 15.00, + descricao: "Sucessões", + situacao: "A" + }, + { + censec_naturezaltigio_id: 16.00, + descricao: "Telefonia", + situacao: "A" + }, + { + censec_naturezaltigio_id: 17.00, + descricao: "Transporte", + situacao: "A" + }, + { + censec_naturezaltigio_id: 18.00, + descricao: "Transporte - Avião", + situacao: "A" + }, + { + censec_naturezaltigio_id: 19.00, + descricao: "Transporte - Barco", + situacao: "A" + }, + { + censec_naturezaltigio_id: 20.00, + descricao: "Transporte Metrô", + situacao: "A" + }, + { + censec_naturezaltigio_id: 21.00, + descricao: "Transporte - Ônibus", + situacao: "A" + } +] + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts new file mode 100644 index 0000000..3e59dfa --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts @@ -0,0 +1,27 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; +import TCensecNaturezaLitigioIndexService from "../../_services/t_censecnaturezalitigio/TCensecNaturezaLitigioIndexService"; + +export const useTCensecNaturezaLitigioReadHook = () => { + + const { setResponse } = useResponse(); + const [tCensecNaturezaLitigio, setTCensecNaturezaLitigio] = useState([]); + + const fetchTCensecNaturezaLitigio = async () => { + + try { + const response = await TCensecNaturezaLitigioIndexService(); + + setTCensecNaturezaLitigio(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { tCensecNaturezaLitigio, fetchTCensecNaturezaLitigio } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts new file mode 100644 index 0000000..a350a84 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; +import TCensecNaturezaLitigioRemoveService from "../../_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService"; + +export const useTCensecNaturezaLitigioRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeTCensecNaturezaLitigio = async (data: TCensecNaturezaLitigioInterface) => { + + const response = await TCensecNaturezaLitigioRemoveService(data); + + setResponse(response); + + } + + return { removeTCensecNaturezaLitigio } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioSaveHook.ts new file mode 100644 index 0000000..9ba939b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; +import TCensecNaturezaLitigioSaveService from "../../_services/t_censecnaturezalitigio/TCensecNaturezaLitigioSaveService"; + +export const useTCensecNaturezaLitigioSaveHook = () => { + + const { setResponse } = useResponse(); + const [TCensecNaturezaLitigio, setTCensecNaturezaLitigio] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveTCensecNaturezaLitigio = async (data: TCensecNaturezaLitigioInterface) => { + + const response = await TCensecNaturezaLitigioSaveService(data); + + setTCensecNaturezaLitigio(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { TCensecNaturezaLitigio, saveTCensecNaturezaLitigio } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts new file mode 100644 index 0000000..d3f471c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts @@ -0,0 +1,5 @@ +export interface TCensecNaturezaLitigioInterface { + censec_naturezaltigio_id: number; + descricao: string; + situacao: 'A' | 'I'; +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts new file mode 100644 index 0000000..8815d19 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts @@ -0,0 +1,7 @@ +import { z } from 'zod'; + +export const TCensecNaturezaLitigioSchema = z.object({ + censec_naturezaltigio_id: z.number(), + descricao: z.string(), + situacao: z.enum(['A', 'I']), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioIndexService.ts new file mode 100644 index 0000000..2b6bacc --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioIndexService.ts @@ -0,0 +1,12 @@ +import TCensecNaturezaLitigioIndexData from "../../_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData"; + +export default async function TCensecNaturezaLitigioIndexService() { + + try { + const response = await TCensecNaturezaLitigioIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService.ts new file mode 100644 index 0000000..9530497 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService.ts @@ -0,0 +1,10 @@ +import TCensecNaturezaLitigioRemoveData from "../../_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; + +export default async function TCensecNaturezaLitigioRemoveService(data: TCensecNaturezaLitigioInterface) { + + const response = await TCensecNaturezaLitigioRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioSaveService.ts new file mode 100644 index 0000000..1f063c2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censecnaturezalitigio/TCensecNaturezaLitigioSaveService.ts @@ -0,0 +1,10 @@ +import TCensecNaturezaLitigioSaveData from "../../_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData"; +import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; + +export default async function TCensecNaturezaLitigioSaveService(data: TCensecNaturezaLitigioInterface) { + + const response = await TCensecNaturezaLitigioSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index aa0bd20..dede44c 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -112,6 +112,10 @@ const data = { { title: "Tipo de Medida", url: "/cadastros/medida-tipo" + }, + { + title: "Natureza Litígio (Censec)", + url: "/cadastros/censec-natureza-litigio" } ], }, From de4a2dafdb1a60f7ce00f322ea1094ad8b567782 Mon Sep 17 00:00:00 2001 From: keven Date: Fri, 19 Sep 2025 16:36:41 -0300 Subject: [PATCH 50/56] =?UTF-8?q?feat(logout/Info):=20Aidiciona=20dados=20?= =?UTF-8?q?do=20usu=C3=A1rio=20no=20menu.=20Adiciona=20a=20op=C3=A7=C3=A3o?= =?UTF-8?q?=20de=20realizar=20logout=20da=20aplica=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 32 ++- package.json | 7 +- public/images/logo.svg | 27 ++ src/actions/cookies/CookiesGet.ts | 16 +- src/actions/text/GetSigla.ts | 15 ++ .../_hooks/g_usuario/useGUsuarioLogoutHook.ts | 14 + .../g_usuario/GUsuarioLogoutService.ts | 19 ++ src/app/(protected)/layout.tsx | 2 +- src/components/app-sidebar.tsx | 67 ++++- src/components/nav-main.tsx | 50 +++- src/components/nav-user.tsx | 251 ++++++++++++------ src/hooks/auth/useGUsuarioGetJWTHook.ts | 67 +++++ .../GUsuarioAuthenticatedInterface.ts | 13 + 13 files changed, 486 insertions(+), 94 deletions(-) create mode 100644 public/images/logo.svg create mode 100644 src/actions/text/GetSigla.ts create mode 100644 src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioLogoutHook.ts create mode 100644 src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogoutService.ts create mode 100644 src/hooks/auth/useGUsuarioGetJWTHook.ts create mode 100644 src/interfaces/GUsuarioAuthenticatedInterface.ts diff --git a/package-lock.json b/package-lock.json index 73cb6d5..41066c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "app", - "version": "0.1.0", + "version": "25.9.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "app", - "version": "0.1.0", + "version": "25.9.1", "dependencies": { "@faker-js/faker": "^10.0.0", "@hookform/resolvers": "^5.2.1", @@ -26,7 +26,9 @@ "clsx": "^2.1.1", "cookies-next": "^6.1.0", "faker-js": "^1.0.0", + "js-cookie": "^3.0.5", "jsonwebtoken": "^9.0.2", + "jwt-decode": "^4.0.0", "lucide-react": "^0.540.0", "next": "^15.5.3", "next-themes": "^0.4.6", @@ -39,6 +41,7 @@ }, "devDependencies": { "@tailwindcss/postcss": "^4", + "@types/js-cookie": "^3.0.6", "@types/jsonwebtoken": "^9.0.10", "@types/node": "^20", "@types/react": "^19", @@ -1949,6 +1952,13 @@ "tailwindcss": "4.1.12" } }, + "node_modules/@types/js-cookie": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-3.0.6.tgz", + "integrity": "sha512-wkw9yd1kEXOPnvEeEV1Go1MmxtBJL0RR79aOTAApecWFVu7w0NNXNqhcWgvw2YgZDYadliXkl14pa3WXw5jlCQ==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/jsonwebtoken": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", @@ -2224,6 +2234,15 @@ "jiti": "lib/jiti-cli.mjs" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, "node_modules/jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", @@ -2267,6 +2286,15 @@ "safe-buffer": "^5.0.1" } }, + "node_modules/jwt-decode": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz", + "integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/lightningcss": { "version": "1.30.1", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.30.1.tgz", diff --git a/package.json b/package.json index 88fd872..8e3e0f5 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "app", - "version": "0.1.0", + "version": "25.9.1", "private": true, "scripts": { - "dev": "next dev", + "dev": "next dev --turbopack", "build": "next build", "start": "next start", "lint": "next lint" @@ -27,7 +27,9 @@ "clsx": "^2.1.1", "cookies-next": "^6.1.0", "faker-js": "^1.0.0", + "js-cookie": "^3.0.5", "jsonwebtoken": "^9.0.2", + "jwt-decode": "^4.0.0", "lucide-react": "^0.540.0", "next": "^15.5.3", "next-themes": "^0.4.6", @@ -40,6 +42,7 @@ }, "devDependencies": { "@tailwindcss/postcss": "^4", + "@types/js-cookie": "^3.0.6", "@types/jsonwebtoken": "^9.0.10", "@types/node": "^20", "@types/react": "^19", diff --git a/public/images/logo.svg b/public/images/logo.svg new file mode 100644 index 0000000..6199398 --- /dev/null +++ b/public/images/logo.svg @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/actions/cookies/CookiesGet.ts b/src/actions/cookies/CookiesGet.ts index 238470d..194669f 100644 --- a/src/actions/cookies/CookiesGet.ts +++ b/src/actions/cookies/CookiesGet.ts @@ -1,11 +1,19 @@ -'use client' +'use server' import { cookies } from "next/headers"; -export default async function CookiesGet() { +/** + * Função para obter tokens do lado servidorde acordo com o nome informado +*/ +export default async function CookiesGet(token: string) { + // Obtem a lista de Tokens const cookieStore = await cookies(); - const token = cookieStore.get('access_token'); - return token?.value; + + // Obtem um token em especifico + const data = cookieStore.get(token); + + // Retorna nulo ou o valor do token desejado + return data?.value; } \ No newline at end of file diff --git a/src/actions/text/GetSigla.ts b/src/actions/text/GetSigla.ts new file mode 100644 index 0000000..f6550ae --- /dev/null +++ b/src/actions/text/GetSigla.ts @@ -0,0 +1,15 @@ +export default function GetSigla(data: string): string { + + if (!data) return ""; + + // Remove espaços extras no início e no fim e divide em palavras + const palavras = data.trim().split(/\s+/); + + if (palavras.length === 1) { + // Apenas uma palavra → retorna as duas primeiras letras + return palavras[0].substring(0, 2).toUpperCase(); + } + + // Duas ou mais palavras → retorna a primeira letra de cada + return palavras.map(palavra => palavra.charAt(0).toUpperCase()).join(''); +} \ No newline at end of file diff --git a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioLogoutHook.ts b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioLogoutHook.ts new file mode 100644 index 0000000..7220189 --- /dev/null +++ b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioLogoutHook.ts @@ -0,0 +1,14 @@ +'use client' + +import GUsuarioLogoutService from "../../_services/g_usuario/GUsuarioLogoutService"; + +export const useGUsuarioLogoutHook = () => { + + const logoutUsuario = async () => { + + await GUsuarioLogoutService('access_token') + + } + + return { logoutUsuario } +} \ No newline at end of file diff --git a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogoutService.ts b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogoutService.ts new file mode 100644 index 0000000..4747715 --- /dev/null +++ b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogoutService.ts @@ -0,0 +1,19 @@ +'use server' + +import { + cookies +} from "next/headers"; + +import { redirect } from "next/navigation"; + +export default async function GUsuarioLogoutService(token: string) { + + const cookieStore = await cookies(); + cookieStore.set(token, '', { + expires: new Date(0), + path: '/', + }); + + redirect('/login'); + +} \ No newline at end of file diff --git a/src/app/(protected)/layout.tsx b/src/app/(protected)/layout.tsx index 1ab8b42..982240e 100644 --- a/src/app/(protected)/layout.tsx +++ b/src/app/(protected)/layout.tsx @@ -49,7 +49,7 @@ export default function RootLayout({ -
+
) { + + const { userAuthenticated } = useGUsuarioGetJWTHook(); + return ( + + - + + + + + + + + + +
+ + + +
+ +
+ + + + Orius Tecnologia + + + + + + 25.9.1 + + + +
+ +
+ +
+ +
+ +
+
+ + + + - + + + + +
+ ) } diff --git a/src/components/nav-main.tsx b/src/components/nav-main.tsx index c7d45b5..a622c89 100644 --- a/src/components/nav-main.tsx +++ b/src/components/nav-main.tsx @@ -34,41 +34,85 @@ export function NavMain({ }[] }) { return ( + - Platform + + + + Platform + + + + {items.map((item) => ( + + + + + {item.icon && } - {item.title} + + + + {item.title} + + + + + + + + {item.items?.map((subItem) => ( + + + - {subItem.title} + + + + {subItem.title} + + + + + + ))} + + + + + ))} + + + ) } diff --git a/src/components/nav-user.tsx b/src/components/nav-user.tsx index 3d6d9f8..0db31d3 100644 --- a/src/components/nav-user.tsx +++ b/src/components/nav-user.tsx @@ -1,14 +1,10 @@ "use client" import { - BadgeCheck, - Bell, ChevronsUpDown, - CreditCard, LogOut, Sparkles, } from "lucide-react" - import { Avatar, AvatarFallback, @@ -30,85 +26,192 @@ import { useSidebar, } from "@/components/ui/sidebar" +import GUsuarioAuthenticatedInterface from "@/interfaces/GUsuarioAuthenticatedInterface" +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog" +import { useGUsuarioLogoutHook } from "@/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioLogoutHook" +import { use, useCallback, useState } from "react" + export function NavUser({ - user, + + user + }: { - user: { - name: string - email: string - avatar: string - } + + user: GUsuarioAuthenticatedInterface + }) { - const { isMobile } = useSidebar() + + // Hook para encerrar sessão + const { logoutUsuario } = useGUsuarioLogoutHook(); + + // Controle de exibição do formulário de confirmação + const [isConfirmOpen, setIsConfirmOpen] = useState(false); + + const { isMobile } = useSidebar(); + + // Manipulação de formulário de confirmação + const handleConfirmOpen = useCallback(async () => { + + setIsConfirmOpen(true); + + }, []); + + const handleLogoutConfirm = useCallback(async () => { + + logoutUsuario(); + + }, []); + + const handleLogoutCancel = useCallback(async () => { + + setIsConfirmOpen(false); + + }, []) + + if (!user) { + + return 'Carregando...'; + + } return ( - - - - - - - - CN - -
- {user.name} - {user.email} -
- -
-
- - -
+ + <> + + + + + + + + + + - - CN + + + + + + {user.sigla} + + + +
- {user.name} - {user.email} + + + + {user.nome} + + + + + + {user.email} + + +
-
-
- - - - - Upgrade to Pro + + + + + + + + + + + +
+ + + + + + + + {user.sigla} + + + + + +
+ + + + {user.nome} + + + + + + {user.email} + + + +
+ +
+ +
+ + + + + + + + + + Configurações + + + + + + + + handleConfirmOpen()}> + + + + Log out + -
- - - - - Account - - - - Billing - - - - Notifications - - - - - - Log out - -
-
-
-
+ + + + + + + + + + {/* Modal de confirmação */} + handleLogoutConfirm()} + onCancel={() => handleLogoutCancel()} + /> + + + ) } diff --git a/src/hooks/auth/useGUsuarioGetJWTHook.ts b/src/hooks/auth/useGUsuarioGetJWTHook.ts new file mode 100644 index 0000000..02d1571 --- /dev/null +++ b/src/hooks/auth/useGUsuarioGetJWTHook.ts @@ -0,0 +1,67 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { jwtDecode } from "jwt-decode"; +import CookiesGet from "../../actions/cookies/CookiesGet"; +import GetSigla from "@/actions/text/GetSigla"; + +interface JwtPayload { + id: string; + iat: number; + exp: number; + data?: string; +} + +export default function useGUsuarioGetJWTHook() { + + const [userAuthenticated, setUserAuthenticated] = useState(null); + + useEffect(() => { + + async function fetchToken() { + + try { + + // Executa a serve action para obtem o token, salvo em cookies + const token = await CookiesGet("access_token"); + + // Verifica se o token esta preenchido + if (!token) { + + console.error("Não foi localizado dados dentro do token"); + + // Encerra a aplicação + return; + } + + // Decodifica os dados do JWT + const decoded = jwtDecode(token); + + // Se existir campo data e for string, corrige aspas simples + if (decoded.data && typeof decoded.data === "string") { + + // Decodifica os dados enviado via json + decoded.data = JSON.parse(decoded.data); + + // Gera Sigla para o nome + decoded.data.sigla = GetSigla(decoded.data.nome) + + } + + // Armazena os dados decodificados + setUserAuthenticated(decoded); + + } catch (error) { + + console.error("Erro ao buscar token", error); + + } + } + + // Busca o TOken + fetchToken(); + + }, []); + + return { userAuthenticated }; +} diff --git a/src/interfaces/GUsuarioAuthenticatedInterface.ts b/src/interfaces/GUsuarioAuthenticatedInterface.ts new file mode 100644 index 0000000..da1f8f3 --- /dev/null +++ b/src/interfaces/GUsuarioAuthenticatedInterface.ts @@ -0,0 +1,13 @@ +export default interface GUsuarioAuthenticatedInterface { + usuario_id?: number, + login?: string, + situacao?: string, + nome_completo?: string, + funcao?: string, + assina?: string, + sigla?: string, + email?: string, + assina_certidao?: string, + foto?: string, + cpf?: string, +} \ No newline at end of file From 957bb86be1de52c0a949f37fb2def2541127c8de Mon Sep 17 00:00:00 2001 From: keven Date: Fri, 19 Sep 2025 17:08:35 -0300 Subject: [PATCH 51/56] =?UTF-8?q?feat(LoadingButton):=20Implementa=20parci?= =?UTF-8?q?almente=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.
-
- ) } From 156784f83694b7f14cbac4052d25fdeba49ca6d1 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 22 Sep 2025 14:44:22 -0300 Subject: [PATCH 52/56] [MVPTN-76] feat(CRUD): implementada nova tela de cadastro de minuta, e corrigido os dados mockados nas telas que estavam usando os dados mockados --- package-lock.json | 71 ++++++++ package.json | 2 + .../usuarios/[id]/detalhes/page.tsx | 1 + .../_hooks/g_usuario/useGUsuarioReadHooks.ts | 1 + .../_services/g_usuario/GUsuarioRead.ts | 10 +- .../(g_tb_regimebens)/regime-bens/page.tsx | 163 ++++++++++++++++++ .../page.tsx | 0 .../censec-natureza-litigio/page.tsx | 11 +- .../(t_minuta)/minuta/[id]/detalhes/page.tsx | 83 +++++++++ .../(t_minuta)/minuta/formulario/page.tsx | 113 ++++++++++++ .../cadastros/(t_minuta)/minuta/page.tsx | 107 ++++++++++++ .../andamentos/page.tsx | 8 +- .../g_tb_regimebens/GTBRegimeBensForm.tsx | 127 ++++++++++++++ .../g_tb_regimebens/GTBRegimeBensTable.tsx | 126 ++++++++++++++ .../GTBRegimeComunhaoForm.tsx | 48 +++++- .../TCensecNaturezaLitigioForm.tsx | 5 +- .../TCensecNaturezaLitigioTable.tsx | 4 +- .../_components/t_minuta/TMinutaForm.tsx | 155 +++++++++++++++++ .../_components/t_minuta/TMinutaTable.tsx | 97 +++++++++++ .../_data/GTBBairro/GTBBairroIndexData.ts | 2 +- .../GTBRegimeBens/GTBRegimeBensIndexData.ts | 13 ++ .../GTBRegimeBens/GTBRegimeBensRemoveData.ts | 14 ++ .../GTBRegimeBens/GTBRegimeBensSaveData.ts | 16 ++ .../GTBTipoLogradouroIndexData.ts | 2 +- .../GTBRegimeComunhaoIndexData.ts | 2 +- .../TCensecNaturezaLitigioIndexData.ts | 5 +- .../TCensecNaturezaLitigioRemoveData.ts | 4 +- .../TCensecNaturezaLitigioSaveData.ts | 6 +- .../mockCensecNaturezaLitigio.ts | 42 ++--- .../cadastros/_data/TMinuta/MinutaTexto.ts | 81 +++++++++ .../cadastros/_data/TMinuta/TMinutaIndex.ts | 24 +++ .../_data/TMinuta/TMinutaIndexData.ts | 23 +++ .../_data/TMinuta/TMinutaRemoveData.ts | 14 ++ .../_data/TMinuta/TMinutaSaveData.ts | 17 ++ .../cadastros/_data/TMinuta/mockMinuta.ts | 41 +++++ .../useGTBRegimeBensReadHook.ts | 25 +++ .../useGTBRegimeBensRemoveHook.ts | 19 ++ .../useGTBRegimeBensSaveHook.ts | 33 ++++ .../useGTBRegimeComunhaoReadHook.ts | 2 +- .../useTCensecNaturezaLitigioReadHook.ts | 2 + .../useTCensecNaturezaLitigioRemoveHook.ts | 13 +- .../_hooks/t_minuta/useTMinutaIndexHook.ts | 27 +++ .../_hooks/t_minuta/useTMinutaReadHook.ts | 28 +++ .../_hooks/t_minuta/useTMinutaRemoveHook.ts | 19 ++ .../_hooks/t_minuta/useTMinutaSaveHook.ts | 31 ++++ .../useTTBAndamentoServicoReadHook.ts | 2 + .../_interfaces/GTBRegimeBensInterface.ts | 6 + .../TCensecNaturezaLitigioInterface.ts | 2 +- .../cadastros/_interfaces/TMinutaInterface.ts | 7 + .../cadastros/_schemas/GTBRegimeBensSchema.ts | 7 + .../_schemas/TCensecNaturezaLitigioSchema.ts | 2 +- .../cadastros/_schemas/TMinutaSchema.ts | 8 + .../GTBRegimeBensIndexService.ts | 9 + .../GTBRegimeBensRemoveService.ts | 10 ++ .../GTBRegimeBensSaveService.ts | 10 ++ .../_services/t_minuta/TMinutaIndex.ts | 13 ++ .../_services/t_minuta/TMinutaIndexService.ts | 21 +++ .../t_minuta/TMinutaRemoveService.ts | 10 ++ .../_services/t_minuta/TMinutaSaveService.ts | 10 ++ .../cadastros/pessoas/complementos/page.tsx | 73 ++++++++ src/app/_components/structure/Header.tsx | 8 +- src/app/_response/ResponseContext.tsx | 8 +- src/app/_response/response.tsx | 2 +- src/components/MainEditor.tsx | 132 ++++++++++++++ src/components/app-sidebar.tsx | 18 +- src/components/nav-main.tsx | 5 +- src/config/app.json | 8 - 67 files changed, 1936 insertions(+), 72 deletions(-) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx rename src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/{regime_comunhao => regime-comunhao}/page.tsx (100%) create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/[id]/detalhes/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/formulario/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/page.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaTable.tsx create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/MinutaTexto.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndex.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndexData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaRemoveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaSaveData.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/mockMinuta.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaIndexHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaReadHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaRemoveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaSaveHook.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_interfaces/TMinutaInterface.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndex.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndexService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaRemoveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaSaveService.ts create mode 100644 src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx create mode 100644 src/components/MainEditor.tsx delete mode 100644 src/config/app.json diff --git a/package-lock.json b/package-lock.json index 73cb6d5..5270c0d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-tooltip": "^1.2.8", + "@tinymce/tinymce-react": "^6.3.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cookies-next": "^6.1.0", @@ -35,6 +36,7 @@ "react-hook-form": "^7.62.0", "sonner": "^2.0.7", "tailwind-merge": "^3.3.1", + "tinymce": "^8.1.2", "zod": "^4.0.17" }, "devDependencies": { @@ -1949,6 +1951,25 @@ "tailwindcss": "4.1.12" } }, + "node_modules/@tinymce/tinymce-react": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/@tinymce/tinymce-react/-/tinymce-react-6.3.0.tgz", + "integrity": "sha512-E++xnn0XzDzpKr40jno2Kj7umfAE6XfINZULEBBeNjTMvbACWzA6CjiR6V8eTDc9yVmdVhIPqVzV4PqD5TZ/4g==", + "license": "MIT", + "dependencies": { + "prop-types": "^15.6.2" + }, + "peerDependencies": { + "react": "^19.0.0 || ^18.0.0 || ^17.0.1 || ^16.7.0", + "react-dom": "^19.0.0 || ^18.0.0 || ^17.0.1 || ^16.7.0", + "tinymce": "^8.0.0 || ^7.0.0 || ^6.0.0 || ^5.5.1" + }, + "peerDependenciesMeta": { + "tinymce": { + "optional": true + } + } + }, "node_modules/@types/jsonwebtoken": { "version": "9.0.10", "resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz", @@ -2224,6 +2245,12 @@ "jiti": "lib/jiti-cli.mjs" } }, + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT" + }, "node_modules/jsonwebtoken": { "version": "9.0.2", "resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-9.0.2.tgz", @@ -2548,6 +2575,18 @@ "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==", "license": "MIT" }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", + "dependencies": { + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" + } + }, "node_modules/lucide-react": { "version": "0.540.0", "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.540.0.tgz", @@ -2720,6 +2759,15 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -2755,6 +2803,17 @@ "node": "^10 || ^12 || >=14" } }, + "node_modules/prop-types": { + "version": "15.8.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", + "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "license": "MIT", + "dependencies": { + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.13.1" + } + }, "node_modules/react": { "version": "19.1.0", "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz", @@ -2792,6 +2851,12 @@ "react": "^16.8.0 || ^17 || ^18 || ^19" } }, + "node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "license": "MIT" + }, "node_modules/react-remove-scroll": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/react-remove-scroll/-/react-remove-scroll-2.7.1.tgz", @@ -3039,6 +3104,12 @@ "node": ">=18" } }, + "node_modules/tinymce": { + "version": "8.1.2", + "resolved": "https://registry.npmjs.org/tinymce/-/tinymce-8.1.2.tgz", + "integrity": "sha512-KITxHEEHRlxC5xOnxA123eAJ67NgsWxNphtItWt9TRu07DiTZrWIqJeIKRX9euE51/l3kJO4WQiqoBXKTJJGsA==", + "license": "GPL-2.0-or-later" + }, "node_modules/tslib": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", diff --git a/package.json b/package.json index 88fd872..dce6c14 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", "@radix-ui/react-tooltip": "^1.2.8", + "@tinymce/tinymce-react": "^6.3.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cookies-next": "^6.1.0", @@ -36,6 +37,7 @@ "react-hook-form": "^7.62.0", "sonner": "^2.0.7", "tailwind-merge": "^3.3.1", + "tinymce": "^8.1.2", "zod": "^4.0.17" }, "devDependencies": { diff --git a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx index 42f4757..125a254 100644 --- a/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx +++ b/src/app/(protected)/(administrativo)/(g_usuario)/usuarios/[id]/detalhes/page.tsx @@ -22,6 +22,7 @@ export default function UsuarioDetalhes() { if (params.id) { fetchUsuario({ usuario_id: Number(params.id) } as Usuario); } + console.log("pagina",usuario) }, []); if (!usuario) return ; diff --git a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts index da75695..9f73250 100644 --- a/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts +++ b/src/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks.ts @@ -14,6 +14,7 @@ export const useGUsuarioReadHooks = () => { const fetchUsuario = async (Usuario: Usuario) => { const response = await GUsuarioRead(Usuario.usuario_id); + console.log("hook",response.data) setUsuario(response.data); diff --git a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioRead.ts b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioRead.ts index 95ce84e..037a1ea 100644 --- a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioRead.ts +++ b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioRead.ts @@ -12,6 +12,14 @@ export default async function GUsuarioRead(usuarioId: number) { } } - return await GUsuarioReadData(usuarioId); + try { + const response = await GUsuarioReadData(usuarioId); + console.log("service",response) + return response + } catch (error) { + console.log(error) + return error + } + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx new file mode 100644 index 0000000..a637e10 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx @@ -0,0 +1,163 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; + +import Loading from "@/app/_components/loading/loading"; +import GTBRegimeBensTable from "../../_components/g_tb_regimebens/GTBRegimeBensTable"; +import GTBRegimeBensForm from "../../_components/g_tb_regimebens/GTBRegimeBensForm"; + +import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook"; +import { useGTBRegimeBensSaveHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook"; +import { useGTBRegimeBensRemoveHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook"; + +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 { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook(); + const { saveGTBRegimeComunhao } = useGTBRegimeBensSaveHook(); + const { removeGTBRegimeComunhao } = useGTBRegimeBensRemoveHook(); + + // 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); + + // Atualiza a lista de dados + fetchGTBRegimeBens(); + + }, [saveGTBRegimeComunhao, fetchGTBRegimeBens]); + + /** + * 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 fetchGTBRegimeBens(); + + // Limpa o item selecionado + setItemToDelete(null); + + // Fecha o modal + handleCancel(); + + }, [itemToDelete, fetchGTBRegimeBens, handleCancel]); + + /** + * Busca inicial dos dados + */ + useEffect(() => { + fetchGTBRegimeBens(); + }, []); + + /** + * Tela de loading enquanto carrega os dados + */ + if (!gTBRegimeBens) { + 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/(g_tb_regimecomunhao)/regime_comunhao/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime-comunhao/page.tsx similarity index 100% rename from src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime_comunhao/page.tsx rename to src/app/(protected)/(cadastros)/cadastros/(g_tb_regimecomunhao)/regime-comunhao/page.tsx diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx index f0cf8f2..28cca94 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_censecnaturezalitigio)/censec-natureza-litigio/page.tsx @@ -18,9 +18,9 @@ import { useTCensecNaturezaLitigioRemoveHook } from "../../_hooks/t_censecnature import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; const initialCensecNaturezaLitigio: TCensecNaturezaLitigioInterface = { - censec_naturezaltigio_id: 0, - descricao: "", - situacao: 'A' + censec_naturezalitigio_id: 0, + descricao: "", + situacao: 'A' } export default function TCensecNaturezaLitigioPage() { @@ -58,11 +58,13 @@ export default function TCensecNaturezaLitigioPage() { // Salvar item const handleSave = useCallback(async (formData: TCensecNaturezaLitigioInterface) => { await saveTCensecNaturezaLitigio(formData); + console.log(formData) await fetchTCensecNaturezaLitigio(); }, [saveTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio]); // Confirmar remoção const handleConfirmDelete = useCallback((item: TCensecNaturezaLitigioInterface) => { + console.log("item", item) setItemToDelete(item); openConfirmDialog(); }, [openConfirmDialog]); @@ -70,11 +72,12 @@ export default function TCensecNaturezaLitigioPage() { // Executar remoção const handleDelete = useCallback(async () => { if (!itemToDelete) return; + console.log("item to delete",itemToDelete) await removeTCensecNaturezaLitigio(itemToDelete); await fetchTCensecNaturezaLitigio(); setItemToDelete(null); handleCancel(); - }, [itemToDelete, removeTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio, handleCancel]); + }, [itemToDelete, fetchTCensecNaturezaLitigio, handleCancel]); // Fetch inicial useEffect(() => { diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/[id]/detalhes/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/[id]/detalhes/page.tsx new file mode 100644 index 0000000..402df0c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/[id]/detalhes/page.tsx @@ -0,0 +1,83 @@ +'use client' + +import { useEffect, useState } from "react"; +import { useParams } from "next/navigation"; + +import { + Card, + CardContent +} from "@/components/ui/card"; +import MainEditor from "@/components/MainEditor"; + +import Loading from "@/app/_components/loading/loading"; +import { useTMinutaReadHook } from '../../../../_hooks/t_minuta/useTMinutaReadHook'; +import { TMinutaInterface } from '../../../../_interfaces/TMinutaInterface'; + +export default function TMinutaDetalhes() { + const params = useParams(); + const { tMinuta, fetchTMinuta } = useTMinutaReadHook(); + const [editorContent, setEditorContent] = useState(null); // Inicialmente nulo até o texto ser carregado + + useEffect(() => { + if (params.id) { + fetchTMinuta({ t_minuta_id: Number(params.id) } as TMinutaInterface); + } + }, []); + + useEffect(() => { + if (tMinuta?.texto) { + setEditorContent(tMinuta.texto); // Atualiza o conteúdo assim que estiver disponível + } + }, [tMinuta]); // Dependência de `tMinuta` para que a atualização aconteça quando os dados chegarem + + const handleEditorChange = (content: string) => { + setEditorContent(content); // Atualiza o estado com o conteúdo do editor + }; + + if (!tMinuta) return ; + + // Renderiza o editor apenas se o texto foi carregado + if (editorContent === null) { + return ; // Pode mostrar um carregando ou qualquer outra coisa enquanto o conteúdo não está disponível + } + + return ( +
+ + +
+
+
+ Descrição +
+
+ {tMinuta.descricao} +
+
+
+
+ Situação +
+
+ {tMinuta.situacao === "A" ? "Ativo" : "Inativo"} +
+
+
+
+ Texto +
+ +
+
+
+
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/formulario/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/formulario/page.tsx new file mode 100644 index 0000000..9a18d59 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/formulario/page.tsx @@ -0,0 +1,113 @@ +'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 { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage +} from '@/components/ui/form'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; + +import MainEditor from '@/components/MainEditor'; +import { TMinutaSchema } from '../../../_schemas/TMinutaSchema'; +import { useTMinutaSaveHook } from '../../../_hooks/t_minuta/useTMinutaSaveHook'; +import { Card, CardContent } from '@/components/ui/card'; + +type FormValues = z.infer; + +export default function TMinutaForm() { + + const { tMinuta, saveTMinuta } = useTMinutaSaveHook(); + + const form = useForm({ + resolver: zodResolver(TMinutaSchema), + defaultValues: { + natureza_id: undefined, + descricao: '', + situacao: 'A', + texto: '', + } + }); + + async function onSubmit(values: FormValues) { + saveTMinuta(values); + } + + return ( +
+ + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Editor de Texto */} + ( +
+ + {form.formState.errors.texto && ( +

+ {form.formState.errors.texto.message} +

+ )} +
+ )} + /> + + + +
+
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/page.tsx new file mode 100644 index 0000000..691dc29 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/(t_minuta)/minuta/page.tsx @@ -0,0 +1,107 @@ +'use client'; + +import { useEffect, useState, useCallback } from "react"; +import { Card, CardContent } from "@/components/ui/card"; +import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; + +import Header from "@/app/_components/structure/Header"; +import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; +import Loading from "@/app/_components/loading/loading"; + +import TMinutaTable from "../../_components/t_minuta/TMinutaTable"; +import TMinutaForm from "../../_components/t_minuta/TMinutaForm"; + +import { useTMinutaReadHook } from "../../_hooks/t_minuta/useTMinutaReadHook"; +import { useTMinutaSaveHook } from "../../_hooks/t_minuta/useTMinutaSaveHook"; +import { useTMinutaRemoveHook } from "../../_hooks/t_minuta/useTMinutaRemoveHook"; + +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import { useTMinutaIndexHook } from "../../_hooks/t_minuta/useTMinutaIndexHook"; + +export default function TMinutaPage() { + + // Hooks de leitura e escrita + const { tMinuta, fetchTMinuta } = useTMinutaIndexHook(); + const { saveTMinuta } = useTMinutaSaveHook(); + const { removeTMinuta } = useTMinutaRemoveHook(); + + // Estados + const [selectedMinuta, setSelectedMinuta] = useState(null); + const [isFormOpen, setIsFormOpen] = useState(false); + const [itemToDelete, setItemToDelete] = useState(null); + + // Hook de confirmação + const { + isOpen: isConfirmOpen, + openDialog: openConfirmDialog, + handleConfirm, + handleCancel + } = useConfirmDialog(); + + // Abertura do formulário + const handleOpenForm = useCallback((data: TMinutaInterface | null) => { + setSelectedMinuta(data); + setIsFormOpen(true); + }, []); + + // Ação de clique em remover + const handleConfirmDelete = useCallback((item: TMinutaInterface) => { + setItemToDelete(item); + openConfirmDialog(); + }, [openConfirmDialog]); + + // Remoção da minuta após confirmação + const handleDelete = useCallback(async () => { + if (!itemToDelete) return; + + await removeTMinuta(itemToDelete); + await fetchTMinuta(); + setItemToDelete(null); + handleCancel(); + }, [itemToDelete, removeTMinuta, fetchTMinuta, handleCancel]); + + // Fetch inicial + useEffect(() => { + fetchTMinuta(); + }, []); + + // Loading enquanto carrega + if (tMinuta === undefined) { + return ; + } + + return ( +
+ {/* Cabeçalho */} +
handleOpenForm(null)} + /> + + {/* Tabela */} + + + + + + + {/* Diálogo de confirmação */} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index 823afb8..eb747f7 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -63,7 +63,7 @@ export default function TTBAndamentoServico() { // Aguarda salvar o registro await saveTTBAndamentoServico(formData); - + // Atualiza a lista de dados fetchTTBAndamentoServico(); @@ -73,13 +73,8 @@ export default function TTBAndamentoServico() { * Quando o usuário clica em "remover" na tabela */ const handleConfirmDelete = useCallback((item: TTBAndamentoServicoInterface) => { - - // Define o item atual para remoção setItemToDelete(item); - - // Abre o modal de confirmação openConfirmDialog(); - }, [openConfirmDialog]); /** @@ -90,6 +85,7 @@ export default function TTBAndamentoServico() { // Protege contra null if (!itemToDelete) return; + // Executa o Hook de remoção await deleteTTBAndamentoServico(itemToDelete); diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx new file mode 100644 index 0000000..e535fd8 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensForm.tsx @@ -0,0 +1,127 @@ +'use client'; + +import z from "zod"; +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 { GTBRegimeBensSchema } from "../../_schemas/GTBRegimeBensSchema"; +import { useEffect } from "react"; + +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(GTBRegimeBensSchema), + defaultValues: { + tb_regimebens_id: 0, + descricao: "", + 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 Bens + + + Controle de Regimes de Vens + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campo oculto */} + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.tsx new file mode 100644 index 0000000..364df88 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimebens/GTBRegimeBensTable.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 GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +interface GTBRegimeBensTableProps { + data: GTBRegimeBensInterface[]; + onEdit: (item: GTBRegimeBensInterface, isEditingFormStatus: boolean) => void; + onDelete: (item: GTBRegimeBensInterface, 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 GTBRegimeBensTable({ + data, + onEdit, + onDelete +}: GTBRegimeBensTableProps) { + return ( + + + + # + Situação + Descrição + Ações + + + + + {data.map((item) => ( + + + {item.tb_regimebens_id} + + + + + + + + {item.descricao} + + + + + + + + + + + onEdit(item, true)} + > + + Editar + + + + + onDelete(item, true)} + > + + Remover + + + + + + + ))} + +
+ ); +} 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 index 7691325..9a8dc1f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_regimecomunhao/GTBRegimeComunhaoForm.tsx @@ -28,6 +28,8 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { GTBRegimeComunhaoSchema } from "../../_schemas/GTBRegimeComunhaoSchema"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook"; type FormValues = z.infer; @@ -39,6 +41,9 @@ interface Props { } export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: Props) { + + const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook(); + // Inicializa o react-hook-form com schema zod const form = useForm({ resolver: zodResolver(GTBRegimeComunhaoSchema), @@ -53,7 +58,18 @@ export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: // Atualiza o formulário quando recebe dados para edição useEffect(() => { - if (data) form.reset(data); + + const loadData = async () => { + // Se existir dados, reseta o formulário com os dados informados + if (data) form.reset(data); + + // Aguarda a busca terminar + await fetchGTBRegimeBens(); + }; + + // Dispara a função + loadData(); + }, [data, form]); return ( @@ -106,6 +122,36 @@ export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: )} /> + {/* Tipo */} + ( + + Tipo + + + + )} + /> + {/* Situação */} ; @@ -48,7 +47,7 @@ export default function TCensecNaturezaLitigioForm({ const form = useForm({ resolver: zodResolver(TCensecNaturezaLitigioSchema), defaultValues: { - censec_naturezaltigio_id: 0, + censec_naturezalitigio_id: 0, descricao: "", situacao: "A" } @@ -120,7 +119,7 @@ export default function TCensecNaturezaLitigioForm({ {/* Campo oculto */} - + diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx index 9b6edaf..02f96a5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censecnaturezalitigio/TCensecNaturezaLitigioTable.tsx @@ -67,11 +67,11 @@ export default function TCensecNaturezaLitigioTable({ {data.map((item) => ( - {item.censec_naturezaltigio_id} + {item.censec_naturezalitigio_id} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx new file mode 100644 index 0000000..ccb311c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx @@ -0,0 +1,155 @@ +'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 MainEditor from '@/components/MainEditor'; +import { TMinutaInterface } from '../../_interfaces/TMinutaInterface'; +import { TMinutaSchema } from '../../_schemas/TMinutaSchema'; + +type FormValues = z.infer; + +interface TMinutaFormProps { + isOpen: boolean; + data: FormValues | null; + onClose: (item: null, isFormStatus: boolean) => void; + onSave: (data: FormValues) => void; +} + +export default function TMinutaForm({ + isOpen, + data, + onClose, + onSave +}: TMinutaFormProps) { + + const form = useForm({ + resolver: zodResolver(TMinutaSchema), + defaultValues: { + t_minuta_id: 0, + natureza_id: undefined, + descricao: '', + situacao: 'A', + texto: '', + } + }); + + useEffect(() => { + if (data) form.reset(data); + }, [data, form]); + + return ( + { + if (!open) onClose(null, false); + }} + > + {/* tamanho maior para comportar o editor */} + + Minuta + + Crie ou edite uma minuta de ato notarial. + + + +
+ + + {/* Descrição */} + ( + + Descrição + + + + + + )} + /> + + {/* Situação */} + ( +
+ field.onChange(checked ? "A" : "I")} + /> + +
+ )} + /> + + {/* Editor de Texto */} + ( +
+ + {form.formState.errors.texto && ( +

+ {form.formState.errors.texto.message} +

+ )} +
+ )} + /> + + {/* Rodapé do Dialog */} + + + + + + + + {/* Campos ocultos */} + + + + + +
+
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaTable.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaTable.tsx new file mode 100644 index 0000000..d7fabf9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaTable.tsx @@ -0,0 +1,97 @@ +'use client'; + +import Link from "next/link"; +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 { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; + +interface TMinutaTableProps { + data: TMinutaInterface[]; + onEdit: (item: TMinutaInterface, isEditing: boolean) => void; + onDelete: (item: TMinutaInterface, isEditing: boolean) => void; +} + +/** + * Renderiza o badge de situação + */ +function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) { + const isActive = situacao === "A"; + + const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm mr-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 TMinutaTable({ + data, +}: TMinutaTableProps) { + return ( + + + + # + Situação + Descrição + + + + + {data.length === 0 ? ( + + + Nenhuma minuta encontrada. + + + ) : ( + data.map((item) => ( + + + {item.t_minuta_id} + + + + + + + {item.descricao} + + + + + + )) + )} + +
+ ); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts index 807e864..928f9ff 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts @@ -2,7 +2,7 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; import BairroMockDeDados from "./mockBairro"; -const useMock = true +const useMock = false export default async function GTBBairroIndexData() { if (useMock) { diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts new file mode 100644 index 0000000..c7dda24 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensIndexData.ts @@ -0,0 +1,13 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBRegimeBensIndexData() { + + const api = new API(); + + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_regimebens/` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts new file mode 100644 index 0000000..ebbb985 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export default async function GTBRegimeBensRemoveData(data: GTBRegimeBensInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts new file mode 100644 index 0000000..7bf3c83 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts @@ -0,0 +1,16 @@ +import API from "@/services/api/Api"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function GTBRegimeBensSaveData(data: GTBRegimeBensInterface) { + + const isUpdate = Boolean(data.tb_regimebens_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id || ''}`, + body: data + }); +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts index 227b30b..a9fa5ae 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBTipoLogradouro/GTBTipoLogradouroIndexData.ts @@ -2,7 +2,7 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; import TipoLogradouroMockDeDados from "./mockTipoLogradouro"; -const useMock = true +const useMock = false export default async function GTBTipoLogradouroIndexData() { if (useMock) { diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts index f9fd91a..4dd3d24 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData.ts @@ -2,7 +2,7 @@ import API from "@/services/api/Api"; import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -export default async function GTBRegimeComunhaoIndexData(): Promise { +export default async function GTBRegimeComunhaoIndexData() { const api = new API(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts index 96d722f..806f75f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioIndexData.ts @@ -2,9 +2,10 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; import CensecNaturezaLitigioMockDeDados from "./mockCensecNaturezaLitigio"; -const useMock = true +const useMock = false export default async function TCensecNaturezaLitigioIndexData() { + if (useMock) { return await CensecNaturezaLitigioMockDeDados(); } @@ -13,7 +14,7 @@ export default async function TCensecNaturezaLitigioIndexData() { try { const dados = await api.send({ method: Methods.GET, - endpoint: `administrativo/t_censec_natureza_litigio/` + endpoint: `administrativo/t_censec_naturezalitigio/` }); return dados } catch (error) { diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts index b8dfa54..c12b863 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData.ts @@ -6,9 +6,11 @@ export default async function TCensecNaturezaLitigioRemoveData(data: TCensecNatu const api = new API(); + console.log(typeof(data.censec_naturezalitigio_id)) + return await api.send({ method: Methods.DELETE, - endpoint: `administrativo/t_censec_natureza_litigio/${data.censec_naturezaltigio_id}` + endpoint: `administrativo/t_censec_naturezalitigio/${data.censec_naturezalitigio_id}` }); } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts index 0f33808..8e2688b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioSaveData.ts @@ -4,13 +4,11 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum"; export default async function TCensecNaturezaLitigioTipoSaveData(data: TCensecNaturezaLitigioInterface) { - const isUpdate = Boolean(data.censec_naturezaltigio_id); - const api = new API(); return await api.send({ - method: isUpdate ? Methods.PUT : Methods.POST, - endpoint: `administrativo/t_censec_natureza_litigio/${data.censec_naturezaltigio_id || ''}`, + method: data.censec_naturezalitigio_id ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_censec_naturezalitigio/${data.censec_naturezalitigio_id ? data.censec_naturezalitigio_id : ''}`, body: data }); diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts index 93c6c7c..ed360af 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensecNaturezaLitigio/mockCensecNaturezaLitigio.ts @@ -4,107 +4,107 @@ export default async function CensecNaturezaLitigioMockDeDados() { message: 'Dados localizados', data: [ { - censec_naturezaltigio_id: 1.00, + censec_naturezaltigio_id: 1, descricao: "Bancário", situacao: "A" }, { - censec_naturezaltigio_id: 2.00, + censec_naturezaltigio_id: 2, descricao: "Concessionária de Água", situacao: "A" }, { - censec_naturezaltigio_id: 3.00, + censec_naturezaltigio_id: 3, descricao: "Concessionária de Gás", situacao: "A" }, { - censec_naturezaltigio_id: 4.00, + censec_naturezaltigio_id: 4, descricao: "Concessionária de Luz", situacao: "A" }, { - censec_naturezaltigio_id: 5.00, + censec_naturezaltigio_id: 5, descricao: "Consumidor", situacao: "A" }, { - censec_naturezaltigio_id: 6.00, + censec_naturezaltigio_id: 6, descricao: "Contrato", situacao: "A" }, { - censec_naturezaltigio_id: 7.00, + censec_naturezaltigio_id: 7, descricao: "Empresarial", situacao: "A" }, { - censec_naturezaltigio_id: 8.00, + censec_naturezaltigio_id: 8, descricao: "Família", situacao: "A" }, { - censec_naturezaltigio_id: 9.00, + censec_naturezaltigio_id: 9, descricao: "Locação", situacao: "A" }, { - censec_naturezaltigio_id: 10.00, + censec_naturezaltigio_id: 10, descricao: "Mobiliário", situacao: "A" }, { - censec_naturezaltigio_id: 11.00, + censec_naturezaltigio_id: 11, descricao: "Previdência", situacao: "A" }, { - censec_naturezaltigio_id: 12.00, + censec_naturezaltigio_id: 12, descricao: "Saúde", situacao: "A" }, { - censec_naturezaltigio_id: 13.00, + censec_naturezaltigio_id: 13, descricao: "Seguro", situacao: "A" }, { - censec_naturezaltigio_id: 14.00, + censec_naturezaltigio_id: 14, descricao: "Serviço Público", situacao: "A" }, { - censec_naturezaltigio_id: 15.00, + censec_naturezaltigio_id: 15, descricao: "Sucessões", situacao: "A" }, { - censec_naturezaltigio_id: 16.00, + censec_naturezaltigio_id: 16, descricao: "Telefonia", situacao: "A" }, { - censec_naturezaltigio_id: 17.00, + censec_naturezaltigio_id: 17, descricao: "Transporte", situacao: "A" }, { - censec_naturezaltigio_id: 18.00, + censec_naturezaltigio_id: 18, descricao: "Transporte - Avião", situacao: "A" }, { - censec_naturezaltigio_id: 19.00, + censec_naturezaltigio_id: 19, descricao: "Transporte - Barco", situacao: "A" }, { - censec_naturezaltigio_id: 20.00, + censec_naturezaltigio_id: 20, descricao: "Transporte Metrô", situacao: "A" }, { - censec_naturezaltigio_id: 21.00, + censec_naturezaltigio_id: 21, descricao: "Transporte - Ônibus", situacao: "A" } diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/MinutaTexto.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/MinutaTexto.ts new file mode 100644 index 0000000..24e851f --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/MinutaTexto.ts @@ -0,0 +1,81 @@ +export const textoEscrituraCompraEVenda = ` +

ESCRITURA PÚBLICA DE COMPRA E VENDA

+ +

Saibam quantos este público instrumento virem que, aos [[dia]] dias do mês de [[mes]] do ano de [[ano]], nesta cidade de [[cidade]], Estado de [[estado]], neste Tabelionato de Notas, perante mim, [[tabeliao]], Tabelião de Notas, compareceram como partes entre si, de um lado como VENDEDOR(ES):

+ +

[[nome_completo_vendedor]], [[nacionalidade_vendedor]], [[estado_civil_vendedor]], [[profissao_vendedor]], portador da cédula de identidade RG nº [[rg_vendedor]] e inscrito no CPF/MF sob o nº [[cpf_vendedor]], residente e domiciliado à [[endereco_vendedor]];

+ +

E de outro lado como COMPRADOR(ES):

+ +

[[nome_completo_comprador]], [[nacionalidade_comprador]], [[estado_civil_comprador]], [[profissao_comprador]], portador da cédula de identidade RG nº [[rg_comprador]] e inscrito no CPF/MF sob o nº [[cpf_comprador]], residente e domiciliado à [[endereco_comprador]];

+ +

Entre as partes acima identificadas e qualificadas, justas e contratadas, foi ajustada, e por este público instrumento, lavrado na forma da lei, têm como certo e contratado a presente ESCRITURA PÚBLICA DE COMPRA E VENDA do imóvel situado à [[endereco_imovel]], com área de [[area_imovel]]m², registrado sob matrícula nº [[matricula_imovel]], no [[cartorio_registro]] Registro de Imóveis desta cidade.

+ +

O preço certo e ajustado para a presente transação é de R$ [[valor_venda]] ([[valor_extenso]]), que o(s) comprador(es) declara(m) ter pago ao(s) vendedor(es), neste ato, em moeda corrente nacional, dando-lhe(s) plena, geral e irrevogável quitação.

+ +

Assim, justos e contratados, requerem seja lavrada a presente escritura, que lida e achada conforme, vai assinada pelas partes e por mim, [[tabeliao]], que a subscrevo.

+ +

Dou fé.

+`; + +export const textoEscrituraPartilhaAmigavel = ` +

ESCRITURA PÚBLICA DE PARTILHA AMIGÁVEL

+ +

Saibam quantos este público instrumento virem que, aos [[dia]] dias do mês de [[mes]] do ano de [[ano]], nesta cidade de [[cidade]], Estado de [[estado]], neste Tabelionato de Notas, perante mim, [[tabeliao]], Tabelião de Notas, compareceram como partes entre si, de um lado como HERDEIROS(AS):

+ +

[[nome_herdeiro_1]], [[nacionalidade_herdeiro_1]], [[estado_civil_herdeiro_1]], [[profissao_herdeiro_1]], portador(a) do RG nº [[rg_herdeiro_1]] e CPF nº [[cpf_herdeiro_1]], residente e domiciliado(a) à [[endereco_herdeiro_1]];

+ +

[[nome_herdeiro_2]], [[nacionalidade_herdeiro_2]], [[estado_civil_herdeiro_2]], [[profissao_herdeiro_2]], portador(a) do RG nº [[rg_herdeiro_2]] e CPF nº [[cpf_herdeiro_2]], residente e domiciliado(a) à [[endereco_herdeiro_2]];

+ +

e assim por diante, se houver outros herdeiros.

+ +

Declararam os presentes que são únicos e legítimos herdeiros do(a) falecido(a) [[nome_falecido]], falecido(a) em [[data_obito]], na cidade de [[cidade_obito]], conforme certidão de óbito lavrada sob o nº [[numero_certidao_obito]], e que, por meio desta escritura, realizam entre si a PARTILHA AMIGÁVEL dos bens deixados pelo(a) de cujus, na forma seguinte:

+ +

Relação dos bens:

+ +
    +
  • [[descricao_bem_1]] - avaliado em R$ [[valor_bem_1]];
  • +
  • [[descricao_bem_2]] - avaliado em R$ [[valor_bem_2]];
  • +
  • ... (outros bens, se houver)
  • +
+ +

Partilha:

+ +
    +
  • Ao(à) herdeiro(a) [[nome_herdeiro_1]] caberá o(s) bem(ns): [[bens_herdeiro_1]];
  • +
  • Ao(à) herdeiro(a) [[nome_herdeiro_2]] caberá o(s) bem(ns): [[bens_herdeiro_2]];
  • +
  • ... (demais partilhas, se houver)
  • +
+ +

As partes declaram que a partilha foi realizada de comum acordo, de forma livre e consciente, não havendo vícios de consentimento, nem litígios entre os herdeiros.

+ +

Requerem que esta escritura seja registrada onde necessário, e produza todos os efeitos legais.

+ +

E por estarem assim justos e contratados, firmam o presente instrumento, que lido e achado conforme, vai por todos assinado e por mim, [[tabeliao]], que o lavrei e subscrevo.

+ +

Dou fé.

+`; + +export const textoProcuracaoAdJudicia = ` +

PROCURAÇÃO AD JUDICIA

+ +

Outorgante: [[nome_outorgante]], [[nacionalidade_outorgante]], [[estado_civil_outorgante]], [[profissao_outorgante]], portador(a) do RG nº [[rg_outorgante]] e CPF nº [[cpf_outorgante]], residente e domiciliado(a) à [[endereco_outorgante]].

+ +

Outorgado: [[nome_outorgado]], advogado inscrito na OAB/[[uf_oab]] sob o nº [[numero_oab]], com escritório profissional situado à [[endereco_escritorio]].

+ +

Por este instrumento particular, o outorgante nomeia e constitui seu bastante procurador o(a) outorgado(a), para o foro em geral, com poderes para o ajuizamento, defesa, acompanhamento, transação, conciliação, desistência, interposição e recebimento de recursos, substabelecer no todo ou em parte, e praticar todos os demais atos necessários ao fiel cumprimento deste mandato, especialmente para atuar em processos judiciais e administrativos, em todas as instâncias e tribunais, federais ou estaduais, inclusive para firmar compromisso, receber citações, intimações e notificações, assinar petições, requerimentos e demais documentos, e praticar todos os atos necessários para a defesa dos direitos do outorgante.

+ +

Esta procuração é válida por [[validade]] meses a contar da data de sua assinatura.

+ +

E, por assim estar justo e acordado, firma o presente instrumento em [[cidade]], aos [[dia]] dias do mês de [[mes]] do ano de [[ano]].

+ +

_______________________________

+

[[nome_outorgante]]

+ +

Testemunhas:

+

1. ___________________________

+

Nome: [[nome_testemunha_1]] - CPF: [[cpf_testemunha_1]]

+ +

2. ___________________________

+

Nome: [[nome_testemunha_2]] - CPF: [[cpf_testemunha_2]]

+`; diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndex.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndex.ts new file mode 100644 index 0000000..943191c --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndex.ts @@ -0,0 +1,24 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { MinutaMockDeDadosPorId } from "./mockMinuta"; + +const useMock = true; + +export default async function TMinutaIndex(t_minuta_id: number) { + if (useMock) { + console.log(await MinutaMockDeDadosPorId(t_minuta_id)); // Retorna o dado específico do mock + return await MinutaMockDeDadosPorId(t_minuta_id); // Retorna o dado específico do mock + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_minuta/${t_minuta_id}` + }); + return dados; + } catch (error) { + console.log(error); + return error; + } +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndexData.ts new file mode 100644 index 0000000..41908ad --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaIndexData.ts @@ -0,0 +1,23 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import MinutaMockDeDados from "./mockMinuta"; + +const useMock = true; + +export default async function TMinutaIndexData() { + if (useMock) { + return await MinutaMockDeDados(); // Retorna todos os dados mockados + } + + const api = new API(); + try { + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_minuta/` + }); + return dados; + } catch (error) { + console.log(error); + return error; + } +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaRemoveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaRemoveData.ts new file mode 100644 index 0000000..8870452 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaRemoveData.ts @@ -0,0 +1,14 @@ +import API from "@/services/api/Api"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TMinutaRemoveData(data: TMinutaInterface) { + + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_minuta/${data.t_minuta_id}` + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaSaveData.ts new file mode 100644 index 0000000..c75171b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/TMinutaSaveData.ts @@ -0,0 +1,17 @@ +import API from "@/services/api/Api"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; + +export default async function TMinutaSaveData(data: TMinutaInterface) { + + const isUpdate = Boolean(data.t_minuta_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_minuta/${data.t_minuta_id || ''}`, + body: data + }); + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/mockMinuta.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/mockMinuta.ts new file mode 100644 index 0000000..88ae986 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TMinuta/mockMinuta.ts @@ -0,0 +1,41 @@ +// Função para pegar todos os dados (usada em TMinutaIndexData) +import { textoEscrituraCompraEVenda, textoEscrituraPartilhaAmigavel, textoProcuracaoAdJudicia } from "./MinutaTexto"; + +export default async function MinutaMockDeDados() { + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: [ + { + t_minuta_id: 1, + natureza_id: 1, + descricao: 'Escritura de Compra e Venda', + situacao: 'A', + texto: textoEscrituraCompraEVenda, + }, + { + t_minuta_id: 2, + natureza_id: 1, + descricao: 'Escritura de Partilha Amigável', + situacao: 'A', + texto: textoEscrituraPartilhaAmigavel, + }, + { + t_minuta_id: 3, + natureza_id: 2, + descricao: 'Procuração Ad Judicia', + situacao: 'A', + texto: textoProcuracaoAdJudicia, + }, + ] + }); +} + +export async function MinutaMockDeDadosPorId(t_minuta_id: number) { + const allData = await MinutaMockDeDados(); + return Promise.resolve({ + status: 200, + message: 'Dados localizados', + data: allData.data.find((item) => item.t_minuta_id === t_minuta_id) || null + }); +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts new file mode 100644 index 0000000..9294db5 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensReadHook.ts @@ -0,0 +1,25 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import GTBRegimeBensIndexService from "../../_services/g_tb_regimebens/GTBRegimeBensIndexService"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export const useGTBRegimeBensReadHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeBens, setGTBRegimeBens] = useState([]); + + const fetchGTBRegimeBens = async () => { + + const response = await GTBRegimeBensIndexService(); + + setGTBRegimeBens(response.data); + + setResponse(response); + + return response; + + } + + return { gTBRegimeBens, fetchGTBRegimeBens } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts new file mode 100644 index 0000000..748313e --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import GTBRegimeBensRemoveData from "../../_data/GTBRegimeBens/GTBRegimeBensRemoveData"; + +export const useGTBRegimeBensRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeGTBRegimeComunhao = async (data: GTBRegimeBensInterface) => { + + const response = await GTBRegimeBensRemoveData(data); + + setResponse(response); + + } + + return { removeGTBRegimeComunhao } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts new file mode 100644 index 0000000..fa7b3f9 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts @@ -0,0 +1,33 @@ +import { useState } from "react"; +import { useResponse } from "@/app/_response/ResponseContext" +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import GTBRegimeBensSaveService from "../../_services/g_tb_regimebens/GTBRegimeBensSaveService"; + +export const useGTBRegimeBensSaveHook = () => { + + const { setResponse } = useResponse(); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveGTBRegimeComunhao = async (data: GTBRegimeBensInterface) => { + + const response = await GTBRegimeBensSaveService(data); + + // Guardar os dados localizados + setGTBRegimeComunhao(response.data); + + // Manda a resposta para o verificador de resposta + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { gTBRegimeComunhao, saveGTBRegimeComunhao } + +} \ 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 index 73de8d0..1d1ff3a 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimecomunhao/useGTBRegimeComunhaoReadHook.ts @@ -6,7 +6,7 @@ import GTBRegimeComunhaoIndexService from "../../_services/g_tb_regimecomunhao/G export const useGTBRegimeComunhaoReadHook = () => { const { setResponse } = useResponse(); - const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState([]); const fetchGTBRegimeComunhao = async () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts index 3e59dfa..b68ba6f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioReadHook.ts @@ -15,6 +15,8 @@ export const useTCensecNaturezaLitigioReadHook = () => { setTCensecNaturezaLitigio(response.data); + console.log(response) + setResponse(response); } catch (error) { console.log(error) diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts index a350a84..b550167 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts @@ -1,19 +1,26 @@ import { useResponse } from "@/app/_response/ResponseContext" import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface"; -import TCensecNaturezaLitigioRemoveService from "../../_services/t_censecnaturezalitigio/TCensecNaturezaLitigioRemoveService"; +import { useState } from "react"; +import TCensecNaturezaLitigioRemoveData from "../../_data/TCensecNaturezaLitigio/TCensecNaturezaLitigioRemoveData"; export const useTCensecNaturezaLitigioRemoveHook = () => { const { setResponse } = useResponse(); + const [ tCensecNaturezaLitigio, setTCensecNaturezaLitigio ] = useState() + const removeTCensecNaturezaLitigio = async (data: TCensecNaturezaLitigioInterface) => { - const response = await TCensecNaturezaLitigioRemoveService(data); + console.log(data.censec_naturezaltigio_id) + + const response = await TCensecNaturezaLitigioRemoveData(data); + + setTCensecNaturezaLitigio(data) setResponse(response); } - return { removeTCensecNaturezaLitigio } + return { tCensecNaturezaLitigio, removeTCensecNaturezaLitigio } } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaIndexHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaIndexHook.ts new file mode 100644 index 0000000..2354ec6 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaIndexHook.ts @@ -0,0 +1,27 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import TMinutaIndex from "../../_services/t_minuta/TMinutaIndex"; + +export const useTMinutaIndexHook = () => { + + const { setResponse } = useResponse(); + const [tMinuta, setTMinuta] = useState([]); + + const fetchTMinuta = async () => { + + try { + const response = await TMinutaIndex(); + + setTMinuta(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { tMinuta, fetchTMinuta } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaReadHook.ts new file mode 100644 index 0000000..dd8de75 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaReadHook.ts @@ -0,0 +1,28 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import TMinutaIndexService from "../../_services/t_minuta/TMinutaIndexService"; + +export const useTMinutaReadHook = () => { + + const { setResponse } = useResponse(); + const [tMinuta, setTMinuta] = useState(); + + const fetchTMinuta = async (tMinuta: TMinutaInterface) => { + + try { + const response = await TMinutaIndexService(tMinuta.t_minuta_id); + console.log("read hook",response.data) + + setTMinuta(response.data); + + setResponse(response); + } catch (error) { + console.log(error) + } + + } + + return { tMinuta, fetchTMinuta } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaRemoveHook.ts new file mode 100644 index 0000000..240a2a4 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaRemoveHook.ts @@ -0,0 +1,19 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import TMinutaRemoveService from "../../_services/t_minuta/TMinutaRemoveService"; + +export const useTMinutaRemoveHook = () => { + + const { setResponse } = useResponse(); + + const removeTMinuta = async (data: TMinutaInterface) => { + + const response = await TMinutaRemoveService(data); + + setResponse(response); + + } + + return { removeTMinuta } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaSaveHook.ts new file mode 100644 index 0000000..d1a817a --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_minuta/useTMinutaSaveHook.ts @@ -0,0 +1,31 @@ +import { useResponse } from "@/app/_response/ResponseContext" +import { useState } from "react"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; +import TMinutaSaveService from "../../_services/t_minuta/TMinutaSaveService"; + +export const useTMinutaSaveHook = () => { + + const { setResponse } = useResponse(); + const [tMinuta, setTMinuta] = useState(); + // controla se o formulário está aberto ou fechado + const [isOpen, setIsOpen] = useState(false); + + const saveTMinuta = async (data: any) => { + + const response = await TMinutaSaveService(data); + + setTMinuta(response.data); + + setResponse(response); + + // Fecha o formulário automaticamente após salvar + setIsOpen(false); + + // Retorna os dados imediatamente + return response; + + } + + return { tMinuta, saveTMinuta } + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts index a1b0ac1..bc0d99c 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoReadHook.ts @@ -15,6 +15,8 @@ export const useTTBAndamentoServicoReadHook = () => { const response = await TTBAndamentoServicoIndexData(); + console.log(response) + // Armazena os dados consultados setTTBAndamentosServicos(response.data); diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts new file mode 100644 index 0000000..767bc50 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBRegimeBensInterface.ts @@ -0,0 +1,6 @@ + +export default interface GTBRegimeBensInterface { + tb_regimebens_id?: number, + descricao: string, + situacao: string, +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts index d3f471c..5190b85 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TCensecNaturezaLitigioInterface.ts @@ -1,5 +1,5 @@ export interface TCensecNaturezaLitigioInterface { - censec_naturezaltigio_id: number; + censec_naturezalitigio_id?: number; descricao: string; situacao: 'A' | 'I'; } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/TMinutaInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TMinutaInterface.ts new file mode 100644 index 0000000..8c3ec07 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/TMinutaInterface.ts @@ -0,0 +1,7 @@ +export interface TMinutaInterface { + t_minuta_id: number; + natureza_id: number; + descricao: string; + situacao: 'A' | 'I'; + texto: string; +} diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts new file mode 100644 index 0000000..49637f0 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBRegimeBensSchema.ts @@ -0,0 +1,7 @@ +import z from "zod"; + +export const GTBRegimeBensSchema = z.object({ + tb_regimebens_id: z.number().optional(), + descricao: z.string(), + situacao: z.string(), +}); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts index 8815d19..b4a293d 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TCensecNaturezaLitigioSchema.ts @@ -1,7 +1,7 @@ import { z } from 'zod'; export const TCensecNaturezaLitigioSchema = z.object({ - censec_naturezaltigio_id: z.number(), + censec_naturezalitigio_id: z.number().optional(), descricao: z.string(), situacao: z.enum(['A', 'I']), }); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts new file mode 100644 index 0000000..59ca86b --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts @@ -0,0 +1,8 @@ +import { z } from "zod"; + +export const TMinutaSchema = z.object({ + natureza_id: z.number().int(), + descricao: z.string().min(1, "Descrição é obrigatória"), + situacao: z.enum(["A", "I"]), + texto: z.string().min(1, "Texto é obrigatório"), +}); diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts new file mode 100644 index 0000000..b57f1f1 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensIndexService.ts @@ -0,0 +1,9 @@ +import GTBRegimeBensIndexData from "../../_data/GTBRegimeBens/GTBRegimeBensIndexData"; + +export default async function GTBRegimeBensIndexService() { + + const response = await GTBRegimeBensIndexData(); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts new file mode 100644 index 0000000..b194991 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensRemoveService.ts @@ -0,0 +1,10 @@ +import GTBRegimeBensRemoveData from "../../_data/GTBRegimeBens/GTBRegimeBensRemoveData"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export default async function GTBRegimeBensRemoveService(data: GTBRegimeBensInterface) { + + const response = await GTBRegimeBensRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts new file mode 100644 index 0000000..65e80c0 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts @@ -0,0 +1,10 @@ +import GTBRegimeBensSaveData from "../../_data/GTBRegimeBens/GTBRegimeBensSaveData"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; + +export default async function GTBRegimeBensSaveService(data: GTBRegimeBensInterface) { + + const response = await GTBRegimeBensSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndex.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndex.ts new file mode 100644 index 0000000..5038a30 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndex.ts @@ -0,0 +1,13 @@ +import TMinutaIndexData from "../../_data/TMinuta/TMinutaIndexData"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; + +export default async function TMinutaIndex() { + + try { + const response = await TMinutaIndexData(); + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndexService.ts new file mode 100644 index 0000000..00fe3d2 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaIndexService.ts @@ -0,0 +1,21 @@ +import TMinutaIndex from "../../_data/TMinuta/TMinutaIndex"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; + +export default async function TMinutaIndexService(t_minuta_id: number) { + + if (t_minuta_id <= 0) { + return { + 'code': 400, + 'message': 'Usuário informado inválido', + } + } + + try { + const response = await TMinutaIndex(t_minuta_id); + console.log("service",response) + return response; + } catch (error) { + console.log(error) + return error + } +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaRemoveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaRemoveService.ts new file mode 100644 index 0000000..12ed281 --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaRemoveService.ts @@ -0,0 +1,10 @@ +import TMinutaRemoveData from "../../_data/TMinuta/TMinutaRemoveData"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; + +export default async function TMinutaRemoveService(data: TMinutaInterface) { + + const response = await TMinutaRemoveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaSaveService.ts new file mode 100644 index 0000000..5dfc53f --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_minuta/TMinutaSaveService.ts @@ -0,0 +1,10 @@ +import TMinutaSaveData from "../../_data/TMinuta/TMinutaSaveData"; +import { TMinutaInterface } from "../../_interfaces/TMinutaInterface"; + +export default async function TMinutaSaveService(data: TMinutaInterface) { + + const response = await TMinutaSaveData(data); + + return response; + +} \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx new file mode 100644 index 0000000..3aa0daa --- /dev/null +++ b/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx @@ -0,0 +1,73 @@ +import { FileText, Heart, Briefcase, Scale, Link as LinkIcon, MapPin } from "lucide-react"; +import { Card, CardContent } from "@/components/ui/card"; +import Link from "next/link"; + +export default function CadastrosPage() { + + const items = [ + { + title: 'Documentos', + description: 'Gerencie os tipos de documentos aceitos e suas configurações no sistema.', + icon: FileText, + }, + { + title: 'Estado Civil', + description: 'Cadastre e mantenha os diferentes estados civis utilizados nos registros.', + icon: Heart, + }, + { + title: 'Profissão', + description: 'Gerencie a lista de profissões para utilização em cadastros e registros.', + icon: Briefcase, + }, + { + title: 'Regime de Comunhão', + description: 'Defina os regimes de comunhão aplicáveis em matrimônios e registros civis.', + icon: Scale, + }, + { + title: 'Vínculo de Sinal Público', + description: 'Controle e cadastre vínculos relacionados a sinais públicos para autenticações.', + icon: LinkIcon, + }, + { + title: 'Municípios', + description: 'Gerencie a base de municípios para utilização em endereços e cadastros.', + icon: MapPin, + }, + ]; + + return ( +
+
+
+

+ Complementos de Cadastro pessoal +

+

+ Gerencie os cadastros relacionados a regimes, como estado civil, regime de comunhão e outras informações complementares necessárias para o registro de pessoas. +

+
+
+
+ {items.map((item, key) => ( + + + + + + +

+ {item.title} +

+

+ {item.description} +

+
+ +
+ ))} +
+
+ ); +} \ No newline at end of file diff --git a/src/app/_components/structure/Header.tsx b/src/app/_components/structure/Header.tsx index c8c02e6..2fb7a55 100644 --- a/src/app/_components/structure/Header.tsx +++ b/src/app/_components/structure/Header.tsx @@ -1,4 +1,5 @@ import { Button } from "@/components/ui/button"; +import Link from "next/link"; import { PlusIcon } from "lucide-react"; interface HeaderProps { @@ -22,9 +23,10 @@ export default function Header({ title, description, buttonText, buttonAction }: {description}

-
diff --git a/src/app/_response/ResponseContext.tsx b/src/app/_response/ResponseContext.tsx index e4bb515..b387176 100644 --- a/src/app/_response/ResponseContext.tsx +++ b/src/app/_response/ResponseContext.tsx @@ -3,9 +3,11 @@ import React, { createContext, useContext, useState, ReactNode } from 'react'; interface ResponseState { - message: string; - type: 'toast' | 'modal' | 'alert' | null; - status: number; + message?: string; + type?: 'toast' | 'modal' | 'alert' | null; + status?: number; + error?: string; + detail?: string; } interface ResponseContextProps { diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 4b62195..033c585 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -24,7 +24,7 @@ export default function Response() { break; case 422: - toast.danger(response.error, { + toast.error(response.error, { description: response.detail }); break; diff --git a/src/components/MainEditor.tsx b/src/components/MainEditor.tsx new file mode 100644 index 0000000..ab19f59 --- /dev/null +++ b/src/components/MainEditor.tsx @@ -0,0 +1,132 @@ +import React from 'react'; +import { Editor } from '@tinymce/tinymce-react'; + +// 1. Define as propriedades que nosso componente vai receber +interface MainEditorProps { + initialValue: string; + onEditorChange: (content: string) => void; + margins: { + top: string; + bottom: string; + left: string; + right: string; + }; + size: { + width: number; + height: number; + } +} + +const MainEditor: React.FC = ({ initialValue, onEditorChange, margins, size }) => { + + + return ( +
+ { + const customTemplates = [ + { + title: 'Qualificação das Partes (Casamento)', + description: 'Insere o bloco de qualificação para contraentes.', + content: `

QUALIFICAÇÃO DOS CONTRAENTES: Ele, brasileiro, solteiro, maior, [Profissão], portador da CI nº [RG], inscrito no CPF sob o nº [CPF], residente e domiciliado em [Endereço]. Ela, brasileira, solteira, maior, [Profissão], portadora da CI nº [RG], inscrita no CPF sob o nº [CPF], residente e domiciliada em [Endereço].


` + }, + { + title: 'Cláusula de Regime de Bens', + description: 'Cláusula padrão de Comunhão Parcial de Bens.', + content: '

O regime de bens adotado é o da Comunhão Parcial de Bens, nos termos dos artigos 1.658 e seguintes do Código Civil brasileiro.


' + }, + { + title: 'Cláusula de Encerramento (Selo)', + description: 'Texto final com espaço para o selo digital.', + content: '

O referido é verdade e dou fé. Emitida nesta data. Selo Digital de Fiscalização: [Número do Selo]

' + } + ]; + editor.ui.registry.addMenuButton('customTemplates', { + text: 'Modelos', // O texto que aparecerá no botão + fetch: (callback: any) => { + const items = customTemplates.map(template => ({ + type: 'menuitem', + text: template.title, + onAction: () => { + // 3. Ação que acontece ao clicar no item do menu: insere o conteúdo + editor.insertContent(template.content); + } + })); + callback(items); + } + }); + }, + quickbars_selection_toolbar: 'bold italic underline | fontfamily | fontsize | quicklink blockquote | quicklink', + quickbars_insert_toolbar: 'bold italic underline fontfamily fontsize quicklink blockquote quicklink quickimage quicktable hr', + quickbars_image_toolbar: 'alignleft aligncenter alignright | rotateleft rotateright | imageoptions', + fontsize_formats: '4pt 5pt 6pt 7pt 8pt 9pt 10pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 26pt 28pt 30pt 32pt 34pt 36pt', + font_family_formats: ` Times New Roman=Times New Roman, Times, serif; Arial=Arial, Helvetica, sans-serif; Calibri=Calibri, sans-serif; Courier New=Courier New, Courier, monospace; Georgia=Georgia, serif; Verdana=Verdana, Geneva, sans-serif;`, + fullscreen_native: true, + content_style: ` + body { + font-family: 'Times New Roman', Times, serif; + font-size: 12pt; + background: #fff; + margin: ${margins.top}cm ${margins.right}cm ${margins.bottom}cm ${margins.left}cm; + } + .mce-pagebreak { /* Estiliza a linha da quebra de página no editor */ + border-top: 1px dashed #bbb; + width: 100%; + margin-top: 15px; + cursor: default; + } + + .borda-superior { + border-top: 1px solid #000; + padding-top: 5px; + margin-top: 5px; + } + .borda-inferior { + border-bottom: 1px solid #000; + padding-bottom: 5px; + margin-bottom: 5px; + } + ` + }} + /> +
+ ); +}; + +export default MainEditor; \ No newline at end of file diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index dede44c..d0ea716 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -91,7 +91,7 @@ const data = { }, { title: "Profissões", - url: "/cadastros/profissao/", + url: "/cadastros/profissoes/", }, { title: "Regimes", @@ -116,6 +116,22 @@ const data = { { title: "Natureza Litígio (Censec)", url: "/cadastros/censec-natureza-litigio" + }, + { + title: "Pessoas", + url: "/cadastros/pessoas/complementos/", + }, + { + title: "Regimes/Bens", + url: "/cadastros/regime-bens/", + }, + { + title: "Regimes/Comunhão", + url: "/cadastros/regime-comunhao/", + }, + { + title: "Minuta", + url: "/cadastros/minuta/", } ], }, diff --git a/src/components/nav-main.tsx b/src/components/nav-main.tsx index 1d71af1..c7d45b5 100644 --- a/src/components/nav-main.tsx +++ b/src/components/nav-main.tsx @@ -1,6 +1,7 @@ "use client" import { ChevronRight, type LucideIcon } from "lucide-react" +import Link from "next/link"; import { Collapsible, @@ -56,9 +57,9 @@ export function NavMain({ {item.items?.map((subItem) => ( - + {subItem.title} - + ))} diff --git a/src/config/app.json b/src/config/app.json deleted file mode 100644 index d38e8d3..0000000 --- a/src/config/app.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "state": "go", - "api": { - "url": "http://localhost:8000/", - "prefix": "api/v1/", - "content_type": "application/json" - } -} \ No newline at end of file From 4f03c6551754e323c1b7089f8ffe8de1a7fdb47a Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 22 Sep 2025 15:30:51 -0300 Subject: [PATCH 53/56] =?UTF-8?q?[DSAAS-15]=20feat(Handler):=20Cria=20um?= =?UTF-8?q?=20handle=20de=20fun=C3=A7=C3=B5es=20executadas=20de=20forma=20?= =?UTF-8?q?assincrona?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../withClientErrorHandler.ts | 32 +++++++++++++++++++ .../withClientErrorHandlerInterface.ts | 7 ++++ .../_services/g_usuario/GUsuarioLogin.ts | 13 ++++++-- .../GTBRegimeBens/GTBRegimeBensSaveData.ts | 9 ++++-- .../TTBAndamentoServicoSaveData.ts | 8 +++-- .../useGTBRegimeBensSaveHook.ts | 3 +- .../useTTBAndamentoServicoSaveHook.ts | 2 +- .../GTBRegimeBensSaveService.ts | 10 ++++-- src/app/_response/response.tsx | 7 ++++ src/components/login-form.tsx | 12 ++----- 10 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 src/actions/withClientErrorHandler/withClientErrorHandler.ts create mode 100644 src/actions/withClientErrorHandler/withClientErrorHandlerInterface.ts diff --git a/src/actions/withClientErrorHandler/withClientErrorHandler.ts b/src/actions/withClientErrorHandler/withClientErrorHandler.ts new file mode 100644 index 0000000..b7cb4ff --- /dev/null +++ b/src/actions/withClientErrorHandler/withClientErrorHandler.ts @@ -0,0 +1,32 @@ +import withClientErrorHandlerInterface from "./withClientErrorHandlerInterface"; + +/** + * Códigos de erro que começam com 6, são do front entd, na ordem do alfabeto o F de frontend é a sexta letra +*/ +export function withClientErrorHandler Promise>( + action: T +) { + return async (...args: Parameters): Promise => { + + try { + + // Executa a função definida + const data = await action(...args); + + // Retorna exatamente a mesma resposta retornada pela função + return data; + + } catch (error: any) { + + // Retorna o erro de execuçãformatado + return { + status: 600, + message: error?.message || "Erro interno do servidor", + data: error + }; + + } + + }; + +} diff --git a/src/actions/withClientErrorHandler/withClientErrorHandlerInterface.ts b/src/actions/withClientErrorHandler/withClientErrorHandlerInterface.ts new file mode 100644 index 0000000..f27c593 --- /dev/null +++ b/src/actions/withClientErrorHandler/withClientErrorHandlerInterface.ts @@ -0,0 +1,7 @@ +export default interface withClientErrorHandlerInterface { + + status: number; + data?: T; + message?: string; + +} \ No newline at end of file diff --git a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts index 2699a22..b71b1f2 100644 --- a/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts +++ b/src/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin.ts @@ -6,9 +6,11 @@ import { import GUsuarioLoginData from "../../_data/g_usuario/GUsuarioLoginData" import { redirect } from "next/navigation"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function GUsuarioLoginService(form: any) { +async function executeGUsuarioLoginService(form: any) { + // Obtem a resposta da requisição const response = await GUsuarioLoginData(form); // Verifica se localizou o usuário @@ -21,7 +23,10 @@ export default async function GUsuarioLoginService(form: any) { } + // Importação do manipulador de cookies const cookieStore = await cookies(); + + // Cria um novo cookie cookieStore.set("access_token", response.data.token, { httpOnly: true, secure: process.env.NODE_ENV === "production", @@ -30,6 +35,10 @@ export default async function GUsuarioLoginService(form: any) { maxAge: 60 * 60 * 24, }); + // Redireciona para a págian desejada redirect("/usuarios"); -} \ No newline at end of file +} + +// Exporta função encapsulada +export const GUsuarioLoginService = withClientErrorHandler(executeGUsuarioLoginService); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts index 7bf3c83..b469f5b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBRegimeBens/GTBRegimeBensSaveData.ts @@ -1,8 +1,11 @@ import API from "@/services/api/Api"; import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function GTBRegimeBensSaveData(data: GTBRegimeBensInterface) { +async function executeGTBRegimeBensSaveData(data: GTBRegimeBensInterface) { + + throw new Error("Nome e email são obrigatórios"); const isUpdate = Boolean(data.tb_regimebens_id); @@ -13,4 +16,6 @@ export default async function GTBRegimeBensSaveData(data: GTBRegimeBensInterface endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id || ''}`, body: data }); -} \ No newline at end of file +} + +export const GTBRegimeBensSaveData = withClientErrorHandler(executeGTBRegimeBensSaveData); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts index c8ebd33..589ec9b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TTBAndamentoServico/TTBAndamentoServicoSaveData.ts @@ -3,8 +3,9 @@ import API from "@/services/api/Api"; import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function TTBAndamentoServicoSaveData(data: TTBAndamentoServicoInteface) { +async function executeTTBAndamentoServicoSaveData(data: TTBAndamentoServicoInteface) { const api = new API(); @@ -16,4 +17,7 @@ export default async function TTBAndamentoServicoSaveData(data: TTBAndamentoServ return response; -} \ No newline at end of file +} + +// Encapsula a execução da função +export const TTBAndamentoServicoSaveData = withClientErrorHandler(executeTTBAndamentoServicoSaveData); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts index fa7b3f9..4941f94 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_regimebens/useGTBRegimeBensSaveHook.ts @@ -1,12 +1,13 @@ import { useState } from "react"; import { useResponse } from "@/app/_response/ResponseContext" import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; -import GTBRegimeBensSaveService from "../../_services/g_tb_regimebens/GTBRegimeBensSaveService"; +import { GTBRegimeBensSaveService } from "../../_services/g_tb_regimebens/GTBRegimeBensSaveService"; export const useGTBRegimeBensSaveHook = () => { const { setResponse } = useResponse(); const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState(null); + // controla se o formulário está aberto ou fechado const [isOpen, setIsOpen] = useState(false); diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts index 43586da..863b8d1 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_tb_andamentoservico/useTTBAndamentoServicoSaveHook.ts @@ -3,7 +3,7 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface"; -import TTBAndamentoServicoSaveData from "../../_data/TTBAndamentoServico/TTBAndamentoServicoSaveData"; +import { TTBAndamentoServicoSaveData } from "../../_data/TTBAndamentoServico/TTBAndamentoServicoSaveData"; export const useTTBAndamentoServicoSaveHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts index 65e80c0..cf8cefa 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_regimebens/GTBRegimeBensSaveService.ts @@ -1,10 +1,14 @@ -import GTBRegimeBensSaveData from "../../_data/GTBRegimeBens/GTBRegimeBensSaveData"; +import { GTBRegimeBensSaveData } from "../../_data/GTBRegimeBens/GTBRegimeBensSaveData"; import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function GTBRegimeBensSaveService(data: GTBRegimeBensInterface) { +async function executeGTBRegimeBensSaveService(data: GTBRegimeBensInterface) { const response = await GTBRegimeBensSaveData(data); return response; -} \ No newline at end of file +} + +// Executa a função de forma encapsulada +export const GTBRegimeBensSaveService = withClientErrorHandler(executeGTBRegimeBensSaveService); \ No newline at end of file diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 033c585..94c0d0a 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -19,6 +19,7 @@ export default function Response() { useEffect(() => { switch (Number(response?.status)) { + case 201: toast.success(response.message); break; @@ -29,6 +30,12 @@ export default function Response() { }); break; + case 600: + toast.error(response.error, { + description: response.message + }); + break; + default: if (response.status !== 0 && response.status !== 200 && response.status !== 201) { toast.warning(JSON.stringify(response)); diff --git a/src/components/login-form.tsx b/src/components/login-form.tsx index e2b5c6f..c1b7aeb 100644 --- a/src/components/login-form.tsx +++ b/src/components/login-form.tsx @@ -7,7 +7,7 @@ import { Input } from "@/components/ui/input" 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 { GUsuarioLoginService } from "@/app/(protected)/(administrativo)/_services/g_usuario/GUsuarioLogin" import { useForm } from "react-hook-form" import { useState } from "react" import { @@ -37,14 +37,8 @@ export function LoginForm({ className, ...props }: React.ComponentProps<"div">) // 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); - } + await GUsuarioLoginService(values); + setLoading(false); } return ( From 634fe16331b24addd690770c2ee6f4fe6ca5c585 Mon Sep 17 00:00:00 2001 From: keven Date: Mon, 22 Sep 2025 16:55:57 -0300 Subject: [PATCH 54/56] fix(Build): Ajusta partes do sistema para ser possivel realizar a build do mesmo --- .../(g_tb_regimebens)/regime-bens/page.tsx | 12 ++++++------ .../_components/t_minuta/TMinutaForm.tsx | 4 ++-- .../useTCensecNaturezaLitigioRemoveHook.ts | 4 +--- .../cadastros/_schemas/TMinutaSchema.ts | 1 + .../cadastros/pessoas/complementos/page.tsx | 8 ++++---- src/components/app-sidebar.tsx | 6 +++++- src/components/nav-user.tsx | 4 ++-- src/config/app_example.json | 8 ++++++++ src/hooks/auth/useGUsuarioGetJWTHook.ts | 12 ++++++++---- src/interfaces/GUsuarioAuthenticatedInterface.ts | 16 +++++----------- 10 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 src/config/app_example.json diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx index a637e10..a241d19 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_regimebens)/regime-bens/page.tsx @@ -14,7 +14,7 @@ import { useGTBRegimeBensRemoveHook } from "../../_hooks/g_tb_regimebens/useGTBR import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; -import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface"; +import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface"; import Header from "@/app/_components/structure/Header"; export default function TTBAndamentoServico() { @@ -24,11 +24,11 @@ export default function TTBAndamentoServico() { const { removeGTBRegimeComunhao } = useGTBRegimeBensRemoveHook(); // Estados - const [selectedAndamento, setSelectedAndamento] = useState(null); + const [selectedAndamento, setSelectedAndamento] = useState(null); const [isFormOpen, setIsFormOpen] = useState(false); // Estado para saber qual item será deletado - const [itemToDelete, setItemToDelete] = useState(null); + const [itemToDelete, setItemToDelete] = useState(null); /** * Hook do modal de confirmação @@ -43,7 +43,7 @@ export default function TTBAndamentoServico() { /** * Abre o formulário no modo de edição ou criação */ - const handleOpenForm = useCallback((data: GTBRegimeComunhaoInterface | null) => { + const handleOpenForm = useCallback((data: GTBRegimeBensInterface | null) => { setSelectedAndamento(data); setIsFormOpen(true); }, []); @@ -59,7 +59,7 @@ export default function TTBAndamentoServico() { /** * Salva os dados do formulário */ - const handleSave = useCallback(async (formData: GTBRegimeComunhaoInterface) => { + const handleSave = useCallback(async (formData: GTBRegimeBensInterface) => { // Aguarda salvar o registro await saveGTBRegimeComunhao(formData); @@ -72,7 +72,7 @@ export default function TTBAndamentoServico() { /** * Quando o usuário clica em "remover" na tabela */ - const handleConfirmDelete = useCallback((item: GTBRegimeComunhaoInterface) => { + const handleConfirmDelete = useCallback((item: GTBRegimeBensInterface) => { // Define o item atual para remoção setItemToDelete(item); diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx index ccb311c..2a05718 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_minuta/TMinutaForm.tsx @@ -50,7 +50,7 @@ export default function TMinutaForm({ const form = useForm({ resolver: zodResolver(TMinutaSchema), defaultValues: { - t_minuta_id: 0, + minuta_id: 0, natureza_id: undefined, descricao: '', situacao: 'A', @@ -144,7 +144,7 @@ export default function TMinutaForm({ {/* Campos ocultos */} - + diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts index b550167..bbf5cda 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censecnaturezalitigio/useTCensecNaturezaLitigioRemoveHook.ts @@ -7,12 +7,10 @@ export const useTCensecNaturezaLitigioRemoveHook = () => { const { setResponse } = useResponse(); - const [ tCensecNaturezaLitigio, setTCensecNaturezaLitigio ] = useState() + const [tCensecNaturezaLitigio, setTCensecNaturezaLitigio] = useState() const removeTCensecNaturezaLitigio = async (data: TCensecNaturezaLitigioInterface) => { - console.log(data.censec_naturezaltigio_id) - const response = await TCensecNaturezaLitigioRemoveData(data); setTCensecNaturezaLitigio(data) diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts index 59ca86b..7177819 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/TMinutaSchema.ts @@ -1,6 +1,7 @@ import { z } from "zod"; export const TMinutaSchema = z.object({ + minuta_id: z.number().optional(), natureza_id: z.number().int(), descricao: z.string().min(1, "Descrição é obrigatória"), situacao: z.enum(["A", "I"]), diff --git a/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx index 3aa0daa..5dc31bb 100644 --- a/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/pessoas/complementos/page.tsx @@ -51,8 +51,8 @@ export default function CadastrosPage() {
{items.map((item, key) => ( - - + + @@ -64,8 +64,8 @@ export default function CadastrosPage() { {item.description}

- -
+
+ ))}
diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index c73ea68..aa0e027 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -267,7 +267,11 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - + {userAuthenticated?.data ? ( + + ) : ( + "Carregando..." + )} diff --git a/src/components/nav-user.tsx b/src/components/nav-user.tsx index 0db31d3..6b16114 100644 --- a/src/components/nav-user.tsx +++ b/src/components/nav-user.tsx @@ -92,7 +92,7 @@ export function NavUser({ - + @@ -137,7 +137,7 @@ export function NavUser({ - + diff --git a/src/config/app_example.json b/src/config/app_example.json new file mode 100644 index 0000000..d38e8d3 --- /dev/null +++ b/src/config/app_example.json @@ -0,0 +1,8 @@ +{ + "state": "go", + "api": { + "url": "http://localhost:8000/", + "prefix": "api/v1/", + "content_type": "application/json" + } +} \ No newline at end of file diff --git a/src/hooks/auth/useGUsuarioGetJWTHook.ts b/src/hooks/auth/useGUsuarioGetJWTHook.ts index 02d1571..4d60499 100644 --- a/src/hooks/auth/useGUsuarioGetJWTHook.ts +++ b/src/hooks/auth/useGUsuarioGetJWTHook.ts @@ -4,12 +4,13 @@ import { useEffect, useState } from "react"; import { jwtDecode } from "jwt-decode"; import CookiesGet from "../../actions/cookies/CookiesGet"; import GetSigla from "@/actions/text/GetSigla"; +import GUsuarioAuthenticatedInterface from "@/interfaces/GUsuarioAuthenticatedInterface"; interface JwtPayload { id: string; iat: number; exp: number; - data?: string; + data?: GUsuarioAuthenticatedInterface; } export default function useGUsuarioGetJWTHook() { @@ -41,10 +42,13 @@ export default function useGUsuarioGetJWTHook() { if (decoded.data && typeof decoded.data === "string") { // Decodifica os dados enviado via json - decoded.data = JSON.parse(decoded.data); + decoded.data = JSON.parse(decoded.data) - // Gera Sigla para o nome - decoded.data.sigla = GetSigla(decoded.data.nome) + if (decoded.data) { + + // Gera Sigla para o nome + decoded.data.sigla = GetSigla(decoded.data.nome || ""); + }; } diff --git a/src/interfaces/GUsuarioAuthenticatedInterface.ts b/src/interfaces/GUsuarioAuthenticatedInterface.ts index da1f8f3..346c06d 100644 --- a/src/interfaces/GUsuarioAuthenticatedInterface.ts +++ b/src/interfaces/GUsuarioAuthenticatedInterface.ts @@ -1,13 +1,7 @@ export default interface GUsuarioAuthenticatedInterface { - usuario_id?: number, - login?: string, - situacao?: string, - nome_completo?: string, - funcao?: string, - assina?: string, - sigla?: string, - email?: string, - assina_certidao?: string, - foto?: string, - cpf?: string, + usuario_id?: number; + login?: string; + nome?: string; + email?: string; + sigla?: string; } \ No newline at end of file From c7f86522fb27db6a782267fd586c80ed48154ff5 Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 23 Sep 2025 14:14:26 -0300 Subject: [PATCH 55/56] =?UTF-8?q?fix(Review):=20Revis=C3=A3o=20de=20c?= =?UTF-8?q?=C3=B3digo=20para=20refatora=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cadastros/(g_tb_bairro)/bairro/page.tsx | 51 ++++++++++++++++--- .../andamentos/page.tsx | 1 + .../_components/g_tb_bairro/GTBBairroForm.tsx | 17 ++++--- .../_data/GTBBairro/GTBBairroIndexData.ts | 24 +++------ .../g_tb_bairro/useGTBBairroReadHook.ts | 19 ++++--- .../g_tb_bairro/useGTBBairroSaveHook.ts | 1 + .../_interfaces/GTBBairroInterface.ts | 4 +- .../cadastros/_schemas/GTBBairroSchema.ts | 7 +-- .../g_tb_bairro/GTBBairroIndexService.ts | 10 ++-- .../g_tb_bairro/GTBBairroSaveService.ts | 2 - .../loadingButton/LoadingButton.tsx | 2 +- src/app/_components/structure/Header.tsx | 8 ++- src/app/_response/response.tsx | 6 +++ src/enums/SituacoesEnum.ts | 6 +++ 14 files changed, 100 insertions(+), 58 deletions(-) create mode 100644 src/enums/SituacoesEnum.ts diff --git a/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx index 841f229..4cf949b 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(g_tb_bairro)/bairro/page.tsx @@ -3,6 +3,7 @@ import { useEffect, useState, useCallback } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog"; +import { useResponse } from "@/app/_response/ResponseContext" import Header from "@/app/_components/structure/Header"; import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog"; @@ -15,15 +16,22 @@ import { useGTBBairroSaveHook } from "../../_hooks/g_tb_bairro/useGTBBairroSaveH import { useGTBBairroRemoveHook } from "../../_hooks/g_tb_bairro/useGTBBairroRemoveHook"; import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; +import { SituacoesEnum } from "@/enums/SituacoesEnum"; const initialBairro: GTBBairroInterface = { sistema_id: null, tb_bairro_id: 0, descricao: '', - situacao: 'A' + situacao: SituacoesEnum.A } -export default function TTBAndamentoServico() { +export default function GTBBairroPage() { + + // Controle de exibição de respostas + const { setResponse } = useResponse(); + + // Controle de estado do botão + const [buttonIsLoading, setButtonIsLoading] = useState(false); // Hooks para leitura e salvamento const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook(); @@ -39,7 +47,6 @@ export default function TTBAndamentoServico() { const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, - handleConfirm, handleCancel, } = useConfirmDialog(); @@ -55,8 +62,19 @@ export default function TTBAndamentoServico() { }, []); const handleSave = useCallback(async (data: GTBBairroInterface) => { + + // Coloca o botão em estado de loading + setButtonIsLoading(true); + + // Realiza o procedimento desejado await saveGTBBairro(data); - fetchGTBBairro(); // Atualiza a tabela após salvar + + // Remove o botão do estado de loading + setButtonIsLoading(false); + + // Atualiza a tabela após salvar + fetchGTBBairro(); + }, [saveGTBBairro, fetchGTBBairro]); // Ações de deleção @@ -66,14 +84,29 @@ export default function TTBAndamentoServico() { }, [openConfirmDialog]); const handleDelete = useCallback(async () => { - if (!itemToDelete) return; + // Verifica se existe item para remoção + if (!itemToDelete) { + + // Define os dados da resposta visual + setResponse({ + status: 400, + message: 'Não foi informado um registro para exclusão' + }); + return; + }; + + // Executa o hook de remoção await removeGTBBairro(itemToDelete); - await fetchGTBBairro(); // Atualiza a tabela após remover + // Atualiza a tabela após remover + await fetchGTBBairro(); + + // Limpa o item para remoção setItemToDelete(null) handleCancel(); + }, [itemToDelete, fetchGTBBairro, handleCancel]); // Efeito para carregar os dados na montagem do componente @@ -81,7 +114,10 @@ export default function TTBAndamentoServico() { fetchGTBBairro(); }, []); - if (!gTBBairro) { + /** + * Tela de loading enquanto carrega os dados + */ + if (gTBBairro.length == 0) { return ; } @@ -124,6 +160,7 @@ export default function TTBAndamentoServico() { data={selectedBairro} onClose={handleCloseForm} onSave={handleSave} + buttonIsLoading={buttonIsLoading} />
); diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx index eb747f7..f33c575 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_tb_andamentoservico)/andamentos/page.tsx @@ -18,6 +18,7 @@ import { useTTBAndamentoServicoDeleteHook } from "../../_hooks/t_tb_andamentoser import Header from "@/app/_components/structure/Header"; export default function TTBAndamentoServico() { + // Hooks para leitura e salvamento const { tTBAndamentosServicos, fetchTTBAndamentoServico } = useTTBAndamentoServicoReadHook(); const { saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook(); diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx index 3cb3cd2..4e465b4 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/g_tb_bairro/GTBBairroForm.tsx @@ -1,7 +1,7 @@ 'use client'; import z from "zod"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { useForm, Controller } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; @@ -28,7 +28,8 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { GTBBairroSchema } from "../../_schemas/GTBBairroSchema"; -import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; +import LoadingButton from "@/app/_components/loadingButton/LoadingButton"; +import { SituacoesEnum } from "@/enums/SituacoesEnum"; type FormValues = z.infer; @@ -37,9 +38,11 @@ interface GTBBairroFormProps { data: FormValues | null; onClose: (item: null, isFormStatus: boolean) => void; onSave: (data: FormValues) => void; + buttonIsLoading: boolean; } -export default function GTBBairroForm({ isOpen, data, onClose, onSave }: GTBBairroFormProps) { +export default function GTBBairroForm({ isOpen, data, onClose, onSave, buttonIsLoading }: GTBBairroFormProps) { + // Inicializa o react-hook-form com o schema Zod const form = useForm({ resolver: zodResolver(GTBBairroSchema), @@ -47,7 +50,7 @@ export default function GTBBairroForm({ isOpen, data, onClose, onSave }: GTBBair sistema_id: null, tb_bairro_id: 0, descricao: "", - situacao: "A", + situacao: SituacoesEnum.A, }, }); @@ -113,14 +116,14 @@ export default function GTBBairroForm({ isOpen, data, onClose, onSave }: GTBBair Cancelar - + {/* Botão de loading */} + {/* Campos ocultos */} + diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts index 928f9ff..5506807 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/GTBBairro/GTBBairroIndexData.ts @@ -1,25 +1,15 @@ import API from "@/services/api/Api"; import { Methods } from "@/services/api/enums/ApiMethodEnum"; -import BairroMockDeDados from "./mockBairro"; - -const useMock = false export default async function GTBBairroIndexData() { - if (useMock) { - console.log(BairroMockDeDados()) - return await BairroMockDeDados(); - } const api = new API(); - try { - const dados = await api.send({ - method: Methods.GET, - endpoint: `administrativo/g_tb_bairro/` - }); - return dados - } catch (error) { - console.log(error) - return error - } + + const dados = await api.send({ + method: Methods.GET, + endpoint: `administrativo/g_tb_bairro/` + }); + + return dados } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook.ts index 2b78ab8..2d4ebac 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroReadHook.ts @@ -1,24 +1,27 @@ +'use client' + import { useResponse } from "@/app/_response/ResponseContext" -import { useState } from "react"; +import { use, useState } from "react"; import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface"; import GTBBairroIndexService from "../../_services/g_tb_bairro/GTBBairroIndexService"; export const useGTBBairroReadHook = () => { const { setResponse } = useResponse(); + + // Controle dos dados obtidos via API const [gTBBairro, setGTBBairro] = useState([]); const fetchGTBBairro = async () => { - try { - const response = await GTBBairroIndexService(); + // Realiza a requisição para a api + const response = await GTBBairroIndexService(); - setGTBBairro(response.data); + // Armazena os dados da resposta + setGTBBairro(response.data); - setResponse(response); - } catch (error) { - console.log(error) - } + // Envia os dados da resposta para ser tratado + setResponse(response); } diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts index 8873c44..ecd5d3f 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/g_tb_bairro/useGTBBairroSaveHook.ts @@ -7,6 +7,7 @@ export const useGTBBairroSaveHook = () => { const { setResponse } = useResponse(); const [gTBBairro, setGTBBairro] = useState(null); + // controla se o formulário está aberto ou fechado const [isOpen, setIsOpen] = useState(false); diff --git a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts index e3a8c68..10f70c9 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_interfaces/GTBBairroInterface.ts @@ -1,6 +1,8 @@ +import { SituacoesEnum } from "@/enums/SituacoesEnum"; + export interface GTBBairroInterface { sistema_id: number | null; tb_bairro_id: number; descricao: string; - situacao: 'A' | 'I'; + situacao: SituacoesEnum; } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts index 50fcf25..c4a67d5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_schemas/GTBBairroSchema.ts @@ -1,8 +1,9 @@ +import { SituacoesEnum } from '@/enums/SituacoesEnum'; import { z } from 'zod'; export const GTBBairroSchema = z.object({ - sistema_id: z.number().nullable(), tb_bairro_id: z.number(), - descricao: z.string(), - situacao: z.enum(['A', 'I']), + sistema_id: z.number().nullable(), + descricao: z.string().min(1, 'O campo deve ser preenchido'), + situacao: z.enum(SituacoesEnum), }); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts index fbc3e01..a58e999 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroIndexService.ts @@ -2,11 +2,7 @@ import GTBBairroIndexData from "../../_data/GTBBairro/GTBBairroIndexData"; export default async function GTBBairroIndexService() { - try { - const response = await GTBBairroIndexData(); - return response; - } catch (error) { - console.log(error) - return error - } + const response = await GTBBairroIndexData(); + return response; + } \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts index f7e8da4..d37c2a2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/g_tb_bairro/GTBBairroSaveService.ts @@ -5,8 +5,6 @@ export default async function GTBBairroSaveService(data: GTBBairroInterface) { const response = await GTBBairroSaveData(data); - console.log('GTBRegimeComunhaoSaveData', response) - return response; } \ No newline at end of file diff --git a/src/app/_components/loadingButton/LoadingButton.tsx b/src/app/_components/loadingButton/LoadingButton.tsx index e334b8b..3c890c4 100644 --- a/src/app/_components/loadingButton/LoadingButton.tsx +++ b/src/app/_components/loadingButton/LoadingButton.tsx @@ -15,7 +15,7 @@ const LoadingButton = forwardRef( aria-busy={loading} aria-live="polite" className={clsx( - "flex items-center justify-center gap-2 w-full my-3 cursor-pointer", + "cursor-pointer", className )} {...props} diff --git a/src/app/_components/structure/Header.tsx b/src/app/_components/structure/Header.tsx index 2fb7a55..c8c02e6 100644 --- a/src/app/_components/structure/Header.tsx +++ b/src/app/_components/structure/Header.tsx @@ -1,5 +1,4 @@ import { Button } from "@/components/ui/button"; -import Link from "next/link"; import { PlusIcon } from "lucide-react"; interface HeaderProps { @@ -23,10 +22,9 @@ export default function Header({ title, description, buttonText, buttonAction }: {description}

-
diff --git a/src/app/_response/response.tsx b/src/app/_response/response.tsx index 94c0d0a..fad1bec 100644 --- a/src/app/_response/response.tsx +++ b/src/app/_response/response.tsx @@ -30,6 +30,12 @@ export default function Response() { }); break; + case 400: + toast.error(response.error, { + description: response.message + }); + break; + case 600: toast.error(response.error, { description: response.message diff --git a/src/enums/SituacoesEnum.ts b/src/enums/SituacoesEnum.ts new file mode 100644 index 0000000..451ffb1 --- /dev/null +++ b/src/enums/SituacoesEnum.ts @@ -0,0 +1,6 @@ +export enum SituacoesEnum { + + A = 'A', + I = 'I', + +} \ No newline at end of file From eeab66149fdfc07b5a24ef6b399caa9ffb987055 Mon Sep 17 00:00:00 2001 From: keven Date: Tue, 23 Sep 2025 15:56:14 -0300 Subject: [PATCH 56/56] =?UTF-8?q?[MVPTN-72]=20refactor(Geral):=20Conecta?= =?UTF-8?q?=20o=20crud=20com=20os=20endpoints=20definitivos,=20aplica=20o?= =?UTF-8?q?=20bot=C3=A3o=20de=20loading,=20encapsula=20as=20fun=C3=A7?= =?UTF-8?q?=C3=B5es=20para=20trativas=20de=20erros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cadastros/(t_censec)/censec/page.tsx | 13 +++++- .../_components/t_censec/TCensecForm.tsx | 12 +++--- .../_data/TCensec/TCensecDeleteData.ts | 17 +++++--- .../_data/TCensec/TCensecIndexData.ts | 40 ++++++------------- .../_data/TCensec/TCensecSaveData.ts | 25 +++++++----- .../_hooks/t_censec/useTCensecDeleteHook.ts | 2 +- .../_hooks/t_censec/useTCensecReadHook.ts | 4 +- .../_hooks/t_censec/useTCensecSaveHook.ts | 2 +- .../t_censec/TCensecDeleteService.ts | 9 +++-- .../_services/t_censec/TCensecIndexService.ts | 9 +++-- .../_services/t_censec/TCensecSaveService.ts | 9 +++-- 11 files changed, 80 insertions(+), 62 deletions(-) diff --git a/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx b/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx index e4050c9..24287f2 100644 --- a/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/(t_censec)/censec/page.tsx @@ -18,6 +18,10 @@ import TCensecInterface from "../../_interfaces/TCensecInterface"; import Header from "@/app/_components/structure/Header"; export default function TTBAndamentoServico() { + + // Controle de estado do botão + const [buttonIsLoading, setButtonIsLoading] = useState(false); + // Hooks para leitura e salvamento const { tCensec, fetchTCensec } = useTCensecReadHook(); const { saveTCensec } = useTCensecSaveHook(); @@ -61,9 +65,15 @@ export default function TTBAndamentoServico() { */ const handleSave = useCallback(async (formData: TCensecInterface) => { + // Coloca o botão em estado de loading + setButtonIsLoading(true); + // Aguarda salvar o registro await saveTCensec(formData); + // Remove o botão em estado de loading + setButtonIsLoading(false); + // Atualiza a lista de dados fetchTCensec(); @@ -114,7 +124,7 @@ export default function TTBAndamentoServico() { /** * Tela de loading enquanto carrega os dados */ - if (!tCensec) { + if (tCensec.length == 0) { return ; } @@ -157,6 +167,7 @@ export default function TTBAndamentoServico() { data={selectedAndamento} onClose={handleCloseForm} onSave={handleSave} + buttonIsLoading={buttonIsLoading} />
); 4 diff --git a/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx index 93576d7..a5e58fd 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx +++ b/src/app/(protected)/(cadastros)/cadastros/_components/t_censec/TCensecForm.tsx @@ -28,6 +28,8 @@ import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { TCensecSchema } from "../../_schemas/TCensecSchema"; +import { SituacoesEnum } from "@/enums/SituacoesEnum"; +import LoadingButton from "@/app/_components/loadingButton/LoadingButton"; type FormValues = z.infer; @@ -36,15 +38,16 @@ interface Props { data: FormValues | null; onClose: (item: null, isFormStatus: boolean) => void; onSave: (data: FormValues) => void; + buttonIsLoading: boolean; } -export default function TCensecForm({ isOpen, data, onClose, onSave }: Props) { +export default function TCensecForm({ isOpen, data, onClose, onSave, buttonIsLoading }: Props) { // Inicializa o react-hook-form com schema zod const form = useForm({ resolver: zodResolver(TCensecSchema), defaultValues: { descricao: "", - situacao: "A", + situacao: SituacoesEnum.A, censec_id: 0, }, }); @@ -112,9 +115,8 @@ export default function TCensecForm({ isOpen, data, onClose, onSave }: Props) { Cancelar - + {/* Botão de loading */} + {/* Campo oculto */} diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts index f3f367a..0a0dffe 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecDeleteData.ts @@ -1,10 +1,17 @@ +import API from "@/services/api/Api"; import TCensecInterface from "../../_interfaces/TCensecInterface"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function TCensecDeleteData(data: TCensecInterface) { +async function executeTCensecDeleteData(data: TCensecInterface) { - return Promise.resolve({ - message: 'Dados removidos', - status: 200 + const api = new API(); + + return await api.send({ + method: Methods.DELETE, + endpoint: `administrativo/t_censec/${data.censec_id}`, }); -} \ No newline at end of file +} + +export const TCensecDeleteData = withClientErrorHandler(executeTCensecDeleteData); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts index d1747cf..d8a5896 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecIndexData.ts @@ -1,30 +1,16 @@ -export default async function TCensecIndexData() { +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; - return Promise.resolve({ - message: 'Dados localizados', - status: 200, - data: [ - { - censec_id: 1.00, - descricao: 'CEP - Escritura e Procurações Diversas', - situacao: 'A' - }, - { - censec_id: 2.00, - descricao: 'CESDI - Escrituras Lei 11.441', - situacao: 'A' - }, - { - censec_id: 3.00, - descricao: 'RCTO - Testamentos', - situacao: 'A' - }, - { - censec_id: 9.00, - descricao: 'Não Possui', - situacao: 'A' - } - ] +async function executeTCensecIndexData() { + + const api = new API(); + + return await api.send({ + method: Methods.GET, + endpoint: `administrativo/t_censec/`, }); -} \ No newline at end of file +} + +export const TCensecIndexData = withClientErrorHandler(executeTCensecIndexData); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts index eefb0f8..49804e5 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_data/TCensec/TCensecSaveData.ts @@ -1,15 +1,20 @@ +import API from "@/services/api/Api"; +import { Methods } from "@/services/api/enums/ApiMethodEnum"; import TCensecInterface from "../../_interfaces/TCensecInterface"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; -export default async function TCensecSaveData(data: TCensecInterface) { +async function executeTCensecSaveData(data: TCensecInterface) { - return Promise.resolve({ - message: 'Dados salvos', - status: 201, - data: { - censec_id: 9.00, - descricao: 'Não Possui', - situacao: 'A' - } + const isUpdate = Boolean(data.censec_id); + + const api = new API(); + + return await api.send({ + method: isUpdate ? Methods.PUT : Methods.POST, + endpoint: `administrativo/t_censec/${data.censec_id || ''}`, + body: data }); -} \ No newline at end of file +} + +export const TCensecSaveData = withClientErrorHandler(executeTCensecSaveData); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts index 6542033..1ac288a 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecDeleteHook.ts @@ -1,6 +1,6 @@ import { useResponse } from "@/app/_response/ResponseContext" import TCensecInterface from "../../_interfaces/TCensecInterface"; -import TCensecDeleteService from "../../_services/t_censec/TCensecDeleteService"; +import { TCensecDeleteService } from "../../_services/t_censec/TCensecDeleteService"; export const useTCensecDeleteHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts index b71e8c3..3fd4148 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecReadHook.ts @@ -1,5 +1,5 @@ import { useResponse } from "@/app/_response/ResponseContext" -import TCensecIndexService from "../../_services/t_censec/TCensecIndexService"; +import { TCensecIndexService } from "../../_services/t_censec/TCensecIndexService"; import { useState } from "react"; import TCensecInterface from "../../_interfaces/TCensecInterface"; @@ -17,8 +17,6 @@ export const useTCensecReadHook = () => { setResponse(response); - return response - } return { tCensec, fetchTCensec } diff --git a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts index a1412b7..7efbb56 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_hooks/t_censec/useTCensecSaveHook.ts @@ -3,7 +3,7 @@ import { useResponse } from "@/app/_response/ResponseContext" import { useState } from "react"; import TCensecInterface from "../../_interfaces/TCensecInterface"; -import TCensecSaveService from "../../_services/t_censec/TCensecSaveService"; +import { TCensecSaveService } from "../../_services/t_censec/TCensecSaveService"; export const useTCensecSaveHook = () => { diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts index f70eea2..8a12cad 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecDeleteService.ts @@ -1,10 +1,13 @@ -import TCensecDeleteData from "../../_data/TCensec/TCensecDeleteData"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; +import { TCensecDeleteData } from "../../_data/TCensec/TCensecDeleteData"; import TCensecInterface from "../../_interfaces/TCensecInterface"; -export default async function TCensecDeleteService(data: TCensecInterface) { +async function executeTCensecDeleteService(data: TCensecInterface) { const response = await TCensecDeleteData(data); return response; -} \ No newline at end of file +} + +export const TCensecDeleteService = withClientErrorHandler(executeTCensecDeleteService); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts index 1e37031..7909527 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecIndexService.ts @@ -1,9 +1,12 @@ -import TCensecIndexData from "../../_data/TCensec/TCensecIndexData"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; +import { TCensecIndexData } from "../../_data/TCensec/TCensecIndexData"; -export default async function TCensecIndexService() { +export default async function executeTCensecIndexService() { const response = await TCensecIndexData(); return response; -} \ No newline at end of file +} + +export const TCensecIndexService = withClientErrorHandler(executeTCensecIndexService); \ No newline at end of file diff --git a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts index 0240cb8..f7d1739 100644 --- a/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts +++ b/src/app/(protected)/(cadastros)/cadastros/_services/t_censec/TCensecSaveService.ts @@ -1,10 +1,13 @@ -import TCensecSaveData from "../../_data/TCensec/TCensecSaveData"; +import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler"; +import { TCensecSaveData } from "../../_data/TCensec/TCensecSaveData"; import TCensecInterface from "../../_interfaces/TCensecInterface"; -export default async function TCensecSaveService(data: TCensecInterface) { +async function executeTCensecSaveService(data: TCensecInterface) { const response = await TCensecSaveData(data); return response; -} \ No newline at end of file +} + +export const TCensecSaveService = withClientErrorHandler(executeTCensecSaveService); \ No newline at end of file