Merge remote-tracking branch 'origin/release(MVP/Sprint9)'
This commit is contained in:
commit
4da16c3fe2
39 changed files with 1685 additions and 1 deletions
|
|
@ -0,0 +1,9 @@
|
|||
'use client';
|
||||
|
||||
import GCartorioIndex from "@/packages/administrativo/components/GCartorio/GCartorioIndex";
|
||||
|
||||
export default function GCartorioPage() {
|
||||
return (
|
||||
< GCartorioIndex />
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import GGramaticaIndex from "@/packages/administrativo/components/GGramatica/GGramaticaIndex";
|
||||
|
||||
export default function GGramaticaPage() {
|
||||
|
||||
return (
|
||||
<GGramaticaIndex />
|
||||
);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
|
||||
export default function GCartorioColumns(
|
||||
onEdit: (item: GCartorioInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: GCartorioInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<GCartorioInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'cartorio_id',
|
||||
header: ({ column }) => SortableHeader('ID', column),
|
||||
cell: ({ row }) => Number(row.getValue('cartorio_id')),
|
||||
enableSorting: true,
|
||||
},
|
||||
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: 'razao_social',
|
||||
header: ({ column }) => SortableHeader('Razão Social', column),
|
||||
cell: ({ row }) => GetCapitalize(String(row.getValue('razao_social') || '')),
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const natureza = row.original;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(natureza, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(natureza, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,415 @@
|
|||
'use client';
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
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 { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData';
|
||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||
|
||||
import { useGCartorioFormHook } from '../../hooks/GCartorio/useGCartorioFormHook';
|
||||
import { GCartorioFormInterface } from '../../interfaces/GCartorio/GCartorioFormInterface';
|
||||
|
||||
/**
|
||||
* Formulário de cadastro/edição de Natureza
|
||||
* Baseado nos campos da tabela G_NATUREZA
|
||||
*/
|
||||
export default function GCartorioForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: GCartorioFormInterface) {
|
||||
const form = useGCartorioFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
ResetFormIfData(form, data);
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
console.log('Erro no formulário:', error);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-2xl lg:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-lg sm:text-xl">Formulário de Cartório</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground text-sm">
|
||||
Cadastro e edição de cartórios
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
<div className="grid w-full grid-cols-12 gap-4">
|
||||
{/* Identificação */}
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="razao_social"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Razão Social</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="denominacao_serventia"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Denominação da Serventia</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cnpj"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CNPJ</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cns"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CNS</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="seq"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>SEQ</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Localização */}
|
||||
<div className="col-span-12 sm:col-span-8">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="endereco"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Endereço</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="endereco_numero"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Número</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="bairro"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Bairro</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="municipio"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Município</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-4 md:col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="uf"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>UF</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" maxLength={2} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-4 md:col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cep"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CEP</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Contatos */}
|
||||
<div className="col-span-12 sm:col-span-4 md:col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="telefone1"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Telefone</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-4 md:col-span-3">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="fax"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Fax</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="email"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="email" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="home_page"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Site</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="url" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Titular */}
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="nome_titular"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Nome do Titular</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cpf_titular"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CPF do Titular</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Substituto */}
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="nome_substituto"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Nome do Substituto</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="cpf_substituto"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>CPF do Substituto</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="col-span-12 sm:col-span-12">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="email_substituto"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Email do Substituto</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="email" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Rodapé */}
|
||||
<DialogFooter className="mt-6 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button">
|
||||
Cancelar
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<LoadingButton
|
||||
text="Salvar"
|
||||
textLoading="Salvando..."
|
||||
type="submit"
|
||||
loading={buttonIsLoading}
|
||||
/>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
'use client';
|
||||
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
|
||||
|
||||
import { useGCartorioDeleteHook } from '@/packages/administrativo/hooks/GCartorio/useGCartorioDeleteHook';
|
||||
import { useGCartorioIndexHook } from '@/packages/administrativo/hooks/GCartorio/useGCartorioIndexHook';
|
||||
import { useGCartorioSaveHook } from '@/packages/administrativo/hooks/GCartorio/useGCartorioSaveHook';
|
||||
import GCartorioInterface from '@/packages/administrativo/interfaces/GCartorio/GCartorioInterface';
|
||||
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
||||
import { useConfirmDialog } from '@/shared/components/confirmDialog/useConfirmDialog';
|
||||
import Loading from '@/shared/components/loading/loading';
|
||||
import Header from '@/shared/components/structure/Header';
|
||||
|
||||
import GCartorioForm from './GCartorioForm';
|
||||
import GCartorioTable from './GCartorioTable';
|
||||
|
||||
export default function GCartorioIndex() {
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
// Hooks para leitura e salvamento
|
||||
const { gGramatica, indexGCartorio } = useGCartorioIndexHook();
|
||||
const { saveGCartorio } = useGCartorioSaveHook();
|
||||
const { deleteGCartorio } = useGCartorioDeleteHook();
|
||||
|
||||
// Estados
|
||||
const [selectedData, setSelectedData] = useState<GCartorioInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<GCartorioInterface | null>(null);
|
||||
|
||||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: GCartorioInterface | null) => {
|
||||
setSelectedData(data);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Fecha o formulário e limpa o andamento selecionado
|
||||
*/
|
||||
const handleCloseForm = useCallback(() => {
|
||||
setSelectedData(null);
|
||||
setIsFormOpen(false);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Salva os dados do formulário
|
||||
*/
|
||||
const handleSave = useCallback(
|
||||
async (formData: GCartorioInterface) => {
|
||||
// Coloca o botão em estado de loading
|
||||
setButtonIsLoading(true);
|
||||
|
||||
// Aguarda salvar o registro
|
||||
await saveGCartorio(formData);
|
||||
|
||||
// Remove o botão em estado de loading
|
||||
setButtonIsLoading(false);
|
||||
|
||||
// Atualiza a lista de dados
|
||||
indexGCartorio();
|
||||
},
|
||||
[saveGCartorio, indexGCartorio, handleCloseForm],
|
||||
);
|
||||
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: GCartorioInterface) => {
|
||||
// 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 deleteGCartorio(itemToDelete);
|
||||
|
||||
// Atualiza a lista
|
||||
await indexGCartorio();
|
||||
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, indexGCartorio, handleCancel]);
|
||||
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
indexGCartorio();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (gGramatica?.length == 0) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Cartório'}
|
||||
description={'Cartório'}
|
||||
buttonText={'Novo Cartório'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
{/* Tabela de andamentos */}
|
||||
<GCartorioTable data={gGramatica} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir o valor "${itemToDelete?.razao_social}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
{/* Formulário de criação/edição */}
|
||||
{isFormOpen && (
|
||||
<GCartorioForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedData}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
buttonIsLoading={buttonIsLoading}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
'use client';
|
||||
|
||||
import { DataTable } from '@/shared/components/dataTable/DataTable';
|
||||
|
||||
import GCartorioColumns from './GCartorioColumns';
|
||||
import GCartorioTableInterface from '../../interfaces/GCartorio/GCartorioTableInterface';
|
||||
|
||||
/**
|
||||
* Componente principal da tabela de Naturezas
|
||||
*/
|
||||
export default function GCartorioTable({ data, onEdit, onDelete }: GCartorioTableInterface) {
|
||||
const columns = GCartorioColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
filterColumn="razao_social"
|
||||
filterPlaceholder="Buscar por descrição da razão social..."
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
|
||||
export default function GGramaticaColumns(
|
||||
onEdit: (item: GGramaticaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: GGramaticaInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<GGramaticaInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'gramatica_id',
|
||||
header: ({ column }) => SortableHeader('ID', column),
|
||||
cell: ({ row }) => Number(row.getValue('gramatica_id')),
|
||||
enableSorting: true,
|
||||
},
|
||||
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: 'palavra',
|
||||
header: ({ column }) => SortableHeader('Palavra', column),
|
||||
cell: ({ row }) => GetCapitalize(String(row.getValue('palavra') || '')),
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const natureza = row.original;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(natureza, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(natureza, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
'use client';
|
||||
|
||||
import React, { useEffect } from 'react';
|
||||
|
||||
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 { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData';
|
||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||
|
||||
import { useGGramaticaFormHook } from '../../hooks/GGramatica/useGGramaticaFormHook';
|
||||
import { GGramaticaFormInterface } from '../../interfaces/GGramatica/GGramaticaFormInterface';
|
||||
|
||||
/**
|
||||
* Formulário de cadastro/edição de Natureza
|
||||
* Baseado nos campos da tabela G_NATUREZA
|
||||
*/
|
||||
export default function GGramaticaForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: GGramaticaFormInterface) {
|
||||
const form = useGGramaticaFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
ResetFormIfData(form, data);
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
console.log('Erro no formulário:', error);
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={isOpen}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-2xl lg:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="text-lg sm:text-xl">Formulário de Gramática</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground text-sm">
|
||||
Formulário de Gramática
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Formulário principal */}
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
{/* GRID MOBILE FIRST */}
|
||||
<div className="grid w-full grid-cols-12 gap-4">
|
||||
{/* Palavra */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-12">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="palavra"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Palavra</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{/* Prefixo */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-12">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="prefixo"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Prefixo</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{/* Singular Masculino */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="sufixo_ms"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Sufixo Masculino Singular</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{/* Plural Masculino */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="sufixo_mp"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Sufixo Masculino Plural</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{/* Singular Feminino */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="sufixo_fs"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Sufixo Feminino Singular</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
{/* Plural Feminino */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="sufixo_fp"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Sufixo Feminino Plural</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
type="text"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/* Rodapé */}
|
||||
<DialogFooter className="mt-6 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button">
|
||||
Cancelar
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<LoadingButton
|
||||
text="Salvar"
|
||||
textLoading="Salvando..."
|
||||
type="submit"
|
||||
loading={buttonIsLoading}
|
||||
/>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
'use client';
|
||||
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
|
||||
|
||||
import { useGGramaticaDeleteHook } from '@/packages/administrativo/hooks/GGramatica/useGGramaticaDeleteHook';
|
||||
import { useGGramaticaIndexHook } from '@/packages/administrativo/hooks/GGramatica/useGGramaticaIndexHook';
|
||||
import { useGGramaticaSaveHook } from '@/packages/administrativo/hooks/GGramatica/useGGramaticaSaveHook';
|
||||
import GGramaticaInterface from '@/packages/administrativo/interfaces/GGramatica/GGramaticaInterface';
|
||||
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
||||
import { useConfirmDialog } from '@/shared/components/confirmDialog/useConfirmDialog';
|
||||
import Loading from '@/shared/components/loading/loading';
|
||||
import Header from '@/shared/components/structure/Header';
|
||||
|
||||
import GGramaticaForm from './GGramaticaForm';
|
||||
import GGramaticaTable from './GGramaticaTable';
|
||||
|
||||
export default function GGramaticaIndex() {
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
// Hooks para leitura e salvamento
|
||||
const { gGramatica, indexGGramatica } = useGGramaticaIndexHook();
|
||||
const { saveGGramatica } = useGGramaticaSaveHook();
|
||||
const { deleteGGramatica } = useGGramaticaDeleteHook();
|
||||
|
||||
// Estados
|
||||
const [selectedData, setSelectedData] = useState<GGramaticaInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<GGramaticaInterface | null>(null);
|
||||
|
||||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: GGramaticaInterface | null) => {
|
||||
setSelectedData(data);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Fecha o formulário e limpa o andamento selecionado
|
||||
*/
|
||||
const handleCloseForm = useCallback(() => {
|
||||
setSelectedData(null);
|
||||
setIsFormOpen(false);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Salva os dados do formulário
|
||||
*/
|
||||
const handleSave = useCallback(
|
||||
async (formData: GGramaticaInterface) => {
|
||||
// Coloca o botão em estado de loading
|
||||
setButtonIsLoading(true);
|
||||
|
||||
// Aguarda salvar o registro
|
||||
await saveGGramatica(formData);
|
||||
|
||||
// Remove o botão em estado de loading
|
||||
setButtonIsLoading(false);
|
||||
|
||||
// Atualiza a lista de dados
|
||||
indexGGramatica();
|
||||
},
|
||||
[saveGGramatica, indexGGramatica, handleCloseForm],
|
||||
);
|
||||
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: GGramaticaInterface) => {
|
||||
// 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 deleteGGramatica(itemToDelete);
|
||||
|
||||
// Atualiza a lista
|
||||
await indexGGramatica();
|
||||
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, indexGGramatica, handleCancel]);
|
||||
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
indexGGramatica();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (gGramatica?.length == 0) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Gramatica'}
|
||||
description={'Gramatica'}
|
||||
buttonText={'Nova palavra'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
{/* Tabela de andamentos */}
|
||||
<GGramaticaTable data={gGramatica} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir o valor "${itemToDelete?.palavra}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
{/* Formulário de criação/edição */}
|
||||
{isFormOpen && (
|
||||
<GGramaticaForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedData}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
buttonIsLoading={buttonIsLoading}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
'use client';
|
||||
|
||||
import { DataTable } from '@/shared/components/dataTable/DataTable';
|
||||
|
||||
import GGramaticaColumns from './GGramaticaColumns';
|
||||
import GGramaticaTableInterface from '../../interfaces/GGramatica/GGramaticaTableInterface';
|
||||
|
||||
/**
|
||||
* Componente principal da tabela de Naturezas
|
||||
*/
|
||||
export default function GGramaticaTable({ data, onEdit, onDelete }: GGramaticaTableInterface) {
|
||||
const columns = GGramaticaColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
filterColumn="palavra"
|
||||
filterPlaceholder="Buscar por descrição da natureza..."
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
|
||||
async function executeGCartorioDeleteData(data: GCartorioInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/g_cartorio/${data.cartorio_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GCartorioDeleteData = withClientErrorHandler(executeGCartorioDeleteData);
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
async function executeGCartorioIndexData(): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/g_cartorio/`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GCartorioIndexData = withClientErrorHandler(executeGCartorioIndexData);
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
|
||||
async function executeGCartorioSaveData(data: GCartorioInterface): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.cartorio_id);
|
||||
|
||||
// Instancia o cliente da API
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/g_cartorio/${data.cartorio_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const GCartorioSaveData = withClientErrorHandler(executeGCartorioSaveData);
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
|
||||
async function executeGGramaticaDeleteData(data: GGramaticaInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/g_gramatica/${data.gramatica_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GGramaticaDeleteData = withClientErrorHandler(executeGGramaticaDeleteData);
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
async function executeGGramaticaIndexData(): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/g_gramatica/`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GGramaticaIndexData = withClientErrorHandler(executeGGramaticaIndexData);
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
|
||||
async function executeGGramaticaSaveData(data: GGramaticaInterface): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.gramatica_id);
|
||||
|
||||
// Instancia o cliente da API
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/g_gramatica/${data.gramatica_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const GGramaticaSaveData = withClientErrorHandler(executeGGramaticaSaveData);
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
import { GCartorioDeleteService } from '../../services/GCartorio/GCartorioDeleteService';
|
||||
|
||||
export const useGCartorioDeleteHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGCartorio] = useState<GCartorioInterface>();
|
||||
|
||||
const deleteGCartorio = async (data: GCartorioInterface) => {
|
||||
const response = await GCartorioDeleteService(data);
|
||||
|
||||
setGCartorio(data);
|
||||
setResponse(response);
|
||||
};
|
||||
|
||||
return { gGramatica, deleteGCartorio };
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { GCartorioFormValues, GCartorioSchema } from '../../schemas/GCartorio/GCartorioSchema';
|
||||
|
||||
export function useGCartorioFormHook(defaults?: Partial<GCartorioFormValues>) {
|
||||
return useForm<GCartorioFormValues>({
|
||||
resolver: zodResolver(GCartorioSchema),
|
||||
defaultValues: {
|
||||
cartorio_id: 0,
|
||||
...defaults,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
import { GCartorioIndexService } from '../../services/GCartorio/GCartorioIndexService';
|
||||
|
||||
export const useGCartorioIndexHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGCartorio] = useState<GCartorioInterface[]>([]);
|
||||
|
||||
const indexGCartorio = async () => {
|
||||
const response = await GCartorioIndexService();
|
||||
// Armazena os dados consultados
|
||||
setGCartorio(response.data);
|
||||
// Define a resposta (toast, modal, feedback, etc.)
|
||||
setResponse(response);
|
||||
};
|
||||
|
||||
return {
|
||||
gGramatica,
|
||||
indexGCartorio,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
import { GCartorioSaveService } from '../../services/GCartorio/GCartorioSaveService';
|
||||
|
||||
export const useGCartorioSaveHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGCartorio] = useState<GCartorioInterface | null>(null);
|
||||
|
||||
// controla se o formulário está aberto ou fechado
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const saveGCartorio = async (data: GCartorioInterface) => {
|
||||
const response = await GCartorioSaveService(data);
|
||||
|
||||
// Armazena os dados da resposta
|
||||
setGCartorio(response.data);
|
||||
|
||||
// Define os dados da resposta (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 { gGramatica, saveGCartorio, isOpen, setIsOpen };
|
||||
};
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
import { GGramaticaDeleteService } from '../../services/GGramatica/GGramaticaDeleteService';
|
||||
|
||||
export const useGGramaticaDeleteHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGGramatica] = useState<GGramaticaInterface>();
|
||||
|
||||
const deleteGGramatica = async (data: GGramaticaInterface) => {
|
||||
const response = await GGramaticaDeleteService(data);
|
||||
|
||||
setGGramatica(data);
|
||||
setResponse(response);
|
||||
};
|
||||
|
||||
return { gGramatica, deleteGGramatica };
|
||||
};
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { GGramaticaFormValues, GGramaticaSchema } from '../../schemas/GGramatica/GGramaticaSchema';
|
||||
|
||||
export function useGGramaticaFormHook(defaults?: Partial<GGramaticaFormValues>) {
|
||||
return useForm<GGramaticaFormValues>({
|
||||
resolver: zodResolver(GGramaticaSchema),
|
||||
defaultValues: {
|
||||
gramatica_id: 0,
|
||||
...defaults,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
import { GGramaticaIndexService } from '../../services/GGramatica/GGramaticaIndexService';
|
||||
|
||||
export const useGGramaticaIndexHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGGramatica] = useState<GGramaticaInterface[]>([]);
|
||||
|
||||
const indexGGramatica = async () => {
|
||||
const response = await GGramaticaIndexService();
|
||||
// Armazena os dados consultados
|
||||
setGGramatica(response.data);
|
||||
// Define a resposta (toast, modal, feedback, etc.)
|
||||
setResponse(response);
|
||||
};
|
||||
|
||||
return {
|
||||
gGramatica,
|
||||
indexGGramatica,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
import { GGramaticaSaveService } from '../../services/GGramatica/GGramaticaSaveService';
|
||||
|
||||
export const useGGramaticaSaveHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
||||
const [gGramatica, setGGramatica] = useState<GGramaticaInterface | null>(null);
|
||||
|
||||
// controla se o formulário está aberto ou fechado
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
|
||||
const saveGGramatica = async (data: GGramaticaInterface) => {
|
||||
const response = await GGramaticaSaveService(data);
|
||||
|
||||
// Armazena os dados da resposta
|
||||
setGGramatica(response.data);
|
||||
|
||||
// Define os dados da resposta (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 { gGramatica, saveGGramatica, isOpen, setIsOpen };
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { GCartorioFormValues } from '../../schemas/GCartorio/GCartorioSchema';
|
||||
|
||||
export interface GCartorioFormInterface {
|
||||
isOpen: boolean;
|
||||
data: GCartorioFormValues | null;
|
||||
onClose: (item: null, isFormStatus: boolean) => void;
|
||||
onSave: (data: GCartorioFormValues) => void;
|
||||
buttonIsLoading: boolean;
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
export default interface GCartorioInterface {
|
||||
cartorio_id?: number;
|
||||
seq?: string;
|
||||
cns?: string;
|
||||
cnpj?: string;
|
||||
denominacao_serventia?: string;
|
||||
status_serventia?: number;
|
||||
atribuicao?: string;
|
||||
dt_instalacao?: Date;
|
||||
dat_inclusao?: Date;
|
||||
dat_alteracao?: Date;
|
||||
uf?: string;
|
||||
municipio?: string;
|
||||
cod_ibge?: number;
|
||||
bairro?: string;
|
||||
distrito?: string;
|
||||
sub_distrito?: string;
|
||||
endereco?: string;
|
||||
complemento?: string;
|
||||
cep?: string;
|
||||
telefone1?: string;
|
||||
fax?: string;
|
||||
email?: string;
|
||||
home_page?: string;
|
||||
dt_inativacao?: Date;
|
||||
nome_titular?: string;
|
||||
cpf_titular?: string;
|
||||
dt_ingresso_titular?: Date;
|
||||
dt_nomeacao_titular?: Date;
|
||||
tipo_titular?: number;
|
||||
forma_ingresso_titular?: number;
|
||||
dt_assuncao_serventia_titular?: Date;
|
||||
dt_colacao_grau_titular?: Date;
|
||||
bacharelado_titular?: number;
|
||||
nome_substituto?: string;
|
||||
cpf_substituto?: string;
|
||||
email_substituto?: string;
|
||||
dat_inclusao_substituto?: Date;
|
||||
dat_alteracao_substituto?: Date;
|
||||
emitente?: string;
|
||||
cpf_escrevente?: string;
|
||||
nome_escrevente?: string;
|
||||
cargo_tituloar?: string;
|
||||
endereco_numero?: string;
|
||||
ddd?: string;
|
||||
insc_estadual?: string;
|
||||
insc_municipal?: string;
|
||||
razao_social?: string;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import GCartorioInterface from './GCartorioInterface';
|
||||
|
||||
export default interface GCartorioTableInterface {
|
||||
data?: GCartorioInterface[];
|
||||
onEdit: (item: GCartorioInterface, isEditingFormStatus: boolean) => void;
|
||||
onDelete: (item: GCartorioInterface, isEditingFormStatus: boolean) => void;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { GGramaticaFormValues } from '../../schemas/GGramatica/GGramaticaSchema';
|
||||
|
||||
export interface GGramaticaFormInterface {
|
||||
isOpen: boolean;
|
||||
data: GGramaticaFormValues | null;
|
||||
onClose: (item: null, isFormStatus: boolean) => void;
|
||||
onSave: (data: GGramaticaFormValues) => void;
|
||||
buttonIsLoading: boolean;
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
export default interface GGramaticaInterface {
|
||||
gramatica_id?: number,
|
||||
palavra?: string,
|
||||
prefixo?: string,
|
||||
sufixo_ms?: string,
|
||||
sufixo_mp?: string,
|
||||
sufixo_fs?: string,
|
||||
sufixo_fp?: string,
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
import GGramaticaInterface from './GGramaticaInterface';
|
||||
|
||||
export default interface GGramaticaTableInterface {
|
||||
data?: GGramaticaInterface[];
|
||||
onEdit: (item: GGramaticaInterface, isEditingFormStatus: boolean) => void;
|
||||
onDelete: (item: GGramaticaInterface, isEditingFormStatus: boolean) => void;
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import z from "zod";
|
||||
|
||||
export const GCartorioSchema = z.object({
|
||||
cartorio_id: z.number().optional(),
|
||||
seq: z.string().optional(),
|
||||
cns: z.string().optional(),
|
||||
cnpj: z.string().optional(),
|
||||
denominacao_serventia: z.string().optional(),
|
||||
status_serventia: z.number().optional(),
|
||||
atribuicao: z.string().optional(),
|
||||
uf: z.string().optional(),
|
||||
municipio: z.string().optional(),
|
||||
cod_ibge: z.number().optional(),
|
||||
bairro: z.string().optional(),
|
||||
distrito: z.string().optional(),
|
||||
sub_distrito: z.string().optional(),
|
||||
endereco: z.string().optional(),
|
||||
complemento: z.string().optional(),
|
||||
cep: z.string().optional(),
|
||||
telefone1: z.string().optional(),
|
||||
fax: z.string().optional(),
|
||||
email: z.string().optional(),
|
||||
home_page: z.string().optional(),
|
||||
nome_titular: z.string().optional(),
|
||||
cpf_titular: z.string().optional(),
|
||||
nome_substituto: z.string().optional(),
|
||||
cpf_substituto: z.string().optional(),
|
||||
email_substituto: z.string().optional(),
|
||||
emitente: z.string().optional(),
|
||||
cpf_escrevente: z.string().optional(),
|
||||
nome_escrevente: z.string().optional(),
|
||||
cargo_tituloar: z.string().optional(),
|
||||
endereco_numero: z.string().optional(),
|
||||
ddd: z.string().optional(),
|
||||
insc_estadual: z.string().optional(),
|
||||
insc_municipal: z.string().optional(),
|
||||
razao_social: z.string().optional(),
|
||||
});
|
||||
|
||||
export type GCartorioFormValues = z.infer<typeof GCartorioSchema>;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import z from "zod";
|
||||
|
||||
export const GGramaticaSchema = z.object({
|
||||
gramatica_id: z.number().optional(),
|
||||
palavra: z.string().optional(),
|
||||
prefixo: z.string().optional(),
|
||||
sufixo_ms: z.string().optional(),
|
||||
sufixo_mp: z.string().optional(),
|
||||
sufixo_fs: z.string().optional(),
|
||||
sufixo_fp: z.string().optional(),
|
||||
});
|
||||
|
||||
export type GGramaticaFormValues = z.infer<typeof GGramaticaSchema>;
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
import z from "zod";
|
||||
|
||||
import { ConfirmacaoEnum } from "@/shared/enums/ConfirmacaoEnum";
|
||||
import { SituacoesEnum } from "@/shared/enums/SituacoesEnum";
|
||||
|
||||
export const GNaturezaTituloSchema = z.object({
|
||||
natureza_titulo_id: z.number().optional(),
|
||||
emolumento_id: z.number().optional(),
|
||||
descricao: z.string().optional(),
|
||||
situacao: z.enum(["A", "I"]).optional(),
|
||||
situacao: z.enum(SituacoesEnum).optional(),
|
||||
sistema_id: z.number().optional(),
|
||||
tipo_cobranca: z.number().optional(),
|
||||
possui_valor: z.enum(ConfirmacaoEnum).optional(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
import { GCartorioDeleteData } from '../../data/GCartorio/GCartorioDeleteData';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
|
||||
|
||||
async function executeGCartorioDeleteService(data: GCartorioInterface) {
|
||||
const response = await GCartorioDeleteData(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GCartorioDeleteService = withClientErrorHandler(executeGCartorioDeleteService);
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import { GCartorioIndexData } from '../../data/GCartorio/GCartorioIndexData';
|
||||
|
||||
export default async function executeGCartorioIndexService() {
|
||||
const response = await GCartorioIndexData();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GCartorioIndexService = withClientErrorHandler(executeGCartorioIndexService);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import { GCartorioSaveData } from '../../data/GCartorio/GCartorioSaveData';
|
||||
import GCartorioInterface from '../../interfaces/GCartorio/GCartorioInterface';
|
||||
|
||||
async function executeGCartorioSaveService(data: GCartorioInterface) {
|
||||
const response = await GCartorioSaveData(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GCartorioSaveService = withClientErrorHandler(executeGCartorioSaveService);
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
import { GGramaticaDeleteData } from '../../data/GGramatica/GGramaticaDeleteData';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
|
||||
|
||||
async function executeGGramaticaDeleteService(data: GGramaticaInterface) {
|
||||
const response = await GGramaticaDeleteData(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GGramaticaDeleteService = withClientErrorHandler(executeGGramaticaDeleteService);
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import { GGramaticaIndexData } from '../../data/GGramatica/GGramaticaIndexData';
|
||||
|
||||
export default async function executeGGramaticaIndexService() {
|
||||
const response = await GGramaticaIndexData();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GGramaticaIndexService = withClientErrorHandler(executeGGramaticaIndexService);
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
import { GGramaticaSaveData } from '../../data/GGramatica/GGramaticaSaveData';
|
||||
import GGramaticaInterface from '../../interfaces/GGramatica/GGramaticaInterface';
|
||||
|
||||
async function executeGGramaticaSaveService(data: GGramaticaInterface) {
|
||||
const response = await GGramaticaSaveData(data);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GGramaticaSaveService = withClientErrorHandler(executeGGramaticaSaveService);
|
||||
Loading…
Add table
Reference in a new issue