Merge branch 'release(MVP)' into homologacao
This commit is contained in:
commit
db993dba9f
39 changed files with 871 additions and 26 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -40,4 +40,4 @@ yarn-error.log*
|
|||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
|
||||
src/config/app.json
|
||||
/src/config/app.json
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 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<GTBRegimeComunhaoInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<GTBRegimeComunhaoInterface | null>(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
|
||||
fetchGTBRegimeComunhao();
|
||||
|
||||
}, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao]);
|
||||
|
||||
/**
|
||||
* 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 <Loading type={2} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={"Regimes de Comunhão"}
|
||||
description={"Gerenciamento de Regimes de Comunhão"}
|
||||
buttonText={"Novo Regime"}
|
||||
buttonAction={() => { handleOpenForm(null) }}
|
||||
/>
|
||||
|
||||
{/* Tabela de andamentos */}
|
||||
<Card>
|
||||
<CardContent>
|
||||
<GTBRegimeComunhaoTable
|
||||
data={gTBRegimeComunhao}
|
||||
onEdit={handleOpenForm}
|
||||
onDelete={handleConfirmDelete}
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Modal de confirmação */}
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
|
||||
{/* Formulário de criação/edição */}
|
||||
<GTBRegimeComunhaoForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedAndamento}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
</div>
|
||||
); 4
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Prop
|
|||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Profissões
|
||||
|
|
|
|||
|
|
@ -0,0 +1,189 @@
|
|||
'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";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook";
|
||||
|
||||
type FormValues = z.infer<typeof GTBRegimeComunhaoSchema>;
|
||||
|
||||
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) {
|
||||
|
||||
const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook();
|
||||
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useForm<FormValues>({
|
||||
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(() => {
|
||||
|
||||
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 (
|
||||
<Dialog
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Regimes de Comunhão
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Controle de Regimes de Comunhão
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||
|
||||
{/* Descrição */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="descricao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Descrição</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="Digite a descrição" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Texto */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="texto"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Texto</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder="Digite o texto" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Tipo */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tb_regimebens_id"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo</FormLabel>
|
||||
<Select
|
||||
value={String(field.value)}
|
||||
// Converter o valor inteiro para ser aceito pelo zod
|
||||
onValueChange={(val) => field.onChange(Number(val))}
|
||||
>
|
||||
<FormControl className="w-full">
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Escolha o tipo do andamento" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{gTBRegimeBens.map((item) => (
|
||||
<SelectItem key={item.tb_regimebens_id} value={String(item.tb_regimebens_id)}>
|
||||
{item.descricao}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Situação */}
|
||||
<Controller
|
||||
name="situacao"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
checked={field.value === "A"}
|
||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
||||
/>
|
||||
<Label>Ativo</Label>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
||||
Cancelar
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<Button type="submit" className="cursor-pointer">
|
||||
Salvar
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
{/* Campo oculto */}
|
||||
<input type="hidden" {...form.register("tb_regimecomunhao_id")} />
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -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 (
|
||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
||||
{isActive ? "Ativo" : "Inativo"}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export default function GTBRegimeComunhaoTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete
|
||||
}: GTBRegimeComunhaoTableProps) {
|
||||
return (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>#</TableHead>
|
||||
<TableHead>Situação</TableHead>
|
||||
<TableHead>Descrição</TableHead>
|
||||
<TableHead className="text-right">Ações</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{data.map((item) => (
|
||||
<TableRow
|
||||
key={item.tb_regimecomunhao_id}
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<TableCell className="font-medium">
|
||||
{item.tb_regimecomunhao_id}
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
<StatusBadge situacao={item.situacao} />
|
||||
</TableCell>
|
||||
|
||||
<TableCell>
|
||||
{item.descricao}
|
||||
</TableCell>
|
||||
|
||||
<TableCell className="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
onSelect={() => onEdit(item, true)}
|
||||
>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer"
|
||||
onSelect={() => onDelete(item, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
);
|
||||
}
|
||||
|
|
@ -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/`
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -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}`
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import API from "@/services/api/Api";
|
||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||
|
||||
export default async function GTBRegimeComunhaoIndexData() {
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/g_tb_regimecomunhao/`
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import API from "@/services/api/Api";
|
||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||
|
||||
export default async function GTBRegimeComunhaoRemoveData(data: GTBRegimeComunhaoInterface) {
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id}`
|
||||
});
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import API from "@/services/api/Api";
|
||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||
|
||||
export default async function GTBRegimeComunhaoSaveData(data: GTBRegimeComunhaoInterface) {
|
||||
|
||||
const isUpdate = Boolean(data.tb_regimecomunhao_id);
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id || ''}`,
|
||||
body: data
|
||||
});
|
||||
}
|
||||
|
|
@ -7,6 +7,8 @@ export const useGTBProfissaoSaveHook = () => {
|
|||
|
||||
const { setResponse } = useResponse();
|
||||
const [gTBProfissao, setGTBProfissao] = useState<GTBProfissaoInterface | null>(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 }
|
||||
|
|
|
|||
|
|
@ -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<GTBRegimeBensInterface[]>([]);
|
||||
|
||||
const fetchGTBRegimeBens = async () => {
|
||||
|
||||
const response = await GTBRegimeBensIndexService();
|
||||
|
||||
setGTBRegimeBens(response.data);
|
||||
|
||||
setResponse(response);
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
return { gTBRegimeBens, fetchGTBRegimeBens }
|
||||
|
||||
}
|
||||
|
|
@ -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 }
|
||||
|
||||
}
|
||||
|
|
@ -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<GTBRegimeComunhaoInterface | null>(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 }
|
||||
|
||||
}
|
||||
|
|
@ -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<GTBRegimeComunhaoInterface[]>([]);
|
||||
|
||||
const fetchGTBRegimeComunhao = async () => {
|
||||
|
||||
const response = await GTBRegimeComunhaoIndexService();
|
||||
|
||||
setGTBRegimeComunhao(response.data);
|
||||
|
||||
setResponse(response);
|
||||
|
||||
}
|
||||
|
||||
return { gTBRegimeComunhao, fetchGTBRegimeComunhao }
|
||||
|
||||
}
|
||||
|
|
@ -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 }
|
||||
|
||||
}
|
||||
|
|
@ -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 useGTBRegimeComunhaoSaveHook = () => {
|
||||
|
||||
const { setResponse } = useResponse();
|
||||
const [gTBRegimeComunhao, setGTBRegimeComunhao] = useState<GTBRegimeComunhaoInterface | null>(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 }
|
||||
|
||||
}
|
||||
|
|
@ -11,6 +11,9 @@ export const useTTBAndamentoServicoSaveHook = () => {
|
|||
|
||||
const [tTBAndamentoServico, setTTBAndamentoServico] = useState<TTBAndamentoServicoInteface>();
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ export const useTTBReconhecimentoTipoSaveHook = () => {
|
|||
|
||||
const [tTBReconhecimentoTipo, setTTBReconhcimentoTipo] = useState<ITTTBReconhecimentoTipo>();
|
||||
|
||||
// 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;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
export default interface GTBRegimeBensInterface {
|
||||
tb_regimebens_id?: number,
|
||||
descricao: string,
|
||||
situacao: string,
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
export default interface GTBRegimeComunhaoInterface {
|
||||
tb_regimecomunhao_id?: number,
|
||||
tb_regimebens_id: number,
|
||||
descricao: string,
|
||||
texto: string,
|
||||
situacao: string,
|
||||
}
|
||||
|
|
@ -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(),
|
||||
});
|
||||
|
|
@ -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(),
|
||||
});
|
||||
|
|
@ -5,6 +5,8 @@ export default async function GTProfissaoSaveService(data: GTBProfissaoInterface
|
|||
|
||||
const response = await GTBProfissaoSaveData(data);
|
||||
|
||||
console.log('GTBRegimeComunhaoSaveData', response)
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import GTBRegimeBensIndexData from "../../_data/GTBRegimeBens/GTBRegimeBensIndexData";
|
||||
|
||||
export default async function GTBRegimeBensIndexService() {
|
||||
|
||||
const response = await GTBRegimeBensIndexData();
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import GTBRegimeComunhaoIndexData from "../../_data/GTRegimeComunhao/GTBRegimeComunhaoIndexData";
|
||||
|
||||
export default async function GTBRegimeComunhaoIndexService() {
|
||||
|
||||
const response = await GTBRegimeComunhaoIndexData();
|
||||
|
||||
return response;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
@ -74,7 +74,7 @@ export default function RootLayout({
|
|||
<ResponseProvider>
|
||||
<div className="flex flex-1 flex-col gap-4 p-4 pt-0">
|
||||
{children}
|
||||
<Toaster position="top-center" />
|
||||
<Toaster richColors position="top-center" />
|
||||
<Response />
|
||||
</div>
|
||||
</ResponseProvider>
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -17,10 +19,10 @@ interface ResponseContextProps {
|
|||
const ResponseContext = createContext<ResponseContextProps | undefined>(undefined);
|
||||
|
||||
export const ResponseProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||
const [response, setResponseState] = useState<ResponseState>({ message: '', type: null, status : 0});
|
||||
const [response, setResponseState] = useState<ResponseState>({ 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 (
|
||||
<ResponseContext.Provider value={{ response, setResponse, clearResponse }}>
|
||||
|
|
|
|||
|
|
@ -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.error(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 <div></div>;
|
||||
}
|
||||
}
|
||||
|
|
@ -93,6 +93,10 @@ const data = {
|
|||
title: "Profissões",
|
||||
url: "/cadastros/profissoes/",
|
||||
},
|
||||
{
|
||||
title: "Regimes/Comunhão",
|
||||
url: "/cadastros/regime-comunhao/",
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue