fix(Formatter): Formata o código utilizando o prettier
This commit is contained in:
parent
5297d6ab2e
commit
8d5e786f74
238 changed files with 3834 additions and 3835 deletions
|
|
@ -67,7 +67,6 @@ export default function GCidadeForm({ isOpen, data, onClose, onSave }: Props) {
|
|||
|
||||
// Quando recebe dados para edição, atualiza os valores do formulário
|
||||
useEffect(() => {
|
||||
|
||||
if (data) {
|
||||
// Se for edição, carrega os dados recebidos
|
||||
form.reset({
|
||||
|
|
@ -88,7 +87,7 @@ export default function GCidadeForm({ isOpen, data, onClose, onSave }: Props) {
|
|||
});
|
||||
}
|
||||
|
||||
// Carrega todos os estados
|
||||
// Carrega todos os estados
|
||||
// brasileiros para o formulário
|
||||
const loadData = async () => {
|
||||
// Aguarda a busca terminar
|
||||
|
|
@ -97,7 +96,6 @@ export default function GCidadeForm({ isOpen, data, onClose, onSave }: Props) {
|
|||
|
||||
// Dispara a função
|
||||
loadData();
|
||||
|
||||
}, [data, form]);
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -18,146 +18,145 @@ import GCidadeInterface from '@/packages/administrativo/interfaces/GCidade/GCida
|
|||
import Header from '@/shared/components/structure/Header';
|
||||
|
||||
export default function GCidadeIndex() {
|
||||
// Hooks para leitura e salvamento
|
||||
const { gCidade, fetchGCidade } = useGCidadeReadHook();
|
||||
const { saveGCidade } = useGCidadeSaveHook();
|
||||
const { removeGCidade } = useGCidadeRemoveHook();
|
||||
// Hooks para leitura e salvamento
|
||||
const { gCidade, fetchGCidade } = useGCidadeReadHook();
|
||||
const { saveGCidade } = useGCidadeSaveHook();
|
||||
const { removeGCidade } = useGCidadeRemoveHook();
|
||||
|
||||
// Estados
|
||||
const [selectedCidade, setSelectedCidade] = useState<GCidadeInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
// Estados
|
||||
const [selectedCidade, setSelectedCidade] = useState<GCidadeInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<GCidadeInterface | null>(null);
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<GCidadeInterface | null>(null);
|
||||
|
||||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleConfirm,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
/**
|
||||
* 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: GCidadeInterface | null) => {
|
||||
setSelectedCidade(data);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: GCidadeInterface | null) => {
|
||||
setSelectedCidade(data);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Fecha o formulário e limpa o andamento selecionado
|
||||
*/
|
||||
const handleCloseForm = useCallback((_: null, __: boolean) => {
|
||||
setSelectedCidade(null);
|
||||
setIsFormOpen(false);
|
||||
}, []);
|
||||
/**
|
||||
* Fecha o formulário e limpa o andamento selecionado
|
||||
*/
|
||||
const handleCloseForm = useCallback((_: null, __: boolean) => {
|
||||
setSelectedCidade(null);
|
||||
setIsFormOpen(false);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Salva os dados do formulário
|
||||
*/
|
||||
const handleSave = useCallback(async (formData: GCidadeInterface) => {
|
||||
/**
|
||||
* Salva os dados do formulário
|
||||
*/
|
||||
const handleSave = useCallback(
|
||||
async (formData: GCidadeInterface) => {
|
||||
// Aguarda salvar o registro
|
||||
await saveGCidade(formData);
|
||||
|
||||
|
||||
// Aguarda salvar o registro
|
||||
await saveGCidade(formData);
|
||||
|
||||
// Atualiza a lista de dados
|
||||
fetchGCidade();
|
||||
// Atualiza a lista de dados
|
||||
fetchGCidade();
|
||||
},
|
||||
[saveGCidade, fetchGCidade],
|
||||
);
|
||||
[saveGCidade, fetchGCidade],
|
||||
);
|
||||
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: GCidadeInterface) => {
|
||||
// Define o item atual para remoção
|
||||
setItemToDelete(item);
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: GCidadeInterface) => {
|
||||
// Define o item atual para remoção
|
||||
setItemToDelete(item);
|
||||
|
||||
// Abre o modal de confirmação
|
||||
openConfirmDialog();
|
||||
},
|
||||
[openConfirmDialog],
|
||||
);
|
||||
// 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 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 removeGCidade(itemToDelete);
|
||||
// Executa o Hook de remoção
|
||||
await removeGCidade(itemToDelete);
|
||||
|
||||
// Atualiza a lista
|
||||
await fetchGCidade();
|
||||
// Atualiza a lista
|
||||
await fetchGCidade();
|
||||
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, fetchGCidade, handleCancel]);
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, fetchGCidade, handleCancel]);
|
||||
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
fetchGCidade();
|
||||
}, []);
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
fetchGCidade();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (!gCidade) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (!gCidade) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Cidades'}
|
||||
description={'Gerenciamento de Cidades'}
|
||||
buttonText={'Nova Cidade'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Cidades'}
|
||||
description={'Gerenciamento de Cidades'}
|
||||
buttonText={'Nova Cidade'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Tabela de andamentos */}
|
||||
<Card>
|
||||
<CardContent>
|
||||
<GCidadeTable data={gCidade} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Tabela de andamentos */}
|
||||
<Card>
|
||||
<CardContent>
|
||||
<GCidadeTable data={gCidade} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Modal de confirmação */}
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir a cidade "${itemToDelete?.cidade_nome}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
{/* Modal de confirmação */}
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir a cidade "${itemToDelete?.cidade_nome}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
|
||||
{/* Formulário de criação/edição */}
|
||||
<GCidadeForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedCidade}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
4;
|
||||
{/* Formulário de criação/edição */}
|
||||
<GCidadeForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedCidade}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,123 +1,118 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
|
||||
export default function GNaturezaColumns(
|
||||
onEdit: (item: GNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: GNaturezaInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: GNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: GNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<GNaturezaInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "natureza_id",
|
||||
header: ({ column }) => SortableHeader("ID", column),
|
||||
cell: ({ row }) => Number(row.getValue("natureza_id")),
|
||||
enableSorting: true,
|
||||
},
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'natureza_id',
|
||||
header: ({ column }) => SortableHeader('ID', column),
|
||||
cell: ({ row }) => Number(row.getValue('natureza_id')),
|
||||
enableSorting: true,
|
||||
},
|
||||
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: "descricao",
|
||||
header: ({ column }) => SortableHeader("Descrição", column),
|
||||
cell: ({ row }) =>
|
||||
GetCapitalize(String(row.getValue("descricao") || "")),
|
||||
},
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => SortableHeader('Descrição', column),
|
||||
cell: ({ row }) => GetCapitalize(String(row.getValue('descricao') || '')),
|
||||
},
|
||||
|
||||
// Situação
|
||||
{
|
||||
accessorKey: "situacao",
|
||||
header: ({ column }) => SortableHeader("Situação", column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue("situacao") || "").toUpperCase();
|
||||
if (value === "A") return "Ativo";
|
||||
if (value === "I") return "Inativo";
|
||||
return "-";
|
||||
},
|
||||
},
|
||||
// Situação
|
||||
{
|
||||
accessorKey: 'situacao',
|
||||
header: ({ column }) => SortableHeader('Situação', column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue('situacao') || '').toUpperCase();
|
||||
if (value === 'A') return 'Ativo';
|
||||
if (value === 'I') return 'Inativo';
|
||||
return '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Sistema ID
|
||||
{
|
||||
accessorKey: "sistema_id",
|
||||
header: ({ column }) => SortableHeader("Sistema ID", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("sistema_id");
|
||||
return value ? Number(value) : "-";
|
||||
},
|
||||
},
|
||||
// Sistema ID
|
||||
{
|
||||
accessorKey: 'sistema_id',
|
||||
header: ({ column }) => SortableHeader('Sistema ID', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('sistema_id');
|
||||
return value ? Number(value) : '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Pedir Número Imóvel
|
||||
{
|
||||
accessorKey: "pedir_numero_imovel",
|
||||
header: ({ column }) => SortableHeader("Pedir Nº Imóvel", column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue("pedir_numero_imovel") || "").toUpperCase();
|
||||
return value === "S" ? "Sim" : "Não";
|
||||
},
|
||||
},
|
||||
// Pedir Número Imóvel
|
||||
{
|
||||
accessorKey: 'pedir_numero_imovel',
|
||||
header: ({ column }) => SortableHeader('Pedir Nº Imóvel', column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue('pedir_numero_imovel') || '').toUpperCase();
|
||||
return value === 'S' ? 'Sim' : 'Não';
|
||||
},
|
||||
},
|
||||
|
||||
// Controle Frente/Verso
|
||||
{
|
||||
accessorKey: "controle_frenteverso",
|
||||
header: ({ column }) => SortableHeader("Controle Frente/Verso", column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue("controle_frenteverso") || "").toUpperCase();
|
||||
return value === "S" ? "Sim" : "Não";
|
||||
},
|
||||
},
|
||||
// Controle Frente/Verso
|
||||
{
|
||||
accessorKey: 'controle_frenteverso',
|
||||
header: ({ column }) => SortableHeader('Controle Frente/Verso', column),
|
||||
cell: ({ row }) => {
|
||||
const value = String(row.getValue('controle_frenteverso') || '').toUpperCase();
|
||||
return value === 'S' ? 'Sim' : 'Não';
|
||||
},
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const natureza = row.original;
|
||||
// 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>
|
||||
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>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(natureza, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
<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,
|
||||
},
|
||||
];
|
||||
<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,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
'use client';
|
||||
|
||||
import React, { useEffect } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import React, { useEffect } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
|
|
@ -10,7 +10,7 @@ import {
|
|||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
} from '@/components/ui/dialog';
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
|
|
@ -18,15 +18,15 @@ import {
|
|||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
} from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
|
||||
import LoadingButton from "@/shared/components/loadingButton/LoadingButton";
|
||||
import { ResetFormIfData } from "@/shared/actions/form/ResetFormIfData";
|
||||
import { useGNaturezaFormHook } from "../../hooks/GNatureza/useGNaturezaFormHook";
|
||||
import { GNaturezaFormInterface } from "../../interfaces/GNatureza/GNaturezaFormInterface";
|
||||
import SituacoesSelect from "@/shared/components/situacoes/SituacoesSelect";
|
||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||
import { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData';
|
||||
import { useGNaturezaFormHook } from '../../hooks/GNatureza/useGNaturezaFormHook';
|
||||
import { GNaturezaFormInterface } from '../../interfaces/GNatureza/GNaturezaFormInterface';
|
||||
import SituacoesSelect from '@/shared/components/situacoes/SituacoesSelect';
|
||||
|
||||
/**
|
||||
* Formulário de cadastro/edição de Natureza
|
||||
|
|
@ -47,7 +47,7 @@ export default function GNaturezaForm({
|
|||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
console.log("Erro no formulário:", error);
|
||||
console.log('Erro no formulário:', error);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -59,19 +59,14 @@ export default function GNaturezaForm({
|
|||
>
|
||||
<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">
|
||||
Natureza de Minutas
|
||||
</DialogTitle>
|
||||
<DialogDescription className="text-sm text-muted-foreground">
|
||||
<DialogTitle className="text-lg sm:text-xl">Natureza de Minutas</DialogTitle>
|
||||
<DialogDescription className="text-muted-foreground text-sm">
|
||||
Natureza de MInutas
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Formulário principal */}
|
||||
<Form {...form}>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(onSave, onError)}
|
||||
className="space-y-6"
|
||||
>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
{/* GRID MOBILE FIRST */}
|
||||
<div className="grid w-full grid-cols-12 gap-4">
|
||||
{/* DESCRIÇÃO */}
|
||||
|
|
@ -154,7 +149,7 @@ export default function GNaturezaForm({
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé */}
|
||||
<DialogFooter className="flex flex-col sm:flex-row gap-2 justify-end mt-6">
|
||||
<DialogFooter className="mt-6 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button">
|
||||
Cancelar
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@ import GNaturezaForm from './GNaturezaForm';
|
|||
import { GNaturezaIndexInterface } from '../../interfaces/GNatureza/GNaturezaIndexInterface';
|
||||
|
||||
export default function GNaturezaIndex({ sistema_id }: GNaturezaIndexInterface) {
|
||||
|
||||
const GNaturezaIndexParams: GNaturezaIndexInterface = {
|
||||
sistema_id: sistema_id
|
||||
}
|
||||
sistema_id: sistema_id,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -41,18 +40,15 @@ export default function GNaturezaIndex({ sistema_id }: GNaturezaIndexInterface)
|
|||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: GNaturezaInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com pessoa_tipo
|
||||
const initialData: GNaturezaInterface = data ?? { sistema_id: GNaturezaIndexParams.sistema_id } as GNaturezaInterface;
|
||||
const initialData: GNaturezaInterface =
|
||||
data ?? ({ sistema_id: GNaturezaIndexParams.sistema_id } as GNaturezaInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
@ -144,11 +140,7 @@ export default function GNaturezaIndex({ sistema_id }: GNaturezaIndexInterface)
|
|||
}}
|
||||
/>
|
||||
{/* Tabela de andamentos */}
|
||||
<GNaturezaTable
|
||||
data={gNatureza}
|
||||
onEdit={handleOpenForm}
|
||||
onDelete={handleConfirmDelete}
|
||||
/>
|
||||
<GNaturezaTable data={gNatureza} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
|
|
@ -174,4 +166,4 @@ export default function GNaturezaIndex({ sistema_id }: GNaturezaIndexInterface)
|
|||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
'use client';
|
||||
|
||||
import { DataTable } from "@/shared/components/dataTable/DataTable";
|
||||
import GNaturezaColumns from "./GNaturezaColumns";
|
||||
import GNaturezaTableInterface from "../../interfaces/GNatureza/GNaturezaTableInterface";
|
||||
import { DataTable } from '@/shared/components/dataTable/DataTable';
|
||||
import GNaturezaColumns from './GNaturezaColumns';
|
||||
import GNaturezaTableInterface from '../../interfaces/GNatureza/GNaturezaTableInterface';
|
||||
|
||||
/**
|
||||
* Componente principal da tabela de Naturezas
|
||||
*/
|
||||
export default function GNaturezaTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: GNaturezaTableInterface) {
|
||||
export default function GNaturezaTable({ data, onEdit, onDelete }: GNaturezaTableInterface) {
|
||||
const columns = GNaturezaColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -74,12 +74,8 @@ export default function GTBBairroForm({
|
|||
>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Bairro
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Crie ou edite um bairro
|
||||
</DialogDescription>
|
||||
<DialogTitle>Bairro</DialogTitle>
|
||||
<DialogDescription>Crie ou edite um bairro</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
import React, { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
|
|
@ -19,96 +19,95 @@ import { useGTBBairroReadHook } from '@/packages/administrativo/hooks/GTBBairro/
|
|||
import GTBairroSelectInterface from '../../interfaces/GTBBairro/GTBairroSelectInterface';
|
||||
|
||||
export default function GTBBairroSelect({ field }: GTBairroSelectInterface) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const { gTBBairro = [], fetchGTBBairro } = useGTBBairroReadHook();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const { gTBBairro = [], fetchGTBBairro } = useGTBBairroReadHook();
|
||||
/**
|
||||
* Efeito para buscar os dados apenas uma vez.
|
||||
* useCallback evita recriação desnecessária da função.
|
||||
*/
|
||||
const loadData = useCallback(async () => {
|
||||
if (gTBBairro.length) return;
|
||||
setIsLoading(true);
|
||||
await fetchGTBBairro();
|
||||
setIsLoading(false);
|
||||
}, [gTBBairro.length, fetchGTBBairro]);
|
||||
|
||||
/**
|
||||
* Efeito para buscar os dados apenas uma vez.
|
||||
* useCallback evita recriação desnecessária da função.
|
||||
*/
|
||||
const loadData = useCallback(async () => {
|
||||
if (gTBBairro.length) return;
|
||||
setIsLoading(true);
|
||||
await fetchGTBBairro();
|
||||
setIsLoading(false);
|
||||
}, [gTBBairro.length, fetchGTBBairro]);
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
/**
|
||||
* Memoriza o bairro selecionado para evitar reprocessamentos.
|
||||
*/
|
||||
const selected = useMemo(
|
||||
() => gTBBairro.find((b) => String(b.tb_bairro_id) === String(field?.value ?? '')),
|
||||
[gTBBairro, field?.value],
|
||||
);
|
||||
|
||||
/**
|
||||
* Memoriza o bairro selecionado para evitar reprocessamentos.
|
||||
*/
|
||||
const selected = useMemo(
|
||||
() => gTBBairro.find((b) => String(b.tb_bairro_id) === String(field?.value ?? '')),
|
||||
[gTBBairro, field?.value]
|
||||
);
|
||||
/**
|
||||
* Manipulador de seleção com verificação segura.
|
||||
*/
|
||||
const handleSelect = useCallback(
|
||||
(bairroId: string | number) => {
|
||||
if (!field?.onChange) return;
|
||||
field.onChange(bairroId);
|
||||
setOpen(false);
|
||||
},
|
||||
[field],
|
||||
);
|
||||
|
||||
/**
|
||||
* Manipulador de seleção com verificação segura.
|
||||
*/
|
||||
const handleSelect = useCallback(
|
||||
(bairroId: string | number) => {
|
||||
if (!field?.onChange) return;
|
||||
field.onChange(bairroId);
|
||||
setOpen(false);
|
||||
},
|
||||
[field]
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar bairro..." disabled={isLoading} />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{gTBBairro.map((item) => (
|
||||
<CommandItem
|
||||
key={item.tb_bairro_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => handleSelect(item.tb_bairro_id)}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field?.value ?? '') === String(item.tb_bairro_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0'
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao ?? '')}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar bairro..." disabled={isLoading} />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{gTBBairro.map((item) => (
|
||||
<CommandItem
|
||||
key={item.tb_bairro_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => handleSelect(item.tb_bairro_id)}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field?.value ?? '') === String(item.tb_bairro_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao ?? '')}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,129 +1,122 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import TAtoParteTipoInterface from "../../interfaces/TAtoParteTipo/TAtoParteTipoInterface";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import TAtoParteTipoInterface from '../../interfaces/TAtoParteTipo/TAtoParteTipoInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { SituacoesEnum } from "@/shared/enums/SituacoesEnum";
|
||||
import { ConfirmacaoEnum } from "@/shared/enums/ConfirmacaoEnum";
|
||||
import { TipoDaParteEnum } from "@/shared/enums/TIpoDaParteEnum";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { SituacoesEnum } from '@/shared/enums/SituacoesEnum';
|
||||
import { ConfirmacaoEnum } from '@/shared/enums/ConfirmacaoEnum';
|
||||
import { TipoDaParteEnum } from '@/shared/enums/TIpoDaParteEnum';
|
||||
|
||||
export default function TAtoParteTipoColumns(
|
||||
onEdit: (item: TAtoParteTipoInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TAtoParteTipoInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TAtoParteTipoInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TAtoParteTipoInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TAtoParteTipoInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "ato_partetipo_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("ato_partetipo_id")),
|
||||
enableSorting: false,
|
||||
},
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'ato_partetipo_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('ato_partetipo_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: "descricao",
|
||||
header: ({ column }) => SortableHeader("Descrição", column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue("descricao")),
|
||||
},
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => SortableHeader('Descrição', column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('descricao')),
|
||||
},
|
||||
|
||||
// Tipo de Parte
|
||||
{
|
||||
accessorKey: "tipo_parte",
|
||||
header: ({ column }) => SortableHeader("Tipo Parte", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("tipo_parte") as keyof typeof TipoDaParteEnum;
|
||||
return TipoDaParteEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// Tipo de Parte
|
||||
{
|
||||
accessorKey: 'tipo_parte',
|
||||
header: ({ column }) => SortableHeader('Tipo Parte', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('tipo_parte') as keyof typeof TipoDaParteEnum;
|
||||
return TipoDaParteEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Auto Qualifica
|
||||
{
|
||||
accessorKey: "auto_qualifica",
|
||||
header: ({ column }) => SortableHeader("Auto Qualifica", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("auto_qualifica") as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// Auto Qualifica
|
||||
{
|
||||
accessorKey: 'auto_qualifica',
|
||||
header: ({ column }) => SortableHeader('Auto Qualifica', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('auto_qualifica') as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Declara DOI
|
||||
{
|
||||
accessorKey: "declara_doi",
|
||||
header: ({ column }) => SortableHeader("Declara DOI", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("declara_doi") as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// Declara DOI
|
||||
{
|
||||
accessorKey: 'declara_doi',
|
||||
header: ({ column }) => SortableHeader('Declara DOI', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('declara_doi') as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Possui Documento Externo
|
||||
{
|
||||
accessorKey: "possui_documento_ext",
|
||||
header: ({ column }) => SortableHeader("Doc. Externo", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("possui_documento_ext") as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// Possui Documento Externo
|
||||
{
|
||||
accessorKey: 'possui_documento_ext',
|
||||
header: ({ column }) => SortableHeader('Doc. Externo', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('possui_documento_ext') as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Situação
|
||||
{
|
||||
accessorKey: "situacao",
|
||||
header: ({ column }) => SortableHeader("Situação", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("situacao") as keyof typeof SituacoesEnum;
|
||||
return SituacoesEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// Situação
|
||||
{
|
||||
accessorKey: 'situacao',
|
||||
header: ({ column }) => SortableHeader('Situação', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('situacao') as keyof typeof SituacoesEnum;
|
||||
return SituacoesEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,20 @@ import { parseNumberInput } from '@/shared/actions/form/parseNumberInput';
|
|||
import TCensecQualidadeSelect from '../TCensecQualidade/TCensecQualidadeSelect';
|
||||
import TipoDaParteSelect from '@/shared/components/tipoDaParte/TipoDaParteSelect';
|
||||
|
||||
export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TAtoParteTipoFormInterface) {
|
||||
|
||||
export default function TAtoParteTipoForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TAtoParteTipoFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTAtoParteTipoFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
|
||||
// Se existir dados, reseta o formulário com os mesmos
|
||||
ResetFormIfData(form, data);
|
||||
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
|
|
@ -57,12 +60,8 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-2xl lg:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Tipo de Partes do Ato
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Tipo de Partes do Ato
|
||||
</DialogDescription>
|
||||
<DialogTitle>Tipo de Partes do Ato</DialogTitle>
|
||||
<DialogDescription>Tipo de Partes do Ato</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
|
|
@ -76,7 +75,7 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
<FormItem>
|
||||
<FormLabel>Descrição</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="Descrição" />
|
||||
<Input {...field} type="text" placeholder="Descrição" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -91,7 +90,7 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo da Parte</FormLabel>
|
||||
< TipoDaParteSelect field={field} />
|
||||
<TipoDaParteSelect field={field} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
|
|
@ -105,7 +104,7 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Censec Qualidade</FormLabel>
|
||||
< TCensecQualidadeSelect field={field} />
|
||||
<TCensecQualidadeSelect field={field} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
|
|
@ -197,7 +196,7 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
@ -212,7 +211,7 @@ export default function TAtoParteTipoForm({ isOpen, data, onClose, onSave, butto
|
|||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent >
|
||||
</Dialog >
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import TAtoParteTipoTable from './TAtoParteTipoTable';
|
|||
import TAtoParteTipoForm from './TAtoParteTipoForm';
|
||||
|
||||
export default function TAtoParteTipoIndex() {
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
|
|
@ -131,8 +130,8 @@ export default function TAtoParteTipoIndex() {
|
|||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={"Tipos de Partes"}
|
||||
description={"Tipos de Partes"}
|
||||
title={'Tipos de Partes'}
|
||||
description={'Tipos de Partes'}
|
||||
buttonText={'Novo tipo de parte'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import TAtoParteTipoTableInterface from '../../interfaces/TAtoParteTipo/TAtoPart
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TAtoParteTipoTable({ data, onEdit, onDelete }: TAtoParteTipoTableInterface) {
|
||||
export default function TAtoParteTipoTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TAtoParteTipoTableInterface) {
|
||||
const columns = TAtoParteTipoColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
|
|
@ -19,4 +23,4 @@ export default function TAtoParteTipoTable({ data, onEdit, onDelete }: TAtoParte
|
|||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +1,69 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import TCensecQualidadeInterface from "../../interfaces/TCensecQualidade/TCensecQualidadeInterface";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import TCensecQualidadeInterface from '../../interfaces/TCensecQualidade/TCensecQualidadeInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
|
||||
export default function TCensecQualidadeColumns(
|
||||
onEdit: (item: TCensecQualidadeInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TCensecQualidadeInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TCensecQualidadeInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TCensecQualidadeInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TCensecQualidadeInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "censec_qualidade_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("censec_qualidade_id")),
|
||||
enableSorting: false,
|
||||
},
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'censec_qualidade_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('censec_qualidade_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: "descricao",
|
||||
header: ({ column }) => SortableHeader("Descrição", column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue("descricao")),
|
||||
},
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => SortableHeader('Descrição', column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('descricao')),
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,17 +29,20 @@ import { TCensecQualidadeFormInterface } from '../../interfaces/TCensecQualidade
|
|||
import SituacoesSelect from '@/shared/components/situacoes/SituacoesSelect';
|
||||
import ConfirmacaoSelect from '@/shared/components/confirmacao/ConfirmacaoSelect';
|
||||
|
||||
export default function TCensecQualidadeForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TCensecQualidadeFormInterface) {
|
||||
|
||||
export default function TCensecQualidadeForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TCensecQualidadeFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTCensecQualidadeFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
|
||||
// Se existir dados, reseta o formulário com os mesmos
|
||||
ResetFormIfData(form, data);
|
||||
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
|
|
@ -55,12 +58,8 @@ export default function TCensecQualidadeForm({ isOpen, data, onClose, onSave, bu
|
|||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-2xl lg:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Tipo de Partes do Ato
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Tipo de Partes do Ato
|
||||
</DialogDescription>
|
||||
<DialogTitle>Tipo de Partes do Ato</DialogTitle>
|
||||
<DialogDescription>Tipo de Partes do Ato</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
|
|
@ -74,7 +73,7 @@ export default function TCensecQualidadeForm({ isOpen, data, onClose, onSave, bu
|
|||
<FormItem>
|
||||
<FormLabel>Descrição</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="Descrição" />
|
||||
<Input {...field} type="text" placeholder="Descrição" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -111,7 +110,7 @@ export default function TCensecQualidadeForm({ isOpen, data, onClose, onSave, bu
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
@ -126,7 +125,7 @@ export default function TCensecQualidadeForm({ isOpen, data, onClose, onSave, bu
|
|||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent >
|
||||
</Dialog >
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import TCensecQualidadeTable from './TCensecQualidadeTable';
|
|||
import TCensecQualidadeForm from './TCensecQualidadeForm';
|
||||
|
||||
export default function TCensecQualidadeIndex() {
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
|
|
@ -131,8 +130,8 @@ export default function TCensecQualidadeIndex() {
|
|||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={"Qualidades do CENSEC"}
|
||||
description={"Qualidades do CENSEC"}
|
||||
title={'Qualidades do CENSEC'}
|
||||
description={'Qualidades do CENSEC'}
|
||||
buttonText={'Nova qualdiade'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
|
|
|
|||
|
|
@ -1,92 +1,92 @@
|
|||
'use client';
|
||||
|
||||
import React from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import React from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { useTCensecQualidadeIndexHook } from "../../hooks/TCensecQualidade/useTCensecQualidadeIndexHook";
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { useTCensecQualidadeIndexHook } from '../../hooks/TCensecQualidade/useTCensecQualidadeIndexHook';
|
||||
|
||||
export default function TCensecQualidadeSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { tCensecQualidade, indexTCensecQualidade } = useTCensecQualidadeIndexHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!tCensecQualidade.length) {
|
||||
setIsLoading(true);
|
||||
await indexTCensecQualidade();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = tCensecQualidade.find(
|
||||
(item) => String(item.censec_qualidade_id) === String(field.value)
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? "Carregando..."
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: "Selecione..."}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? "Carregando..." : "Nenhum resultado encontrado."}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{tCensecQualidade?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.censec_qualidade_id}
|
||||
value={item.descricao?.toLowerCase() ?? ""}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.censec_qualidade_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
String(field.value) === String(item.censec_qualidade_id)
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { tCensecQualidade, indexTCensecQualidade } = useTCensecQualidadeIndexHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!tCensecQualidade.length) {
|
||||
setIsLoading(true);
|
||||
await indexTCensecQualidade();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = tCensecQualidade.find(
|
||||
(item) => String(item.censec_qualidade_id) === String(field.value),
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{tCensecQualidade?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.censec_qualidade_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.censec_qualidade_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field.value) === String(item.censec_qualidade_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import TCensecQualidadeTableInterface from '../../interfaces/TCensecQualidade/TC
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TCensecQualidadeTable({ data, onEdit, onDelete }: TCensecQualidadeTableInterface) {
|
||||
export default function TCensecQualidadeTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TCensecQualidadeTableInterface) {
|
||||
const columns = TCensecQualidadeColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
|
|
@ -19,4 +23,4 @@ export default function TCensecQualidadeTable({ data, onEdit, onDelete }: TCense
|
|||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,16 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowUpDownIcon, EllipsisIcon, Trash2Icon } from "lucide-react";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import TCensecQualidadeAtoJoinedInterface from "../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoPageInterface";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowUpDownIcon, EllipsisIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import TCensecQualidadeAtoJoinedInterface from '../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoPageInterface';
|
||||
|
||||
export default function TCensecQualidadeAtoColumns(
|
||||
onDelete: (item: TCensecQualidadeAtoJoinedInterface, isEditingFormStatus: boolean) => void,
|
||||
|
|
@ -26,9 +32,9 @@ export default function TCensecQualidadeAtoColumns(
|
|||
},
|
||||
// Descrição
|
||||
{
|
||||
accessorKey: "tcq_descricao",
|
||||
header: ({ column }) => SortableHeader("Descrição", column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue("tcq_descricao")),
|
||||
accessorKey: 'tcq_descricao',
|
||||
header: ({ column }) => SortableHeader('Descrição', column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('tcq_descricao')),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
|
|
@ -61,4 +67,4 @@ export default function TCensecQualidadeAtoColumns(
|
|||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,10 +30,10 @@ export default function TCensecQualidadeAtoForm({
|
|||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TCensecQualidadeAtoFormInterface) {
|
||||
|
||||
const { tCensecQualidade, indexTCensecQualidade } = useTCensecQualidadeIndexHook();
|
||||
|
||||
const [selectedTCensecQualidadeAto, setSelectedTCensecQualidadeAto] = useState<TCensecQualidadeAtoInterface | null>(null);
|
||||
const [selectedTCensecQualidadeAto, setSelectedTCensecQualidadeAto] =
|
||||
useState<TCensecQualidadeAtoInterface | null>(null);
|
||||
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTCensecQualidadeAtoFormHook();
|
||||
|
|
@ -68,14 +68,10 @@ export default function TCensecQualidadeAtoForm({
|
|||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-4xl md:max-w-4xl lg:max-w-4xl max-h-[70vh] overflow-auto">
|
||||
<DialogContent className="max-h-[70vh] w-full max-w-full overflow-auto p-6 sm:max-w-4xl md:max-w-4xl lg:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Qualidades
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Qualidades vinculadas
|
||||
</DialogDescription>
|
||||
<DialogTitle>Qualidades</DialogTitle>
|
||||
<DialogDescription>Qualidades vinculadas</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
|
|
|
|||
|
|
@ -1,60 +1,62 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowUpDownIcon } from "lucide-react";
|
||||
import TCensecQualidadeAtoInterface from "../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoInterface";
|
||||
import TCensecQualidadeInterface from "../../interfaces/TCensecQualidade/TCensecQualidadeInterface";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowUpDownIcon } from 'lucide-react';
|
||||
import TCensecQualidadeAtoInterface from '../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoInterface';
|
||||
import TCensecQualidadeInterface from '../../interfaces/TCensecQualidade/TCensecQualidadeInterface';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
|
||||
export default function TCensecQualidadeAtoFormColumns(
|
||||
setSelectedTCensecQualidadeAto: React.Dispatch<React.SetStateAction<TCensecQualidadeAtoInterface | null>>,
|
||||
setSelectedTCensecQualidadeAto: React.Dispatch<
|
||||
React.SetStateAction<TCensecQualidadeAtoInterface | null>
|
||||
>,
|
||||
): ColumnDef<TCensecQualidadeInterface>[] {
|
||||
return [
|
||||
{
|
||||
id: 'select',
|
||||
header: '',
|
||||
cell: ({ row, table }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => {
|
||||
// Limpa todas as seleções antes de selecionar uma nova
|
||||
table.resetRowSelection();
|
||||
row.toggleSelected(!!value);
|
||||
setSelectedTCensecQualidadeAto(value ? row.original : null);
|
||||
}}
|
||||
aria-label="Select row"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'censec_qualidade_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('censec_qualidade_id')),
|
||||
enableSorting: true,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('descricao')),
|
||||
enableSorting: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
return [
|
||||
{
|
||||
id: 'select',
|
||||
header: '',
|
||||
cell: ({ row, table }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => {
|
||||
// Limpa todas as seleções antes de selecionar uma nova
|
||||
table.resetRowSelection();
|
||||
row.toggleSelected(!!value);
|
||||
setSelectedTCensecQualidadeAto(value ? row.original : null);
|
||||
}}
|
||||
aria-label="Select row"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'censec_qualidade_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('censec_qualidade_id')),
|
||||
enableSorting: true,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('descricao')),
|
||||
enableSorting: true,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,12 @@ import TCensecQualidadeAtoForm from './TCensecQualidadeAtoForm';
|
|||
import TCensecQualidadeAtoPageInterface from '../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoPageInterface';
|
||||
import TCensecQualidadeAtoInterface from '../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoInterface';
|
||||
|
||||
export default function TCensecQualidadeAtoIndex({ censec_tipoato_id }: TCensecQualidadeAtoPageInterface) {
|
||||
|
||||
export default function TCensecQualidadeAtoIndex({
|
||||
censec_tipoato_id,
|
||||
}: TCensecQualidadeAtoPageInterface) {
|
||||
const TCensecQualidadeAtoPage: TCensecQualidadeAtoPageInterface = {
|
||||
censec_tipoato_id: censec_tipoato_id
|
||||
}
|
||||
censec_tipoato_id: censec_tipoato_id,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -39,18 +40,15 @@ export default function TCensecQualidadeAtoIndex({ censec_tipoato_id }: TCensecQ
|
|||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: TCensecQualidadeAtoInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com imovel_id
|
||||
const initialData: TCensecQualidadeAtoPageInterface = data ?? { censec_tipoato_id } as TCensecQualidadeAtoPageInterface;
|
||||
const initialData: TCensecQualidadeAtoPageInterface =
|
||||
data ?? ({ censec_tipoato_id } as TCensecQualidadeAtoPageInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
|
|||
|
|
@ -15,16 +15,13 @@ export default function TCensecQualidadeAtoTable({
|
|||
const columns = TCensecQualidadeAtoColumns(onDelete);
|
||||
const isEmpty = !data || data.length === 0;
|
||||
return (
|
||||
<div className='max-h-[50vh] overflow-auto'>
|
||||
<div className="max-h-[50vh] overflow-auto">
|
||||
{isEmpty ? (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
<div className="text-muted-foreground p-6 text-center">
|
||||
Nenhuma unidade cadastrada ainda.
|
||||
</div>
|
||||
) : (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
/>
|
||||
<DataTable data={data} columns={columns} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,257 +1,255 @@
|
|||
'use client';
|
||||
|
||||
import z from "zod";
|
||||
import { useEffect } from "react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import LoadingButton from "@/shared/components/loadingButton/LoadingButton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import z from 'zod';
|
||||
import { useEffect } from 'react';
|
||||
import { useForm, Controller } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from "@/components/ui/dialog";
|
||||
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 { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { TCensecTipoAtoSchema } from "../../schemas/TCensecTipoAto/TCensecTipoAtoSchema";
|
||||
import TCensecInterface from "../../interfaces/TCensec/TCensecInterface";
|
||||
import { SituacoesEnum } from "@/shared/enums/SituacoesEnum";
|
||||
import SituacoesSelect from "@/shared/components/situacoes/SituacoesSelect";
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { IdCardIcon, UserIcon } from "lucide-react";
|
||||
import TCensecQualidadeAtoIndex from "@/packages/administrativo/components/TCensecQualidadeAto/TCensecQualidadeAtoIndex";
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage,
|
||||
} from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { TCensecTipoAtoSchema } from '../../schemas/TCensecTipoAto/TCensecTipoAtoSchema';
|
||||
import TCensecInterface from '../../interfaces/TCensec/TCensecInterface';
|
||||
import { SituacoesEnum } from '@/shared/enums/SituacoesEnum';
|
||||
import SituacoesSelect from '@/shared/components/situacoes/SituacoesSelect';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import { IdCardIcon, UserIcon } from 'lucide-react';
|
||||
import TCensecQualidadeAtoIndex from '@/packages/administrativo/components/TCensecQualidadeAto/TCensecQualidadeAtoIndex';
|
||||
|
||||
type FormValues = z.infer<typeof TCensecTipoAtoSchema>;
|
||||
|
||||
interface TCensecTipoAtoFormProps {
|
||||
isOpen: boolean;
|
||||
data: FormValues | null;
|
||||
tCensec: TCensecInterface[];
|
||||
onClose: (item: null, isFormStatus: boolean) => void;
|
||||
onSave: (data: FormValues) => void;
|
||||
buttonIsLoading: boolean;
|
||||
isOpen: boolean;
|
||||
data: FormValues | null;
|
||||
tCensec: TCensecInterface[];
|
||||
onClose: (item: null, isFormStatus: boolean) => void;
|
||||
onSave: (data: FormValues) => void;
|
||||
buttonIsLoading: boolean;
|
||||
}
|
||||
|
||||
export default function TCensecTipoAtoForm({
|
||||
isOpen,
|
||||
data,
|
||||
tCensec,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading
|
||||
isOpen,
|
||||
data,
|
||||
tCensec,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TCensecTipoAtoFormProps) {
|
||||
const form = useForm<FormValues>({
|
||||
resolver: zodResolver(TCensecTipoAtoSchema),
|
||||
defaultValues: {
|
||||
censec_tipoato_id: 0,
|
||||
censec_id: 0,
|
||||
codigo: null,
|
||||
descricao: '',
|
||||
situacao: SituacoesEnum.A,
|
||||
tipo_separacao: null,
|
||||
tipo_revogacao: null,
|
||||
},
|
||||
});
|
||||
|
||||
const form = useForm<FormValues>({
|
||||
resolver: zodResolver(TCensecTipoAtoSchema),
|
||||
defaultValues: {
|
||||
censec_tipoato_id: 0,
|
||||
censec_id: 0,
|
||||
codigo: null,
|
||||
descricao: "",
|
||||
situacao: SituacoesEnum.A,
|
||||
tipo_separacao: null,
|
||||
tipo_revogacao: null,
|
||||
},
|
||||
});
|
||||
useEffect(() => {
|
||||
if (data) form.reset(data);
|
||||
}, [data, form]);
|
||||
|
||||
useEffect(() => {
|
||||
if (data) form.reset(data);
|
||||
}, [data, form]);
|
||||
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-4xl lg:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Tipo de Ato CENSEC</DialogTitle>
|
||||
<DialogDescription>Crie ou edite um tipo de ato da CENSEC</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
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-4xl lg:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Tipo de Ato CENSEC</DialogTitle>
|
||||
<DialogDescription>
|
||||
Crie ou edite um tipo de ato da CENSEC
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
{/* Conteúdo principal dentro das Tabs */}
|
||||
<Tabs defaultValue="dadosGerais" className="space-y-4">
|
||||
<TabsList className="flex w-full">
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="dadosGerais">
|
||||
<UserIcon className="me-1" />
|
||||
Dados Gerais
|
||||
</TabsTrigger>
|
||||
{data?.censec_tipoato_id && (
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="qualidades">
|
||||
<IdCardIcon className="me-1" />
|
||||
Qualidades
|
||||
</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
|
||||
{/* Conteúdo principal dentro das Tabs */}
|
||||
<Tabs defaultValue="dadosGerais" className="space-y-4">
|
||||
<TabsList className="flex w-full">
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="dadosGerais">
|
||||
<UserIcon className="me-1" />
|
||||
Dados Gerais
|
||||
</TabsTrigger>
|
||||
{data?.censec_tipoato_id && (
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="qualidades">
|
||||
<IdCardIcon className="me-1" />
|
||||
Qualidades
|
||||
</TabsTrigger>
|
||||
)}
|
||||
</TabsList>
|
||||
<div className="max-h-[80vh] overflow-y-auto">
|
||||
{/* ABA DADOS GERAIS */}
|
||||
<TabsContent value="dadosGerais">
|
||||
<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>
|
||||
)}
|
||||
/>
|
||||
|
||||
<div className="max-h-[80vh] overflow-y-auto">
|
||||
{/* ABA DADOS GERAIS */}
|
||||
<TabsContent value="dadosGerais">
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||
{/* Select Censec */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="censec_id"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Central do Censec</FormLabel>
|
||||
<Select
|
||||
value={field.value?.toString()}
|
||||
onValueChange={(val) => field.onChange(Number(val))}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione um Censec" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
{tCensec.map((c) => (
|
||||
<SelectItem key={c.censec_id} value={String(c.censec_id)}>
|
||||
{c.descricao}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* 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>
|
||||
)}
|
||||
/>
|
||||
{/* Situação */}
|
||||
<Controller
|
||||
name="situacao"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Situação</FormLabel>
|
||||
<FormControl>
|
||||
<SituacoesSelect field={field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Select Censec */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="censec_id"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Central do Censec</FormLabel>
|
||||
<Select
|
||||
value={field.value?.toString()}
|
||||
onValueChange={(val) => field.onChange(Number(val))}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione um Censec" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
{tCensec.map((c) => (
|
||||
<SelectItem key={c.censec_id} value={String(c.censec_id)}>
|
||||
{c.descricao}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Tipo de Separação */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tipo_separacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo de Separação</FormLabel>
|
||||
<Select
|
||||
onValueChange={(val) => field.onChange(val || null)}
|
||||
value={field.value ?? ''}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
<SelectItem value="S">Sim</SelectItem>
|
||||
<SelectItem value="N">Não</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Situação */}
|
||||
<Controller
|
||||
name="situacao"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Situação</FormLabel>
|
||||
<FormControl>
|
||||
<SituacoesSelect field={field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Tipo de Revogação */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tipo_revogacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo de Revogação</FormLabel>
|
||||
<Select
|
||||
onValueChange={(val) => field.onChange(val || null)}
|
||||
value={field.value ?? ''}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
<SelectItem value="S">Sim</SelectItem>
|
||||
<SelectItem value="N">Não</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Tipo de Separação */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tipo_separacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo de Separação</FormLabel>
|
||||
<Select
|
||||
onValueChange={(val) => field.onChange(val || null)}
|
||||
value={field.value ?? ""}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
<SelectItem value="S">Sim</SelectItem>
|
||||
<SelectItem value="N">Não</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Rodapé do formulário */}
|
||||
<DialogFooter className="mt-6">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<LoadingButton
|
||||
text="Salvar"
|
||||
textLoading="Aguarde..."
|
||||
type="submit"
|
||||
loading={buttonIsLoading}
|
||||
/>
|
||||
</DialogFooter>
|
||||
|
||||
{/* Tipo de Revogação */}
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tipo_revogacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo de Revogação</FormLabel>
|
||||
<Select
|
||||
onValueChange={(val) => field.onChange(val || null)}
|
||||
value={field.value ?? ""}
|
||||
>
|
||||
<FormControl>
|
||||
<SelectTrigger className="w-full">
|
||||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent className="w-full">
|
||||
<SelectItem value="S">Sim</SelectItem>
|
||||
<SelectItem value="N">Não</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
{/* Campos ocultos */}
|
||||
<input type="hidden" {...form.register('censec_tipoato_id')} />
|
||||
<input type="hidden" {...form.register('codigo')} />
|
||||
</form>
|
||||
</Form>
|
||||
</TabsContent>
|
||||
|
||||
{/* Rodapé do formulário */}
|
||||
<DialogFooter className="mt-6">
|
||||
<DialogClose asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
type="button"
|
||||
onClick={() => onClose(null, false)}
|
||||
>
|
||||
Cancelar
|
||||
</Button>
|
||||
</DialogClose>
|
||||
<LoadingButton
|
||||
text="Salvar"
|
||||
textLoading="Aguarde..."
|
||||
type="submit"
|
||||
loading={buttonIsLoading}
|
||||
/>
|
||||
</DialogFooter>
|
||||
|
||||
{/* Campos ocultos */}
|
||||
<input type="hidden" {...form.register("censec_tipoato_id")} />
|
||||
<input type="hidden" {...form.register("codigo")} />
|
||||
</form>
|
||||
</Form>
|
||||
</TabsContent>
|
||||
|
||||
{/* ======== ABA QUALIDADES ======== */}
|
||||
{data?.censec_tipoato_id && (
|
||||
<TabsContent value="qualidades" className="space-y-4">
|
||||
<TCensecQualidadeAtoIndex censec_tipoato_id={data.censec_tipoato_id} />
|
||||
</TabsContent>
|
||||
)}
|
||||
</div>
|
||||
</Tabs>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
{/* ======== ABA QUALIDADES ======== */}
|
||||
{data?.censec_tipoato_id && (
|
||||
<TabsContent value="qualidades" className="space-y-4">
|
||||
<TCensecQualidadeAtoIndex censec_tipoato_id={data.censec_tipoato_id} />
|
||||
</TabsContent>
|
||||
)}
|
||||
</div>
|
||||
</Tabs>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,30 @@
|
|||
'use client';
|
||||
|
||||
import { useEffect, useState, useCallback } from "react";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { useConfirmDialog } from "@/shared/components/confirmDialog/useConfirmDialog";
|
||||
import { useEffect, useState, useCallback } from 'react';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { useConfirmDialog } from '@/shared/components/confirmDialog/useConfirmDialog';
|
||||
|
||||
import Header from "@/shared/components/structure/Header";
|
||||
import ConfirmDialog from "@/shared/components/confirmDialog/ConfirmDialog";
|
||||
import Loading from "@/shared/components/loading/loading";
|
||||
import Header from '@/shared/components/structure/Header';
|
||||
import ConfirmDialog from '@/shared/components/confirmDialog/ConfirmDialog';
|
||||
import Loading from '@/shared/components/loading/loading';
|
||||
|
||||
import TCensecTipoAtoTable from "./TCensecTipoAtoTable";
|
||||
import TCensecTipoAtoForm from "./TCensecTipoAtoForm";
|
||||
import TCensecTipoAtoTable from './TCensecTipoAtoTable';
|
||||
import TCensecTipoAtoForm from './TCensecTipoAtoForm';
|
||||
|
||||
import { useTCensecTipoAtoReadHook } from "../../hooks/TCensecTipoAto/useTCensecTipoAtoReadHook";
|
||||
import { useTCensecTipoAtoSaveHook } from "../../hooks/TCensecTipoAto/useTCensecTipoAtoSaveHook";
|
||||
import { useTCensecTipoAtoRemoveHook } from "../../hooks/TCensecTipoAto/useTCensecTipoAtoRemoveHook";
|
||||
import { useTCensecReadHook } from "../../hooks/TCensec/useTCensecReadHook";
|
||||
import { useTCensecTipoAtoReadHook } from '../../hooks/TCensecTipoAto/useTCensecTipoAtoReadHook';
|
||||
import { useTCensecTipoAtoSaveHook } from '../../hooks/TCensecTipoAto/useTCensecTipoAtoSaveHook';
|
||||
import { useTCensecTipoAtoRemoveHook } from '../../hooks/TCensecTipoAto/useTCensecTipoAtoRemoveHook';
|
||||
import { useTCensecReadHook } from '../../hooks/TCensec/useTCensecReadHook';
|
||||
|
||||
import { TCensecTipoAtoInterface } from "../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface";
|
||||
import { SituacoesEnum } from "@/shared/enums/SituacoesEnum";
|
||||
import { TCensecTipoAtoInterface } from '../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface';
|
||||
import { SituacoesEnum } from '@/shared/enums/SituacoesEnum';
|
||||
|
||||
// Estado inicial para criação
|
||||
const initialTCensecTipoAto: TCensecTipoAtoInterface = {
|
||||
censec_tipoato_id: 0,
|
||||
censec_id: 0,
|
||||
codigo: null,
|
||||
descricao: "",
|
||||
descricao: '',
|
||||
situacao: SituacoesEnum.A,
|
||||
tipo_separacao: null,
|
||||
tipo_revogacao: null,
|
||||
|
|
@ -36,7 +36,7 @@ export default function TCensecTipoAtoIndex() {
|
|||
const { saveTCensecTipoAto } = useTCensecTipoAtoSaveHook();
|
||||
const { removeTCensecTipoAto } = useTCensecTipoAtoRemoveHook();
|
||||
|
||||
const { tCensec, fetchTCensec } = useTCensecReadHook()
|
||||
const { tCensec, fetchTCensec } = useTCensecReadHook();
|
||||
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ export default function TCensecTipoAtoIndex() {
|
|||
await fetchTCensecTipoAto();
|
||||
handleCloseForm();
|
||||
},
|
||||
[saveTCensecTipoAto, fetchTCensecTipoAto]
|
||||
[saveTCensecTipoAto, fetchTCensecTipoAto],
|
||||
);
|
||||
|
||||
// Deleção
|
||||
|
|
@ -80,7 +80,7 @@ export default function TCensecTipoAtoIndex() {
|
|||
setItemToDelete(item);
|
||||
openConfirmDialog();
|
||||
},
|
||||
[openConfirmDialog]
|
||||
[openConfirmDialog],
|
||||
);
|
||||
|
||||
const handleDelete = useCallback(async () => {
|
||||
|
|
@ -94,7 +94,7 @@ export default function TCensecTipoAtoIndex() {
|
|||
// Carregar dados ao montar
|
||||
useEffect(() => {
|
||||
fetchTCensecTipoAto();
|
||||
fetchTCensec()
|
||||
fetchTCensec();
|
||||
}, []);
|
||||
|
||||
if (!tCensecTipoAto) {
|
||||
|
|
|
|||
|
|
@ -1,92 +1,92 @@
|
|||
'use client';
|
||||
|
||||
import React from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import React from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { useTCensecTipoAtoReadHook } from "@/packages/administrativo/hooks/TCensecTipoAto/useTCensecTipoAtoReadHook";
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { useTCensecTipoAtoReadHook } from '@/packages/administrativo/hooks/TCensecTipoAto/useTCensecTipoAtoReadHook';
|
||||
|
||||
export default function TCensecTipoAtoSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { tCensecTipoAto, fetchTCensecTipoAto } = useTCensecTipoAtoReadHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!tCensecTipoAto.length) {
|
||||
setIsLoading(true);
|
||||
await fetchTCensecTipoAto();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = tCensecTipoAto.find(
|
||||
(item) => String(item.censec_tipoato_id) === String(field.value)
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? "Carregando..."
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: "Selecione..."}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? "Carregando..." : "Nenhum resultado encontrado."}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{tCensecTipoAto?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.censec_tipoato_id}
|
||||
value={item.descricao?.toLowerCase() ?? ""}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.censec_tipoato_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
String(field.value) === String(item.censec_tipoato_id)
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { tCensecTipoAto, fetchTCensecTipoAto } = useTCensecTipoAtoReadHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!tCensecTipoAto.length) {
|
||||
setIsLoading(true);
|
||||
await fetchTCensecTipoAto();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = tCensecTipoAto.find(
|
||||
(item) => String(item.censec_tipoato_id) === String(field.value),
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{tCensecTipoAto?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.censec_tipoato_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.censec_tipoato_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field.value) === String(item.censec_tipoato_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
'use client';
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
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 { TCensecTipoAtoInterface } from "../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface";
|
||||
import TCensecInterface from "../../interfaces/TCensec/TCensecInterface";
|
||||
TableRow,
|
||||
} from '@/components/ui/table';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import { TCensecTipoAtoInterface } from '../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface';
|
||||
import TCensecInterface from '../../interfaces/TCensec/TCensecInterface';
|
||||
|
||||
interface TCensecTipoAtoTableProps {
|
||||
data: TCensecTipoAtoInterface[];
|
||||
|
|
@ -29,20 +29,17 @@ interface TCensecTipoAtoTableProps {
|
|||
}
|
||||
|
||||
function StatusBadge({ situacao }: { situacao: string }) {
|
||||
const isActive = situacao === "A";
|
||||
const isActive = situacao === 'A';
|
||||
|
||||
const baseClasses =
|
||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||
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 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";
|
||||
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"}
|
||||
{isActive ? 'Ativo' : 'Inativo'}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
|
@ -51,7 +48,7 @@ export default function TCensecTipoAtoTable({
|
|||
data,
|
||||
tCensec,
|
||||
onEdit,
|
||||
onDelete
|
||||
onDelete,
|
||||
}: TCensecTipoAtoTableProps) {
|
||||
return (
|
||||
<Table>
|
||||
|
|
@ -70,28 +67,23 @@ export default function TCensecTipoAtoTable({
|
|||
|
||||
<TableBody>
|
||||
{data.map((item) => {
|
||||
const censecDesc = tCensec.find(c => c.censec_id === item.censec_id)?.descricao || "N/A"
|
||||
const censecDesc =
|
||||
tCensec.find((c) => c.censec_id === item.censec_id)?.descricao || 'N/A';
|
||||
return (
|
||||
<TableRow key={item.censec_tipoato_id} className="cursor-pointer">
|
||||
<TableCell className="font-medium">
|
||||
{item.censec_tipoato_id}
|
||||
</TableCell>
|
||||
<TableCell className="font-medium">{item.censec_tipoato_id}</TableCell>
|
||||
<TableCell>
|
||||
<StatusBadge situacao={item.situacao} />
|
||||
</TableCell>
|
||||
<TableCell>{censecDesc}</TableCell>
|
||||
{/*<TableCell>{item.codigo ?? "-"}</TableCell>*/}
|
||||
<TableCell>{item.descricao}</TableCell>
|
||||
<TableCell>{item.tipo_separacao ?? "-"}</TableCell>
|
||||
<TableCell>{item.tipo_revogacao ?? "-"}</TableCell>
|
||||
<TableCell>{item.tipo_separacao ?? '-'}</TableCell>
|
||||
<TableCell>{item.tipo_revogacao ?? '-'}</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="cursor-pointer"
|
||||
>
|
||||
<Button variant="outline" size="icon" className="cursor-pointer">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
|
|
@ -120,7 +112,7 @@ export default function TCensecTipoAtoTable({
|
|||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
);
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
|
|
|||
|
|
@ -1,97 +1,90 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import TCensecTipoNaturezaInterface from "../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import TCensecTipoNaturezaInterface from '../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { ConfirmacaoEnum } from "@/shared/enums/ConfirmacaoEnum";
|
||||
import { TipoAtoAnteriorEnum } from "@/shared/enums/TipoAtoAnteriorEnum";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { ConfirmacaoEnum } from '@/shared/enums/ConfirmacaoEnum';
|
||||
import { TipoAtoAnteriorEnum } from '@/shared/enums/TipoAtoAnteriorEnum';
|
||||
|
||||
export default function TCensecTipoNaturezaColumns(
|
||||
onEdit: (item: TCensecTipoNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TCensecTipoNaturezaInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TCensecTipoNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TCensecTipoNaturezaInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TCensecTipoNaturezaInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "censec_tiponatureza_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("censec_tiponatureza_id")),
|
||||
enableSorting: false,
|
||||
},
|
||||
// descricao
|
||||
{
|
||||
accessorKey: "descricao",
|
||||
header: ({ column }) => SortableHeader("Descrição", column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue("descricao")),
|
||||
},
|
||||
// possui_ato_anterior
|
||||
{
|
||||
accessorKey: "possui_ato_anterior",
|
||||
header: ({ column }) => SortableHeader("Possui Ato Anterior", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("possui_ato_anterior") as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? "-";
|
||||
},
|
||||
},
|
||||
// situacao_ato_anterior
|
||||
{
|
||||
accessorKey: "situacao_ato_anterior",
|
||||
header: ({ column }) => SortableHeader("Situação Ato Anterior", column),
|
||||
cell: ({ row }) => {
|
||||
const value = Number(row.getValue("situacao_ato_anterior"));
|
||||
const label = Object.prototype.hasOwnProperty.call(TipoAtoAnteriorEnum, value)
|
||||
? TipoAtoAnteriorEnum[value as keyof typeof TipoAtoAnteriorEnum]
|
||||
: "-";
|
||||
return label;
|
||||
},
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'censec_tiponatureza_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('censec_tiponatureza_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
// descricao
|
||||
{
|
||||
accessorKey: 'descricao',
|
||||
header: ({ column }) => SortableHeader('Descrição', column),
|
||||
cell: ({ row }) => GetCapitalize(row.getValue('descricao')),
|
||||
},
|
||||
// possui_ato_anterior
|
||||
{
|
||||
accessorKey: 'possui_ato_anterior',
|
||||
header: ({ column }) => SortableHeader('Possui Ato Anterior', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('possui_ato_anterior') as keyof typeof ConfirmacaoEnum;
|
||||
return ConfirmacaoEnum[value] ?? '-';
|
||||
},
|
||||
},
|
||||
// situacao_ato_anterior
|
||||
{
|
||||
accessorKey: 'situacao_ato_anterior',
|
||||
header: ({ column }) => SortableHeader('Situação Ato Anterior', column),
|
||||
cell: ({ row }) => {
|
||||
const value = Number(row.getValue('situacao_ato_anterior'));
|
||||
const label = Object.prototype.hasOwnProperty.call(TipoAtoAnteriorEnum, value)
|
||||
? TipoAtoAnteriorEnum[value as keyof typeof TipoAtoAnteriorEnum]
|
||||
: '-';
|
||||
return label;
|
||||
},
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,17 +32,20 @@ import ConfirmacaoSelect from '@/shared/components/confirmacao/ConfirmacaoSelect
|
|||
import TipoAtoAnteriorSelect from '@/shared/components/tipoAtoAnterior/TipoAtoAnteriorSelect';
|
||||
import TipoNaturezaSelect from '@/shared/components/tipoNatureza/TipoNaturezaSelect';
|
||||
|
||||
export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TCensecTipoNaturezaFormInterface) {
|
||||
|
||||
export default function TCensecTipoNaturezaForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TCensecTipoNaturezaFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTCensecTipoNaturezaFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
|
||||
// Se existir dados, reseta o formulário com os mesmos
|
||||
ResetFormIfData(form, data);
|
||||
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
|
|
@ -58,12 +61,8 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-2xl lg:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Censec tipos de natureza
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Censec tipos de natureza
|
||||
</DialogDescription>
|
||||
<DialogTitle>Censec tipos de natureza</DialogTitle>
|
||||
<DialogDescription>Censec tipos de natureza</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
|
|
@ -77,7 +76,7 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
<FormItem>
|
||||
<FormLabel>Descrição</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' />
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -93,7 +92,7 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Tipo do Ato</FormLabel>
|
||||
< TCensecTipoAtoSelect field={field} />
|
||||
<TCensecTipoAtoSelect field={field} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
|
|
@ -169,7 +168,11 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
<FormItem>
|
||||
<FormLabel>Código</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='number' onChange={e => field.onChange(parseNumberInput(e))} />
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -178,7 +181,7 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
@ -193,7 +196,7 @@ export default function TCensecTipoNaturezaForm({ isOpen, data, onClose, onSave,
|
|||
</DialogFooter>
|
||||
</form>
|
||||
</Form>
|
||||
</DialogContent >
|
||||
</Dialog >
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ import TCensecTipoNaturezaTable from './TCensecTipoNaturezaTable';
|
|||
import TCensecTipoNaturezaForm from './TCensecTipoNaturezaForm';
|
||||
|
||||
export default function TCensecTipoNaturezaIndex() {
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
|
|
@ -131,8 +130,8 @@ export default function TCensecTipoNaturezaIndex() {
|
|||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={"CENSEC Tipos de Natureza"}
|
||||
description={"CENSEC Tipos de Natureza"}
|
||||
title={'CENSEC Tipos de Natureza'}
|
||||
description={'CENSEC Tipos de Natureza'}
|
||||
buttonText={'Novo tipo de natureza'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import TCensecTipoNaturezaTableInterface from '../../interfaces/TCensecTipoNatur
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TCensecTipoNaturezaTable({ data, onEdit, onDelete }: TCensecTipoNaturezaTableInterface) {
|
||||
export default function TCensecTipoNaturezaTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TCensecTipoNaturezaTableInterface) {
|
||||
const columns = TCensecTipoNaturezaColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
|
|
@ -19,4 +23,4 @@ export default function TCensecTipoNaturezaTable({ data, onEdit, onDelete }: TCe
|
|||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,124 +1,116 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import TImovelInterface from '../../interfaces/TImovel/TImovelInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import { FormatDateTime } from '@/shared/actions/dateTime/FormatDateTime';
|
||||
import { FormatCEP } from '@/shared/actions/CEP/FormatCEP';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import { FormatDateTime } from "@/shared/actions/dateTime/FormatDateTime";
|
||||
import { FormatCEP } from "@/shared/actions/CEP/FormatCEP";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { ImovelTipoRegistro } from "@/shared/enums/ImovelTipoRegistro";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { ImovelTipoRegistro } from '@/shared/enums/ImovelTipoRegistro';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
|
||||
export default function TImovelColumns(
|
||||
onEdit: (item: TImovelInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TImovelInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TImovelInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "imovel_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("imovel_id")),
|
||||
enableSorting: false,
|
||||
},
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'imovel_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('imovel_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
|
||||
// Tipo Registro
|
||||
{
|
||||
accessorKey: "tipo_registro",
|
||||
header: ({ column }) => SortableHeader("Tipo Registro", column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue("tipo_registro") as keyof typeof ImovelTipoRegistro;
|
||||
return ImovelTipoRegistro[value] ?? value;
|
||||
},
|
||||
},
|
||||
// Tipo Registro
|
||||
{
|
||||
accessorKey: 'tipo_registro',
|
||||
header: ({ column }) => SortableHeader('Tipo Registro', column),
|
||||
cell: ({ row }) => {
|
||||
const value = row.getValue('tipo_registro') as keyof typeof ImovelTipoRegistro;
|
||||
return ImovelTipoRegistro[value] ?? value;
|
||||
},
|
||||
},
|
||||
|
||||
// Número
|
||||
{
|
||||
accessorKey: "numero",
|
||||
header: ({ column }) => SortableHeader("Número", column),
|
||||
cell: ({ row }) => row.getValue("numero"),
|
||||
},
|
||||
// Número
|
||||
{
|
||||
accessorKey: 'numero',
|
||||
header: ({ column }) => SortableHeader('Número', column),
|
||||
cell: ({ row }) => row.getValue('numero'),
|
||||
},
|
||||
|
||||
// UF / Cidade / Bairro
|
||||
{
|
||||
id: "uf_cidade_bairro",
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => SortableHeader("Cidade / UF / Bairro", column),
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<span className="font-semibold text-gray-900 capitalize">
|
||||
{GetCapitalize(imovel.cidade)}/{imovel.uf}
|
||||
</span>
|
||||
<span className="text-sm text-gray-500">{GetCapitalize(imovel.gtbb_descricao)}</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
Number(a.original.numero || 0) - Number(b.original.numero || 0),
|
||||
},
|
||||
// UF / Cidade / Bairro
|
||||
{
|
||||
id: 'uf_cidade_bairro',
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => SortableHeader('Cidade / UF / Bairro', column),
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<div className="flex flex-col">
|
||||
<span className="font-semibold text-gray-900 capitalize">
|
||||
{GetCapitalize(imovel.cidade)}/{imovel.uf}
|
||||
</span>
|
||||
<span className="text-sm text-gray-500">{GetCapitalize(imovel.gtbb_descricao)}</span>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) => Number(a.original.numero || 0) - Number(b.original.numero || 0),
|
||||
},
|
||||
|
||||
// CEP
|
||||
{
|
||||
accessorKey: "cep",
|
||||
header: ({ column }) => SortableHeader("CEP", column),
|
||||
cell: ({ row }) => FormatCEP(row.getValue("cep")),
|
||||
},
|
||||
// CEP
|
||||
{
|
||||
accessorKey: 'cep',
|
||||
header: ({ column }) => SortableHeader('CEP', column),
|
||||
cell: ({ row }) => FormatCEP(row.getValue('cep')),
|
||||
},
|
||||
|
||||
// Data de Registro
|
||||
{
|
||||
accessorKey: "data_registro",
|
||||
header: ({ column }) => SortableHeader("Cadastro", column),
|
||||
cell: ({ row }) => FormatDateTime(row.getValue("data_registro")),
|
||||
sortingFn: "datetime",
|
||||
},
|
||||
// Data de Registro
|
||||
{
|
||||
accessorKey: 'data_registro',
|
||||
header: ({ column }) => SortableHeader('Cadastro', column),
|
||||
cell: ({ row }) => FormatDateTime(row.getValue('data_registro')),
|
||||
sortingFn: 'datetime',
|
||||
},
|
||||
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,17 +34,21 @@ import { parseNumberInput } from '@/shared/actions/form/parseNumberInput';
|
|||
import TImovelTipoRegistroSelect from './TImovelTipoRegistroSelect';
|
||||
import GTBBairroSelect from '../GTBBairro/GTBBairroSelect';
|
||||
|
||||
export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoading, tipoClasse }: TImovelFormInterface) {
|
||||
|
||||
export default function TImovelForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
tipoClasse,
|
||||
}: TImovelFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTImovelFormHook({});
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
|
||||
// Se existir dados, reseta o formulário com os mesmos
|
||||
ResetFormIfData(form, data);
|
||||
|
||||
}, [data, form]);
|
||||
|
||||
function onError(error: any) {
|
||||
|
|
@ -60,9 +64,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-4xl lg:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
{tipoClasse === 1 ? 'Imóvel Urbano' : 'Imóvel Rural'}
|
||||
</DialogTitle>
|
||||
<DialogTitle>{tipoClasse === 1 ? 'Imóvel Urbano' : 'Imóvel Rural'}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{tipoClasse === 1 ? 'Cadastro de imóvel urbano' : 'Cadastro de imóvel rural'}
|
||||
</DialogDescription>
|
||||
|
|
@ -70,12 +72,12 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
{/* Tabs */}
|
||||
<Tabs defaultValue="dadosDoImovel" className="space-y-4">
|
||||
<TabsList className="flex w-full">
|
||||
<TabsTrigger className="flex-1 text-center cursor-pointer" value="dadosDoImovel">
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="dadosDoImovel">
|
||||
<HouseIcon className="me-1 inline" />
|
||||
Dados do Imóvel
|
||||
</TabsTrigger>
|
||||
{data?.imovel_id && (
|
||||
<TabsTrigger className="flex-1 text-center cursor-pointer" value="unidades">
|
||||
<TabsTrigger className="flex-1 cursor-pointer text-center" value="unidades">
|
||||
<IdCardIcon className="inline" />
|
||||
Unidades
|
||||
</TabsTrigger>
|
||||
|
|
@ -95,7 +97,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>UF</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="UF" maxLength={2} />
|
||||
<Input {...field} type="text" placeholder="UF" maxLength={2} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -111,7 +113,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>CEP</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="Digite o CEP" />
|
||||
<Input {...field} type="text" placeholder="Digite o CEP" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -159,7 +161,12 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>Cartório</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='number' placeholder="Digite o cartório" onChange={e => field.onChange(parseNumberInput(e))} />
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
placeholder="Digite o cartório"
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -175,7 +182,12 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>CNS</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="number" placeholder="Digite o CNS" onChange={e => field.onChange(parseNumberInput(e))} />
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
placeholder="Digite o CNS"
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -191,7 +203,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>Livro</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="Digite o livro" />
|
||||
<Input {...field} type="text" placeholder="Digite o livro" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -221,7 +233,12 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>Número</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type="number" placeholder="Digite o número" onChange={e => field.onChange(parseNumberInput(e))} />
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
placeholder="Digite o número"
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -237,7 +254,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
<FormItem>
|
||||
<FormLabel>Número Letra</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' placeholder="Digite a letra" />
|
||||
<Input {...field} type="text" placeholder="Digite a letra" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -246,7 +263,7 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
@ -266,17 +283,13 @@ export default function TImovelForm({ isOpen, data, onClose, onSave, buttonIsLoa
|
|||
{data?.imovel_id && (
|
||||
<TabsContent value="unidades" className="space-y-4">
|
||||
{/* Imóvel Urbano */}
|
||||
{tipoClasse === 1 && (
|
||||
<TImovelUnidadeUrbanoPage imovel_id={data?.imovel_id} />
|
||||
)}
|
||||
{tipoClasse === 1 && <TImovelUnidadeUrbanoPage imovel_id={data?.imovel_id} />}
|
||||
{/* Imóvel Rural */}
|
||||
{tipoClasse === 3 && (
|
||||
<TImovelUnidadeRuralIndex imovel_id={data?.imovel_id} />
|
||||
)}
|
||||
{tipoClasse === 3 && <TImovelUnidadeRuralIndex imovel_id={data?.imovel_id} />}
|
||||
</TabsContent>
|
||||
)}
|
||||
</Tabs>
|
||||
</DialogContent >
|
||||
</Dialog >
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,14 @@ import TImovelTable from './TImovelTable';
|
|||
import TImovelForm from './TImovelForm';
|
||||
import { TImovelIndexDataInterface } from '../../interfaces/TImovel/TImovelIndexDataInterface';
|
||||
|
||||
export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }: TImovelIndexInterface) {
|
||||
|
||||
export default function TImovelIndex({
|
||||
pageTitle,
|
||||
pageDescription,
|
||||
tipoClasse,
|
||||
}: TImovelIndexInterface) {
|
||||
const TImovelIndexDataInterface: TImovelIndexDataInterface = {
|
||||
tipo_classe: tipoClasse
|
||||
}
|
||||
tipo_classe: tipoClasse,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -54,7 +57,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }:
|
|||
*/
|
||||
const handleOpenForm = useCallback((data: TImovelInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com pessoa_tipo
|
||||
const initialData: TImovelInterface = data ?? { tipo_classe: tipoClasse } as TImovelInterface;
|
||||
const initialData: TImovelInterface = data ?? ({ tipo_classe: tipoClasse } as TImovelInterface);
|
||||
|
||||
// Se existir dado de tipo_classe preenchido, converte para inteiro
|
||||
if (initialData.tipo_classe !== undefined && initialData.tipo_classe !== null) {
|
||||
|
|
@ -152,11 +155,7 @@ export default function TImovelIndex({ pageTitle, pageDescription, tipoClasse }:
|
|||
}}
|
||||
/>
|
||||
{/* Tabela de andamentos */}
|
||||
<TImovelTable
|
||||
data={tImovel}
|
||||
onEdit={handleOpenForm}
|
||||
onDelete={handleConfirmDelete}
|
||||
/>
|
||||
<TImovelTable data={tImovel} onEdit={handleOpenForm} onDelete={handleConfirmDelete} />
|
||||
{/* Modal de confirmação */}
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,4 @@ export default function TImovelTable({ data, onEdit, onDelete }: TImovelTableInt
|
|||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,66 +1,70 @@
|
|||
import { Button } from "@/components/ui/button";
|
||||
import { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ImovelConstrucaoEnum } from "@/shared/enums/ImovelConstrucaoEnum";
|
||||
import { Command } from "cmdk";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import React from "react";
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ImovelConstrucaoEnum } from '@/shared/enums/ImovelConstrucaoEnum';
|
||||
import { Command } from 'cmdk';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
export default function TImovelTipoConstrucaoSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const options = Object.entries(ImovelConstrucaoEnum).map(([id, label]) => ({
|
||||
value: Number(id),
|
||||
label,
|
||||
}));
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="justify-between"
|
||||
>
|
||||
{field.value
|
||||
? options.find((item) => item.value === field.value)?.label
|
||||
: "Selecione..."}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo construção..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
field.value === item.value
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const options = Object.entries(ImovelConstrucaoEnum).map(([id, label]) => ({
|
||||
value: Number(id),
|
||||
label,
|
||||
}));
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="justify-between"
|
||||
>
|
||||
{field.value
|
||||
? options.find((item) => item.value === field.value)?.label
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo construção..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
field.value === item.value ? 'opacity-100' : 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,60 +1,71 @@
|
|||
import { Button } from "@/components/ui/button";
|
||||
import { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ImovelTipoEnum } from "@/shared/enums/ImovelTipoEnum";
|
||||
import { Command } from "cmdk";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import React from "react";
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ImovelTipoEnum } from '@/shared/enums/ImovelTipoEnum';
|
||||
import { Command } from 'cmdk';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
export default function TImovelTipoImovelSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const options = Object.entries(ImovelTipoEnum).map(([id, label]) => ({
|
||||
value: Number(id),
|
||||
label,
|
||||
}));
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const options = Object.entries(ImovelTipoEnum).map(([id, label]) => ({
|
||||
value: Number(id),
|
||||
label,
|
||||
}));
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button variant="outline" role="combobox" aria-expanded={open} className="justify-between">
|
||||
{field.value
|
||||
? options.find((item) => item.value === field.value)?.label
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo imóvel..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
field.value === item.value ? 'opacity-100' : 'opacity-0'
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="justify-between"
|
||||
>
|
||||
{field.value
|
||||
? options.find((item) => item.value === field.value)?.label
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo imóvel..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
field.value === item.value ? 'opacity-100' : 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,92 +1,92 @@
|
|||
'use client';
|
||||
|
||||
import React from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import React from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import GetCapitalize from "@/shared/actions/text/GetCapitalize";
|
||||
import { useGTBTipoLogradouroReadHook } from "@/packages/administrativo/hooks/GTBTipoLogradouro/useGTBTipoLogradouroReadHook";
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
import { useGTBTipoLogradouroReadHook } from '@/packages/administrativo/hooks/GTBTipoLogradouro/useGTBTipoLogradouroReadHook';
|
||||
|
||||
export default function TImovelTipoLogradouroSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!gTBTipoLogradouro.length) {
|
||||
setIsLoading(true);
|
||||
await fetchGTBTipoLogradouro();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = gTBTipoLogradouro.find(
|
||||
(item) => String(item.tb_tipologradouro_id) === String(field.value)
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? "Carregando..."
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: "Selecione..."}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? "Carregando..." : "Nenhum resultado encontrado."}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{gTBTipoLogradouro?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.tb_tipologradouro_id}
|
||||
value={item.descricao?.toLowerCase() ?? ""}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.tb_tipologradouro_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
String(field.value) === String(item.tb_tipologradouro_id)
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook();
|
||||
// Busca os dados uma única vez ao montar
|
||||
React.useEffect(() => {
|
||||
const loadData = async () => {
|
||||
if (!gTBTipoLogradouro.length) {
|
||||
setIsLoading(true);
|
||||
await fetchGTBTipoLogradouro();
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
loadData();
|
||||
}, []);
|
||||
const selected = gTBTipoLogradouro.find(
|
||||
(item) => String(item.tb_tipologradouro_id) === String(field.value),
|
||||
);
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className="justify-between"
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo logradouro..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{gTBTipoLogradouro?.map((item) => (
|
||||
<CommandItem
|
||||
key={item.tb_tipologradouro_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => {
|
||||
field.onChange(Number(item.tb_tipologradouro_id));
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field.value) === String(item.tb_tipologradouro_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao)}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,67 +1,73 @@
|
|||
import { Button } from "@/components/ui/button";
|
||||
import { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "@/components/ui/command";
|
||||
import { FormControl } from "@/components/ui/form";
|
||||
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ImovelTipoRegistro } from "@/shared/enums/ImovelTipoRegistro";
|
||||
import { Command } from "cmdk";
|
||||
import { CheckIcon, ChevronsUpDownIcon } from "lucide-react";
|
||||
import React from "react";
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { ImovelTipoRegistro } from '@/shared/enums/ImovelTipoRegistro';
|
||||
import { Command } from 'cmdk';
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import React from 'react';
|
||||
|
||||
export default function TImovelTipoRegistroSelect({ field }: any) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [open, setOpen] = React.useState(false);
|
||||
|
||||
const options = Object.entries(ImovelTipoRegistro).map(([id, label]) => ({
|
||||
value: id,
|
||||
label,
|
||||
}));
|
||||
const options = Object.entries(ImovelTipoRegistro).map(([id, label]) => ({
|
||||
value: id,
|
||||
label,
|
||||
}));
|
||||
|
||||
const selected = options.find((item) => item.value === field?.value);
|
||||
const selected = options.find((item) => item.value === field?.value);
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="justify-between"
|
||||
>
|
||||
{selected ? selected.label : "Selecione..."}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="justify-between"
|
||||
>
|
||||
{selected ? selected.label : 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo construção..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
field?.value === item.value ? "opacity-100" : "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar tipo construção..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>Nenhum resultado encontrado.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{options.map((item) => (
|
||||
<CommandItem
|
||||
key={item.value}
|
||||
value={item.label.toLowerCase()}
|
||||
onSelect={() => {
|
||||
field.onChange(item.value);
|
||||
setOpen(false);
|
||||
}}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
field?.value === item.value ? 'opacity-100' : 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{item.label}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,90 +1,83 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import { TImovelUnidadeRuralInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural';
|
||||
|
||||
export default function TImovelUnidadeColumns(
|
||||
onEdit: (item: TImovelUnidadeRuralInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelUnidadeRuralInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TImovelUnidadeRuralInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelUnidadeRuralInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TImovelUnidadeRuralInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "imovel_unidade_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("imovel_unidade_id")),
|
||||
},
|
||||
// Número da Unidade
|
||||
{
|
||||
accessorKey: "numero_unidade",
|
||||
header: ({ column }) => SortableHeader("Número da Unidade", column),
|
||||
cell: ({ row }) => row.getValue("numero_unidade"),
|
||||
},
|
||||
// Quadra
|
||||
{
|
||||
accessorKey: "quadra",
|
||||
header: ({ column }) => SortableHeader("Quadra", column),
|
||||
cell: ({ row }) => row.getValue("quadra"),
|
||||
},
|
||||
// Area
|
||||
{
|
||||
accessorKey: "area",
|
||||
header: ({ column }) => SortableHeader("Área", column),
|
||||
cell: ({ row }) => row.getValue("area"),
|
||||
},
|
||||
// Logradouros
|
||||
{
|
||||
accessorKey: "logradouro",
|
||||
header: ({ column }) => SortableHeader("Logradouro", column),
|
||||
cell: ({ row }) => row.getValue("logradouro"),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'imovel_unidade_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('imovel_unidade_id')),
|
||||
},
|
||||
// Número da Unidade
|
||||
{
|
||||
accessorKey: 'numero_unidade',
|
||||
header: ({ column }) => SortableHeader('Número da Unidade', column),
|
||||
cell: ({ row }) => row.getValue('numero_unidade'),
|
||||
},
|
||||
// Quadra
|
||||
{
|
||||
accessorKey: 'quadra',
|
||||
header: ({ column }) => SortableHeader('Quadra', column),
|
||||
cell: ({ row }) => row.getValue('quadra'),
|
||||
},
|
||||
// Area
|
||||
{
|
||||
accessorKey: 'area',
|
||||
header: ({ column }) => SortableHeader('Área', column),
|
||||
cell: ({ row }) => row.getValue('area'),
|
||||
},
|
||||
// Logradouros
|
||||
{
|
||||
accessorKey: 'logradouro',
|
||||
header: ({ column }) => SortableHeader('Logradouro', column),
|
||||
cell: ({ row }) => row.getValue('logradouro'),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,22 +26,31 @@ import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
|||
import { ResetFormIfData } from '@/shared/actions/form/ResetFormIfData';
|
||||
import { TImovelUnidadeRuralFormInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRuralFormInterface';
|
||||
import { useTImovelUnidadeRuralFormHook } from '@/packages/administrativo/hooks/TImovelUnidade/TImovelUnidadeRural/useTImovelUnidadeRuralFormHook';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select';
|
||||
import { SituacoesEnum } from '@/shared/enums/SituacoesEnum';
|
||||
import TImovelTipoImovelSelect from '../../TImovel/TImovelTipoImovelSelect';
|
||||
import TImovelTipoConstrucaoSelect from '../../TImovel/TImovelTipoConstrucaoSelect';
|
||||
|
||||
export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelUnidadeRuralFormInterface) {
|
||||
|
||||
export default function TImovelUnidadeRuralForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TImovelUnidadeRuralFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTImovelUnidadeRuralFormHook();
|
||||
|
||||
// Atualiza o formulário quando recebe dados para edição
|
||||
useEffect(() => {
|
||||
|
||||
// Se existir dados, reseta o formulário com os mesmos
|
||||
ResetFormIfData(form, data);
|
||||
|
||||
}, [data]);
|
||||
|
||||
function onErro(errors: any) {
|
||||
|
|
@ -55,18 +64,14 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-2xl md:max-w-2xl lg:max-w-3xl max-h-[60vh] overflow-auto">
|
||||
<DialogContent className="max-h-[60vh] w-full max-w-full overflow-auto p-6 sm:max-w-2xl md:max-w-2xl lg:max-w-3xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Unidades do Imóvel
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Cadastro de unidades do imóvel
|
||||
</DialogDescription>
|
||||
<DialogTitle>Unidades do Imóvel</DialogTitle>
|
||||
<DialogDescription>Cadastro de unidades do imóvel</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onErro)} className="space-y-6">
|
||||
<div className="grid grid-cols-12 sm:grid-cols-12 lg:grid-cols-12 gap-4">
|
||||
<div className="grid grid-cols-12 gap-4 sm:grid-cols-12 lg:grid-cols-12">
|
||||
{/* Tipo Imóvel */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<FormField
|
||||
|
|
@ -106,9 +111,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
name="nome_identificacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
Nome Identificação
|
||||
</FormLabel>
|
||||
<FormLabel>Nome Identificação</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
|
@ -124,9 +127,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
name="denominacao"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
Denominação
|
||||
</FormLabel>
|
||||
<FormLabel>Denominação</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
|
@ -142,9 +143,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
name="area_descritiva"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
Área Descritiva
|
||||
</FormLabel>
|
||||
<FormLabel>Área Descritiva</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
|
@ -160,9 +159,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
name="ccir"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
CCIR (Incra)
|
||||
</FormLabel>
|
||||
<FormLabel>CCIR (Incra)</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
|
@ -178,9 +175,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
name="nirf"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
NIRF
|
||||
</FormLabel>
|
||||
<FormLabel>NIRF</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} />
|
||||
</FormControl>
|
||||
|
|
@ -195,14 +190,11 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
control={form.control}
|
||||
name="geo_referenciamento"
|
||||
render={({ field }) => (
|
||||
<FormItem className='w-full'>
|
||||
<FormItem className="w-full">
|
||||
<FormLabel>Geo Referenciamento</FormLabel>
|
||||
<FormControl>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
value={field.value}
|
||||
>
|
||||
<SelectTrigger id="geo_referenciamento" className='w-full'>
|
||||
<Select onValueChange={field.onChange} value={field.value}>
|
||||
<SelectTrigger id="geo_referenciamento" className="w-full">
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
|
@ -222,14 +214,11 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
control={form.control}
|
||||
name="reserva_florestal"
|
||||
render={({ field }) => (
|
||||
<FormItem className='w-full'>
|
||||
<FormItem className="w-full">
|
||||
<FormLabel>Reserva Florestal</FormLabel>
|
||||
<FormControl>
|
||||
<Select
|
||||
onValueChange={field.onChange}
|
||||
value={field.value}
|
||||
>
|
||||
<SelectTrigger id="reserva_florestal" className='w-full'>
|
||||
<Select onValueChange={field.onChange} value={field.value}>
|
||||
<SelectTrigger id="reserva_florestal" className="w-full">
|
||||
<SelectValue placeholder="Selecione..." />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
|
|
@ -245,7 +234,7 @@ export default function TImovelUnidadeRuralForm({ isOpen, data, onClose, onSave,
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
|
|||
|
|
@ -16,10 +16,9 @@ import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfac
|
|||
import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface';
|
||||
|
||||
export default function TImovelUnidadeRuralIndex({ imovel_id }: TImovelUnidadePageInterface) {
|
||||
|
||||
const TImovelUnidadePage: TImovelUnidadePageInterface = {
|
||||
imovel_id: imovel_id
|
||||
}
|
||||
imovel_id: imovel_id,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -39,18 +38,15 @@ export default function TImovelUnidadeRuralIndex({ imovel_id }: TImovelUnidadePa
|
|||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: TImovelUnidadeRuralInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com imovel_id
|
||||
const initialData: TImovelUnidadeRuralInterface = data ?? { imovel_id } as TImovelUnidadeRuralInterface;
|
||||
const initialData: TImovelUnidadeRuralInterface =
|
||||
data ?? ({ imovel_id } as TImovelUnidadeRuralInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
@ -139,7 +135,8 @@ export default function TImovelUnidadeRuralIndex({ imovel_id }: TImovelUnidadePa
|
|||
<TImovelUnidadeRuralTable
|
||||
data={tImovelUnidadeRural}
|
||||
onEdit={handleOpenForm}
|
||||
onDelete={handleConfirmDelete} />
|
||||
onDelete={handleConfirmDelete}
|
||||
/>
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
|
|
|
|||
|
|
@ -7,13 +7,17 @@ import TImovelUnidadeRuralTableInterface from '@/packages/administrativo/interfa
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TImovelUnidadeRuralTable({ data, onEdit, onDelete }: TImovelUnidadeRuralTableInterface) {
|
||||
export default function TImovelUnidadeRuralTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TImovelUnidadeRuralTableInterface) {
|
||||
const columns = TImovelUnidadeColumns(onEdit, onDelete);
|
||||
const isEmpty = !data || data.length === 0;
|
||||
return (
|
||||
<div className="max-h-[40vh] overflow-y-auto" >
|
||||
<div className="max-h-[40vh] overflow-y-auto">
|
||||
{isEmpty ? (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
<div className="text-muted-foreground p-6 text-center">
|
||||
Nenhuma unidade cadastrada ainda.
|
||||
</div>
|
||||
) : (
|
||||
|
|
@ -24,6 +28,6 @@ export default function TImovelUnidadeRuralTable({ data, onEdit, onDelete }: TIm
|
|||
filterPlaceholder="Busque pelo numero da unidade"
|
||||
/>
|
||||
)}
|
||||
</div >
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,90 +1,83 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
EllipsisIcon,
|
||||
PencilIcon,
|
||||
Trash2Icon,
|
||||
} from "lucide-react";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { SortableHeader } from "@/shared/components/dataTable/SortableHeader";
|
||||
import { TImovelUnidadeUrbanoInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface";
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { SortableHeader } from '@/shared/components/dataTable/SortableHeader';
|
||||
import { TImovelUnidadeUrbanoInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface';
|
||||
|
||||
export default function TImovelUnidadeUrbanoColumns(
|
||||
onEdit: (item: TImovelUnidadeUrbanoInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelUnidadeUrbanoInterface, isEditingFormStatus: boolean) => void
|
||||
onEdit: (item: TImovelUnidadeUrbanoInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TImovelUnidadeUrbanoInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TImovelUnidadeUrbanoInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: "imovel_unidade_id",
|
||||
header: ({ column }) => SortableHeader("#", column),
|
||||
cell: ({ row }) => Number(row.getValue("imovel_unidade_id")),
|
||||
},
|
||||
// Número da Unidade
|
||||
{
|
||||
accessorKey: "numero_unidade",
|
||||
header: ({ column }) => SortableHeader("Número da Unidade", column),
|
||||
cell: ({ row }) => row.getValue("numero_unidade"),
|
||||
},
|
||||
// Quadra
|
||||
{
|
||||
accessorKey: "quadra",
|
||||
header: ({ column }) => SortableHeader("Quadra", column),
|
||||
cell: ({ row }) => row.getValue("quadra"),
|
||||
},
|
||||
// Area
|
||||
{
|
||||
accessorKey: "area",
|
||||
header: ({ column }) => SortableHeader("Área", column),
|
||||
cell: ({ row }) => row.getValue("area"),
|
||||
},
|
||||
// Logradouros
|
||||
{
|
||||
accessorKey: "logradouro",
|
||||
header: ({ column }) => SortableHeader("Logradouro", column),
|
||||
cell: ({ row }) => row.getValue("logradouro"),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: "actions",
|
||||
header: "Ações",
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onSelect={() => onDelete(imovel, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'imovel_unidade_id',
|
||||
header: ({ column }) => SortableHeader('#', column),
|
||||
cell: ({ row }) => Number(row.getValue('imovel_unidade_id')),
|
||||
},
|
||||
// Número da Unidade
|
||||
{
|
||||
accessorKey: 'numero_unidade',
|
||||
header: ({ column }) => SortableHeader('Número da Unidade', column),
|
||||
cell: ({ row }) => row.getValue('numero_unidade'),
|
||||
},
|
||||
// Quadra
|
||||
{
|
||||
accessorKey: 'quadra',
|
||||
header: ({ column }) => SortableHeader('Quadra', column),
|
||||
cell: ({ row }) => row.getValue('quadra'),
|
||||
},
|
||||
// Area
|
||||
{
|
||||
accessorKey: 'area',
|
||||
header: ({ column }) => SortableHeader('Área', column),
|
||||
cell: ({ row }) => row.getValue('area'),
|
||||
},
|
||||
// Logradouros
|
||||
{
|
||||
accessorKey: 'logradouro',
|
||||
header: ({ column }) => SortableHeader('Logradouro', column),
|
||||
cell: ({ row }) => row.getValue('logradouro'),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const imovel = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem onSelect={() => onEdit(imovel, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem className="text-red-600" onSelect={() => onDelete(imovel, true)}>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,13 @@ import TImovelTipoImovelSelect from '../../TImovel/TImovelTipoImovelSelect';
|
|||
import TImovelTipoConstrucaoSelect from '../../TImovel/TImovelTipoConstrucaoSelect';
|
||||
import TImovelTipoLogradouroSelect from '../../TImovel/TImovelTipoLogradouroSelect';
|
||||
|
||||
export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TImovelUnidadeUrbanoFormInterface) {
|
||||
|
||||
export default function TImovelUnidadeUrbanoForm({
|
||||
isOpen,
|
||||
data,
|
||||
onClose,
|
||||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TImovelUnidadeUrbanoFormInterface) {
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTImovelUnidadeUrbanoFormHook({});
|
||||
|
||||
|
|
@ -48,18 +53,14 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
|
|||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-2xl md:max-w-2xl lg:max-w-3xl max-h-[60vh] overflow-auto">
|
||||
<DialogContent className="max-h-[60vh] w-full max-w-full overflow-auto p-6 sm:max-w-2xl md:max-w-2xl lg:max-w-3xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Unidades Urbanas do Imóvel
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Cadastro de unidades do imóvel
|
||||
</DialogDescription>
|
||||
<DialogTitle>Unidades Urbanas do Imóvel</DialogTitle>
|
||||
<DialogDescription>Cadastro de unidades do imóvel</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||
<div className="grid grid-cols-12 sm:grid-cols-12 lg:grid-cols-12 gap-4">
|
||||
<div className="grid grid-cols-12 gap-4 sm:grid-cols-12 lg:grid-cols-12">
|
||||
{/* Quadra */}
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-3">
|
||||
<FormField
|
||||
|
|
@ -69,7 +70,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
|
|||
<FormItem>
|
||||
<FormLabel>Quadra</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} type='text' />
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -101,9 +102,10 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
|
|||
<FormItem>
|
||||
<FormLabel>Área(m2)</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field}
|
||||
type='number'
|
||||
onChange={e => field.onChange(parseNumberInput(e))}
|
||||
<Input
|
||||
{...field}
|
||||
type="number"
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
|
|
@ -246,9 +248,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
|
|||
<FormItem>
|
||||
<FormLabel>Condominio</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field}
|
||||
type='text'
|
||||
/>
|
||||
<Input {...field} type="text" />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -353,7 +353,7 @@ export default function TImovelUnidadeUrbanoForm({ isOpen, data, onClose, onSave
|
|||
</div>
|
||||
</div>
|
||||
{/* Rodapé do Dialog */}
|
||||
<DialogFooter className="mt-4 flex flex-col sm:flex-row gap-2 justify-end">
|
||||
<DialogFooter className="mt-4 flex flex-col justify-end gap-2 sm:flex-row">
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
||||
Cancelar
|
||||
|
|
|
|||
|
|
@ -15,10 +15,9 @@ import TImovelUnidadeUrbanoForm from './TImovelUnidadeUrbanoForm';
|
|||
import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface';
|
||||
|
||||
export default function TImovelUnidadeUrbanoPage({ imovel_id }: TImovelUnidadePageInterface) {
|
||||
|
||||
const TImovelUnidadePage: TImovelUnidadePageInterface = {
|
||||
imovel_id: imovel_id
|
||||
}
|
||||
imovel_id: imovel_id,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -50,7 +49,8 @@ export default function TImovelUnidadeUrbanoPage({ imovel_id }: TImovelUnidadePa
|
|||
*/
|
||||
const handleOpenForm = useCallback((data: TImovelUnidadeUrbanoInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com imovel_id
|
||||
const initialData: TImovelUnidadeUrbanoInterface = data ?? { imovel_id } as TImovelUnidadeUrbanoInterface;
|
||||
const initialData: TImovelUnidadeUrbanoInterface =
|
||||
data ?? ({ imovel_id } as TImovelUnidadeUrbanoInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
@ -156,7 +156,7 @@ export default function TImovelUnidadeUrbanoPage({ imovel_id }: TImovelUnidadePa
|
|||
)}
|
||||
{/* Formulário de criação/edição, só aparece quando solicitado */}
|
||||
{isFormOpen && (
|
||||
< TImovelUnidadeUrbanoForm
|
||||
<TImovelUnidadeUrbanoForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedData}
|
||||
onClose={handleCloseForm}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,17 @@ import TImovelUnidadeUrbanoTableInterface from '@/packages/administrativo/interf
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TImovelUnidadeUrbanoTable({ data, onEdit, onDelete }: TImovelUnidadeUrbanoTableInterface) {
|
||||
export default function TImovelUnidadeUrbanoTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TImovelUnidadeUrbanoTableInterface) {
|
||||
const columns = TImovelUnidadeColumns(onEdit, onDelete);
|
||||
const isEmpty = !data || data.length === 0;
|
||||
return (
|
||||
<div className="max-h-[40vh] overflow-y-auto">
|
||||
{isEmpty ? (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
<div className="text-muted-foreground p-6 text-center">
|
||||
Nenhuma unidade cadastrada ainda.
|
||||
</div>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -1,13 +1,20 @@
|
|||
import { FormatCPF } from "@/shared/actions/CPF/FormatCPF";
|
||||
import { FormatDateTime } from "@/shared/actions/dateTime/FormatDateTime";
|
||||
import { FormatPhone } from "@/shared/actions/phone/FormatPhone";
|
||||
import GetNameInitials from "@/shared/actions/text/GetNameInitials";
|
||||
import empty from "@/shared/actions/validations/empty";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import TPessoaFisicaInterface from "@/packages/administrativo/interfaces/TPessoa/TPessoaFisica/TPessoaFisicaInterface";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { ArrowUpDownIcon, EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||
import { FormatCPF } from '@/shared/actions/CPF/FormatCPF';
|
||||
import { FormatDateTime } from '@/shared/actions/dateTime/FormatDateTime';
|
||||
import { FormatPhone } from '@/shared/actions/phone/FormatPhone';
|
||||
import GetNameInitials from '@/shared/actions/text/GetNameInitials';
|
||||
import empty from '@/shared/actions/validations/empty';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import TPessoaFisicaInterface from '@/packages/administrativo/interfaces/TPessoa/TPessoaFisica/TPessoaFisicaInterface';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { ArrowUpDownIcon, EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
|
||||
/**
|
||||
* Função para criar a definição das colunas da tabela
|
||||
|
|
@ -176,4 +183,4 @@ export function TPessoaFisicaColumns(
|
|||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,7 @@ import { Input } from '@/components/ui/input';
|
|||
|
||||
import LoadingButton from '@/shared/components/loadingButton/LoadingButton';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
} from '@/components/ui/select';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger } from '@/components/ui/select';
|
||||
import { CheckIcon, ChevronsUpDownIcon, HouseIcon, IdCardIcon, UserIcon } from 'lucide-react';
|
||||
import { Sexo } from '@/shared/enums/SexoEnum';
|
||||
import { useGTBEstadoCivilReadHook } from '../../../hooks/GTBEstadoCivil/useGTBEstadoCivilReadHook';
|
||||
|
|
@ -57,7 +52,6 @@ export default function TPessoaFisicaForm({
|
|||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TPessoaFisicaFormInterface) {
|
||||
|
||||
const { gTBProfissao, fetchGTBProfissao } = useGTBProfissaoReadHook();
|
||||
const { gTBEstadoCivil, fetchGTBEstadoCivil } = useGTBEstadoCivilReadHook();
|
||||
const { gTBRegimeComunhao, fetchGTBRegimeComunhao } = useGTBRegimeComunhaoReadHook();
|
||||
|
|
@ -70,7 +64,7 @@ export default function TPessoaFisicaForm({
|
|||
// Função para carregar os dados de forma sincrona
|
||||
const loadData = async () => {
|
||||
// Se existir dados, reseta o formulário com os dados informados
|
||||
ResetFormIfData(form, data)
|
||||
ResetFormIfData(form, data);
|
||||
// Aguarda a busca terminar
|
||||
await fetchGTBProfissao();
|
||||
await fetchGTBEstadoCivil();
|
||||
|
|
@ -93,12 +87,8 @@ export default function TPessoaFisicaForm({
|
|||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-3xl md:max-w-4xl lg:max-w-5xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
Pessoa Física
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
Preencha os dados da pessoa
|
||||
</DialogDescription>
|
||||
<DialogTitle>Pessoa Física</DialogTitle>
|
||||
<DialogDescription>Preencha os dados da pessoa</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSave, onError)} className="space-y-6">
|
||||
|
|
@ -299,9 +289,9 @@ export default function TPessoaFisicaForm({
|
|||
>
|
||||
{field.value
|
||||
? gTBEstadoCivil?.find(
|
||||
(item) =>
|
||||
String(item.tb_estadocivil_id) === String(field.value),
|
||||
)?.descricao
|
||||
(item) =>
|
||||
String(item.tb_estadocivil_id) === String(field.value),
|
||||
)?.descricao
|
||||
: 'Escolha o estado civil'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
|
|
@ -365,10 +355,10 @@ export default function TPessoaFisicaForm({
|
|||
>
|
||||
{field.value
|
||||
? gTBRegimeComunhao?.find(
|
||||
(item) =>
|
||||
String(item.tb_regimecomunhao_id) ===
|
||||
String(field.value),
|
||||
)?.descricao
|
||||
(item) =>
|
||||
String(item.tb_regimecomunhao_id) ===
|
||||
String(field.value),
|
||||
)?.descricao
|
||||
: 'Escolha o regime'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
|
|
@ -433,9 +423,9 @@ export default function TPessoaFisicaForm({
|
|||
>
|
||||
{field.value
|
||||
? gTBProfissao?.find(
|
||||
(item) =>
|
||||
String(item.tb_profissao_id) === String(field.value),
|
||||
)?.descricao
|
||||
(item) =>
|
||||
String(item.tb_profissao_id) === String(field.value),
|
||||
)?.descricao
|
||||
: 'Escolha a profissão'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ export default function TPessoaFisicaIndex() {
|
|||
*/
|
||||
const handleOpenForm = useCallback((data: TPessoaFisicaInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com pessoa_tipo
|
||||
const initialData: TPessoaFisicaInterface = data ?? { pessoa_tipo: "F" } as TPessoaFisicaInterface;
|
||||
const initialData: TPessoaFisicaInterface =
|
||||
data ?? ({ pessoa_tipo: 'F' } as TPessoaFisicaInterface);
|
||||
setSelectedAndamento(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
@ -140,9 +141,7 @@ export default function TPessoaFisicaIndex() {
|
|||
}}
|
||||
/>
|
||||
{/* Tabela de Registros */}
|
||||
<TPessoaTable data={tPessoaFisica}
|
||||
onDelete={handleConfirmDelete}
|
||||
onEdit={handleOpenForm} />
|
||||
<TPessoaTable data={tPessoaFisica} onDelete={handleConfirmDelete} onEdit={handleOpenForm} />
|
||||
{/* Modal de confirmação */}
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ import { TPessoaFisicaColumns } from './TPessoaFisicaColumns';
|
|||
/**
|
||||
* Componente principal da tabela
|
||||
*/
|
||||
export default function TPessoaFisicaTable({ data, onEdit, onDelete }: TPessoaFisicaTableInterface) {
|
||||
export default function TPessoaFisicaTable({
|
||||
data,
|
||||
onEdit,
|
||||
onDelete,
|
||||
}: TPessoaFisicaTableInterface) {
|
||||
const columns = TPessoaFisicaColumns(onEdit, onDelete);
|
||||
return (
|
||||
<div>
|
||||
|
|
|
|||
|
|
@ -1,151 +1,158 @@
|
|||
import { FormatCNPJ } from "@/shared/actions/CNPJ/FormatCNPJ";
|
||||
import { FormatDateTime } from "@/shared/actions/dateTime/FormatDateTime";
|
||||
import { FormatPhone } from "@/shared/actions/phone/FormatPhone";
|
||||
import empty from "@/shared/actions/validations/empty";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import TPessoaJuridicaInterface from "@/packages/administrativo/interfaces/TPessoa/TPessoaJuridica/TPessoaJuridicaInterface";
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { ArrowUpDownIcon, EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||
import { FormatCNPJ } from '@/shared/actions/CNPJ/FormatCNPJ';
|
||||
import { FormatDateTime } from '@/shared/actions/dateTime/FormatDateTime';
|
||||
import { FormatPhone } from '@/shared/actions/phone/FormatPhone';
|
||||
import empty from '@/shared/actions/validations/empty';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import TPessoaJuridicaInterface from '@/packages/administrativo/interfaces/TPessoa/TPessoaJuridica/TPessoaJuridicaInterface';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { ArrowUpDownIcon, EllipsisIcon, PencilIcon, Trash2Icon } from 'lucide-react';
|
||||
|
||||
export default function TPessoaJuridicaColumns(
|
||||
onEdit: (item: TPessoaJuridicaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TPessoaJuridicaInterface, isEditingFormStatus: boolean) => void,
|
||||
onEdit: (item: TPessoaJuridicaInterface, isEditingFormStatus: boolean) => void,
|
||||
onDelete: (item: TPessoaJuridicaInterface, isEditingFormStatus: boolean) => void,
|
||||
): ColumnDef<TPessoaJuridicaInterface>[] {
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'pessoa_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('pessoa_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
return [
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'pessoa_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('pessoa_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
|
||||
// Nome / Email / Foto
|
||||
{
|
||||
id: 'nome_completo',
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
// Nome / Email / Foto
|
||||
{
|
||||
id: 'nome_completo',
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Nome / Email <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Nome e Email */}
|
||||
<div>
|
||||
<div className="font-semibold text-gray-900 capitalize">{pessoa.nome || '-'}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.nome?.toLowerCase() || '').localeCompare(b.original.nome?.toLowerCase() || ''),
|
||||
},
|
||||
// CPF
|
||||
{
|
||||
accessorKey: 'cpf_cnpj',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
CNPJ <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatCNPJ(row.getValue('cpf_cnpj')),
|
||||
},
|
||||
// Telefone
|
||||
{
|
||||
accessorKey: 'telefone',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Telefone <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatPhone(row.getValue('telefone')),
|
||||
},
|
||||
// Cidade / UF
|
||||
{
|
||||
id: 'cidade_uf',
|
||||
accessorFn: (row) => `${row.cidade}/${row.uf}`,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Cidade/UF <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => <span>{row.getValue('cidade_uf') || '-'}</span>,
|
||||
sortingFn: (a, b) =>
|
||||
`${a.original.cidade}/${a.original.uf}`
|
||||
.toLowerCase()
|
||||
.localeCompare(`${b.original.cidade}/${b.original.uf}`.toLowerCase()),
|
||||
},
|
||||
// Data de cadastro
|
||||
{
|
||||
accessorKey: 'data_cadastro',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Cadastro <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatDateTime(row.getValue('data_cadastro')),
|
||||
sortingFn: 'datetime',
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="cursor-pointer">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem className="cursor-pointer" onSelect={() => onEdit(pessoa, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer text-red-600"
|
||||
onSelect={() => onDelete(pessoa, true)}
|
||||
>
|
||||
Nome / Email <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Nome e Email */}
|
||||
<div>
|
||||
<div className="font-semibold text-gray-900 capitalize">{pessoa.nome || '-'}</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.nome?.toLowerCase() || '').localeCompare(b.original.nome?.toLowerCase() || ''),
|
||||
},
|
||||
// CPF
|
||||
{
|
||||
accessorKey: 'cpf_cnpj',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
CNPJ <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatCNPJ(row.getValue('cpf_cnpj')),
|
||||
},
|
||||
// Telefone
|
||||
{
|
||||
accessorKey: 'telefone',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Telefone <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatPhone(row.getValue('telefone')),
|
||||
},
|
||||
// Cidade / UF
|
||||
{
|
||||
id: 'cidade_uf',
|
||||
accessorFn: (row) => `${row.cidade}/${row.uf}`,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Cidade/UF <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => <span>{row.getValue('cidade_uf') || '-'}</span>,
|
||||
sortingFn: (a, b) =>
|
||||
`${a.original.cidade}/${a.original.uf}`
|
||||
.toLowerCase()
|
||||
.localeCompare(`${b.original.cidade}/${b.original.uf}`.toLowerCase()),
|
||||
},
|
||||
// Data de cadastro
|
||||
{
|
||||
accessorKey: 'data_cadastro',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Cadastro <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatDateTime(row.getValue('data_cadastro')),
|
||||
sortingFn: 'datetime',
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
id: 'actions',
|
||||
header: 'Ações',
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon" className="cursor-pointer">
|
||||
<EllipsisIcon />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent side="left" align="start">
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuItem className="cursor-pointer" onSelect={() => onEdit(pessoa, true)}>
|
||||
<PencilIcon className="mr-2 h-4 w-4" />
|
||||
Editar
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
className="cursor-pointer text-red-600"
|
||||
onSelect={() => onDelete(pessoa, true)}
|
||||
>
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||
Remover
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
},
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ export default function TPessoaJuridicaForm({
|
|||
onSave,
|
||||
buttonIsLoading,
|
||||
}: TPessoaJuridicaFormInterface) {
|
||||
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTPessoaJuridicaFormHook({});
|
||||
|
||||
|
|
@ -114,9 +113,7 @@ export default function TPessoaJuridicaForm({
|
|||
name="nome_fantasia"
|
||||
render={({ field }) => (
|
||||
<FormItem className="w-full">
|
||||
<FormLabel>
|
||||
Nome Fantasia
|
||||
</FormLabel>
|
||||
<FormLabel>Nome Fantasia</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
{...field}
|
||||
|
|
@ -215,9 +212,11 @@ export default function TPessoaJuridicaForm({
|
|||
<FormItem className="w-full">
|
||||
<FormLabel>País</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field}
|
||||
onChange={e => field.onChange(parseNumberInput(e))}
|
||||
className="w-full" />
|
||||
<Input
|
||||
{...field}
|
||||
onChange={(e) => field.onChange(parseNumberInput(e))}
|
||||
className="w-full"
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -364,6 +363,6 @@ export default function TPessoaJuridicaForm({
|
|||
</Tabs>
|
||||
</Form>
|
||||
</DialogContent>
|
||||
</Dialog >
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,156 +18,157 @@ import TPessoaJuridicaForm from '@/packages/administrativo/components/TPessoa/TP
|
|||
import TPessoaJuridicaInterface from '@/packages/administrativo/interfaces/TPessoa/TPessoaJuridica/TPessoaJuridicaInterface';
|
||||
|
||||
export default function TPessoaJuridicaIndex() {
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
// Hooks para leitura e salvamento
|
||||
const { tPessoaJuridica, fetchTPessoaJuridica } = useTPessoaJuridicaIndexHook();
|
||||
const { saveTPessoaJuridica } = useTPessoaJuridicaSaveHook();
|
||||
const { deleteTPessoaJuridica } = useTPessoaJuridicaDeleteHook();
|
||||
|
||||
// Hooks para leitura e salvamento
|
||||
const { tPessoaJuridica, fetchTPessoaJuridica } = useTPessoaJuridicaIndexHook();
|
||||
const { saveTPessoaJuridica } = useTPessoaJuridicaSaveHook();
|
||||
const { deleteTPessoaJuridica } = useTPessoaJuridicaDeleteHook();
|
||||
// Estados
|
||||
const [selectedData, setSelectedData] = useState<TPessoaInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
|
||||
// Estados
|
||||
const [selectedData, setSelectedData] = useState<TPessoaInterface | null>(null);
|
||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<TPessoaInterface | null>(null);
|
||||
|
||||
// Estado para saber qual item será deletado
|
||||
const [itemToDelete, setItemToDelete] = useState<TPessoaInterface | null>(null);
|
||||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleConfirm,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* 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: TPessoaInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com pessoa_tipo
|
||||
const initialData: TPessoaJuridicaInterface =
|
||||
data ?? ({ pessoa_tipo: 'J' } as TPessoaJuridicaInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: TPessoaInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com pessoa_tipo
|
||||
const initialData: TPessoaJuridicaInterface = data ?? { pessoa_tipo: "J" } as TPessoaJuridicaInterface;
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
/**
|
||||
* Fecha o formulário e limpa o andamento selecionado
|
||||
*/
|
||||
const handleCloseForm = useCallback(() => {
|
||||
setSelectedData(null);
|
||||
setIsFormOpen(false);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* 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: TPessoaInterface) => {
|
||||
// Coloca o botão em estado de loading
|
||||
setButtonIsLoading(true);
|
||||
|
||||
/**
|
||||
* Salva os dados do formulário
|
||||
*/
|
||||
const handleSave = useCallback(
|
||||
async (formData: TPessoaInterface) => {
|
||||
// Coloca o botão em estado de loading
|
||||
setButtonIsLoading(true);
|
||||
// Aguarda salvar o registro
|
||||
await saveTPessoaJuridica(formData);
|
||||
|
||||
// Aguarda salvar o registro
|
||||
await saveTPessoaJuridica(formData);
|
||||
// Remove o botão em estado de loading
|
||||
setButtonIsLoading(false);
|
||||
|
||||
// Remove o botão em estado de loading
|
||||
setButtonIsLoading(false);
|
||||
// Atualiza a lista de dados
|
||||
fetchTPessoaJuridica();
|
||||
},
|
||||
[saveTPessoaJuridica, fetchTPessoaJuridica, handleCloseForm],
|
||||
);
|
||||
|
||||
// Atualiza a lista de dados
|
||||
fetchTPessoaJuridica();
|
||||
},
|
||||
[saveTPessoaJuridica, fetchTPessoaJuridica, handleCloseForm],
|
||||
);
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: TPessoaInterface) => {
|
||||
// Define o item atual para remoção
|
||||
setItemToDelete(item);
|
||||
// Abre o modal de confirmação
|
||||
openConfirmDialog();
|
||||
},
|
||||
[openConfirmDialog],
|
||||
);
|
||||
|
||||
/**
|
||||
* Quando o usuário clica em "remover" na tabela
|
||||
*/
|
||||
const handleConfirmDelete = useCallback(
|
||||
(item: TPessoaInterface) => {
|
||||
// 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 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 deleteTPessoaJuridica(itemToDelete);
|
||||
|
||||
// Executa o Hook de remoção
|
||||
await deleteTPessoaJuridica(itemToDelete);
|
||||
// Atualiza a lista
|
||||
await fetchTPessoaJuridica();
|
||||
|
||||
// Atualiza a lista
|
||||
await fetchTPessoaJuridica();
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
|
||||
// Limpa o item selecionado
|
||||
setItemToDelete(null);
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, fetchTPessoaJuridica, handleCancel]);
|
||||
|
||||
// Fecha o modal
|
||||
handleCancel();
|
||||
}, [itemToDelete, fetchTPessoaJuridica, handleCancel]);
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
fetchTPessoaJuridica();
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Busca inicial dos dados
|
||||
*/
|
||||
useEffect(() => {
|
||||
fetchTPessoaJuridica();
|
||||
}, []);
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (tPessoaJuridica.length == 0) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tela de loading enquanto carrega os dados
|
||||
*/
|
||||
if (tPessoaJuridica.length == 0) {
|
||||
return <Loading type={2} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Pessoas Jurídicas'}
|
||||
description={'Gerenciamento de pessoas jurídicas'}
|
||||
buttonText={'Nova Pessoa'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
{/* Tabela de Registros */}
|
||||
<TPessoaJuridicaTable
|
||||
data={tPessoaJuridica}
|
||||
onDelete={handleConfirmDelete}
|
||||
onEdit={handleOpenForm} />
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.nome}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
{/* Formulário de criação/edição */}
|
||||
{isFormOpen && (
|
||||
<TPessoaJuridicaForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedData}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
buttonIsLoading={buttonIsLoading}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
{/* Cabeçalho */}
|
||||
<Header
|
||||
title={'Pessoas Jurídicas'}
|
||||
description={'Gerenciamento de pessoas jurídicas'}
|
||||
buttonText={'Nova Pessoa'}
|
||||
buttonAction={() => {
|
||||
handleOpenForm(null);
|
||||
}}
|
||||
/>
|
||||
{/* Tabela de Registros */}
|
||||
<TPessoaJuridicaTable
|
||||
data={tPessoaJuridica}
|
||||
onDelete={handleConfirmDelete}
|
||||
onEdit={handleOpenForm}
|
||||
/>
|
||||
{/* Modal de confirmação */}
|
||||
{isConfirmOpen && (
|
||||
<ConfirmDialog
|
||||
isOpen={isConfirmOpen}
|
||||
title="Confirmar exclusão"
|
||||
description="Atenção"
|
||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.nome}"?`}
|
||||
confirmText="Sim, excluir"
|
||||
cancelText="Cancelar"
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleCancel}
|
||||
/>
|
||||
)}
|
||||
{/* Formulário de criação/edição */}
|
||||
{isFormOpen && (
|
||||
<TPessoaJuridicaForm
|
||||
isOpen={isFormOpen}
|
||||
data={selectedData}
|
||||
onClose={handleCloseForm}
|
||||
onSave={handleSave}
|
||||
buttonIsLoading={buttonIsLoading}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import TPessoaRepresentanteInterface from "../../interfaces/TPessoaRepresentante/TPessoaRepresentanteInterface";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowUpDownIcon, EllipsisIcon, Trash2Icon } from "lucide-react";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import TPessoaRepresentanteJoinedInterface from "../../interfaces/TPessoaRepresentante/TPessoaRepresentanteJoinedInterface";
|
||||
import GetNameInitials from "@/shared/actions/text/GetNameInitials";
|
||||
import empty from "@/shared/actions/validations/empty";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import TPessoaRepresentanteInterface from '../../interfaces/TPessoaRepresentante/TPessoaRepresentanteInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowUpDownIcon, EllipsisIcon, Trash2Icon } from 'lucide-react';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import TPessoaRepresentanteJoinedInterface from '../../interfaces/TPessoaRepresentante/TPessoaRepresentanteJoinedInterface';
|
||||
import GetNameInitials from '@/shared/actions/text/GetNameInitials';
|
||||
import empty from '@/shared/actions/validations/empty';
|
||||
|
||||
export default function TPessoaRepresentanteColumns(
|
||||
onDelete: (item: TPessoaRepresentanteInterface, isEditingFormStatus: boolean) => void,
|
||||
|
|
@ -58,7 +64,9 @@ export default function TPessoaRepresentanteColumns(
|
|||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.tpf_nome?.toLowerCase() || '').localeCompare(b.original.tpf_nome?.toLowerCase() || ''),
|
||||
(a.original.tpf_nome?.toLowerCase() || '').localeCompare(
|
||||
b.original.tpf_nome?.toLowerCase() || '',
|
||||
),
|
||||
},
|
||||
// Ações
|
||||
{
|
||||
|
|
@ -91,4 +99,4 @@ export default function TPessoaRepresentanteColumns(
|
|||
enableHiding: false,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ export default function TPessoaRepresentanteForm({
|
|||
}: TPessoaRepresentanteFormInterface) {
|
||||
const { tPessoaFisica, fetchTPessoaFisica } = useTPessoaFisicaIndexHook();
|
||||
|
||||
const [selectedTPessoaRepresentante, setSelectedTPessoaRepresentante] = useState<TPessoaRepresentanteInterface | null>(null);
|
||||
const [selectedTPessoaRepresentante, setSelectedTPessoaRepresentante] =
|
||||
useState<TPessoaRepresentanteInterface | null>(null);
|
||||
|
||||
// Inicializa o react-hook-form com schema zod
|
||||
const form = useTPessoaRepresentanteFormHook();
|
||||
|
|
@ -63,7 +64,7 @@ export default function TPessoaRepresentanteForm({
|
|||
if (!open) onClose(null, false);
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-full max-w-full p-6 sm:max-w-4xl md:max-w-4xl lg:max-w-4xl max-h-[70vh] overflow-auto">
|
||||
<DialogContent className="max-h-[70vh] w-full max-w-full overflow-auto p-6 sm:max-w-4xl md:max-w-4xl lg:max-w-4xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Representante</DialogTitle>
|
||||
<DialogDescription>Busque o representante desejado</DialogDescription>
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@ import TPessoaRepresentantePageInterface from '../../interfaces/TPessoaRepresent
|
|||
import TPessoaRepresentanteInterface from '../../interfaces/TPessoaRepresentante/TPessoaRepresentanteInterface';
|
||||
|
||||
export default function TPessoaRepresentantePage({ pessoa_id }: TPessoaRepresentantePageInterface) {
|
||||
|
||||
const TPessoaRepresentantePage: TPessoaRepresentantePageInterface = {
|
||||
pessoa_id: pessoa_id
|
||||
}
|
||||
pessoa_id: pessoa_id,
|
||||
};
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
|
|
@ -41,18 +40,15 @@ export default function TPessoaRepresentantePage({ pessoa_id }: TPessoaRepresent
|
|||
/**
|
||||
* Hook do modal de confirmação
|
||||
*/
|
||||
const {
|
||||
isOpen: isConfirmOpen,
|
||||
openDialog: openConfirmDialog,
|
||||
handleCancel,
|
||||
} = useConfirmDialog();
|
||||
const { isOpen: isConfirmOpen, openDialog: openConfirmDialog, handleCancel } = useConfirmDialog();
|
||||
|
||||
/**
|
||||
* Abre o formulário no modo de edição ou criação
|
||||
*/
|
||||
const handleOpenForm = useCallback((data: TPessoaRepresentanteInterface | null) => {
|
||||
// Se não houver dados (criação), cria um objeto inicial com imovel_id
|
||||
const initialData: TPessoaRepresentantePageInterface = data ?? { pessoa_id } as TPessoaRepresentantePageInterface;
|
||||
const initialData: TPessoaRepresentantePageInterface =
|
||||
data ?? ({ pessoa_id } as TPessoaRepresentantePageInterface);
|
||||
setSelectedData(initialData);
|
||||
setIsFormOpen(true);
|
||||
}, []);
|
||||
|
|
|
|||
|
|
@ -15,16 +15,13 @@ export default function TPessoaRepresentanteTable({
|
|||
const columns = TPessoaRepresentanteColumns(onDelete);
|
||||
const isEmpty = !data || data.length === 0;
|
||||
return (
|
||||
<div className='max-h-[50vh] overflow-auto'>
|
||||
<div className="max-h-[50vh] overflow-auto">
|
||||
{isEmpty ? (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
<div className="text-muted-foreground p-6 text-center">
|
||||
Nenhuma unidade cadastrada ainda.
|
||||
</div>
|
||||
) : (
|
||||
<DataTable
|
||||
data={data}
|
||||
columns={columns}
|
||||
/>
|
||||
<DataTable data={data} columns={columns} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,121 +1,123 @@
|
|||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { Checkbox } from "@/components/ui/checkbox";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { ArrowUpDownIcon } from "lucide-react";
|
||||
import empty from "@/shared/actions/validations/empty";
|
||||
import { FormatCPF } from "@/shared/actions/CPF/FormatCPF";
|
||||
import { FormatPhone } from "@/shared/actions/phone/FormatPhone";
|
||||
import TPessoaFisicaInterface from "../../interfaces/TPessoa/TPessoaFisica/TPessoaFisicaInterface";
|
||||
import GetNameInitials from "@/shared/actions/text/GetNameInitials";
|
||||
import TPessoaRepresentanteInterface from "../../interfaces/TPessoaRepresentante/TPessoaRepresentanteInterface";
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowUpDownIcon } from 'lucide-react';
|
||||
import empty from '@/shared/actions/validations/empty';
|
||||
import { FormatCPF } from '@/shared/actions/CPF/FormatCPF';
|
||||
import { FormatPhone } from '@/shared/actions/phone/FormatPhone';
|
||||
import TPessoaFisicaInterface from '../../interfaces/TPessoa/TPessoaFisica/TPessoaFisicaInterface';
|
||||
import GetNameInitials from '@/shared/actions/text/GetNameInitials';
|
||||
import TPessoaRepresentanteInterface from '../../interfaces/TPessoaRepresentante/TPessoaRepresentanteInterface';
|
||||
|
||||
/**
|
||||
* Função para criar a definição das colunas da tabela
|
||||
*/
|
||||
export default function TPessoasRepresentanteFormColumns(
|
||||
setSelectedTPessoaRepresentante: React.Dispatch<React.SetStateAction<TPessoaRepresentanteInterface | null>>,
|
||||
setSelectedTPessoaRepresentante: React.Dispatch<
|
||||
React.SetStateAction<TPessoaRepresentanteInterface | null>
|
||||
>,
|
||||
): ColumnDef<TPessoaFisicaInterface>[] {
|
||||
return [
|
||||
{
|
||||
id: 'select',
|
||||
header: '',
|
||||
cell: ({ row, table }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => {
|
||||
// Limpa todas as seleções antes de selecionar uma nova
|
||||
table.resetRowSelection();
|
||||
row.toggleSelected(!!value);
|
||||
setSelectedTPessoaRepresentante(value ? row.original : null);
|
||||
}}
|
||||
aria-label="Select row"
|
||||
return [
|
||||
{
|
||||
id: 'select',
|
||||
header: '',
|
||||
cell: ({ row, table }) => (
|
||||
<Checkbox
|
||||
checked={row.getIsSelected()}
|
||||
onCheckedChange={(value) => {
|
||||
// Limpa todas as seleções antes de selecionar uma nova
|
||||
table.resetRowSelection();
|
||||
row.toggleSelected(!!value);
|
||||
setSelectedTPessoaRepresentante(value ? row.original : null);
|
||||
}}
|
||||
aria-label="Select row"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'pessoa_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('pessoa_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
// Nome / Email / Foto
|
||||
{
|
||||
id: 'nome_completo',
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Nome / Email <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Foto ou Iniciais */}
|
||||
<div className="flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200">
|
||||
{pessoa.foto ? (
|
||||
<img
|
||||
src={pessoa.foto}
|
||||
alt={pessoa.nome || 'Avatar'}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
},
|
||||
// ID
|
||||
{
|
||||
accessorKey: 'pessoa_id',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
# <ArrowUpDownIcon className="ml-1 h-4 w-4" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => Number(row.getValue('pessoa_id')),
|
||||
enableSorting: false,
|
||||
},
|
||||
// Nome / Email / Foto
|
||||
{
|
||||
id: 'nome_completo',
|
||||
accessorFn: (row) => row,
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Nome / Email <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
const pessoa = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Foto ou Iniciais */}
|
||||
<div className="flex h-10 w-10 items-center justify-center overflow-hidden rounded-full bg-gray-200">
|
||||
{pessoa.foto ? (
|
||||
<img
|
||||
src={pessoa.foto}
|
||||
alt={pessoa.nome || 'Avatar'}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : (
|
||||
<span className="text-sm font-medium text-gray-700">
|
||||
{GetNameInitials(pessoa.nome)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{/* Nome e Email */}
|
||||
<div>
|
||||
<div className="font-semibold text-gray-900 capitalize">{pessoa.nome || '-'}</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
{empty(pessoa.email) ? 'Email não informado' : pessoa.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.nome?.toLowerCase() || '').localeCompare(b.original.nome?.toLowerCase() || ''),
|
||||
},
|
||||
// CPF
|
||||
{
|
||||
accessorKey: 'cpf_cnpj',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
CPF <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatCPF(row.getValue('cpf_cnpj')),
|
||||
},
|
||||
// Telefone
|
||||
{
|
||||
accessorKey: 'telefone',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Telefone <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatPhone(row.getValue('telefone')),
|
||||
},
|
||||
];
|
||||
}
|
||||
) : (
|
||||
<span className="text-sm font-medium text-gray-700">
|
||||
{GetNameInitials(pessoa.nome)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{/* Nome e Email */}
|
||||
<div>
|
||||
<div className="font-semibold text-gray-900 capitalize">{pessoa.nome || '-'}</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
{empty(pessoa.email) ? 'Email não informado' : pessoa.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.nome?.toLowerCase() || '').localeCompare(b.original.nome?.toLowerCase() || ''),
|
||||
},
|
||||
// CPF
|
||||
{
|
||||
accessorKey: 'cpf_cnpj',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
CPF <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatCPF(row.getValue('cpf_cnpj')),
|
||||
},
|
||||
// Telefone
|
||||
{
|
||||
accessorKey: 'telefone',
|
||||
header: ({ column }) => (
|
||||
<Button
|
||||
variant="ghost"
|
||||
onClick={() => column.toggleSorting(column.getIsSorted() === 'asc')}
|
||||
>
|
||||
Telefone <ArrowUpDownIcon className="ml-1 h-4 w-4 cursor-pointer" />
|
||||
</Button>
|
||||
),
|
||||
cell: ({ row }) => FormatPhone(row.getValue('telefone')),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,13 @@ import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/
|
|||
|
||||
// Função assíncrona que implementa a lógica de salvar (criar/atualizar) uma cidade
|
||||
async function executeGcidadeIndexData() {
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: Methods.GET, // GET listar todos os itens
|
||||
endpoint: `administrativo/g_cidade/` // endpoint dinâmico
|
||||
endpoint: `administrativo/g_cidade/`, // endpoint dinâmico
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/
|
|||
|
||||
// Função assíncrona que implementa a lógica de salvar (criar/atualizar) uma cidade
|
||||
async function executeGcidadeRemoveData(data: GCidadeInterface) {
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/
|
|||
|
||||
// Função assíncrona que implementa a lógica de salvar (criar/atualizar) uma cidade
|
||||
async function executeGcidadeSaveData(data: GCidadeInterface) {
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.cidade_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
|
||||
async function executeGNaturezaDeleteData(
|
||||
data: GNaturezaInterface
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
async function executeGNaturezaDeleteData(data: GNaturezaInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/g_natureza/${data.natureza_id}`,
|
||||
});
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/g_natureza/${data.natureza_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GNaturezaDeleteData = withClientErrorHandler(executeGNaturezaDeleteData);
|
||||
export const GNaturezaDeleteData = withClientErrorHandler(executeGNaturezaDeleteData);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
|
||||
async function executeGNaturezaIndexData(
|
||||
data: GNaturezaInterface
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
async function executeGNaturezaIndexData(data: GNaturezaInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/g_natureza/sistema/${data.sistema_id}`,
|
||||
});
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/g_natureza/sistema/${data.sistema_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const GNaturezaIndexData = withClientErrorHandler(executeGNaturezaIndexData);
|
||||
export const GNaturezaIndexData = withClientErrorHandler(executeGNaturezaIndexData);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
|
||||
async function executeGNaturezaSaveData(
|
||||
data: GNaturezaInterface
|
||||
): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.natureza_id);
|
||||
async function executeGNaturezaSaveData(data: GNaturezaInterface): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.natureza_id);
|
||||
|
||||
// Instancia o cliente da API
|
||||
const api = new API();
|
||||
// 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_natureza/${data.natureza_id || ""}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a 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_natureza/${data.natureza_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const GNaturezaSaveData = withClientErrorHandler(executeGNaturezaSaveData);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TAtoParteTipoInterface from "../../interfaces/TAtoParteTipo/TAtoParteTipoInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import TAtoParteTipoInterface from '../../interfaces/TAtoParteTipo/TAtoParteTipoInterface';
|
||||
|
||||
async function executeTAtoParteTipoDeleteData(data: TAtoParteTipoInterface): Promise<ApiResponseInterface> {
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_ato_partetipo/${data.ato_partetipo_id}`
|
||||
});
|
||||
async function executeTAtoParteTipoDeleteData(
|
||||
data: TAtoParteTipoInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_ato_partetipo/${data.ato_partetipo_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TAtoParteTipoDeleteData = withClientErrorHandler(executeTAtoParteTipoDeleteData);
|
||||
export const TAtoParteTipoDeleteData = withClientErrorHandler(executeTAtoParteTipoDeleteData);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
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 { 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 executeTAtoParteTipoIndexData(): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_ato_partetipo`
|
||||
});
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_ato_partetipo`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TAtoParteTipoIndexData = withClientErrorHandler(executeTAtoParteTipoIndexData);
|
||||
export const TAtoParteTipoIndexData = withClientErrorHandler(executeTAtoParteTipoIndexData);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import TAtoParteTipoInterface from "../../interfaces/TAtoParteTipo/TAtoParteTipoInterface";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import TAtoParteTipoInterface from '../../interfaces/TAtoParteTipo/TAtoParteTipoInterface';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTAtoParteTipoSaveData(data: TAtoParteTipoInterface): Promise<ApiResponseInterface> {
|
||||
async function executeTAtoParteTipoSaveData(
|
||||
data: TAtoParteTipoInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.ato_partetipo_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.ato_partetipo_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_ato_partetipo/${data.ato_partetipo_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_ato_partetipo/${data.ato_partetipo_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TAtoParteTipoSaveData = withClientErrorHandler(executeTAtoParteTipoSaveData);
|
||||
export const TAtoParteTipoSaveData = withClientErrorHandler(executeTAtoParteTipoSaveData);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TCensecQualidadeInterface from "../../interfaces/TCensecQualidade/TCensecQualidadeInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import TCensecQualidadeInterface from '../../interfaces/TCensecQualidade/TCensecQualidadeInterface';
|
||||
|
||||
async function executeTCensecQualidadeDeleteData(data: TCensecQualidadeInterface): Promise<ApiResponseInterface> {
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_qualidade/${data.censec_qualidade_id}`
|
||||
});
|
||||
async function executeTCensecQualidadeDeleteData(
|
||||
data: TCensecQualidadeInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_qualidade/${data.censec_qualidade_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeDeleteData = withClientErrorHandler(executeTCensecQualidadeDeleteData);
|
||||
export const TCensecQualidadeDeleteData = withClientErrorHandler(executeTCensecQualidadeDeleteData);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
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 { 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 executeTCensecQualidadeIndexData(): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_qualidade`
|
||||
});
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_qualidade`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeIndexData = withClientErrorHandler(executeTCensecQualidadeIndexData);
|
||||
export const TCensecQualidadeIndexData = withClientErrorHandler(executeTCensecQualidadeIndexData);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import TCensecQualidadeInterface from "../../interfaces/TCensecQualidade/TCensecQualidadeInterface";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import TCensecQualidadeInterface from '../../interfaces/TCensecQualidade/TCensecQualidadeInterface';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTCensecQualidadeSaveData(data: TCensecQualidadeInterface): Promise<ApiResponseInterface> {
|
||||
async function executeTCensecQualidadeSaveData(
|
||||
data: TCensecQualidadeInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.censec_qualidade_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.censec_qualidade_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_censec_qualidade/${data.censec_qualidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_censec_qualidade/${data.censec_qualidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeSaveData = withClientErrorHandler(executeTCensecQualidadeSaveData);
|
||||
export const TCensecQualidadeSaveData = withClientErrorHandler(executeTCensecQualidadeSaveData);
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ async function executeTCensecQualidadeAtoIndexData(data: TCensecQualidadeAtoInte
|
|||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeAtoIndexData = withClientErrorHandler(executeTCensecQualidadeAtoIndexData);
|
||||
export const TCensecQualidadeAtoIndexData = withClientErrorHandler(
|
||||
executeTCensecQualidadeAtoIndexData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ async function executeTCensecQualidadeAtoRemoveData(data: TCensecQualidadeAtoInt
|
|||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeAtoRemoveData = withClientErrorHandler(executeTCensecQualidadeAtoRemoveData);
|
||||
export const TCensecQualidadeAtoRemoveData = withClientErrorHandler(
|
||||
executeTCensecQualidadeAtoRemoveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
|||
import TCensecQualidadeAtoInterface from '../../interfaces/TCensecQualidadeAto/TCensecQualidadeAtoInterface';
|
||||
|
||||
async function executeTCensecQualidadeAtoSaveData(data: TCensecQualidadeAtoInterface) {
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
|
|
@ -16,4 +15,6 @@ async function executeTCensecQualidadeAtoSaveData(data: TCensecQualidadeAtoInter
|
|||
});
|
||||
}
|
||||
|
||||
export const TCensecQualidadeAtoSaveData = withClientErrorHandler(executeTCensecQualidadeAtoSaveData);
|
||||
export const TCensecQualidadeAtoSaveData = withClientErrorHandler(
|
||||
executeTCensecQualidadeAtoSaveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
async function executeTCensecTipoAtoIndexData() {
|
||||
const api = new API();
|
||||
return await api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_tipoato/`
|
||||
});
|
||||
|
||||
const api = new API();
|
||||
return await api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_tipoato/`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoAtoIndexData = withClientErrorHandler(executeTCensecTipoAtoIndexData)
|
||||
export const TCensecTipoAtoIndexData = withClientErrorHandler(executeTCensecTipoAtoIndexData);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
import API from "@/shared/services/api/Api";
|
||||
import { TCensecTipoAtoInterface } from "../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { TCensecTipoAtoInterface } from '../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
async function executeTCensecTipoAtoRemoveData(data: TCensecTipoAtoInterface) {
|
||||
const api = new API();
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_tipoato/${data.censec_tipoato_id}`
|
||||
});
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_tipoato/${data.censec_tipoato_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoAtoRemoveData = withClientErrorHandler(executeTCensecTipoAtoRemoveData)
|
||||
export const TCensecTipoAtoRemoveData = withClientErrorHandler(executeTCensecTipoAtoRemoveData);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
import API from "@/shared/services/api/Api";
|
||||
import { TCensecTipoAtoInterface } from "../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { TCensecTipoAtoInterface } from '../../interfaces/TCensecTipoAto/TCensecTipoAtoInterface';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
|
||||
async function executeTCensecTipoAtoSaveData(data: TCensecTipoAtoInterface) {
|
||||
const isUpdate = Boolean(data.censec_tipoato_id);
|
||||
|
||||
const isUpdate = Boolean(data.censec_tipoato_id);
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||
endpoint: `administrativo/t_censec_tipoato/${data.censec_tipoato_id || ''}`,
|
||||
body: data
|
||||
});
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||
endpoint: `administrativo/t_censec_tipoato/${data.censec_tipoato_id || ''}`,
|
||||
body: data,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoAtoSaveData = withClientErrorHandler(executeTCensecTipoAtoSaveData)
|
||||
export const TCensecTipoAtoSaveData = withClientErrorHandler(executeTCensecTipoAtoSaveData);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TCensecTipoNaturezaInterface from "../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import TCensecTipoNaturezaInterface from '../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface';
|
||||
|
||||
async function executeTCensecTipoNaturezaDeleteData(data: TCensecTipoNaturezaInterface): Promise<ApiResponseInterface> {
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_tiponatureza/${data.censec_tiponatureza_id}`
|
||||
});
|
||||
async function executeTCensecTipoNaturezaDeleteData(
|
||||
data: TCensecTipoNaturezaInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_censec_tiponatureza/${data.censec_tiponatureza_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoNaturezaDeleteData = withClientErrorHandler(executeTCensecTipoNaturezaDeleteData);
|
||||
export const TCensecTipoNaturezaDeleteData = withClientErrorHandler(
|
||||
executeTCensecTipoNaturezaDeleteData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
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 { 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 executeTCensecTipoNaturezaIndexData(): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_tiponatureza`
|
||||
});
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_censec_tiponatureza`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoNaturezaIndexData = withClientErrorHandler(executeTCensecTipoNaturezaIndexData);
|
||||
export const TCensecTipoNaturezaIndexData = withClientErrorHandler(
|
||||
executeTCensecTipoNaturezaIndexData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import TCensecTipoNaturezaInterface from "../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import TCensecTipoNaturezaInterface from '../../interfaces/TCensecTipoNatureza/TCensecTipoNaturezaInterface';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTCensecTipoNaturezaSaveData(data: TCensecTipoNaturezaInterface): Promise<ApiResponseInterface> {
|
||||
async function executeTCensecTipoNaturezaSaveData(
|
||||
data: TCensecTipoNaturezaInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
console.log('executeTCensecTipoNaturezaSaveData', data);
|
||||
|
||||
console.log('executeTCensecTipoNaturezaSaveData', data)
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.censec_tiponatureza_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.censec_tiponatureza_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_censec_tiponatureza/${data.censec_tiponatureza_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_censec_tiponatureza/${data.censec_tiponatureza_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TCensecTipoNaturezaSaveData = withClientErrorHandler(executeTCensecTipoNaturezaSaveData);
|
||||
export const TCensecTipoNaturezaSaveData = withClientErrorHandler(
|
||||
executeTCensecTipoNaturezaSaveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import TImovelInterface from '../../interfaces/TImovel/TImovelInterface';
|
||||
|
||||
async function executeTImovelDeleteData(data: TImovelInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
|
||||
const api = new API();
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel/${data.imovel_id}`
|
||||
});
|
||||
|
||||
return await api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel/${data.imovel_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelDeleteData = withClientErrorHandler(executeTImovelDeleteData);
|
||||
export const TImovelDeleteData = withClientErrorHandler(executeTImovelDeleteData);
|
||||
|
|
|
|||
|
|
@ -1,15 +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 { TImovelIndexDataInterface } from "../../interfaces/TImovel/TImovelIndexDataInterface";
|
||||
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 { TImovelIndexDataInterface } from '../../interfaces/TImovel/TImovelIndexDataInterface';
|
||||
|
||||
async function executeTImovelIndexData(data: TImovelIndexDataInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel/classe/${data.tipo_classe}`
|
||||
});
|
||||
async function executeTImovelIndexData(
|
||||
data: TImovelIndexDataInterface,
|
||||
): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel/classe/${data.tipo_classe}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelIndexData = withClientErrorHandler(executeTImovelIndexData);
|
||||
export const TImovelIndexData = withClientErrorHandler(executeTImovelIndexData);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import TImovelInterface from "../../interfaces/TImovel/TImovelInterface";
|
||||
import ApiResponseInterface from "@/shared/services/api/interfaces/ApiResponseInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import TImovelInterface from '../../interfaces/TImovel/TImovelInterface';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelSaveData(data: TImovelInterface): Promise<ApiResponseInterface> {
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel/${data.imovel_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel/${data.imovel_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelSaveData = withClientErrorHandler(executeTImovelSaveData);
|
||||
export const TImovelSaveData = withClientErrorHandler(executeTImovelSaveData);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import { TImovelUnidadeRuralInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import API from '@/shared/services/api/Api';
|
||||
|
||||
async function executeTImovelUnidadeRuralDeleteData(data: TImovelUnidadeRuralInterface) {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}`
|
||||
});
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeRuralDeleteData = withClientErrorHandler(executeTImovelUnidadeRuralDeleteData);
|
||||
export const TImovelUnidadeRuralDeleteData = withClientErrorHandler(
|
||||
executeTImovelUnidadeRuralDeleteData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import TImovelUnidadePageInterface from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelUnidadeRuralIndexData(data: TImovelUnidadePageInterface) {
|
||||
|
||||
const api = new API();
|
||||
return await api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}`
|
||||
});
|
||||
|
||||
const api = new API();
|
||||
return await api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeRuralIndexData = withClientErrorHandler(executeTImovelUnidadeRuralIndexData);
|
||||
export const TImovelUnidadeRuralIndexData = withClientErrorHandler(
|
||||
executeTImovelUnidadeRuralIndexData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import { TImovelUnidadeRuralInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import { TImovelUnidadeRuralInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeRural/TImovelUnidadeRural';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelUnidadeRuralSaveData(data: TImovelUnidadeRuralInterface) {
|
||||
console.log(data);
|
||||
|
||||
console.log(data);
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_unidade_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_unidade_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeRuralSaveData = withClientErrorHandler(executeTImovelUnidadeRuralSaveData);
|
||||
export const TImovelUnidadeRuralSaveData = withClientErrorHandler(
|
||||
executeTImovelUnidadeRuralSaveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import { TImovelUnidadeUrbanoInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import { TImovelUnidadeUrbanoInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelUnidadeUrbanoDeleteData(data: TImovelUnidadeUrbanoInterface) {
|
||||
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}`
|
||||
});
|
||||
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.DELETE,
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeUrbanoDeleteData = withClientErrorHandler(executeTImovelUnidadeUrbanoDeleteData);
|
||||
export const TImovelUnidadeUrbanoDeleteData = withClientErrorHandler(
|
||||
executeTImovelUnidadeUrbanoDeleteData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,16 @@
|
|||
import TImovelUnidadePageInterface from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface";
|
||||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import TImovelUnidadePageInterface from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadePageInterface';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelUnidadeUrbanoIndexData(data: TImovelUnidadePageInterface) {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}`
|
||||
});
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.GET,
|
||||
endpoint: `administrativo/t_imovel_unidade/imovel/${data.imovel_id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeUrbanoIndexData = withClientErrorHandler(executeTImovelUnidadeUrbanoIndexData);
|
||||
export const TImovelUnidadeUrbanoIndexData = withClientErrorHandler(
|
||||
executeTImovelUnidadeUrbanoIndexData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
import { TImovelUnidadeUrbanoInterface } from "@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface";
|
||||
import API from "@/shared/services/api/Api";
|
||||
import { Methods } from "@/shared/services/api/enums/ApiMethodEnum";
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import { TImovelUnidadeUrbanoInterface } from '@/packages/administrativo/interfaces/TImovelUnidade/TImovelUnidadeUrbano/TImovelUnidadeUrbanoInterface';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTImovelUnidadeUrbanoSaveData(data: TImovelUnidadeUrbanoInterface) {
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_unidade_id);
|
||||
|
||||
// Verifica se existe ID da cidade para decidir se é atualização (PUT) ou criação (POST)
|
||||
const isUpdate = Boolean(data.imovel_unidade_id);
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
// Executa a requisição para a API com o método apropriado e envia os dados no corpo
|
||||
return await api.send({
|
||||
method: isUpdate ? Methods.PUT : Methods.POST, // PUT se atualizar, POST se criar
|
||||
endpoint: `administrativo/t_imovel_unidade/${data.imovel_unidade_id || ''}`, // endpoint dinâmico
|
||||
body: data, // payload enviado para a API
|
||||
});
|
||||
}
|
||||
|
||||
export const TImovelUnidadeUrbanoSaveData = withClientErrorHandler(executeTImovelUnidadeUrbanoSaveData);
|
||||
export const TImovelUnidadeUrbanoSaveData = withClientErrorHandler(
|
||||
executeTImovelUnidadeUrbanoSaveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,4 +11,4 @@ async function executeTPessoaFisicaRemoveData(data: TPessoaFisicaInterface) {
|
|||
});
|
||||
}
|
||||
|
||||
export const TPessoaFisicaRemoveData = withClientErrorHandler(executeTPessoaFisicaRemoveData);
|
||||
export const TPessoaFisicaRemoveData = withClientErrorHandler(executeTPessoaFisicaRemoveData);
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ async function executeTPessoaJuridicaIndexData() {
|
|||
});
|
||||
}
|
||||
|
||||
export const TPessoaJuridicaIndexData = withClientErrorHandler(executeTPessoaJuridicaIndexData);
|
||||
export const TPessoaJuridicaIndexData = withClientErrorHandler(executeTPessoaJuridicaIndexData);
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ async function executeTPessoaRepresentanteIndexData(data: TPessoaRepresentanteIn
|
|||
});
|
||||
}
|
||||
|
||||
export const TPessoaRepresentanteIndexData = withClientErrorHandler(executeTPessoaRepresentanteIndexData);
|
||||
export const TPessoaRepresentanteIndexData = withClientErrorHandler(
|
||||
executeTPessoaRepresentanteIndexData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@ async function executeTPessoaRepresentanteRemoveData(data: TPessoaRepresentanteI
|
|||
});
|
||||
}
|
||||
|
||||
export const TPessoaRepresentanteRemoveData = withClientErrorHandler(executeTPessoaRepresentanteRemoveData);
|
||||
export const TPessoaRepresentanteRemoveData = withClientErrorHandler(
|
||||
executeTPessoaRepresentanteRemoveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import API from '@/shared/services/api/Api';
|
|||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
async function executeTPessoaRepresentanteSaveData(data: TPessoaRepresentanteInterface) {
|
||||
|
||||
// Instancia o cliente da API para enviar a requisição
|
||||
const api = new API();
|
||||
|
||||
|
|
@ -16,4 +15,6 @@ async function executeTPessoaRepresentanteSaveData(data: TPessoaRepresentanteInt
|
|||
});
|
||||
}
|
||||
|
||||
export const TPessoaRepresentanteSaveData = withClientErrorHandler(executeTPessoaRepresentanteSaveData);
|
||||
export const TPessoaRepresentanteSaveData = withClientErrorHandler(
|
||||
executeTPessoaRepresentanteSaveData,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useResponse } from "@/shared/components/response/ResponseContext"; // Contexto global para gerenciar respostas da API
|
||||
import GCidadeInterface from "@/packages/administrativo/interfaces/GCidade/GCidadeInterface"; // Interface tipada da cidade
|
||||
import { GCidadeRemoveData } from "@/packages/administrativo/data/GCidade/GCidadeRemoveData"; // Função que remove a cidade via API
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext'; // Contexto global para gerenciar respostas da API
|
||||
import GCidadeInterface from '@/packages/administrativo/interfaces/GCidade/GCidadeInterface'; // Interface tipada da cidade
|
||||
import { GCidadeRemoveData } from '@/packages/administrativo/data/GCidade/GCidadeRemoveData'; // Função que remove a cidade via API
|
||||
|
||||
// Hook customizado para remoção de cidades
|
||||
export const useGCidadeRemoveHook = () => {
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ export const useGCidadeSaveHook = () => {
|
|||
|
||||
// Manda a resposta para o verificador de resposta
|
||||
setResponse(response);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return { gCidade, saveGCidade };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useResponse } from "@/shared/components/response/ResponseContext";
|
||||
import { useState } from "react";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import { GNaturezaDeleteService } from "../../services/GNatureza/GNaturezaDeleteService";
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
import { useState } from 'react';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
import { GNaturezaDeleteService } from '../../services/GNatureza/GNaturezaDeleteService';
|
||||
|
||||
export const useGNaturezaDeleteHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useForm } from "react-hook-form";
|
||||
import { GNaturezaFormValues, GNaturezaSchema } from "../../schemas/GNatureza/GNaturezaSchema";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { GNaturezaFormValues, GNaturezaSchema } from '../../schemas/GNatureza/GNaturezaSchema';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
|
||||
export function useGNaturezaFormHook(defaults?: Partial<GNaturezaFormValues>) {
|
||||
return useForm<GNaturezaFormValues>({
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use client';
|
||||
|
||||
import { useResponse } from "@/shared/components/response/ResponseContext";
|
||||
import { useState } from "react";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import { GNaturezaIndexService } from "../../services/GNatureza/GNaturezaIndexService";
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
import { useState } from 'react';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
import { GNaturezaIndexService } from '../../services/GNatureza/GNaturezaIndexService';
|
||||
|
||||
export const useGNaturezaIndexHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
'use client';
|
||||
|
||||
import { useResponse } from "@/shared/components/response/ResponseContext";
|
||||
import { useState } from "react";
|
||||
import GNaturezaInterface from "../../interfaces/GNatureza/GNaturezaInterface";
|
||||
import { GNaturezaSaveService } from "../../services/GNatureza/GNaturezaSaveService";
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
import { useState } from 'react';
|
||||
import GNaturezaInterface from '../../interfaces/GNatureza/GNaturezaInterface';
|
||||
import { GNaturezaSaveService } from '../../services/GNatureza/GNaturezaSaveService';
|
||||
|
||||
export const useGNaturezaSaveHook = () => {
|
||||
const { setResponse } = useResponse();
|
||||
|
|
@ -30,4 +30,4 @@ export const useGNaturezaSaveHook = () => {
|
|||
};
|
||||
|
||||
return { gNatureza, saveGNatureza, isOpen, setIsOpen };
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,5 +23,4 @@ export const useGTBBairroReadHook = () => {
|
|||
};
|
||||
|
||||
return useMemo(() => ({ gTBBairro, fetchGTBBairro }), [gTBBairro, fetchGTBBairro]);
|
||||
|
||||
};
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue