[MVPTN-80] deploy
This commit is contained in:
parent
de86ba1e7f
commit
47dfcf509f
273 changed files with 12218 additions and 7889 deletions
|
|
@ -1,2 +1 @@
|
||||||
# saas_app
|
# saas_app
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,4 +18,4 @@
|
||||||
"hooks": "@/hooks"
|
"hooks": "@/hooks"
|
||||||
},
|
},
|
||||||
"iconLibrary": "lucide"
|
"iconLibrary": "lucide"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
23
eslint.config.js
Normal file
23
eslint.config.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import next from "eslint-config-next";
|
||||||
|
import importPlugin from "eslint-plugin-import";
|
||||||
|
|
||||||
|
export default [
|
||||||
|
next,
|
||||||
|
{
|
||||||
|
plugins: {
|
||||||
|
import: importPlugin
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
"import/order": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
groups: ["builtin", "external", "internal", ["parent", "sibling", "index"]],
|
||||||
|
"newlines-between": "always",
|
||||||
|
alphabetize: { order: "asc", caseInsensitive: true }
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"semi": ["error", "always"],
|
||||||
|
"quotes": ["error", "double"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
@ -2,7 +2,7 @@ import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
// Isso gera um diretório otimizado que inclui tudo o que a aplicação precisa para rodar
|
// Isso gera um diretório otimizado que inclui tudo o que a aplicação precisa para rodar
|
||||||
output: 'standalone',
|
output: "standalone",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|
|
||||||
5012
package-lock.json
generated
5012
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "app",
|
"type": "module",
|
||||||
|
"name": "saas",
|
||||||
"version": "25.9.1",
|
"version": "25.9.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
@ -43,12 +44,15 @@
|
||||||
"zod": "^4.0.17"
|
"zod": "^4.0.17"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@rushstack/eslint-patch": "^1.12.0",
|
||||||
"@tailwindcss/postcss": "^4",
|
"@tailwindcss/postcss": "^4",
|
||||||
"@types/js-cookie": "^3.0.6",
|
"@types/js-cookie": "^3.0.6",
|
||||||
"@types/jsonwebtoken": "^9.0.10",
|
"@types/jsonwebtoken": "^9.0.10",
|
||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
|
"eslint-config-next": "^15.5.4",
|
||||||
|
"eslint-plugin-import": "^2.32.0",
|
||||||
"tailwindcss": "^4",
|
"tailwindcss": "^4",
|
||||||
"tw-animate-css": "^1.3.7",
|
"tw-animate-css": "^1.3.7",
|
||||||
"typescript": "^5"
|
"typescript": "^5"
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
|
|
||||||
export default class Schema {
|
export default class Schema {
|
||||||
|
private _errors: any[] = [];
|
||||||
|
|
||||||
private _errors: any[] = []
|
get errors(): any {
|
||||||
|
return this._errors;
|
||||||
|
}
|
||||||
|
|
||||||
get errors(): any {
|
set errors(value: any) {
|
||||||
return this._errors;
|
this._errors.push(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
set errors(value: any) {
|
|
||||||
this._errors.push(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Função para obter tokens do lado servidorde acordo com o nome informado
|
* Função para obter tokens do lado servidorde acordo com o nome informado
|
||||||
*/
|
*/
|
||||||
export default async function CookiesGet(token: string) {
|
export default async function CookiesGet(token: string) {
|
||||||
|
// Obtem a lista de Tokens
|
||||||
|
const cookieStore = await cookies();
|
||||||
|
|
||||||
// Obtem a lista de Tokens
|
// Obtem um token em especifico
|
||||||
const cookieStore = await cookies();
|
const data = cookieStore.get(token);
|
||||||
|
|
||||||
// Obtem um token em especifico
|
// Retorna nulo ou o valor do token desejado
|
||||||
const data = cookieStore.get(token);
|
return data?.value;
|
||||||
|
}
|
||||||
// Retorna nulo ou o valor do token desejado
|
|
||||||
return data?.value;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import appConfig from '../../config/app.json';
|
import appConfig from "../../config/app.json";
|
||||||
export default class Json {
|
export default class Json {
|
||||||
static execute() {
|
static execute() {
|
||||||
return appConfig;
|
return appConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
export default function GetSigla(data: string): string {
|
export default function GetSigla(data: string): string {
|
||||||
|
if (!data) return "";
|
||||||
|
|
||||||
if (!data) return "";
|
// Remove espaços extras no início e no fim e divide em palavras
|
||||||
|
const palavras = data.trim().split(/\s+/);
|
||||||
|
|
||||||
// Remove espaços extras no início e no fim e divide em palavras
|
if (palavras.length === 1) {
|
||||||
const palavras = data.trim().split(/\s+/);
|
// Apenas uma palavra → retorna as duas primeiras letras
|
||||||
|
return palavras[0].substring(0, 2).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
if (palavras.length === 1) {
|
// Duas ou mais palavras → retorna a primeira letra de cada
|
||||||
// Apenas uma palavra → retorna as duas primeiras letras
|
return palavras.map((palavra) => palavra.charAt(0).toUpperCase()).join("");
|
||||||
return palavras[0].substring(0, 2).toUpperCase();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Duas ou mais palavras → retorna a primeira letra de cada
|
|
||||||
return palavras.map(palavra => palavra.charAt(0).toUpperCase()).join('');
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export default async function TokenGet() {
|
export default async function TokenGet() {
|
||||||
|
const cookieStore = await cookies();
|
||||||
const cookieStore = await cookies();
|
const token = cookieStore.get("access_token");
|
||||||
const token = cookieStore.get('access_token');
|
return token?.value;
|
||||||
return token?.value;
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
export default function empty(data: any) {
|
export default function empty(data: any) {
|
||||||
if (!data || !data === null || !data === undefined) {
|
if (!data || !data === null || !data === undefined) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,27 @@
|
||||||
import withClientErrorHandlerInterface from "./withClientErrorHandlerInterface";
|
import withClientErrorHandlerInterface from "./withClientErrorHandlerInterface";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Códigos de erro que começam com 6, são do front entd, na ordem do alfabeto o F de frontend é a sexta letra
|
* Códigos de erro que começam com 6, são do front entd, na ordem do alfabeto o F de frontend é a sexta letra
|
||||||
*/
|
*/
|
||||||
export function withClientErrorHandler<T extends (...args: any[]) => Promise<any>>(
|
export function withClientErrorHandler<
|
||||||
action: T
|
T extends (...args: any[]) => Promise<any>,
|
||||||
) {
|
>(action: T) {
|
||||||
return async (...args: Parameters<T>): Promise<withClientErrorHandlerInterface> => {
|
return async (
|
||||||
|
...args: Parameters<T>
|
||||||
try {
|
): Promise<withClientErrorHandlerInterface> => {
|
||||||
|
try {
|
||||||
// Executa a função definida
|
// Executa a função definida
|
||||||
const data = await action(...args);
|
const data = await action(...args);
|
||||||
|
|
||||||
// Retorna exatamente a mesma resposta retornada pela função
|
|
||||||
return data;
|
|
||||||
|
|
||||||
} catch (error: any) {
|
|
||||||
|
|
||||||
// Retorna o erro de execuçãformatado
|
|
||||||
return {
|
|
||||||
status: 600,
|
|
||||||
message: error?.message || "Erro interno do servidor",
|
|
||||||
data: error
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
// Retorna exatamente a mesma resposta retornada pela função
|
||||||
|
return data;
|
||||||
|
} catch (error: any) {
|
||||||
|
// Retorna o erro de execuçãformatado
|
||||||
|
return {
|
||||||
|
status: 600,
|
||||||
|
message: error?.message || "Erro interno do servidor",
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
export default interface withClientErrorHandlerInterface<T = any> {
|
export default interface withClientErrorHandlerInterface<T = any> {
|
||||||
|
status: number;
|
||||||
status: number;
|
data?: T;
|
||||||
data?: T;
|
message?: string;
|
||||||
message?: string;
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,73 +1,51 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
|
|
||||||
import {
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardContent
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
import { useGUsuarioReadHooks } from "@/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks";
|
import { useGUsuarioReadHooks } from "@/app/(protected)/(administrativo)/_hooks/g_usuario/useGUsuarioReadHooks";
|
||||||
import Usuario from "@/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface";
|
import Usuario from "@/app/(protected)/(administrativo)/_interfaces/GUsuarioInterface";
|
||||||
import Loading from "@/app/_components/loading/loading";
|
import Loading from "@/app/_components/loading/loading";
|
||||||
|
|
||||||
export default function UsuarioDetalhes() {
|
export default function UsuarioDetalhes() {
|
||||||
|
const params = useParams();
|
||||||
|
|
||||||
const params = useParams();
|
const { usuario, fetchUsuario } = useGUsuarioReadHooks();
|
||||||
|
|
||||||
const { usuario, fetchUsuario } = useGUsuarioReadHooks();
|
useEffect(() => {
|
||||||
|
if (params.id) {
|
||||||
|
fetchUsuario({ usuario_id: Number(params.id) } as Usuario);
|
||||||
|
}
|
||||||
|
console.log("pagina", usuario);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
if (!usuario) return <Loading type={1} />;
|
||||||
|
|
||||||
if (params.id) {
|
return (
|
||||||
fetchUsuario({ usuario_id: Number(params.id) } as Usuario);
|
<div>
|
||||||
}
|
<Card>
|
||||||
console.log("pagina",usuario)
|
<CardContent>
|
||||||
}, []);
|
<div className="mb-4 grid gap-4 grid-cols-4">
|
||||||
|
<div>
|
||||||
if (!usuario) return <Loading type={1} />;
|
<div className="text-2xl font-semibold">Nome</div>
|
||||||
|
<div className="text-xl">{usuario?.nome_completo}</div>
|
||||||
return (
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Card>
|
<div className="text-2xl font-semibold">CPF</div>
|
||||||
<CardContent>
|
<div className="text-xl">{usuario?.cpf}</div>
|
||||||
<div className="mb-4 grid gap-4 grid-cols-4">
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="text-2xl font-semibold">
|
<div className="text-2xl font-semibold">Função</div>
|
||||||
Nome
|
<div className="text-xl">{usuario?.funcao}</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xl">
|
<div>
|
||||||
{usuario?.nome_completo}
|
<div className="text-2xl font-semibold">Email</div>
|
||||||
</div>
|
<div className="text-xl">{usuario?.email}</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<div className="text-2xl font-semibold">
|
</CardContent>
|
||||||
CPF
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-xl">
|
);
|
||||||
{usuario?.cpf}
|
}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-2xl font-semibold">
|
|
||||||
Função
|
|
||||||
</div>
|
|
||||||
<div className="text-xl">
|
|
||||||
{usuario?.funcao}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="text-2xl font-semibold">
|
|
||||||
Email
|
|
||||||
</div>
|
|
||||||
<div className="text-xl">
|
|
||||||
{usuario?.email}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,136 +1,127 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form";
|
||||||
import { z } from "zod"
|
import { z } from "zod";
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input";
|
||||||
import { GUsuarioSchema } from "../../../_schemas/GUsuarioSchema"
|
import { GUsuarioSchema } from "../../../_schemas/GUsuarioSchema";
|
||||||
|
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Button
|
Form,
|
||||||
} from "@/components/ui/button"
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form";
|
||||||
|
|
||||||
import {
|
import { useGUsuarioSaveHook } from "../../../_hooks/g_usuario/useGUsuarioSaveHook";
|
||||||
Card,
|
|
||||||
CardContent
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
|
|
||||||
import {
|
type FormValues = z.infer<typeof GUsuarioSchema>;
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from "@/components/ui/form"
|
|
||||||
|
|
||||||
import { useGUsuarioSaveHook } from "../../../_hooks/g_usuario/useGUsuarioSaveHook"
|
|
||||||
|
|
||||||
type FormValues = z.infer<typeof GUsuarioSchema>
|
|
||||||
|
|
||||||
export default function UsuarioFormularioPage() {
|
export default function UsuarioFormularioPage() {
|
||||||
|
const { usuario, saveUsuario } = useGUsuarioSaveHook();
|
||||||
|
|
||||||
const { usuario, saveUsuario } = useGUsuarioSaveHook();
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(GUsuarioSchema),
|
||||||
|
defaultValues: {
|
||||||
|
login: "",
|
||||||
|
nome_completo: "",
|
||||||
|
funcao: "",
|
||||||
|
email: "",
|
||||||
|
cpf: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
async function onSubmit(values: FormValues) {
|
||||||
resolver: zodResolver(GUsuarioSchema),
|
saveUsuario(values);
|
||||||
defaultValues: {
|
}
|
||||||
login: '',
|
|
||||||
nome_completo: '',
|
|
||||||
funcao: '',
|
|
||||||
email: '',
|
|
||||||
cpf: ''
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onSubmit(values: FormValues) {
|
return (
|
||||||
saveUsuario(values);
|
<div>
|
||||||
}
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="login"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Login</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
return (
|
<FormField
|
||||||
<div>
|
control={form.control}
|
||||||
<Card>
|
name="nome_completo"
|
||||||
<CardContent>
|
render={({ field }) => (
|
||||||
<Form {...form}>
|
<FormItem>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
<FormLabel>Nome Completo</FormLabel>
|
||||||
<FormField
|
<FormControl>
|
||||||
control={form.control}
|
<Input {...field} />
|
||||||
name="login"
|
</FormControl>
|
||||||
render={({ field }) => (
|
<FormMessage />
|
||||||
<FormItem>
|
</FormItem>
|
||||||
<FormLabel>Login</FormLabel>
|
)}
|
||||||
<FormControl>
|
/>
|
||||||
<Input {...field} />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="nome_completo"
|
name="funcao"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Nome Completo</FormLabel>
|
<FormLabel>Função</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="funcao"
|
name="email"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Função</FormLabel>
|
<FormLabel>Email</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="email"
|
name="cpf"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Email</FormLabel>
|
<FormLabel>Cpf</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} />
|
<Input {...field} />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
<Button type="submit">Salvar</Button>
|
||||||
control={form.control}
|
</form>
|
||||||
name="cpf"
|
</Form>
|
||||||
render={({ field }) => (
|
</CardContent>
|
||||||
<FormItem>
|
</Card>
|
||||||
<FormLabel>Cpf</FormLabel>
|
</div>
|
||||||
<FormControl>
|
);
|
||||||
<Input {...field} />
|
}
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button type="submit">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,15 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Card,
|
Table,
|
||||||
CardContent,
|
TableBody,
|
||||||
} from "@/components/ui/card"
|
TableCell,
|
||||||
|
TableHead,
|
||||||
import {
|
TableHeader,
|
||||||
Table,
|
TableRow,
|
||||||
TableBody,
|
} from "@/components/ui/table";
|
||||||
TableCell,
|
|
||||||
TableHead,
|
|
||||||
TableHeader,
|
|
||||||
TableRow,
|
|
||||||
} from "@/components/ui/table"
|
|
||||||
|
|
||||||
import Usuario from "../../_interfaces/GUsuarioInterface";
|
import Usuario from "../../_interfaces/GUsuarioInterface";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
@ -22,91 +19,70 @@ import { useEffect } from "react";
|
||||||
import Loading from "@/app/_components/loading/loading";
|
import Loading from "@/app/_components/loading/loading";
|
||||||
|
|
||||||
export default function UsuarioPage() {
|
export default function UsuarioPage() {
|
||||||
|
const { usuarios, fetchUsuarios } = useGUsuarioIndexHook();
|
||||||
|
|
||||||
const { usuarios, fetchUsuarios } = useGUsuarioIndexHook();
|
useEffect(() => {
|
||||||
|
fetchUsuarios();
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
if (!usuarios) return <Loading type={2} />;
|
||||||
fetchUsuarios();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!usuarios) return <Loading type={2} />;
|
return (
|
||||||
|
<div>
|
||||||
return (
|
<Card>
|
||||||
<div>
|
<CardContent>
|
||||||
<Card>
|
<div className="grid grid-cols-2">
|
||||||
<CardContent>
|
<div className="text-2xl font-semibold">Usuarios</div>
|
||||||
<div className="grid grid-cols-2">
|
<div className="text-right">
|
||||||
<div className="text-2xl font-semibold">
|
<Button asChild>
|
||||||
Usuarios
|
<Link href="/usuarios/formulario">+ Usuário</Link>
|
||||||
</div>
|
</Button>
|
||||||
<div className="text-right">
|
</div>
|
||||||
<Button asChild>
|
</div>
|
||||||
<Link href="/usuarios/formulario">
|
<Table>
|
||||||
+ Usuário
|
<TableHeader>
|
||||||
</Link>
|
<TableRow>
|
||||||
</Button>
|
<TableHead className="text-center">#</TableHead>
|
||||||
</div>
|
<TableHead>Situação</TableHead>
|
||||||
|
<TableHead>CPF</TableHead>
|
||||||
|
<TableHead>Login / Sigla / Nome</TableHead>
|
||||||
|
<TableHead>Função</TableHead>
|
||||||
|
<TableHead></TableHead>
|
||||||
|
<TableHead></TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{usuarios.map((usuario: Usuario) => (
|
||||||
|
<TableRow key={usuario.usuario_id} className="cursor-pointer">
|
||||||
|
<TableCell className="text-center">
|
||||||
|
{usuario.usuario_id}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{usuario.situacao}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell className="font-medium">{usuario.cpf}</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<div className="font-semibold text-xs">
|
||||||
|
{usuario.login} - {usuario.sigla}
|
||||||
</div>
|
</div>
|
||||||
<Table>
|
<div className="text-base">{usuario.nome_completo}</div>
|
||||||
<TableHeader>
|
</TableCell>
|
||||||
<TableRow>
|
<TableCell>
|
||||||
<TableHead className="text-center">
|
<div className="text-base">{usuario.funcao}</div>
|
||||||
#
|
</TableCell>
|
||||||
</TableHead>
|
<TableCell>
|
||||||
<TableHead>
|
<Button asChild>
|
||||||
Situação
|
<Link href={`/usuarios/${usuario.usuario_id}/detalhes`}>
|
||||||
</TableHead>
|
Detalhes
|
||||||
<TableHead>
|
</Link>
|
||||||
CPF
|
</Button>
|
||||||
</TableHead>
|
</TableCell>
|
||||||
<TableHead>
|
</TableRow>
|
||||||
Login / Sigla / Nome
|
))}
|
||||||
</TableHead>
|
</TableBody>
|
||||||
<TableHead>
|
</Table>
|
||||||
Função
|
</CardContent>
|
||||||
</TableHead>
|
</Card>
|
||||||
<TableHead></TableHead>
|
</div>
|
||||||
<TableHead></TableHead>
|
);
|
||||||
</TableRow>
|
}
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{usuarios.map((usuario: Usuario) => (
|
|
||||||
<TableRow key={usuario.usuario_id} className="cursor-pointer">
|
|
||||||
<TableCell className="text-center">
|
|
||||||
{usuario.usuario_id}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="font-medium">
|
|
||||||
{usuario.situacao}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="font-medium">
|
|
||||||
{usuario.cpf}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="font-semibold text-xs">
|
|
||||||
{usuario.login} - {usuario.sigla}
|
|
||||||
</div>
|
|
||||||
<div className="text-base">
|
|
||||||
{usuario.nome_completo}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<div className="text-base">
|
|
||||||
{usuario.funcao}
|
|
||||||
</div>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<Button asChild>
|
|
||||||
<Link href={`/usuarios/${usuario.usuario_id}/detalhes`}>
|
|
||||||
Detalhes
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GUsuarioDeleteData(usuarioId: number) {
|
export default async function GUsuarioDeleteData(usuarioId: number) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
const response = await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
|
endpoint: `administrativo/g_usuario/${usuarioId}`,
|
||||||
|
});
|
||||||
|
|
||||||
const response = await api.send({
|
return response;
|
||||||
'method': Methods.DELETE,
|
}
|
||||||
'endpoint': `administrativo/g_usuario/${usuarioId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GUsuarioIndexData() {
|
export default async function GUsuarioIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
const response = await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
|
endpoint: `administrativo/g_usuario/`,
|
||||||
|
});
|
||||||
|
|
||||||
const response = await api.send({
|
return response;
|
||||||
'method': Methods.GET,
|
}
|
||||||
'endpoint': `administrativo/g_usuario/`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
|
|
||||||
export default async function GUsuarioLoginData(form: any) {
|
export default async function GUsuarioLoginData(form: any) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
// Realiza o envio dos dados
|
||||||
|
const response = await api.send({
|
||||||
|
method: Methods.POST,
|
||||||
|
endpoint: `administrativo/g_usuario/authenticate`,
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
|
||||||
// Realiza o envio dos dados
|
return response;
|
||||||
const response = await api.send({
|
}
|
||||||
method: Methods.POST,
|
|
||||||
endpoint: `administrativo/g_usuario/authenticate`,
|
|
||||||
body: form
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,15 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GUsuarioReadData(usuarioId: number) {
|
export default async function GUsuarioReadData(usuarioId: number) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
const response = await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
|
endpoint: `administrativo/g_usuario/${usuarioId}`,
|
||||||
|
});
|
||||||
|
|
||||||
const response = await api.send({
|
return response;
|
||||||
'method': Methods.GET,
|
}
|
||||||
'endpoint': `administrativo/g_usuario/${usuarioId}`
|
|
||||||
});
|
|
||||||
|
|
||||||
return response
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GUsuarioSaveData(form: any) {
|
export default async function GUsuarioSaveData(form: any) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
const response = await api.send({
|
||||||
|
method: Methods.POST,
|
||||||
|
endpoint: `administrativo/g_usuario/`,
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
|
||||||
const response = await api.send({
|
return response;
|
||||||
'method': Methods.POST,
|
}
|
||||||
'endpoint': `administrativo/g_usuario/`,
|
|
||||||
'body': form
|
|
||||||
});
|
|
||||||
|
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,23 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useState } from "react";
|
||||||
import Usuario from "../../_interfaces/GUsuarioInterface"
|
import Usuario from "../../_interfaces/GUsuarioInterface";
|
||||||
import GUsuarioIndex from "../../_services/g_usuario/GUsuarioIndex";
|
import GUsuarioIndex from "../../_services/g_usuario/GUsuarioIndex";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext";
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
export const useGUsuarioIndexHook = () => {
|
export const useGUsuarioIndexHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
const { setResponse } = useResponse();
|
const [usuarios, setUsuarios] = useState<Usuario[] | null>(null);
|
||||||
|
|
||||||
const [usuarios, setUsuarios] = useState<Usuario[] | null>(null);
|
const fetchUsuarios = async () => {
|
||||||
|
const response = await GUsuarioIndex();
|
||||||
|
|
||||||
const fetchUsuarios = async () => {
|
setUsuarios(response.data);
|
||||||
|
|
||||||
const response = await GUsuarioIndex();
|
// Define os dados do componente de resposta (toast, modal, etc)
|
||||||
|
setResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
setUsuarios(response.data);
|
return { usuarios, fetchUsuarios };
|
||||||
|
};
|
||||||
// Define os dados do componente de resposta (toast, modal, etc)
|
|
||||||
setResponse(response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return { usuarios, fetchUsuarios }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,11 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import GUsuarioLogoutService from "../../_services/g_usuario/GUsuarioLogoutService";
|
import GUsuarioLogoutService from "../../_services/g_usuario/GUsuarioLogoutService";
|
||||||
|
|
||||||
export const useGUsuarioLogoutHook = () => {
|
export const useGUsuarioLogoutHook = () => {
|
||||||
|
const logoutUsuario = async () => {
|
||||||
|
await GUsuarioLogoutService("access_token");
|
||||||
|
};
|
||||||
|
|
||||||
const logoutUsuario = async () => {
|
return { logoutUsuario };
|
||||||
|
};
|
||||||
await GUsuarioLogoutService('access_token')
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return { logoutUsuario }
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,23 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useState } from "react";
|
||||||
import Usuario from "../../_interfaces/GUsuarioInterface"
|
import Usuario from "../../_interfaces/GUsuarioInterface";
|
||||||
import GUsuarioRead from "../../_services/g_usuario/GUsuarioRead";
|
import GUsuarioRead from "../../_services/g_usuario/GUsuarioRead";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext";
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
export const useGUsuarioReadHooks = () => {
|
export const useGUsuarioReadHooks = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
const { setResponse } = useResponse();
|
const [usuario, setUsuario] = useState<Usuario>();
|
||||||
|
|
||||||
const [usuario, setUsuario] = useState<Usuario>();
|
const fetchUsuario = async (Usuario: Usuario) => {
|
||||||
|
const response = await GUsuarioRead(Usuario.usuario_id);
|
||||||
|
console.log("hook", response.data);
|
||||||
|
|
||||||
const fetchUsuario = async (Usuario: Usuario) => {
|
setUsuario(response.data);
|
||||||
|
|
||||||
const response = await GUsuarioRead(Usuario.usuario_id);
|
setResponse(response);
|
||||||
console.log("hook",response.data)
|
};
|
||||||
|
|
||||||
setUsuario(response.data);
|
return { usuario, fetchUsuario };
|
||||||
|
};
|
||||||
setResponse(response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return { usuario, fetchUsuario }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,22 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useState } from "react"
|
import { useState } from "react";
|
||||||
import Usuario from "../../_interfaces/GUsuarioInterface"
|
import Usuario from "../../_interfaces/GUsuarioInterface";
|
||||||
import GUsuarioSave from "../../_services/g_usuario/GUsuarioSave";
|
import GUsuarioSave from "../../_services/g_usuario/GUsuarioSave";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext";
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
export const useGUsuarioSaveHook = () => {
|
export const useGUsuarioSaveHook = () => {
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
const { setResponse } = useResponse();
|
const [usuario, setUsuario] = useState<Usuario>();
|
||||||
|
|
||||||
const [usuario, setUsuario] = useState<Usuario>();
|
const saveUsuario = async (Usuario: any) => {
|
||||||
|
const response = await GUsuarioSave(Usuario);
|
||||||
|
|
||||||
const saveUsuario = async (Usuario: any) => {
|
setUsuario(response.data);
|
||||||
|
|
||||||
const response = await GUsuarioSave(Usuario);
|
setResponse(response);
|
||||||
|
};
|
||||||
|
|
||||||
setUsuario(response.data);
|
return { usuario, saveUsuario };
|
||||||
|
};
|
||||||
setResponse(response);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return { usuario, saveUsuario }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,34 @@
|
||||||
export default interface GUsuario {
|
export default interface GUsuario {
|
||||||
usuario_id: number,
|
usuario_id: number;
|
||||||
trocarsenha: string,
|
trocarsenha: string;
|
||||||
login: string,
|
login: string;
|
||||||
senha: string,
|
senha: string;
|
||||||
situacao: string,
|
situacao: string;
|
||||||
nome_completo: string,
|
nome_completo: string;
|
||||||
funcao: string,
|
funcao: string;
|
||||||
assina: string,
|
assina: string;
|
||||||
sigla: string,
|
sigla: string;
|
||||||
usuario_tab: string,
|
usuario_tab: string;
|
||||||
ultimo_login: string,
|
ultimo_login: string;
|
||||||
ultimo_login_regs: string,
|
ultimo_login_regs: string;
|
||||||
data_expiracao: string,
|
data_expiracao: string;
|
||||||
senha_anterior: string,
|
senha_anterior: string;
|
||||||
andamento_padrao: string,
|
andamento_padrao: string;
|
||||||
lembrete_pergunta: string,
|
lembrete_pergunta: string;
|
||||||
lembrete_resposta: string,
|
lembrete_resposta: string;
|
||||||
andamento_padrao2: string,
|
andamento_padrao2: string;
|
||||||
receber_mensagem_arrolamento: string,
|
receber_mensagem_arrolamento: string;
|
||||||
email: string,
|
email: string;
|
||||||
assina_certidao: string,
|
assina_certidao: string;
|
||||||
receber_email_penhora: string,
|
receber_email_penhora: string;
|
||||||
foto: string,
|
foto: string;
|
||||||
nao_receber_chat_todos: string,
|
nao_receber_chat_todos: string;
|
||||||
pode_alterar_caixa: string,
|
pode_alterar_caixa: string;
|
||||||
receber_chat_certidao_online: string,
|
receber_chat_certidao_online: string;
|
||||||
receber_chat_cancelamento: string,
|
receber_chat_cancelamento: string;
|
||||||
cpf: string,
|
cpf: string;
|
||||||
somente_leitura: string,
|
somente_leitura: string;
|
||||||
receber_chat_envio_onr: string,
|
receber_chat_envio_onr: string;
|
||||||
tipo_usuario: string,
|
tipo_usuario: string;
|
||||||
senha_api: string,
|
senha_api: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const GUsuarioLoginSchema = z.object({
|
export const GUsuarioLoginSchema = z.object({
|
||||||
login: z.string().min(1, "O campo deve ser preenchido"),
|
login: z.string().min(1, "O campo deve ser preenchido"),
|
||||||
senha_api: z.string().min(1, "O campo deve ser preenchido"),
|
senha_api: z.string().min(1, "O campo deve ser preenchido"),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,35 @@
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const GUsuarioSchema = z.object({
|
export const GUsuarioSchema = z.object({
|
||||||
trocarsenha: z.string().optional(),
|
trocarsenha: z.string().optional(),
|
||||||
login: z.string().optional(),
|
login: z.string().optional(),
|
||||||
senha: z.string().optional(),
|
senha: z.string().optional(),
|
||||||
situacao: z.string().optional(),
|
situacao: z.string().optional(),
|
||||||
nome_completo: z.string().optional(),
|
nome_completo: z.string().optional(),
|
||||||
funcao: z.string().optional(),
|
funcao: z.string().optional(),
|
||||||
assina: z.string().optional(),
|
assina: z.string().optional(),
|
||||||
sigla: z.string().optional(),
|
sigla: z.string().optional(),
|
||||||
usuario_tab: z.string().optional(),
|
usuario_tab: z.string().optional(),
|
||||||
ultimo_login: z.string().optional(),
|
ultimo_login: z.string().optional(),
|
||||||
ultimo_login_regs: z.string().optional(),
|
ultimo_login_regs: z.string().optional(),
|
||||||
data_expiracao: z.string().optional(),
|
data_expiracao: z.string().optional(),
|
||||||
senha_anterior: z.string().optional(),
|
senha_anterior: z.string().optional(),
|
||||||
andamento_padrao: z.string().optional(),
|
andamento_padrao: z.string().optional(),
|
||||||
lembrete_pergunta: z.string().optional(),
|
lembrete_pergunta: z.string().optional(),
|
||||||
lembrete_resposta: z.string().optional(),
|
lembrete_resposta: z.string().optional(),
|
||||||
andamento_padrao2: z.string().optional(),
|
andamento_padrao2: z.string().optional(),
|
||||||
receber_mensagem_arrolamento: z.string().optional(),
|
receber_mensagem_arrolamento: z.string().optional(),
|
||||||
email: z.string().optional(),
|
email: z.string().optional(),
|
||||||
assina_certidao: z.string().optional(),
|
assina_certidao: z.string().optional(),
|
||||||
receber_email_penhora: z.string().optional(),
|
receber_email_penhora: z.string().optional(),
|
||||||
foto: z.string().optional(),
|
foto: z.string().optional(),
|
||||||
nao_receber_chat_todos: z.string().optional(),
|
nao_receber_chat_todos: z.string().optional(),
|
||||||
pode_alterar_caixa: z.string().optional(),
|
pode_alterar_caixa: z.string().optional(),
|
||||||
receber_chat_certidao_online: z.string().optional(),
|
receber_chat_certidao_online: z.string().optional(),
|
||||||
receber_chat_cancelamento: z.string().optional(),
|
receber_chat_cancelamento: z.string().optional(),
|
||||||
cpf: z.string().optional(),
|
cpf: z.string().optional(),
|
||||||
somente_leitura: z.string().optional(),
|
somente_leitura: z.string().optional(),
|
||||||
receber_chat_envio_onr: z.string().optional(),
|
receber_chat_envio_onr: z.string().optional(),
|
||||||
tipo_usuario: z.string().optional(),
|
tipo_usuario: z.string().optional(),
|
||||||
senha_api: z.string().optional(),
|
senha_api: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import GUsuarioIndexData from "../../_data/g_usuario/GUsuarioIndexData"
|
import GUsuarioIndexData from "../../_data/g_usuario/GUsuarioIndexData";
|
||||||
|
|
||||||
export default async function GUsuarioIndex() {
|
export default async function GUsuarioIndex() {
|
||||||
|
const response = await GUsuarioIndexData();
|
||||||
|
|
||||||
const response = await GUsuarioIndexData();
|
return response;
|
||||||
|
}
|
||||||
return response;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,34 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import {
|
import { cookies } from "next/headers";
|
||||||
cookies
|
|
||||||
} from "next/headers";
|
|
||||||
|
|
||||||
import GUsuarioLoginData from "../../_data/g_usuario/GUsuarioLoginData"
|
import GUsuarioLoginData from "../../_data/g_usuario/GUsuarioLoginData";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default async function GUsuarioLoginService(form: any) {
|
export default async function GUsuarioLoginService(form: any) {
|
||||||
|
// Obtem a resposta da requisição
|
||||||
|
const response = await GUsuarioLoginData(form);
|
||||||
|
|
||||||
// Obtem a resposta da requisição
|
// Verifica se localizou o usuário
|
||||||
const response = await GUsuarioLoginData(form);
|
if (response.data.usuario_id <= 0) {
|
||||||
|
return {
|
||||||
|
code: 404,
|
||||||
|
message: "Não foi localizado o usuário",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Verifica se localizou o usuário
|
// Importação do manipulador de cookies
|
||||||
if (response.data.usuario_id <= 0) {
|
const cookieStore = await cookies();
|
||||||
|
|
||||||
return {
|
// Cria um novo cookie
|
||||||
'code': 404,
|
cookieStore.set("access_token", response.data.token, {
|
||||||
'message': 'Não foi localizado o usuário'
|
httpOnly: true,
|
||||||
}
|
secure: process.env.NODE_ENV === "production",
|
||||||
|
sameSite: "strict",
|
||||||
|
path: "/",
|
||||||
|
maxAge: 60 * 60 * 24,
|
||||||
|
});
|
||||||
|
|
||||||
}
|
// Redireciona para a págian desejada
|
||||||
|
redirect("/servicos");
|
||||||
// Importação do manipulador de cookies
|
}
|
||||||
const cookieStore = await cookies();
|
|
||||||
|
|
||||||
// Cria um novo cookie
|
|
||||||
cookieStore.set("access_token", response.data.token, {
|
|
||||||
httpOnly: true,
|
|
||||||
secure: process.env.NODE_ENV === "production",
|
|
||||||
sameSite: "strict",
|
|
||||||
path: "/",
|
|
||||||
maxAge: 60 * 60 * 24,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Redireciona para a págian desejada
|
|
||||||
redirect("/servicos");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,15 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import {
|
import { cookies } from "next/headers";
|
||||||
cookies
|
|
||||||
} from "next/headers";
|
|
||||||
|
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
export default async function GUsuarioLogoutService(token: string) {
|
export default async function GUsuarioLogoutService(token: string) {
|
||||||
|
const cookieStore = await cookies();
|
||||||
|
cookieStore.set(token, "", {
|
||||||
|
expires: new Date(0),
|
||||||
|
path: "/",
|
||||||
|
});
|
||||||
|
|
||||||
const cookieStore = await cookies();
|
redirect("/login");
|
||||||
cookieStore.set(token, '', {
|
}
|
||||||
expires: new Date(0),
|
|
||||||
path: '/',
|
|
||||||
});
|
|
||||||
|
|
||||||
redirect('/login');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +1,22 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import GUsuarioReadData from "../../_data/g_usuario/GUsuarioReadData";
|
import GUsuarioReadData from "../../_data/g_usuario/GUsuarioReadData";
|
||||||
|
|
||||||
export default async function GUsuarioRead(usuarioId: number) {
|
export default async function GUsuarioRead(usuarioId: number) {
|
||||||
|
// Verifica se o id informado é válido
|
||||||
|
if (usuarioId <= 0) {
|
||||||
|
return {
|
||||||
|
code: 400,
|
||||||
|
message: "Usuário informado inválido",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Verifica se o id informado é válido
|
try {
|
||||||
if (usuarioId <= 0) {
|
const response = await GUsuarioReadData(usuarioId);
|
||||||
return {
|
console.log("service", response);
|
||||||
'code': 400,
|
return response;
|
||||||
'message': 'Usuário informado inválido',
|
} catch (error) {
|
||||||
}
|
console.log(error);
|
||||||
}
|
return error;
|
||||||
|
}
|
||||||
try {
|
}
|
||||||
const response = await GUsuarioReadData(usuarioId);
|
|
||||||
console.log("service",response)
|
|
||||||
return response
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
return error
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
'use server'
|
"use server";
|
||||||
|
|
||||||
import GUsuarioSaveData from "../../_data/g_usuario/GUsuarioSaveData";
|
import GUsuarioSaveData from "../../_data/g_usuario/GUsuarioSaveData";
|
||||||
|
|
||||||
export default async function GUsuarioSave(form: any) {
|
export default async function GUsuarioSave(form: any) {
|
||||||
|
return await GUsuarioSaveData(form);
|
||||||
return await GUsuarioSaveData(form);
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,147 +18,153 @@ import GCidadeInterface from "../../_interfaces/GCidadeInterface";
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function GCidadePage() {
|
export default function GCidadePage() {
|
||||||
|
// Hooks para leitura e salvamento
|
||||||
|
const { gCidade, fetchGCidade } = useGCidadeReadHook();
|
||||||
|
const { saveGCidade } = useGCidadeSaveHook();
|
||||||
|
const { removeGCidade } = useGCidadeRemoveHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estados
|
||||||
const { gCidade, fetchGCidade } = useGCidadeReadHook();
|
const [selectedCidade, setSelectedCidade] = useState<GCidadeInterface | null>(
|
||||||
const { saveGCidade } = useGCidadeSaveHook();
|
null,
|
||||||
const { removeGCidade } = useGCidadeRemoveHook();
|
);
|
||||||
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estados
|
// Estado para saber qual item será deletado
|
||||||
const [selectedCidade, setSelectedCidade] = useState<GCidadeInterface | null>(null);
|
const [itemToDelete, setItemToDelete] = useState<GCidadeInterface | null>(
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
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
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const {
|
const handleOpenForm = useCallback((data: GCidadeInterface | null) => {
|
||||||
isOpen: isConfirmOpen,
|
setSelectedCidade(data);
|
||||||
openDialog: openConfirmDialog,
|
setIsFormOpen(true);
|
||||||
handleConfirm,
|
}, []);
|
||||||
handleCancel,
|
|
||||||
} = useConfirmDialog();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: GCidadeInterface | null) => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedCidade(data);
|
setSelectedCidade(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setSelectedCidade(null);
|
async (formData: GCidadeInterface) => {
|
||||||
setIsFormOpen(false);
|
// Aguarda salvar o registro
|
||||||
}, []);
|
await saveGCidade(formData);
|
||||||
|
|
||||||
/**
|
// Atualiza a lista de dados
|
||||||
* Salva os dados do formulário
|
fetchGCidade();
|
||||||
*/
|
},
|
||||||
const handleSave = useCallback(async (formData: GCidadeInterface) => {
|
[saveGCidade, fetchGCidade],
|
||||||
|
);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
/**
|
||||||
await saveGCidade(formData);
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GCidadeInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
// Abre o modal de confirmação
|
||||||
fetchGCidade();
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
}, [saveGCidade, fetchGCidade]);
|
/**
|
||||||
|
* 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
|
||||||
* Quando o usuário clica em "remover" na tabela
|
await removeGCidade(itemToDelete);
|
||||||
*/
|
|
||||||
const handleConfirmDelete = useCallback((item: GCidadeInterface) => {
|
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Atualiza a lista
|
||||||
setItemToDelete(item);
|
await fetchGCidade();
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Limpa o item selecionado
|
||||||
openConfirmDialog();
|
setItemToDelete(null);
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Fecha o modal
|
||||||
|
handleCancel();
|
||||||
|
}, [itemToDelete, fetchGCidade, handleCancel]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
* Busca inicial dos dados
|
||||||
*/
|
*/
|
||||||
const handleDelete = useCallback(async () => {
|
useEffect(() => {
|
||||||
|
fetchGCidade();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!gCidade) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
return (
|
||||||
await removeGCidade(itemToDelete);
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Cidades"}
|
||||||
|
description={"Gerenciamento de Cidades"}
|
||||||
|
buttonText={"Nova Cidade"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Atualiza a lista
|
{/* Tabela de andamentos */}
|
||||||
await fetchGCidade();
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GCidadeTable
|
||||||
|
data={gCidade}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Modal de confirmação */}
|
||||||
setItemToDelete(null);
|
<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}
|
||||||
|
/>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Formulário de criação/edição */}
|
||||||
handleCancel();
|
<GCidadeForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
}, [itemToDelete, fetchGCidade, handleCancel]);
|
data={selectedCidade}
|
||||||
|
onClose={handleCloseForm}
|
||||||
/**
|
onSave={handleSave}
|
||||||
* Busca inicial dos dados
|
/>
|
||||||
*/
|
</div>
|
||||||
useEffect(() => {
|
);
|
||||||
fetchGCidade();
|
4;
|
||||||
}, []);
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* 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}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<GCidadeForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedCidade}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext"
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
||||||
|
|
@ -19,132 +19,140 @@ import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface";
|
||||||
import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
||||||
|
|
||||||
const initialMedidaTipo: GMedidaTipoInterface = {
|
const initialMedidaTipo: GMedidaTipoInterface = {
|
||||||
medida_tipo_id: 0,
|
medida_tipo_id: 0,
|
||||||
sigla: '',
|
sigla: "",
|
||||||
descricao: ''
|
descricao: "",
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function GMedidaTipoPage() {
|
export default function GMedidaTipoPage() {
|
||||||
|
// Controle de exibição de respostas
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
// Controle de exibição de respostas
|
// Controle de estado do botão
|
||||||
const { setResponse } = useResponse();
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Controle de estado do botão
|
// Hooks para leitura, salvamento e remoção
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const { gMedidaTipo, fetchGMedidaTipo } = useGMedidaTipoReadHook();
|
||||||
|
const { saveGMedidaTipo } = useGMedidaTipoSaveHook();
|
||||||
|
const { removeGMedidaTipo } = useGMedidaTipoRemoveHook();
|
||||||
|
|
||||||
// Hooks para leitura, salvamento e remoção
|
// Estado para controlar o formulário e o item selecionado
|
||||||
const { gMedidaTipo, fetchGMedidaTipo } = useGMedidaTipoReadHook();
|
const [selectedMedidaTipo, setSelectedMedidaTipo] =
|
||||||
const { saveGMedidaTipo } = useGMedidaTipoSaveHook();
|
useState<GMedidaTipoInterface | null>(null);
|
||||||
const { removeGMedidaTipo } = useGMedidaTipoRemoveHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
const [itemToDelete, setItemToDelete] = useState<GMedidaTipoInterface | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
// Estado para controlar o formulário e o item selecionado
|
// Hook para o modal de confirmação
|
||||||
const [selectedMedidaTipo, setSelectedMedidaTipo] = useState<GMedidaTipoInterface | null>(null);
|
const {
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
isOpen: isConfirmOpen,
|
||||||
const [itemToDelete, setItemToDelete] = useState<GMedidaTipoInterface | null>(null);
|
openDialog: openConfirmDialog,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
// Hook para o modal de confirmação
|
// Ações do formulário
|
||||||
const {
|
const handleOpenForm = useCallback((data: GMedidaTipoInterface | null) => {
|
||||||
isOpen: isConfirmOpen,
|
setSelectedMedidaTipo(data);
|
||||||
openDialog: openConfirmDialog,
|
setIsFormOpen(true);
|
||||||
handleCancel,
|
}, []);
|
||||||
} = useConfirmDialog();
|
|
||||||
|
|
||||||
// Ações do formulário
|
const handleCloseForm = useCallback(() => {
|
||||||
const handleOpenForm = useCallback((data: GMedidaTipoInterface | null) => {
|
setIsFormOpen(false);
|
||||||
setSelectedMedidaTipo(data);
|
setSelectedMedidaTipo(null);
|
||||||
setIsFormOpen(true);
|
}, []);
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setIsFormOpen(false);
|
async (data: GMedidaTipoInterface) => {
|
||||||
setSelectedMedidaTipo(null);
|
// Coloca o botão em estado de loading
|
||||||
}, []);
|
setButtonIsLoading(true);
|
||||||
|
await saveGMedidaTipo(data);
|
||||||
|
// Remove o botão do estado de loading
|
||||||
|
setButtonIsLoading(false);
|
||||||
|
await fetchGMedidaTipo(); // Atualiza a tabela após salvar
|
||||||
|
handleCloseForm();
|
||||||
|
},
|
||||||
|
[saveGMedidaTipo, fetchGMedidaTipo],
|
||||||
|
);
|
||||||
|
|
||||||
const handleSave = useCallback(async (data: GMedidaTipoInterface) => {
|
// Ações de deleção
|
||||||
// Coloca o botão em estado de loading
|
const handleConfirmDelete = useCallback(
|
||||||
setButtonIsLoading(true);
|
(item: GMedidaTipoInterface) => {
|
||||||
await saveGMedidaTipo(data);
|
setItemToDelete(item);
|
||||||
// Remove o botão do estado de loading
|
openConfirmDialog();
|
||||||
setButtonIsLoading(false);
|
},
|
||||||
await fetchGMedidaTipo(); // Atualiza a tabela após salvar
|
[openConfirmDialog],
|
||||||
handleCloseForm();
|
);
|
||||||
}, [saveGMedidaTipo, fetchGMedidaTipo]);
|
|
||||||
|
|
||||||
// Ações de deleção
|
const handleDelete = useCallback(async () => {
|
||||||
const handleConfirmDelete = useCallback((item: GMedidaTipoInterface) => {
|
// Verifica se existe item para remoção
|
||||||
setItemToDelete(item);
|
if (!itemToDelete) {
|
||||||
openConfirmDialog();
|
// Define os dados da resposta visual
|
||||||
}, [openConfirmDialog]);
|
setResponse({
|
||||||
|
status: 400,
|
||||||
const handleDelete = useCallback(async () => {
|
message: "Não foi informado um registro para exclusão",
|
||||||
|
});
|
||||||
// Verifica se existe item para remoção
|
return;
|
||||||
if (!itemToDelete) {
|
|
||||||
|
|
||||||
// Define os dados da resposta visual
|
|
||||||
setResponse({
|
|
||||||
status: 400,
|
|
||||||
message: 'Não foi informado um registro para exclusão'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
await removeGMedidaTipo(itemToDelete);
|
|
||||||
await fetchGMedidaTipo(); // Atualiza a tabela após remover
|
|
||||||
handleCancel();
|
|
||||||
}, [itemToDelete, fetchGMedidaTipo, handleCancel]);
|
|
||||||
|
|
||||||
// Efeito para carregar os dados na montagem do componente
|
|
||||||
useEffect(() => {
|
|
||||||
fetchGMedidaTipo();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Mostra tela de loading enquanto os dados não são carregados
|
|
||||||
if (!gMedidaTipo) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
await removeGMedidaTipo(itemToDelete);
|
||||||
<div>
|
await fetchGMedidaTipo(); // Atualiza a tabela após remover
|
||||||
{/* Cabeçalho */}
|
handleCancel();
|
||||||
<Header
|
}, [itemToDelete, fetchGMedidaTipo, handleCancel]);
|
||||||
title={"Tipos de Medida"}
|
|
||||||
description={"Gerenciamento de tipos de medida"}
|
|
||||||
buttonText={"Novo Tipo de Medida"}
|
|
||||||
buttonAction={(data) => { handleOpenForm(data = initialMedidaTipo) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de Tipos de Medida */}
|
// Efeito para carregar os dados na montagem do componente
|
||||||
<Card>
|
useEffect(() => {
|
||||||
<CardContent>
|
fetchGMedidaTipo();
|
||||||
<GMedidaTipoTable
|
}, []);
|
||||||
data={gMedidaTipo}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
// Mostra tela de loading enquanto os dados não são carregados
|
||||||
<ConfirmDialog
|
if (!gMedidaTipo) {
|
||||||
isOpen={isConfirmOpen}
|
return <Loading type={2} />;
|
||||||
title="Confirmar exclusão"
|
}
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o tipo de medida "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
return (
|
||||||
<GMedidaTipoForm
|
<div>
|
||||||
isOpen={isFormOpen}
|
{/* Cabeçalho */}
|
||||||
data={selectedMedidaTipo}
|
<Header
|
||||||
onClose={handleCloseForm}
|
title={"Tipos de Medida"}
|
||||||
onSave={handleSave}
|
description={"Gerenciamento de tipos de medida"}
|
||||||
buttonIsLoading={buttonIsLoading}
|
buttonText={"Novo Tipo de Medida"}
|
||||||
/>
|
buttonAction={(data) => {
|
||||||
</div>
|
handleOpenForm((data = initialMedidaTipo));
|
||||||
);
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Tabela de Tipos de Medida */}
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GMedidaTipoTable
|
||||||
|
data={gMedidaTipo}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Modal de confirmação */}
|
||||||
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o tipo de medida "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Formulário de criação/edição */}
|
||||||
|
<GMedidaTipoForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
|
data={selectedMedidaTipo}
|
||||||
|
onClose={handleCloseForm}
|
||||||
|
onSave={handleSave}
|
||||||
|
buttonIsLoading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext"
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
||||||
|
|
@ -19,149 +19,153 @@ import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface";
|
||||||
import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
||||||
|
|
||||||
const initialBairro: GTBBairroInterface = {
|
const initialBairro: GTBBairroInterface = {
|
||||||
sistema_id: null,
|
sistema_id: null,
|
||||||
tb_bairro_id: 0,
|
tb_bairro_id: 0,
|
||||||
descricao: '',
|
descricao: "",
|
||||||
situacao: SituacoesEnum.A
|
situacao: SituacoesEnum.A,
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function GTBBairroPage() {
|
export default function GTBBairroPage() {
|
||||||
|
// Controle de exibição de respostas
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
// Controle de exibição de respostas
|
// Controle de estado do botão
|
||||||
const { setResponse } = useResponse();
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Controle de estado do botão
|
// Hooks para leitura e salvamento
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook();
|
||||||
|
const { saveGTBBairro } = useGTBBairroSaveHook();
|
||||||
|
const { removeGTBBairro } = useGTBBairroRemoveHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estado para controlar o formulário e item selecionado
|
||||||
const { gTBBairro, fetchGTBBairro } = useGTBBairroReadHook();
|
const [selectedBairro, setBairro] = useState<GTBBairroInterface | null>(null);
|
||||||
const { saveGTBBairro } = useGTBBairroSaveHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
const { removeGTBBairro } = useGTBBairroRemoveHook();
|
const [itemToDelete, setItemToDelete] = useState<GTBBairroInterface | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
// Estado para controlar o formulário e item selecionado
|
// Hook para o modal de confirmação
|
||||||
const [selectedBairro, setBairro] = useState<GTBBairroInterface | null>(null);
|
const {
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
isOpen: isConfirmOpen,
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBBairroInterface | null>(null);
|
openDialog: openConfirmDialog,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
// Hook para o modal de confirmação
|
// Ações do formulário
|
||||||
const {
|
const handleOpenForm = useCallback((data: GTBBairroInterface | null) => {
|
||||||
isOpen: isConfirmOpen,
|
setBairro(data);
|
||||||
openDialog: openConfirmDialog,
|
setIsFormOpen(true);
|
||||||
handleCancel,
|
}, []);
|
||||||
} = useConfirmDialog();
|
|
||||||
|
|
||||||
// Ações do formulário
|
const handleCloseForm = useCallback(() => {
|
||||||
const handleOpenForm = useCallback((data: GTBBairroInterface | null) => {
|
setBairro(null);
|
||||||
setBairro(data);
|
setIsFormOpen(false);
|
||||||
setIsFormOpen(true);
|
}, []);
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setBairro(null);
|
async (data: GTBBairroInterface) => {
|
||||||
setIsFormOpen(false);
|
// Coloca o botão em estado de loading
|
||||||
}, []);
|
setButtonIsLoading(true);
|
||||||
|
|
||||||
const handleSave = useCallback(async (data: GTBBairroInterface) => {
|
// Realiza o procedimento desejado
|
||||||
|
await saveGTBBairro(data);
|
||||||
|
|
||||||
// Coloca o botão em estado de loading
|
// Remove o botão do estado de loading
|
||||||
setButtonIsLoading(true);
|
setButtonIsLoading(false);
|
||||||
|
|
||||||
// Realiza o procedimento desejado
|
// Atualiza a tabela após salvar
|
||||||
await saveGTBBairro(data);
|
fetchGTBBairro();
|
||||||
|
},
|
||||||
|
[saveGTBBairro, fetchGTBBairro],
|
||||||
|
);
|
||||||
|
|
||||||
// Remove o botão do estado de loading
|
// Ações de deleção
|
||||||
setButtonIsLoading(false);
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GTBBairroInterface) => {
|
||||||
|
setItemToDelete(item);
|
||||||
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
// Atualiza a tabela após salvar
|
const handleDelete = useCallback(async () => {
|
||||||
fetchGTBBairro();
|
// Verifica se existe item para remoção
|
||||||
|
if (!itemToDelete) {
|
||||||
}, [saveGTBBairro, fetchGTBBairro]);
|
// Define os dados da resposta visual
|
||||||
|
setResponse({
|
||||||
// Ações de deleção
|
status: 400,
|
||||||
const handleConfirmDelete = useCallback((item: GTBBairroInterface) => {
|
message: "Não foi informado um registro para exclusão",
|
||||||
setItemToDelete(item);
|
});
|
||||||
openConfirmDialog();
|
return;
|
||||||
}, [openConfirmDialog]);
|
|
||||||
|
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Verifica se existe item para remoção
|
|
||||||
if (!itemToDelete) {
|
|
||||||
|
|
||||||
// Define os dados da resposta visual
|
|
||||||
setResponse({
|
|
||||||
status: 400,
|
|
||||||
message: 'Não foi informado um registro para exclusão'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Executa o hook de remoção
|
|
||||||
await removeGTBBairro(itemToDelete);
|
|
||||||
|
|
||||||
// Atualiza a tabela após remover
|
|
||||||
await fetchGTBBairro();
|
|
||||||
|
|
||||||
// Limpa o item para remoção
|
|
||||||
setItemToDelete(null)
|
|
||||||
|
|
||||||
handleCancel();
|
|
||||||
|
|
||||||
}, [itemToDelete, fetchGTBBairro, handleCancel]);
|
|
||||||
|
|
||||||
// Efeito para carregar os dados na montagem do componente
|
|
||||||
useEffect(() => {
|
|
||||||
fetchGTBBairro();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tela de loading enquanto carrega os dados
|
|
||||||
*/
|
|
||||||
if (gTBBairro.length == 0) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
// Executa o hook de remoção
|
||||||
<div>
|
await removeGTBBairro(itemToDelete);
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Bairros"}
|
|
||||||
description={"Gerenciamento de Bairros"}
|
|
||||||
buttonText={"Novo Bairro"}
|
|
||||||
buttonAction={(data) => { handleOpenForm(data = initialBairro) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de Bairros */}
|
// Atualiza a tabela após remover
|
||||||
<Card>
|
await fetchGTBBairro();
|
||||||
<CardContent>
|
|
||||||
<GTBBairroTable
|
|
||||||
data={gTBBairro}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
// Limpa o item para remoção
|
||||||
<ConfirmDialog
|
setItemToDelete(null);
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o bairro "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
handleCancel();
|
||||||
<GTBBairroForm
|
}, [itemToDelete, fetchGTBBairro, handleCancel]);
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedBairro}
|
// Efeito para carregar os dados na montagem do componente
|
||||||
onClose={handleCloseForm}
|
useEffect(() => {
|
||||||
onSave={handleSave}
|
fetchGTBBairro();
|
||||||
buttonIsLoading={buttonIsLoading}
|
}, []);
|
||||||
/>
|
|
||||||
</div>
|
/**
|
||||||
);
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (gTBBairro.length == 0) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Bairros"}
|
||||||
|
description={"Gerenciamento de Bairros"}
|
||||||
|
buttonText={"Novo Bairro"}
|
||||||
|
buttonAction={(data) => {
|
||||||
|
handleOpenForm((data = initialBairro));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Tabela de Bairros */}
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GTBBairroTable
|
||||||
|
data={gTBBairro}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Modal de confirmação */}
|
||||||
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o bairro "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBBairroForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
|
data={selectedBairro}
|
||||||
|
onClose={handleCloseForm}
|
||||||
|
onSave={handleSave}
|
||||||
|
buttonIsLoading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,130 +18,138 @@ import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterfa
|
||||||
import { useResponse } from "@/app/_response/ResponseContext";
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
const initalEstadoCivil: GTBEstadoCivilInterface = {
|
const initalEstadoCivil: GTBEstadoCivilInterface = {
|
||||||
tb_estadocivil_id: 0,
|
tb_estadocivil_id: 0,
|
||||||
sistema_id: 0,
|
sistema_id: 0,
|
||||||
descricao: '',
|
descricao: "",
|
||||||
situacao: 'A',
|
situacao: "A",
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function TBEstadoCivilPage() {
|
export default function TBEstadoCivilPage() {
|
||||||
|
// Controle de exibição de respostas
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
// Controle de exibição de respostas
|
// Controle de estado do botão
|
||||||
const { setResponse } = useResponse();
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Controle de estado do botão
|
// Hooks para leitura e salvamento
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const { gTBEstadoCivil, fetchGTBEstadoCivil } = useGTBEstadoCivilReadHook();
|
||||||
|
const { saveGTBEstadoCivil } = useGTBEstadoCivilSaveHook();
|
||||||
|
const { removeGTBEstadoCivil } = useGTBEstadoCivilRemoveHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estado para controlar o formulário e item selecionado
|
||||||
const { gTBEstadoCivil, fetchGTBEstadoCivil } = useGTBEstadoCivilReadHook();
|
const [selectedEstadoCivil, setSelectedEstadoCivil] =
|
||||||
const { saveGTBEstadoCivil } = useGTBEstadoCivilSaveHook();
|
useState<GTBEstadoCivilInterface | null>(null);
|
||||||
const { removeGTBEstadoCivil } = useGTBEstadoCivilRemoveHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
const [itemToDelete, setItemToDelete] =
|
||||||
|
useState<GTBEstadoCivilInterface | null>(null);
|
||||||
|
|
||||||
// Estado para controlar o formulário e item selecionado
|
// Hook para o modal de confirmação
|
||||||
const [selectedEstadoCivil, setSelectedEstadoCivil] = useState<GTBEstadoCivilInterface | null>(null);
|
const {
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
isOpen: isConfirmOpen,
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBEstadoCivilInterface | null>(null);
|
openDialog: openConfirmDialog,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
// Hook para o modal de confirmação
|
// Ações do formulário
|
||||||
const {
|
const handleOpenForm = useCallback((data: GTBEstadoCivilInterface | null) => {
|
||||||
isOpen: isConfirmOpen,
|
setSelectedEstadoCivil(data);
|
||||||
openDialog: openConfirmDialog,
|
setIsFormOpen(true);
|
||||||
handleCancel,
|
}, []);
|
||||||
} = useConfirmDialog();
|
|
||||||
|
|
||||||
// Ações do formulário
|
const handleCloseForm = useCallback(() => {
|
||||||
const handleOpenForm = useCallback((data: GTBEstadoCivilInterface | null) => {
|
setIsFormOpen(false);
|
||||||
setSelectedEstadoCivil(data);
|
setSelectedEstadoCivil(null);
|
||||||
setIsFormOpen(true);
|
}, []);
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setIsFormOpen(false);
|
async (data: GTBEstadoCivilInterface) => {
|
||||||
setSelectedEstadoCivil(null);
|
// Coloca o botão em estado de loading
|
||||||
}, []);
|
setButtonIsLoading(true);
|
||||||
|
await saveGTBEstadoCivil(data);
|
||||||
|
// Remove o botão do estado de loading
|
||||||
|
setButtonIsLoading(false);
|
||||||
|
await fetchGTBEstadoCivil(); // Atualiza a tabela após salvar
|
||||||
|
handleCloseForm();
|
||||||
|
},
|
||||||
|
[saveGTBEstadoCivil, fetchGTBEstadoCivil],
|
||||||
|
);
|
||||||
|
|
||||||
const handleSave = useCallback(async (data: GTBEstadoCivilInterface) => {
|
// Ações de deleção
|
||||||
// Coloca o botão em estado de loading
|
const handleConfirmDelete = useCallback(
|
||||||
setButtonIsLoading(true);
|
(item: GTBEstadoCivilInterface) => {
|
||||||
await saveGTBEstadoCivil(data);
|
setItemToDelete(item);
|
||||||
// Remove o botão do estado de loading
|
openConfirmDialog();
|
||||||
setButtonIsLoading(false);
|
},
|
||||||
await fetchGTBEstadoCivil(); // Atualiza a tabela após salvar
|
[openConfirmDialog],
|
||||||
handleCloseForm();
|
);
|
||||||
}, [saveGTBEstadoCivil, fetchGTBEstadoCivil]);
|
|
||||||
|
|
||||||
// Ações de deleção
|
const handleDelete = useCallback(async () => {
|
||||||
const handleConfirmDelete = useCallback((item: GTBEstadoCivilInterface) => {
|
if (!itemToDelete) {
|
||||||
setItemToDelete(item);
|
// Define os dados da resposta visual
|
||||||
openConfirmDialog();
|
setResponse({
|
||||||
}, [openConfirmDialog]);
|
status: 400,
|
||||||
|
message: "Não foi informado um registro para exclusão",
|
||||||
const handleDelete = useCallback(async () => {
|
});
|
||||||
if (!itemToDelete) {
|
return;
|
||||||
|
|
||||||
// Define os dados da resposta visual
|
|
||||||
setResponse({
|
|
||||||
status: 400,
|
|
||||||
message: 'Não foi informado um registro para exclusão'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
await removeGTBEstadoCivil(itemToDelete);
|
|
||||||
await fetchGTBEstadoCivil(); // Atualiza a tabela após remover
|
|
||||||
handleCancel();
|
|
||||||
}, [itemToDelete, fetchGTBEstadoCivil, handleCancel]);
|
|
||||||
|
|
||||||
// Efeito para carregar os dados na montagem do componente
|
|
||||||
useEffect(() => {
|
|
||||||
fetchGTBEstadoCivil();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// Mostra tela de loading enquanto os dados não são carregados
|
|
||||||
if (!gTBEstadoCivil) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
}
|
||||||
|
await removeGTBEstadoCivil(itemToDelete);
|
||||||
|
await fetchGTBEstadoCivil(); // Atualiza a tabela após remover
|
||||||
|
handleCancel();
|
||||||
|
}, [itemToDelete, fetchGTBEstadoCivil, handleCancel]);
|
||||||
|
|
||||||
return (
|
// Efeito para carregar os dados na montagem do componente
|
||||||
<div>
|
useEffect(() => {
|
||||||
{/* Cabeçalho */}
|
fetchGTBEstadoCivil();
|
||||||
<Header
|
}, []);
|
||||||
title={"Estados Civis"}
|
|
||||||
description={"Gerenciamento de Estados Civis"}
|
|
||||||
buttonText={"Novo Estado Civil"}
|
|
||||||
buttonAction={(data) => { handleOpenForm(data = initalEstadoCivil) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de Estados Civis */}
|
// Mostra tela de loading enquanto os dados não são carregados
|
||||||
<Card>
|
if (!gTBEstadoCivil) {
|
||||||
<CardContent>
|
return <Loading type={2} />;
|
||||||
<GTBEstadoCivilTable
|
}
|
||||||
data={gTBEstadoCivil}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
return (
|
||||||
<ConfirmDialog
|
<div>
|
||||||
isOpen={isConfirmOpen}
|
{/* Cabeçalho */}
|
||||||
title="Confirmar exclusão"
|
<Header
|
||||||
description="Atenção"
|
title={"Estados Civis"}
|
||||||
message={`Deseja realmente excluir o estado civil "${itemToDelete?.descricao}"?`}
|
description={"Gerenciamento de Estados Civis"}
|
||||||
confirmText="Sim, excluir"
|
buttonText={"Novo Estado Civil"}
|
||||||
cancelText="Cancelar"
|
buttonAction={(data) => {
|
||||||
onConfirm={handleDelete}
|
handleOpenForm((data = initalEstadoCivil));
|
||||||
onCancel={handleCancel}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
{/* Tabela de Estados Civis */}
|
||||||
<GTBEstadoCivilForm
|
<Card>
|
||||||
isOpen={isFormOpen}
|
<CardContent>
|
||||||
data={selectedEstadoCivil}
|
<GTBEstadoCivilTable
|
||||||
onClose={handleCloseForm}
|
data={gTBEstadoCivil}
|
||||||
onSave={handleSave}
|
onEdit={handleOpenForm}
|
||||||
buttonIsLoading={buttonIsLoading}
|
onDelete={handleConfirmDelete}
|
||||||
/>
|
/>
|
||||||
</div>
|
</CardContent>
|
||||||
);
|
</Card>
|
||||||
|
|
||||||
|
{/* Modal de confirmação */}
|
||||||
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o estado civil "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBEstadoCivilForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
|
data={selectedEstadoCivil}
|
||||||
|
onClose={handleCloseForm}
|
||||||
|
onSave={handleSave}
|
||||||
|
buttonIsLoading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,146 +18,151 @@ import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
// Hooks para leitura e salvamento
|
// Hooks para leitura e salvamento
|
||||||
const { gTBProfissao, fetchGTBProfissao } = useGTBProfissaoReadHook();
|
const { gTBProfissao, fetchGTBProfissao } = useGTBProfissaoReadHook();
|
||||||
const { saveGTBProfissao } = useGTBProfissaoSaveHook();
|
const { saveGTBProfissao } = useGTBProfissaoSaveHook();
|
||||||
const { removeGTBProfissao } = useGTBProfissaoRemoveHook();
|
const { removeGTBProfissao } = useGTBProfissaoRemoveHook();
|
||||||
|
|
||||||
// Estados
|
// Estados
|
||||||
const [selectedAndamento, setSelectedAndamento] = useState<GTBProfissaoInterface | null>(null);
|
const [selectedAndamento, setSelectedAndamento] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<GTBProfissaoInterface | null>(null);
|
||||||
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
// Estado para saber qual item será deletado
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBProfissaoInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
|
useState<GTBProfissaoInterface | null>(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Hook do modal de confirmação
|
||||||
*/
|
*/
|
||||||
const {
|
const {
|
||||||
isOpen: isConfirmOpen,
|
isOpen: isConfirmOpen,
|
||||||
openDialog: openConfirmDialog,
|
openDialog: openConfirmDialog,
|
||||||
handleConfirm,
|
handleConfirm,
|
||||||
handleCancel,
|
handleCancel,
|
||||||
} = useConfirmDialog();
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: GTBProfissaoInterface | null) => {
|
const handleOpenForm = useCallback((data: GTBProfissaoInterface | null) => {
|
||||||
setSelectedAndamento(data);
|
setSelectedAndamento(data);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedAndamento(null);
|
setSelectedAndamento(null);
|
||||||
setIsFormOpen(false);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Salva os dados do formulário
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleSave = useCallback(async (formData: GTBProfissaoInterface) => {
|
const handleSave = useCallback(
|
||||||
|
async (formData: GTBProfissaoInterface) => {
|
||||||
|
// Aguarda salvar o registro
|
||||||
|
await saveGTBProfissao(formData);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
// Atualiza a lista de dados
|
||||||
await saveGTBProfissao(formData);
|
fetchGTBProfissao();
|
||||||
|
},
|
||||||
|
[saveGTBProfissao, fetchGTBProfissao, handleCloseForm],
|
||||||
|
);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
/**
|
||||||
fetchGTBProfissao();
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GTBProfissaoInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
}, [saveGTBProfissao, fetchGTBProfissao, handleCloseForm]);
|
// Abre o modal de confirmação
|
||||||
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quando o usuário clica em "remover" na tabela
|
* Executa a exclusão de fato quando o usuário confirma
|
||||||
*/
|
*/
|
||||||
const handleConfirmDelete = useCallback((item: GTBProfissaoInterface) => {
|
const handleDelete = useCallback(async () => {
|
||||||
|
// Protege contra null
|
||||||
|
if (!itemToDelete) return;
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Executa o Hook de remoção
|
||||||
setItemToDelete(item);
|
await removeGTBProfissao(itemToDelete);
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Atualiza a lista
|
||||||
openConfirmDialog();
|
await fetchGTBProfissao();
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Limpa o item selecionado
|
||||||
|
setItemToDelete(null);
|
||||||
|
|
||||||
/**
|
// Fecha o modal
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
handleCancel();
|
||||||
*/
|
}, [itemToDelete, fetchGTBProfissao, handleCancel]);
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Busca inicial dos dados
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
fetchGTBProfissao();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
/**
|
||||||
await removeGTBProfissao(itemToDelete);
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!gTBProfissao) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Atualiza a lista
|
return (
|
||||||
await fetchGTBProfissao();
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Profissões"}
|
||||||
|
description={"Gerenciamento de Profissões"}
|
||||||
|
buttonText={"Nova Profissão"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Tabela de andamentos */}
|
||||||
setItemToDelete(null);
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GTBProfissaoTable
|
||||||
|
data={gTBProfissao}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Modal de confirmação */}
|
||||||
handleCancel();
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
}, [itemToDelete, fetchGTBProfissao, handleCancel]);
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBProfissaoForm
|
||||||
/**
|
isOpen={isFormOpen}
|
||||||
* Busca inicial dos dados
|
data={selectedAndamento}
|
||||||
*/
|
onClose={handleCloseForm}
|
||||||
useEffect(() => {
|
onSave={handleSave}
|
||||||
fetchGTBProfissao();
|
/>
|
||||||
}, []);
|
</div>
|
||||||
|
);
|
||||||
/**
|
4;
|
||||||
* Tela de loading enquanto carrega os dados
|
}
|
||||||
*/
|
|
||||||
if (!gTBProfissao) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Profissões"}
|
|
||||||
description={"Gerenciamento de Profissões"}
|
|
||||||
buttonText={"Nova Profissão"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<GTBProfissaoTable
|
|
||||||
data={gTBProfissao}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<GTBProfissaoForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedAndamento}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,146 +18,151 @@ import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface";
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
// Hooks para leitura e salvamento
|
// Hooks para leitura e salvamento
|
||||||
const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook();
|
const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook();
|
||||||
const { saveGTBRegimeComunhao } = useGTBRegimeBensSaveHook();
|
const { saveGTBRegimeComunhao } = useGTBRegimeBensSaveHook();
|
||||||
const { removeGTBRegimeComunhao } = useGTBRegimeBensRemoveHook();
|
const { removeGTBRegimeComunhao } = useGTBRegimeBensRemoveHook();
|
||||||
|
|
||||||
// Estados
|
// Estados
|
||||||
const [selectedAndamento, setSelectedAndamento] = useState<GTBRegimeBensInterface | null>(null);
|
const [selectedAndamento, setSelectedAndamento] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<GTBRegimeBensInterface | null>(null);
|
||||||
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
// Estado para saber qual item será deletado
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBRegimeBensInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
|
useState<GTBRegimeBensInterface | null>(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Hook do modal de confirmação
|
||||||
*/
|
*/
|
||||||
const {
|
const {
|
||||||
isOpen: isConfirmOpen,
|
isOpen: isConfirmOpen,
|
||||||
openDialog: openConfirmDialog,
|
openDialog: openConfirmDialog,
|
||||||
handleConfirm,
|
handleConfirm,
|
||||||
handleCancel,
|
handleCancel,
|
||||||
} = useConfirmDialog();
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: GTBRegimeBensInterface | null) => {
|
const handleOpenForm = useCallback((data: GTBRegimeBensInterface | null) => {
|
||||||
setSelectedAndamento(data);
|
setSelectedAndamento(data);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(true);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedAndamento(null);
|
setSelectedAndamento(null);
|
||||||
setIsFormOpen(false);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Salva os dados do formulário
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleSave = useCallback(async (formData: GTBRegimeBensInterface) => {
|
const handleSave = useCallback(
|
||||||
|
async (formData: GTBRegimeBensInterface) => {
|
||||||
|
// Aguarda salvar o registro
|
||||||
|
await saveGTBRegimeComunhao(formData);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
// Atualiza a lista de dados
|
||||||
await saveGTBRegimeComunhao(formData);
|
fetchGTBRegimeBens();
|
||||||
|
},
|
||||||
|
[saveGTBRegimeComunhao, fetchGTBRegimeBens],
|
||||||
|
);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
/**
|
||||||
fetchGTBRegimeBens();
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GTBRegimeBensInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
}, [saveGTBRegimeComunhao, fetchGTBRegimeBens]);
|
// Abre o modal de confirmação
|
||||||
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quando o usuário clica em "remover" na tabela
|
* Executa a exclusão de fato quando o usuário confirma
|
||||||
*/
|
*/
|
||||||
const handleConfirmDelete = useCallback((item: GTBRegimeBensInterface) => {
|
const handleDelete = useCallback(async () => {
|
||||||
|
// Protege contra null
|
||||||
|
if (!itemToDelete) return;
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Executa o Hook de remoção
|
||||||
setItemToDelete(item);
|
await removeGTBRegimeComunhao(itemToDelete);
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Atualiza a lista
|
||||||
openConfirmDialog();
|
await fetchGTBRegimeBens();
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Limpa o item selecionado
|
||||||
|
setItemToDelete(null);
|
||||||
|
|
||||||
/**
|
// Fecha o modal
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
handleCancel();
|
||||||
*/
|
}, [itemToDelete, fetchGTBRegimeBens, handleCancel]);
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Busca inicial dos dados
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
fetchGTBRegimeBens();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
/**
|
||||||
await removeGTBRegimeComunhao(itemToDelete);
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!gTBRegimeBens) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Atualiza a lista
|
return (
|
||||||
await fetchGTBRegimeBens();
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Regimes de Bens"}
|
||||||
|
description={"Gerenciamento de Regimes de Bens"}
|
||||||
|
buttonText={"Novo Regime"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Tabela de andamentos */}
|
||||||
setItemToDelete(null);
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GTBRegimeBensTable
|
||||||
|
data={gTBRegimeBens}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Modal de confirmação */}
|
||||||
handleCancel();
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o regime de bens "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
}, [itemToDelete, fetchGTBRegimeBens, handleCancel]);
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBRegimeBensForm
|
||||||
/**
|
isOpen={isFormOpen}
|
||||||
* Busca inicial dos dados
|
data={selectedAndamento}
|
||||||
*/
|
onClose={handleCloseForm}
|
||||||
useEffect(() => {
|
onSave={handleSave}
|
||||||
fetchGTBRegimeBens();
|
/>
|
||||||
}, []);
|
</div>
|
||||||
|
);
|
||||||
/**
|
4;
|
||||||
* Tela de loading enquanto carrega os dados
|
}
|
||||||
*/
|
|
||||||
if (!gTBRegimeBens) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Regimes de Bens"}
|
|
||||||
description={"Gerenciamento de Regimes de Bens"}
|
|
||||||
buttonText={"Novo Regime"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<GTBRegimeBensTable
|
|
||||||
data={gTBRegimeBens}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o regime de bens "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<GTBRegimeBensForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedAndamento}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,146 +18,155 @@ import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInter
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
// Hooks para leitura e salvamento
|
// Hooks para leitura e salvamento
|
||||||
const { gTBRegimeComunhao, fetchGTBRegimeComunhao } = useGTBRegimeComunhaoReadHook();
|
const { gTBRegimeComunhao, fetchGTBRegimeComunhao } =
|
||||||
const { saveGTBRegimeComunhao } = useGTBRegimeComunhaoSaveHook();
|
useGTBRegimeComunhaoReadHook();
|
||||||
const { removeGTBRegimeComunhao } = useGTBRegimeComunhaoRemoveHook();
|
const { saveGTBRegimeComunhao } = useGTBRegimeComunhaoSaveHook();
|
||||||
|
const { removeGTBRegimeComunhao } = useGTBRegimeComunhaoRemoveHook();
|
||||||
|
|
||||||
// Estados
|
// Estados
|
||||||
const [selectedAndamento, setSelectedAndamento] = useState<GTBRegimeComunhaoInterface | null>(null);
|
const [selectedAndamento, setSelectedAndamento] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<GTBRegimeComunhaoInterface | null>(null);
|
||||||
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
// Estado para saber qual item será deletado
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBRegimeComunhaoInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
|
useState<GTBRegimeComunhaoInterface | null>(null);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Hook do modal de confirmação
|
||||||
*/
|
*/
|
||||||
const {
|
const {
|
||||||
isOpen: isConfirmOpen,
|
isOpen: isConfirmOpen,
|
||||||
openDialog: openConfirmDialog,
|
openDialog: openConfirmDialog,
|
||||||
handleConfirm,
|
handleConfirm,
|
||||||
handleCancel,
|
handleCancel,
|
||||||
} = useConfirmDialog();
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: GTBRegimeComunhaoInterface | null) => {
|
const handleOpenForm = useCallback(
|
||||||
setSelectedAndamento(data);
|
(data: GTBRegimeComunhaoInterface | null) => {
|
||||||
setIsFormOpen(true);
|
setSelectedAndamento(data);
|
||||||
}, []);
|
setIsFormOpen(true);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedAndamento(null);
|
setSelectedAndamento(null);
|
||||||
setIsFormOpen(false);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Salva os dados do formulário
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleSave = useCallback(async (formData: GTBRegimeComunhaoInterface) => {
|
const handleSave = useCallback(
|
||||||
|
async (formData: GTBRegimeComunhaoInterface) => {
|
||||||
|
// Aguarda salvar o registro
|
||||||
|
await saveGTBRegimeComunhao(formData);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
// Atualiza a lista de dados
|
||||||
await saveGTBRegimeComunhao(formData);
|
fetchGTBRegimeComunhao();
|
||||||
|
},
|
||||||
|
[saveGTBRegimeComunhao, fetchGTBRegimeComunhao],
|
||||||
|
);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
/**
|
||||||
fetchGTBRegimeComunhao();
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GTBRegimeComunhaoInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
}, [saveGTBRegimeComunhao, fetchGTBRegimeComunhao]);
|
// Abre o modal de confirmação
|
||||||
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quando o usuário clica em "remover" na tabela
|
* Executa a exclusão de fato quando o usuário confirma
|
||||||
*/
|
*/
|
||||||
const handleConfirmDelete = useCallback((item: GTBRegimeComunhaoInterface) => {
|
const handleDelete = useCallback(async () => {
|
||||||
|
// Protege contra null
|
||||||
|
if (!itemToDelete) return;
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Executa o Hook de remoção
|
||||||
setItemToDelete(item);
|
await removeGTBRegimeComunhao(itemToDelete);
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Atualiza a lista
|
||||||
openConfirmDialog();
|
await fetchGTBRegimeComunhao();
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Limpa o item selecionado
|
||||||
|
setItemToDelete(null);
|
||||||
|
|
||||||
/**
|
// Fecha o modal
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
handleCancel();
|
||||||
*/
|
}, [itemToDelete, fetchGTBRegimeComunhao, handleCancel]);
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Busca inicial dos dados
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
fetchGTBRegimeComunhao();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
/**
|
||||||
await removeGTBRegimeComunhao(itemToDelete);
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!gTBRegimeComunhao) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Atualiza a lista
|
return (
|
||||||
await fetchGTBRegimeComunhao();
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Regimes de Comunhão"}
|
||||||
|
description={"Gerenciamento de Regimes de Comunhão"}
|
||||||
|
buttonText={"Novo Regime"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Tabela de andamentos */}
|
||||||
setItemToDelete(null);
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GTBRegimeComunhaoTable
|
||||||
|
data={gTBRegimeComunhao}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Modal de confirmação */}
|
||||||
handleCancel();
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
}, [itemToDelete, fetchGTBRegimeComunhao, handleCancel]);
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBRegimeComunhaoForm
|
||||||
/**
|
isOpen={isFormOpen}
|
||||||
* Busca inicial dos dados
|
data={selectedAndamento}
|
||||||
*/
|
onClose={handleCloseForm}
|
||||||
useEffect(() => {
|
onSave={handleSave}
|
||||||
fetchGTBRegimeComunhao();
|
/>
|
||||||
}, []);
|
</div>
|
||||||
|
);
|
||||||
/**
|
4;
|
||||||
* Tela de loading enquanto carrega os dados
|
}
|
||||||
*/
|
|
||||||
if (!gTBRegimeComunhao) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Regimes de Comunhão"}
|
|
||||||
description={"Gerenciamento de Regimes de Comunhão"}
|
|
||||||
buttonText={"Novo Regime"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<GTBRegimeComunhaoTable
|
|
||||||
data={gTBRegimeComunhao}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<GTBRegimeComunhaoForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedAndamento}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -19,167 +19,173 @@ import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroI
|
||||||
import { useResponse } from "@/app/_response/ResponseContext";
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
|
// Controle de exibição de respostas
|
||||||
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
// Controle de exibição de respostas
|
// Controle de estado do botão
|
||||||
const { setResponse } = useResponse();
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Controle de estado do botão
|
// Hooks para leitura e salvamento
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const { gTBTipoLogradouro, fetchGTBTipoLogradouro } =
|
||||||
|
useGTBTipoLogradouroReadHook();
|
||||||
|
const { saveGTBTipoLogradouro } = useGTBTipoLogradouroSaveHook();
|
||||||
|
const { removeGTBTipoLogradouro } = useGTBTipoLogradouroRemoveHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estados
|
||||||
const { gTBTipoLogradouro, fetchGTBTipoLogradouro } = useGTBTipoLogradouroReadHook();
|
const [selectedTipoLogradouro, setTipoLogradouro] =
|
||||||
const { saveGTBTipoLogradouro } = useGTBTipoLogradouroSaveHook();
|
useState<GTBTipoLogradouroInterface | null>(null);
|
||||||
const { removeGTBTipoLogradouro } = useGTBTipoLogradouroRemoveHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estados
|
// Estado para saber qual item será deletado
|
||||||
const [selectedTipoLogradouro, setTipoLogradouro] = useState<GTBTipoLogradouroInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<GTBTipoLogradouroInterface | null>(null);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
/**
|
||||||
const [itemToDelete, setItemToDelete] = useState<GTBTipoLogradouroInterface | null>(null);
|
* Hook do modal de confirmação
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
isOpen: isConfirmOpen,
|
||||||
|
openDialog: openConfirmDialog,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const {
|
const handleOpenForm = useCallback(
|
||||||
isOpen: isConfirmOpen,
|
(data: GTBTipoLogradouroInterface | null) => {
|
||||||
openDialog: openConfirmDialog,
|
setTipoLogradouro(data);
|
||||||
handleCancel,
|
setIsFormOpen(true);
|
||||||
} = useConfirmDialog();
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: GTBTipoLogradouroInterface | null) => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setTipoLogradouro(data);
|
setTipoLogradouro(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setTipoLogradouro(null);
|
async (formData: GTBTipoLogradouroInterface) => {
|
||||||
setIsFormOpen(false);
|
// Coloca o botão em estado de loading
|
||||||
}, []);
|
setButtonIsLoading(true);
|
||||||
|
|
||||||
/**
|
// Aguarda salvar o registro
|
||||||
* Salva os dados do formulário
|
await saveGTBTipoLogradouro(formData);
|
||||||
*/
|
|
||||||
const handleSave = useCallback(async (formData: GTBTipoLogradouroInterface) => {
|
|
||||||
|
|
||||||
// Coloca o botão em estado de loading
|
// Remove o botão do estado de loading
|
||||||
setButtonIsLoading(true);
|
setButtonIsLoading(false);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
// Atualiza a lista de dados
|
||||||
await saveGTBTipoLogradouro(formData);
|
fetchGTBTipoLogradouro();
|
||||||
|
},
|
||||||
|
[saveGTBTipoLogradouro, fetchGTBTipoLogradouro],
|
||||||
|
);
|
||||||
|
|
||||||
// Remove o botão do estado de loading
|
/**
|
||||||
setButtonIsLoading(false);
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: GTBTipoLogradouroInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
// Abre o modal de confirmação
|
||||||
fetchGTBTipoLogradouro();
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
}, [saveGTBTipoLogradouro, fetchGTBTipoLogradouro]);
|
/**
|
||||||
|
* Executa a exclusão de fato quando o usuário confirma
|
||||||
/**
|
*/
|
||||||
* Quando o usuário clica em "remover" na tabela
|
const handleDelete = useCallback(async () => {
|
||||||
*/
|
// Protege contra null
|
||||||
const handleConfirmDelete = useCallback((item: GTBTipoLogradouroInterface) => {
|
if (!itemToDelete) {
|
||||||
|
// Define os dados da resposta visual
|
||||||
// Define o item atual para remoção
|
setResponse({
|
||||||
setItemToDelete(item);
|
status: 400,
|
||||||
|
message: "Não foi informado um registro para exclusão",
|
||||||
// Abre o modal de confirmação
|
});
|
||||||
openConfirmDialog();
|
return;
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
|
||||||
*/
|
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Protege contra null
|
|
||||||
if (!itemToDelete) {
|
|
||||||
|
|
||||||
// Define os dados da resposta visual
|
|
||||||
setResponse({
|
|
||||||
status: 400,
|
|
||||||
message: 'Não foi informado um registro para exclusão'
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
|
||||||
await removeGTBTipoLogradouro(itemToDelete);
|
|
||||||
|
|
||||||
// Atualiza a lista
|
|
||||||
await fetchGTBTipoLogradouro();
|
|
||||||
|
|
||||||
// Limpa o item selecionado
|
|
||||||
setItemToDelete(null);
|
|
||||||
|
|
||||||
// Fecha o modal
|
|
||||||
handleCancel();
|
|
||||||
|
|
||||||
}, [itemToDelete, fetchGTBTipoLogradouro, handleCancel]);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Busca inicial dos dados
|
|
||||||
*/
|
|
||||||
useEffect(() => {
|
|
||||||
fetchGTBTipoLogradouro();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tela de loading enquanto carrega os dados
|
|
||||||
*/
|
|
||||||
if (!gTBTipoLogradouro) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
// Executa o Hook de remoção
|
||||||
<div>
|
await removeGTBTipoLogradouro(itemToDelete);
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Tipos de Logradouros"}
|
|
||||||
description={"Gerenciamento de tipos de Logradouros"}
|
|
||||||
buttonText={"Novo Tipo"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
// Atualiza a lista
|
||||||
<Card>
|
await fetchGTBTipoLogradouro();
|
||||||
<CardContent>
|
|
||||||
<GTBTipoLogradouroTable
|
|
||||||
data={gTBTipoLogradouro}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
// Limpa o item selecionado
|
||||||
<ConfirmDialog
|
setItemToDelete(null);
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
// Fecha o modal
|
||||||
<GTBTipoLogradouroForm
|
handleCancel();
|
||||||
isOpen={isFormOpen}
|
}, [itemToDelete, fetchGTBTipoLogradouro, handleCancel]);
|
||||||
data={selectedTipoLogradouro}
|
|
||||||
onClose={handleCloseForm}
|
/**
|
||||||
onSave={handleSave}
|
* Busca inicial dos dados
|
||||||
buttonIsLoading={buttonIsLoading}
|
*/
|
||||||
/>
|
useEffect(() => {
|
||||||
</div>
|
fetchGTBTipoLogradouro();
|
||||||
);
|
}, []);
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!gTBTipoLogradouro) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Tipos de Logradouros"}
|
||||||
|
description={"Gerenciamento de tipos de Logradouros"}
|
||||||
|
buttonText={"Novo Tipo"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Tabela de andamentos */}
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<GTBTipoLogradouroTable
|
||||||
|
data={gTBTipoLogradouro}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{/* Modal de confirmação */}
|
||||||
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Formulário de criação/edição */}
|
||||||
|
<GTBTipoLogradouroForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
|
data={selectedTipoLogradouro}
|
||||||
|
onClose={handleCloseForm}
|
||||||
|
onSave={handleSave}
|
||||||
|
buttonIsLoading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,157 +18,162 @@ import TCensecInterface from "../../_interfaces/TCensecInterface";
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
|
// Controle de estado do botão
|
||||||
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Controle de estado do botão
|
// Hooks para leitura e salvamento
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const { tCensec, fetchTCensec } = useTCensecReadHook();
|
||||||
|
const { saveTCensec } = useTCensecSaveHook();
|
||||||
|
const { deleteTCensec } = useTCensecDeleteHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estados
|
||||||
const { tCensec, fetchTCensec } = useTCensecReadHook();
|
const [selectedAndamento, setSelectedAndamento] =
|
||||||
const { saveTCensec } = useTCensecSaveHook();
|
useState<TCensecInterface | null>(null);
|
||||||
const { deleteTCensec } = useTCensecDeleteHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estados
|
// Estado para saber qual item será deletado
|
||||||
const [selectedAndamento, setSelectedAndamento] = useState<TCensecInterface | null>(null);
|
const [itemToDelete, setItemToDelete] = useState<TCensecInterface | null>(
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
/**
|
||||||
const [itemToDelete, setItemToDelete] = useState<TCensecInterface | null>(null);
|
* Hook do modal de confirmação
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
isOpen: isConfirmOpen,
|
||||||
|
openDialog: openConfirmDialog,
|
||||||
|
handleConfirm,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const {
|
const handleOpenForm = useCallback((data: TCensecInterface | null) => {
|
||||||
isOpen: isConfirmOpen,
|
setSelectedAndamento(data);
|
||||||
openDialog: openConfirmDialog,
|
setIsFormOpen(true);
|
||||||
handleConfirm,
|
}, []);
|
||||||
handleCancel,
|
|
||||||
} = useConfirmDialog();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: TCensecInterface | null) => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedAndamento(data);
|
setSelectedAndamento(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setSelectedAndamento(null);
|
async (formData: TCensecInterface) => {
|
||||||
setIsFormOpen(false);
|
// Coloca o botão em estado de loading
|
||||||
}, []);
|
setButtonIsLoading(true);
|
||||||
|
|
||||||
/**
|
// Aguarda salvar o registro
|
||||||
* Salva os dados do formulário
|
await saveTCensec(formData);
|
||||||
*/
|
|
||||||
const handleSave = useCallback(async (formData: TCensecInterface) => {
|
|
||||||
|
|
||||||
// Coloca o botão em estado de loading
|
// Remove o botão em estado de loading
|
||||||
setButtonIsLoading(true);
|
setButtonIsLoading(false);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
// Atualiza a lista de dados
|
||||||
await saveTCensec(formData);
|
fetchTCensec();
|
||||||
|
},
|
||||||
|
[saveTCensec, fetchTCensec, handleCloseForm],
|
||||||
|
);
|
||||||
|
|
||||||
// Remove o botão em estado de loading
|
/**
|
||||||
setButtonIsLoading(false);
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: TCensecInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
// Abre o modal de confirmação
|
||||||
fetchTCensec();
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
}, [saveTCensec, fetchTCensec, handleCloseForm]);
|
/**
|
||||||
|
* 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
|
||||||
* Quando o usuário clica em "remover" na tabela
|
await deleteTCensec(itemToDelete);
|
||||||
*/
|
|
||||||
const handleConfirmDelete = useCallback((item: TCensecInterface) => {
|
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Atualiza a lista
|
||||||
setItemToDelete(item);
|
await fetchTCensec();
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Limpa o item selecionado
|
||||||
openConfirmDialog();
|
setItemToDelete(null);
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Fecha o modal
|
||||||
|
handleCancel();
|
||||||
|
}, [itemToDelete, fetchTCensec, handleCancel]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
* Busca inicial dos dados
|
||||||
*/
|
*/
|
||||||
const handleDelete = useCallback(async () => {
|
useEffect(() => {
|
||||||
|
fetchTCensec();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (tCensec.length == 0) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
return (
|
||||||
await deleteTCensec(itemToDelete);
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"CENSEC"}
|
||||||
|
description={"Gerenciamento de Centrais"}
|
||||||
|
buttonText={"Nova Central"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Atualiza a lista
|
{/* Tabela de andamentos */}
|
||||||
await fetchTCensec();
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<TCensecTable
|
||||||
|
data={tCensec}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Modal de confirmação */}
|
||||||
setItemToDelete(null);
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Formulário de criação/edição */}
|
||||||
handleCancel();
|
<TCensecForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
}, [itemToDelete, fetchTCensec, handleCancel]);
|
data={selectedAndamento}
|
||||||
|
onClose={handleCloseForm}
|
||||||
/**
|
onSave={handleSave}
|
||||||
* Busca inicial dos dados
|
buttonIsLoading={buttonIsLoading}
|
||||||
*/
|
/>
|
||||||
useEffect(() => {
|
</div>
|
||||||
fetchTCensec();
|
);
|
||||||
}, []);
|
4;
|
||||||
|
}
|
||||||
/**
|
|
||||||
* Tela de loading enquanto carrega os dados
|
|
||||||
*/
|
|
||||||
if (tCensec.length == 0) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"CENSEC"}
|
|
||||||
description={"Gerenciamento de Centrais"}
|
|
||||||
buttonText={"Nova Central"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<TCensecTable
|
|
||||||
data={tCensec}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<TCensecForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedAndamento}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
buttonIsLoading={buttonIsLoading}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDialog";
|
||||||
import { useResponse } from "@/app/_response/ResponseContext"
|
import { useResponse } from "@/app/_response/ResponseContext";
|
||||||
|
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
import ConfirmDialog from "@/app/_components/confirm_dialog/ConfirmDialog";
|
||||||
|
|
@ -22,11 +22,10 @@ import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
||||||
const initialCensecNaturezaLitigio: TCensecNaturezaLitigioInterface = {
|
const initialCensecNaturezaLitigio: TCensecNaturezaLitigioInterface = {
|
||||||
censec_naturezalitigio_id: 0,
|
censec_naturezalitigio_id: 0,
|
||||||
descricao: "",
|
descricao: "",
|
||||||
situacao: SituacoesEnum.A
|
situacao: SituacoesEnum.A,
|
||||||
}
|
};
|
||||||
|
|
||||||
export default function TCensecNaturezaLitigioPage() {
|
export default function TCensecNaturezaLitigioPage() {
|
||||||
|
|
||||||
// Controle de exibição de respostas
|
// Controle de exibição de respostas
|
||||||
const { setResponse } = useResponse();
|
const { setResponse } = useResponse();
|
||||||
|
|
||||||
|
|
@ -34,14 +33,18 @@ export default function TCensecNaturezaLitigioPage() {
|
||||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
const { tCensecNaturezaLitigio, fetchTCensecNaturezaLitigio } = useTCensecNaturezaLitigioReadHook();
|
const { tCensecNaturezaLitigio, fetchTCensecNaturezaLitigio } =
|
||||||
|
useTCensecNaturezaLitigioReadHook();
|
||||||
const { saveTCensecNaturezaLitigio } = useTCensecNaturezaLitigioSaveHook();
|
const { saveTCensecNaturezaLitigio } = useTCensecNaturezaLitigioSaveHook();
|
||||||
const { removeTCensecNaturezaLitigio } = useTCensecNaturezaLitigioRemoveHook();
|
const { removeTCensecNaturezaLitigio } =
|
||||||
|
useTCensecNaturezaLitigioRemoveHook();
|
||||||
|
|
||||||
// Estados
|
// Estados
|
||||||
const [selectedItem, setSelectedItem] = useState<TCensecNaturezaLitigioInterface | null>(null);
|
const [selectedItem, setSelectedItem] =
|
||||||
|
useState<TCensecNaturezaLitigioInterface | null>(null);
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
const [itemToDelete, setItemToDelete] = useState<TCensecNaturezaLitigioInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
|
useState<TCensecNaturezaLitigioInterface | null>(null);
|
||||||
|
|
||||||
// Modal de confirmação
|
// Modal de confirmação
|
||||||
const {
|
const {
|
||||||
|
|
@ -51,10 +54,13 @@ export default function TCensecNaturezaLitigioPage() {
|
||||||
} = useConfirmDialog();
|
} = useConfirmDialog();
|
||||||
|
|
||||||
// Abrir formulário (criação ou edição)
|
// Abrir formulário (criação ou edição)
|
||||||
const handleOpenForm = useCallback((item: TCensecNaturezaLitigioInterface | null) => {
|
const handleOpenForm = useCallback(
|
||||||
setSelectedItem(item);
|
(item: TCensecNaturezaLitigioInterface | null) => {
|
||||||
setIsFormOpen(true);
|
setSelectedItem(item);
|
||||||
}, []);
|
setIsFormOpen(true);
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
// Fechar formulário
|
// Fechar formulário
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleCloseForm = useCallback(() => {
|
||||||
|
|
@ -63,32 +69,37 @@ export default function TCensecNaturezaLitigioPage() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Salvar item
|
// Salvar item
|
||||||
const handleSave = useCallback(async (formData: TCensecNaturezaLitigioInterface) => {
|
const handleSave = useCallback(
|
||||||
// Coloca o botão em estado de loading
|
async (formData: TCensecNaturezaLitigioInterface) => {
|
||||||
setButtonIsLoading(true);
|
// Coloca o botão em estado de loading
|
||||||
await saveTCensecNaturezaLitigio(formData);
|
setButtonIsLoading(true);
|
||||||
// Remove o botão do estado de loading
|
await saveTCensecNaturezaLitigio(formData);
|
||||||
setButtonIsLoading(false);
|
// Remove o botão do estado de loading
|
||||||
await fetchTCensecNaturezaLitigio();
|
setButtonIsLoading(false);
|
||||||
}, [saveTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio]);
|
await fetchTCensecNaturezaLitigio();
|
||||||
|
},
|
||||||
|
[saveTCensecNaturezaLitigio, fetchTCensecNaturezaLitigio],
|
||||||
|
);
|
||||||
|
|
||||||
// Confirmar remoção
|
// Confirmar remoção
|
||||||
const handleConfirmDelete = useCallback((item: TCensecNaturezaLitigioInterface) => {
|
const handleConfirmDelete = useCallback(
|
||||||
setItemToDelete(item);
|
(item: TCensecNaturezaLitigioInterface) => {
|
||||||
openConfirmDialog();
|
setItemToDelete(item);
|
||||||
}, [openConfirmDialog]);
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
// Executar remoção
|
// Executar remoção
|
||||||
const handleDelete = useCallback(async () => {
|
const handleDelete = useCallback(async () => {
|
||||||
if (!itemToDelete) {
|
if (!itemToDelete) {
|
||||||
|
|
||||||
// Define os dados da resposta visual
|
// Define os dados da resposta visual
|
||||||
setResponse({
|
setResponse({
|
||||||
status: 400,
|
status: 400,
|
||||||
message: 'Não foi informado um registro para exclusão'
|
message: "Não foi informado um registro para exclusão",
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
};
|
}
|
||||||
|
|
||||||
await removeTCensecNaturezaLitigio(itemToDelete);
|
await removeTCensecNaturezaLitigio(itemToDelete);
|
||||||
await fetchTCensecNaturezaLitigio();
|
await fetchTCensecNaturezaLitigio();
|
||||||
|
|
@ -113,7 +124,9 @@ export default function TCensecNaturezaLitigioPage() {
|
||||||
title={"Natureza do Litígio"}
|
title={"Natureza do Litígio"}
|
||||||
description={"Gerenciamento de Naturezas do Litígio"}
|
description={"Gerenciamento de Naturezas do Litígio"}
|
||||||
buttonText={"Nova Natureza"}
|
buttonText={"Nova Natureza"}
|
||||||
buttonAction={(data) => handleOpenForm(data = initialCensecNaturezaLitigio)}
|
buttonAction={(data) =>
|
||||||
|
handleOpenForm((data = initialCensecNaturezaLitigio))
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Tabela */}
|
{/* Tabela */}
|
||||||
|
|
@ -149,4 +162,4 @@ export default function TCensecNaturezaLitigioPage() {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
'use client'
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useParams } from "next/navigation";
|
import { useParams } from "next/navigation";
|
||||||
|
|
||||||
import {
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
Card,
|
|
||||||
CardContent
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
import MainEditor from "@/components/MainEditor";
|
import MainEditor from "@/components/MainEditor";
|
||||||
|
|
||||||
import Loading from "@/app/_components/loading/loading";
|
import Loading from "@/app/_components/loading/loading";
|
||||||
import { useTMinutaReadHook } from '../../../../_hooks/t_minuta/useTMinutaReadHook';
|
import { useTMinutaReadHook } from "../../../../_hooks/t_minuta/useTMinutaReadHook";
|
||||||
import { TMinutaInterface } from '../../../../_interfaces/TMinutaInterface';
|
import { TMinutaInterface } from "../../../../_interfaces/TMinutaInterface";
|
||||||
|
|
||||||
export default function TMinutaDetalhes() {
|
export default function TMinutaDetalhes() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
|
@ -47,30 +44,25 @@ export default function TMinutaDetalhes() {
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<div className="mb-4 grid gap-4 grid-cols-2">
|
<div className="mb-4 grid gap-4 grid-cols-2">
|
||||||
<div>
|
<div>
|
||||||
<div className="text-2xl font-semibold">
|
<div className="text-2xl font-semibold">Descrição</div>
|
||||||
Descrição
|
<div className="text-xl">{tMinuta.descricao}</div>
|
||||||
</div>
|
|
||||||
<div className="text-xl">
|
|
||||||
{tMinuta.descricao}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div className="text-2xl font-semibold">
|
<div className="text-2xl font-semibold">Situação</div>
|
||||||
Situação
|
|
||||||
</div>
|
|
||||||
<div className="text-xl">
|
<div className="text-xl">
|
||||||
{tMinuta.situacao === "A" ? "Ativo" : "Inativo"}
|
{tMinuta.situacao === "A" ? "Ativo" : "Inativo"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<div className="text-2xl font-semibold">
|
<div className="text-2xl font-semibold">Texto</div>
|
||||||
Texto
|
|
||||||
</div>
|
|
||||||
<MainEditor
|
<MainEditor
|
||||||
initialValue={editorContent} // Passa o conteúdo do editor
|
initialValue={editorContent} // Passa o conteúdo do editor
|
||||||
onEditorChange={handleEditorChange} // Função que atualiza o estado
|
onEditorChange={handleEditorChange} // Função que atualiza o estado
|
||||||
margins={{
|
margins={{
|
||||||
top: "2", bottom: "2", left: "2", right: "2"
|
top: "2",
|
||||||
|
bottom: "2",
|
||||||
|
left: "2",
|
||||||
|
right: "2",
|
||||||
}}
|
}}
|
||||||
size={{ width: 794, height: 1123 }} // Você pode ajustar o tamanho aqui
|
size={{ width: 794, height: 1123 }} // Você pode ajustar o tamanho aqui
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,113 +1,113 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from 'zod';
|
import z from "zod";
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from "react";
|
||||||
import { useForm, Controller } from 'react-hook-form';
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from "@/components/ui/form";
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
import MainEditor from '@/components/MainEditor';
|
import MainEditor from "@/components/MainEditor";
|
||||||
import { TMinutaSchema } from '../../../_schemas/TMinutaSchema';
|
import { TMinutaSchema } from "../../../_schemas/TMinutaSchema";
|
||||||
import { useTMinutaSaveHook } from '../../../_hooks/t_minuta/useTMinutaSaveHook';
|
import { useTMinutaSaveHook } from "../../../_hooks/t_minuta/useTMinutaSaveHook";
|
||||||
import { Card, CardContent } from '@/components/ui/card';
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof TMinutaSchema>;
|
type FormValues = z.infer<typeof TMinutaSchema>;
|
||||||
|
|
||||||
export default function TMinutaForm() {
|
export default function TMinutaForm() {
|
||||||
|
const { tMinuta, saveTMinuta } = useTMinutaSaveHook();
|
||||||
|
|
||||||
const { tMinuta, saveTMinuta } = useTMinutaSaveHook();
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(TMinutaSchema),
|
||||||
|
defaultValues: {
|
||||||
|
natureza_id: undefined,
|
||||||
|
descricao: "",
|
||||||
|
situacao: "A",
|
||||||
|
texto: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
async function onSubmit(values: FormValues) {
|
||||||
resolver: zodResolver(TMinutaSchema),
|
saveTMinuta(values);
|
||||||
defaultValues: {
|
}
|
||||||
natureza_id: undefined,
|
|
||||||
descricao: '',
|
|
||||||
situacao: 'A',
|
|
||||||
texto: '',
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
async function onSubmit(values: FormValues) {
|
return (
|
||||||
saveTMinuta(values);
|
<div>
|
||||||
}
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Form {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} 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 da minuta"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
return (
|
{/* Situação */}
|
||||||
<div>
|
<Controller
|
||||||
<Card>
|
name="situacao"
|
||||||
<CardContent>
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={field.value === "A"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label>{field.value === "A" ? "Ativo" : "Inativo"}</Label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* Editor de Texto */}
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
|
<Controller
|
||||||
|
name="texto"
|
||||||
{/* Descrição */}
|
control={form.control}
|
||||||
<FormField
|
render={({ field }) => (
|
||||||
control={form.control}
|
<div>
|
||||||
name="descricao"
|
<MainEditor
|
||||||
render={({ field }) => (
|
initialValue={field.value || ""}
|
||||||
<FormItem>
|
onEditorChange={field.onChange}
|
||||||
<FormLabel>Descrição</FormLabel>
|
margins={{ top: "0", bottom: "0", left: "0", right: "0" }}
|
||||||
<FormControl>
|
size={{ width: 794, height: 1123 }}
|
||||||
<Input {...field} placeholder="Digite a descrição da minuta" />
|
/>
|
||||||
</FormControl>
|
{form.formState.errors.texto && (
|
||||||
<FormMessage />
|
<p className="text-sm text-red-500 mt-2">
|
||||||
</FormItem>
|
{form.formState.errors.texto.message}
|
||||||
)}
|
</p>
|
||||||
/>
|
)}
|
||||||
|
</div>
|
||||||
{/* Situação */}
|
)}
|
||||||
<Controller
|
/>
|
||||||
name="situacao"
|
<Button type="submit">Salvar</Button>
|
||||||
control={form.control}
|
</form>
|
||||||
render={({ field }) => (
|
</Form>
|
||||||
<div className="flex items-center space-x-2">
|
</CardContent>
|
||||||
<Checkbox
|
</Card>
|
||||||
checked={field.value === "A"}
|
</div>
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
);
|
||||||
/>
|
|
||||||
<Label>{field.value === "A" ? "Ativo" : "Inativo"}</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Editor de Texto */}
|
|
||||||
<Controller
|
|
||||||
name="texto"
|
|
||||||
control={form.control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<div>
|
|
||||||
<MainEditor
|
|
||||||
initialValue={field.value || ""}
|
|
||||||
onEditorChange={field.onChange}
|
|
||||||
margins={{ top: '0', bottom: '0', left: '0', right: '0' }}
|
|
||||||
size={{ width: 794, height: 1123 }}
|
|
||||||
/>
|
|
||||||
{form.formState.errors.texto && (
|
|
||||||
<p className="text-sm text-red-500 mt-2">
|
|
||||||
{form.formState.errors.texto.message}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Button type="submit">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -19,23 +19,26 @@ import { TMinutaInterface } from "../../_interfaces/TMinutaInterface";
|
||||||
import { useTMinutaIndexHook } from "../../_hooks/t_minuta/useTMinutaIndexHook";
|
import { useTMinutaIndexHook } from "../../_hooks/t_minuta/useTMinutaIndexHook";
|
||||||
|
|
||||||
export default function TMinutaPage() {
|
export default function TMinutaPage() {
|
||||||
|
|
||||||
// Hooks de leitura e escrita
|
// Hooks de leitura e escrita
|
||||||
const { tMinuta, fetchTMinuta } = useTMinutaIndexHook();
|
const { tMinuta, fetchTMinuta } = useTMinutaIndexHook();
|
||||||
const { saveTMinuta } = useTMinutaSaveHook();
|
const { saveTMinuta } = useTMinutaSaveHook();
|
||||||
const { removeTMinuta } = useTMinutaRemoveHook();
|
const { removeTMinuta } = useTMinutaRemoveHook();
|
||||||
|
|
||||||
// Estados
|
// Estados
|
||||||
const [selectedMinuta, setSelectedMinuta] = useState<TMinutaInterface | null>(null);
|
const [selectedMinuta, setSelectedMinuta] = useState<TMinutaInterface | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
const [itemToDelete, setItemToDelete] = useState<TMinutaInterface | null>(null);
|
const [itemToDelete, setItemToDelete] = useState<TMinutaInterface | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
// Hook de confirmação
|
// Hook de confirmação
|
||||||
const {
|
const {
|
||||||
isOpen: isConfirmOpen,
|
isOpen: isConfirmOpen,
|
||||||
openDialog: openConfirmDialog,
|
openDialog: openConfirmDialog,
|
||||||
handleConfirm,
|
handleConfirm,
|
||||||
handleCancel
|
handleCancel,
|
||||||
} = useConfirmDialog();
|
} = useConfirmDialog();
|
||||||
|
|
||||||
// Abertura do formulário
|
// Abertura do formulário
|
||||||
|
|
@ -45,10 +48,13 @@ export default function TMinutaPage() {
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Ação de clique em remover
|
// Ação de clique em remover
|
||||||
const handleConfirmDelete = useCallback((item: TMinutaInterface) => {
|
const handleConfirmDelete = useCallback(
|
||||||
setItemToDelete(item);
|
(item: TMinutaInterface) => {
|
||||||
openConfirmDialog();
|
setItemToDelete(item);
|
||||||
}, [openConfirmDialog]);
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
// Remoção da minuta após confirmação
|
// Remoção da minuta após confirmação
|
||||||
const handleDelete = useCallback(async () => {
|
const handleDelete = useCallback(async () => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,143 +18,152 @@ import { useTTBAndamentoServicoDeleteHook } from "../../_hooks/t_tb_andamentoser
|
||||||
import Header from "@/app/_components/structure/Header";
|
import Header from "@/app/_components/structure/Header";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
|
// Hooks para leitura e salvamento
|
||||||
|
const { tTBAndamentosServicos, fetchTTBAndamentoServico } =
|
||||||
|
useTTBAndamentoServicoReadHook();
|
||||||
|
const { saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook();
|
||||||
|
const { deleteTTBAndamentoServico } = useTTBAndamentoServicoDeleteHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estados
|
||||||
const { tTBAndamentosServicos, fetchTTBAndamentoServico } = useTTBAndamentoServicoReadHook();
|
const [selectedAndamento, setSelectedAndamento] =
|
||||||
const { saveTTBAndamentoServico } = useTTBAndamentoServicoSaveHook();
|
useState<TTBAndamentoServicoInterface | null>(null);
|
||||||
const { deleteTTBAndamentoServico } = useTTBAndamentoServicoDeleteHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estados
|
// Estado para saber qual item será deletado
|
||||||
const [selectedAndamento, setSelectedAndamento] = useState<TTBAndamentoServicoInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<TTBAndamentoServicoInterface | null>(null);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
/**
|
||||||
const [itemToDelete, setItemToDelete] = useState<TTBAndamentoServicoInterface | null>(null);
|
* Hook do modal de confirmação
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
isOpen: isConfirmOpen,
|
||||||
|
openDialog: openConfirmDialog,
|
||||||
|
handleConfirm,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const {
|
const handleOpenForm = useCallback(
|
||||||
isOpen: isConfirmOpen,
|
(data: TTBAndamentoServicoInterface | null) => {
|
||||||
openDialog: openConfirmDialog,
|
setSelectedAndamento(data);
|
||||||
handleConfirm,
|
setIsFormOpen(true);
|
||||||
handleCancel,
|
},
|
||||||
} = useConfirmDialog();
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: TTBAndamentoServicoInterface | null) => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setSelectedAndamento(data);
|
setSelectedAndamento(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setSelectedAndamento(null);
|
async (formData: TTBAndamentoServicoInterface) => {
|
||||||
setIsFormOpen(false);
|
// Aguarda salvar o registro
|
||||||
}, []);
|
await saveTTBAndamentoServico(formData);
|
||||||
|
|
||||||
/**
|
// Atualiza a lista de dados
|
||||||
* Salva os dados do formulário
|
fetchTTBAndamentoServico();
|
||||||
*/
|
},
|
||||||
const handleSave = useCallback(async (formData: TTBAndamentoServicoInterface) => {
|
[saveTTBAndamentoServico, fetchTTBAndamentoServico],
|
||||||
|
);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
/**
|
||||||
await saveTTBAndamentoServico(formData);
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: TTBAndamentoServicoInterface) => {
|
||||||
|
setItemToDelete(item);
|
||||||
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
/**
|
||||||
fetchTTBAndamentoServico();
|
* Executa a exclusão de fato quando o usuário confirma
|
||||||
|
*/
|
||||||
|
const handleDelete = useCallback(async () => {
|
||||||
|
// Protege contra null
|
||||||
|
if (!itemToDelete) return;
|
||||||
|
|
||||||
}, [saveTTBAndamentoServico, fetchTTBAndamentoServico]);
|
// Executa o Hook de remoção
|
||||||
|
await deleteTTBAndamentoServico(itemToDelete);
|
||||||
|
|
||||||
/**
|
// Atualiza a lista
|
||||||
* Quando o usuário clica em "remover" na tabela
|
await fetchTTBAndamentoServico();
|
||||||
*/
|
|
||||||
const handleConfirmDelete = useCallback((item: TTBAndamentoServicoInterface) => {
|
|
||||||
setItemToDelete(item);
|
|
||||||
openConfirmDialog();
|
|
||||||
}, [openConfirmDialog]);
|
|
||||||
|
|
||||||
/**
|
// Limpa o item selecionado
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
setItemToDelete(null);
|
||||||
*/
|
|
||||||
const handleDelete = useCallback(async () => {
|
|
||||||
|
|
||||||
// Protege contra null
|
// Fecha o modal
|
||||||
if (!itemToDelete) return;
|
handleCancel();
|
||||||
|
}, [itemToDelete, fetchTTBAndamentoServico, handleCancel]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Busca inicial dos dados
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
fetchTTBAndamentoServico();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
/**
|
||||||
await deleteTTBAndamentoServico(itemToDelete);
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!tTBAndamentosServicos) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Atualiza a lista
|
return (
|
||||||
await fetchTTBAndamentoServico();
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Andamentos"}
|
||||||
|
description={"Gerenciamento de Andamentos de Atos"}
|
||||||
|
buttonText={"Novo Andamento"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Tabela de andamentos */}
|
||||||
setItemToDelete(null);
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<TTBAndamentoServicoTable
|
||||||
|
data={tTBAndamentosServicos}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Modal de confirmação */}
|
||||||
handleCancel();
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
}, [itemToDelete, fetchTTBAndamentoServico, handleCancel]);
|
{/* Formulário de criação/edição */}
|
||||||
|
<TTBAndamentoServicoForm
|
||||||
/**
|
isOpen={isFormOpen}
|
||||||
* Busca inicial dos dados
|
data={selectedAndamento}
|
||||||
*/
|
onClose={handleCloseForm}
|
||||||
useEffect(() => {
|
onSave={handleSave}
|
||||||
fetchTTBAndamentoServico();
|
/>
|
||||||
}, []);
|
</div>
|
||||||
|
);
|
||||||
/**
|
4;
|
||||||
* Tela de loading enquanto carrega os dados
|
}
|
||||||
*/
|
|
||||||
if (!tTBAndamentosServicos) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Andamentos"}
|
|
||||||
description={"Gerenciamento de Andamentos de Atos"}
|
|
||||||
buttonText={"Novo Andamento"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<TTBAndamentoServicoTable
|
|
||||||
data={tTBAndamentosServicos}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<TTBAndamentoServicoForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedAndamento}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
); 4
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { useEffect, useState, useCallback } from "react";
|
import { useEffect, useState, useCallback } from "react";
|
||||||
import { Card, CardContent } from "@/components/ui/card";
|
import { Card, CardContent } from "@/components/ui/card";
|
||||||
|
|
@ -18,147 +18,154 @@ import { useConfirmDialog } from "@/app/_components/confirm_dialog/useConfirmDia
|
||||||
import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface";
|
import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface";
|
||||||
|
|
||||||
export default function TTBAndamentoServico() {
|
export default function TTBAndamentoServico() {
|
||||||
|
// Hooks para leitura e salvamento
|
||||||
|
const { tTBReconhecimentosTipos, fetchTTBReconhecimentosTipos } =
|
||||||
|
useTTBReconhecimentoTipoReadHook();
|
||||||
|
const { saveTTBReconhecimentoTipo } = useTTBReconhecimentoTipoSaveHook();
|
||||||
|
const { deleteTTBReconhecimentoTipo } = useTTBReconhecimentoTipoDeleteHook();
|
||||||
|
|
||||||
// Hooks para leitura e salvamento
|
// Estados
|
||||||
const { tTBReconhecimentosTipos, fetchTTBReconhecimentosTipos } = useTTBReconhecimentoTipoReadHook();
|
const [selectedReconhecimentoTipo, setReconhecimentoTipo] =
|
||||||
const { saveTTBReconhecimentoTipo } = useTTBReconhecimentoTipoSaveHook();
|
useState<TTBReconhecimentoTipoInterface | null>(null);
|
||||||
const { deleteTTBReconhecimentoTipo } = useTTBReconhecimentoTipoDeleteHook();
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
||||||
|
|
||||||
// Estados
|
// Estado para saber qual item será deletado
|
||||||
const [selectedReconhecimentoTipo, setReconhecimentoTipo] = useState<TTBReconhecimentoTipoInterface | null>(null);
|
const [itemToDelete, setItemToDelete] =
|
||||||
const [isFormOpen, setIsFormOpen] = useState(false);
|
useState<TTBReconhecimentoTipoInterface | null>(null);
|
||||||
|
|
||||||
// Estado para saber qual item será deletado
|
/**
|
||||||
const [itemToDelete, setItemToDelete] = useState<TTBReconhecimentoTipoInterface | null>(null);
|
* Hook do modal de confirmação
|
||||||
|
*/
|
||||||
|
const {
|
||||||
|
isOpen: isConfirmOpen,
|
||||||
|
openDialog: openConfirmDialog,
|
||||||
|
handleConfirm,
|
||||||
|
handleCancel,
|
||||||
|
} = useConfirmDialog();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook do modal de confirmação
|
* Abre o formulário no modo de edição ou criação
|
||||||
*/
|
*/
|
||||||
const {
|
const handleOpenForm = useCallback(
|
||||||
isOpen: isConfirmOpen,
|
(data: TTBReconhecimentoTipoInterface | null) => {
|
||||||
openDialog: openConfirmDialog,
|
setReconhecimentoTipo(data);
|
||||||
handleConfirm,
|
setIsFormOpen(true);
|
||||||
handleCancel,
|
},
|
||||||
} = useConfirmDialog();
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abre o formulário no modo de edição ou criação
|
* Fecha o formulário e limpa o andamento selecionado
|
||||||
*/
|
*/
|
||||||
const handleOpenForm = useCallback((data: TTBReconhecimentoTipoInterface | null) => {
|
const handleCloseForm = useCallback(() => {
|
||||||
setReconhecimentoTipo(data);
|
setReconhecimentoTipo(null);
|
||||||
setIsFormOpen(true);
|
setIsFormOpen(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fecha o formulário e limpa o andamento selecionado
|
* Salva os dados do formulário
|
||||||
*/
|
*/
|
||||||
const handleCloseForm = useCallback(() => {
|
const handleSave = useCallback(
|
||||||
setReconhecimentoTipo(null);
|
async (formData: TTBReconhecimentoTipoInterface) => {
|
||||||
setIsFormOpen(false);
|
// Aguarda salvar o registro
|
||||||
}, []);
|
await saveTTBReconhecimentoTipo(formData);
|
||||||
|
|
||||||
/**
|
// Atualiza a lista de dados
|
||||||
* Salva os dados do formulário
|
fetchTTBReconhecimentosTipos();
|
||||||
*/
|
},
|
||||||
const handleSave = useCallback(async (formData: TTBReconhecimentoTipoInterface) => {
|
[saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos],
|
||||||
|
);
|
||||||
|
|
||||||
// Aguarda salvar o registro
|
/**
|
||||||
await saveTTBReconhecimentoTipo(formData);
|
* Quando o usuário clica em "remover" na tabela
|
||||||
|
*/
|
||||||
|
const handleConfirmDelete = useCallback(
|
||||||
|
(item: TTBReconhecimentoTipoInterface) => {
|
||||||
|
// Define o item atual para remoção
|
||||||
|
setItemToDelete(item);
|
||||||
|
|
||||||
// Atualiza a lista de dados
|
// Abre o modal de confirmação
|
||||||
fetchTTBReconhecimentosTipos();
|
openConfirmDialog();
|
||||||
|
},
|
||||||
|
[openConfirmDialog],
|
||||||
|
);
|
||||||
|
|
||||||
}, [saveTTBReconhecimentoTipo, fetchTTBReconhecimentosTipos]);
|
/**
|
||||||
|
* 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
|
||||||
* Quando o usuário clica em "remover" na tabela
|
await deleteTTBReconhecimentoTipo(itemToDelete);
|
||||||
*/
|
|
||||||
const handleConfirmDelete = useCallback((item: TTBReconhecimentoTipoInterface) => {
|
|
||||||
|
|
||||||
// Define o item atual para remoção
|
// Atualiza a lista
|
||||||
setItemToDelete(item);
|
await fetchTTBReconhecimentosTipos();
|
||||||
|
|
||||||
// Abre o modal de confirmação
|
// Limpa o item selecionado
|
||||||
openConfirmDialog();
|
setItemToDelete(null);
|
||||||
|
|
||||||
}, [openConfirmDialog]);
|
// Fecha o modal
|
||||||
|
handleCancel();
|
||||||
|
}, [itemToDelete, fetchTTBReconhecimentosTipos, handleCancel]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executa a exclusão de fato quando o usuário confirma
|
* Busca inicial dos dados
|
||||||
*/
|
*/
|
||||||
const handleDelete = useCallback(async () => {
|
useEffect(() => {
|
||||||
|
fetchTTBReconhecimentosTipos();
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Protege contra null
|
/**
|
||||||
if (!itemToDelete) return;
|
* Tela de loading enquanto carrega os dados
|
||||||
|
*/
|
||||||
|
if (!tTBReconhecimentosTipos) {
|
||||||
|
return <Loading type={2} />;
|
||||||
|
}
|
||||||
|
|
||||||
// Executa o Hook de remoção
|
return (
|
||||||
await deleteTTBReconhecimentoTipo(itemToDelete);
|
<div>
|
||||||
|
{/* Cabeçalho */}
|
||||||
|
<Header
|
||||||
|
title={"Reconhecimentos"}
|
||||||
|
description={"Gerenciamento de tipos de reconhecimentos"}
|
||||||
|
buttonText={"Novo Tipo"}
|
||||||
|
buttonAction={() => {
|
||||||
|
handleOpenForm(null);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
// Atualiza a lista
|
{/* Tabela de andamentos */}
|
||||||
await fetchTTBReconhecimentosTipos();
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<TTBReconhecimentoTipoTable
|
||||||
|
data={tTBReconhecimentosTipos}
|
||||||
|
onEdit={handleOpenForm}
|
||||||
|
onDelete={handleConfirmDelete}
|
||||||
|
/>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
// Limpa o item selecionado
|
{/* Modal de confirmação */}
|
||||||
setItemToDelete(null);
|
<ConfirmDialog
|
||||||
|
isOpen={isConfirmOpen}
|
||||||
|
title="Confirmar exclusão"
|
||||||
|
description="Atenção"
|
||||||
|
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
||||||
|
confirmText="Sim, excluir"
|
||||||
|
cancelText="Cancelar"
|
||||||
|
onConfirm={handleDelete}
|
||||||
|
onCancel={handleCancel}
|
||||||
|
/>
|
||||||
|
|
||||||
// Fecha o modal
|
{/* Formulário de criação/edição */}
|
||||||
handleCancel();
|
<TTBReconhecimentoTipoForm
|
||||||
|
isOpen={isFormOpen}
|
||||||
}, [itemToDelete, fetchTTBReconhecimentosTipos, handleCancel]);
|
data={selectedReconhecimentoTipo}
|
||||||
|
onClose={handleCloseForm}
|
||||||
/**
|
onSave={handleSave}
|
||||||
* Busca inicial dos dados
|
/>
|
||||||
*/
|
</div>
|
||||||
useEffect(() => {
|
);
|
||||||
fetchTTBReconhecimentosTipos();
|
}
|
||||||
}, []);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tela de loading enquanto carrega os dados
|
|
||||||
*/
|
|
||||||
if (!tTBReconhecimentosTipos) {
|
|
||||||
return <Loading type={2} />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
{/* Cabeçalho */}
|
|
||||||
<Header
|
|
||||||
title={"Reconhecimentos"}
|
|
||||||
description={"Gerenciamento de tipos de reconhecimentos"}
|
|
||||||
buttonText={"Novo Tipo"}
|
|
||||||
buttonAction={() => { handleOpenForm(null) }}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tabela de andamentos */}
|
|
||||||
<Card>
|
|
||||||
<CardContent>
|
|
||||||
<TTBReconhecimentoTipoTable
|
|
||||||
data={tTBReconhecimentosTipos}
|
|
||||||
onEdit={handleOpenForm}
|
|
||||||
onDelete={handleConfirmDelete}
|
|
||||||
/>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
{/* Modal de confirmação */}
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={isConfirmOpen}
|
|
||||||
title="Confirmar exclusão"
|
|
||||||
description="Atenção"
|
|
||||||
message={`Deseja realmente excluir o andamento "${itemToDelete?.descricao}"?`}
|
|
||||||
confirmText="Sim, excluir"
|
|
||||||
cancelText="Cancelar"
|
|
||||||
onConfirm={handleDelete}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Formulário de criação/edição */}
|
|
||||||
<TTBReconhecimentoTipoForm
|
|
||||||
isOpen={isFormOpen}
|
|
||||||
data={selectedReconhecimentoTipo}
|
|
||||||
onClose={handleCloseForm}
|
|
||||||
onSave={handleSave}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
|
|
@ -6,21 +6,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
|
||||||
|
|
@ -32,121 +32,119 @@ type FormValues = z.infer<typeof GCidadeSchema>;
|
||||||
|
|
||||||
// Propriedades esperadas pelo componente
|
// Propriedades esperadas pelo componente
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean; // controla se o Dialog está aberto
|
isOpen: boolean; // controla se o Dialog está aberto
|
||||||
data: FormValues | null; // dados para edição (se existirem)
|
data: FormValues | null; // dados para edição (se existirem)
|
||||||
onClose: (item: null, isFormStatus: boolean) => void; // callback para fechar
|
onClose: (item: null, isFormStatus: boolean) => void; // callback para fechar
|
||||||
onSave: (data: FormValues) => void; // callback para salvar
|
onSave: (data: FormValues) => void; // callback para salvar
|
||||||
}
|
}
|
||||||
|
|
||||||
// Componente principal do formulário
|
// Componente principal do formulário
|
||||||
export default function GCidadeForm({ isOpen, data, onClose, onSave }: Props) {
|
export default function GCidadeForm({ isOpen, data, onClose, onSave }: Props) {
|
||||||
|
// Inicializa o react-hook-form integrado ao Zod para validação
|
||||||
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(GCidadeSchema),
|
||||||
|
defaultValues: {
|
||||||
|
cidade_id: 0,
|
||||||
|
uf: "",
|
||||||
|
cidade_nome: "",
|
||||||
|
codigo_ibge: "",
|
||||||
|
codigo_gyn: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Inicializa o react-hook-form integrado ao Zod para validação
|
// Quando recebe dados para edição, atualiza os valores do formulário
|
||||||
const form = useForm<FormValues>({
|
useEffect(() => {
|
||||||
resolver: zodResolver(GCidadeSchema),
|
if (data) form.reset(data);
|
||||||
defaultValues: {
|
}, [data, form]);
|
||||||
cidade_id: 0,
|
|
||||||
uf: "",
|
|
||||||
cidade_nome: "",
|
|
||||||
codigo_ibge: "",
|
|
||||||
codigo_gyn: ""
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Quando recebe dados para edição, atualiza os valores do formulário
|
return (
|
||||||
useEffect(() => {
|
<Dialog
|
||||||
if (data) form.reset(data);
|
open={isOpen}
|
||||||
}, [data, form]);
|
// Fecha o diálogo quando alterado para "false"
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) onClose(null, false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
{/* Cabeçalho do diálogo */}
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Cidades</DialogTitle>
|
||||||
|
<DialogDescription>Controle de Cidades</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
return (
|
{/* Estrutura do formulário */}
|
||||||
<Dialog
|
<Form {...form}>
|
||||||
open={isOpen}
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
// Fecha o diálogo quando alterado para "false"
|
{/* Campo: Nome da cidade */}
|
||||||
onOpenChange={(open) => {
|
<FormField
|
||||||
if (!open) onClose(null, false);
|
control={form.control}
|
||||||
}}
|
name="cidade_nome"
|
||||||
>
|
render={({ field }) => (
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<FormItem>
|
||||||
{/* Cabeçalho do diálogo */}
|
<FormLabel>Descrição</FormLabel>
|
||||||
<DialogHeader>
|
<FormControl>
|
||||||
<DialogTitle>Cidades</DialogTitle>
|
<Input {...field} placeholder="Digite a descrição" />
|
||||||
<DialogDescription>Controle de Cidades</DialogDescription>
|
</FormControl>
|
||||||
</DialogHeader>
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Estrutura do formulário */}
|
{/* Campo: Código IBGE */}
|
||||||
<Form {...form}>
|
<FormField
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
name="codigo_ibge"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Código IBGE</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} placeholder="Digite o código" />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Campo: Nome da cidade */}
|
{/* Campo: UF (Estado) */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
name="uf"
|
||||||
name="cidade_nome"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Descrição</FormLabel>
|
<FormLabel>Estado</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
<Input {...field} placeholder="Digite a UF" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Campo: Código IBGE */}
|
{/* Rodapé do diálogo com botões */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
name="codigo_ibge"
|
{/* Botão de cancelar */}
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
render={({ field }) => (
|
<Button
|
||||||
<FormItem>
|
variant="outline"
|
||||||
<FormLabel>Código IBGE</FormLabel>
|
type="button"
|
||||||
<FormControl>
|
onClick={() => onClose(null, false)}
|
||||||
<Input {...field} placeholder="Digite o código" />
|
className="cursor-pointer"
|
||||||
</FormControl>
|
>
|
||||||
<FormMessage />
|
Cancelar
|
||||||
</FormItem>
|
</Button>
|
||||||
)}
|
</DialogClose>
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Campo: UF (Estado) */}
|
{/* Botão de salvar */}
|
||||||
<FormField
|
<Button type="submit" className="cursor-pointer">
|
||||||
name="uf"
|
Salvar
|
||||||
control={form.control}
|
</Button>
|
||||||
render={({ field }) => (
|
</DialogFooter>
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Estado</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input {...field} placeholder="Digite a UF" />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do diálogo com botões */}
|
{/* Campo oculto: ID da cidade */}
|
||||||
<DialogFooter className="mt-4">
|
<input type="hidden" {...form.register("cidade_id")} />
|
||||||
{/* Botão de cancelar */}
|
</form>
|
||||||
<DialogClose asChild>
|
</Form>
|
||||||
<Button
|
</DialogContent>
|
||||||
variant="outline"
|
</Dialog>
|
||||||
type="button"
|
);
|
||||||
onClick={() => onClose(null, false)}
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
|
|
||||||
{/* Botão de salvar */}
|
|
||||||
<Button type="submit" className="cursor-pointer">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto: ID da cidade */}
|
|
||||||
<input type="hidden" {...form.register("cidade_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
|
|
@ -23,128 +23,118 @@ import GCidadeInterface from "../../_interfaces/GCidadeInterface";
|
||||||
|
|
||||||
// Tipagem das props do componente da tabela
|
// Tipagem das props do componente da tabela
|
||||||
interface GCidadeTableProps {
|
interface GCidadeTableProps {
|
||||||
data: GCidadeInterface[]; // lista de cidades
|
data: GCidadeInterface[]; // lista de cidades
|
||||||
onEdit: (item: GCidadeInterface, isEditingFormStatus: boolean) => void; // callback para edição
|
onEdit: (item: GCidadeInterface, isEditingFormStatus: boolean) => void; // callback para edição
|
||||||
onDelete: (item: GCidadeInterface, isEditingFormStatus: boolean) => void; // callback para exclusão
|
onDelete: (item: GCidadeInterface, isEditingFormStatus: boolean) => void; // callback para exclusão
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o "badge" de status da cidade (Ativo/Inativo)
|
* Renderiza o "badge" de status da cidade (Ativo/Inativo)
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A"; // define se está ativo ou inativo
|
const isActive = situacao === "A"; // define se está ativo ou inativo
|
||||||
|
|
||||||
// Estilos base
|
// Estilos base
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
// Estilo para ativo
|
// Estilo para ativo
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
// Estilo para inativo
|
// Estilo para inativo
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
// Retorna o badge com classe condicional
|
// Retorna o badge com classe condicional
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Componente principal da tabela de cidades
|
* Componente principal da tabela de cidades
|
||||||
*/
|
*/
|
||||||
export default function GCidadeTable({
|
export default function GCidadeTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GCidadeTableProps) {
|
}: GCidadeTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table className="table-fixed w-full">
|
<Table className="table-fixed w-full">
|
||||||
{/* Cabeçalho da tabela */}
|
{/* Cabeçalho da tabela */}
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead className="w-15 font-bold">#</TableHead>
|
<TableHead className="w-15 font-bold">#</TableHead>
|
||||||
<TableHead className="w-25 font-bold">IBGE</TableHead>
|
<TableHead className="w-25 font-bold">IBGE</TableHead>
|
||||||
<TableHead className="w-25 font-bold">UF</TableHead>
|
<TableHead className="w-25 font-bold">UF</TableHead>
|
||||||
<TableHead className="font-bold">Descrição</TableHead>
|
<TableHead className="font-bold">Descrição</TableHead>
|
||||||
<TableHead className="text-right"></TableHead>
|
<TableHead className="text-right"></TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
{/* Corpo da tabela */}
|
{/* Corpo da tabela */}
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.cidade_id} className="cursor-pointer">
|
||||||
key={item.cidade_id}
|
{/* ID da cidade */}
|
||||||
className="cursor-pointer"
|
<TableCell>{item.cidade_id}</TableCell>
|
||||||
|
|
||||||
|
{/* Código IBGE */}
|
||||||
|
<TableCell>{item.codigo_ibge}</TableCell>
|
||||||
|
|
||||||
|
{/* UF */}
|
||||||
|
<TableCell>{item.uf}</TableCell>
|
||||||
|
|
||||||
|
{/* Nome/descrição da cidade */}
|
||||||
|
<TableCell>{item.cidade_nome}</TableCell>
|
||||||
|
|
||||||
|
{/* Ações (menu dropdown) */}
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
{/* Botão de disparo do menu */}
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
{/* Conteúdo do menu */}
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
{/* Opção editar */}
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
{/* ID da cidade */}
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
<TableCell>
|
Editar
|
||||||
{item.cidade_id}
|
</DropdownMenuItem>
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
{/* Código IBGE */}
|
<DropdownMenuSeparator />
|
||||||
<TableCell>
|
|
||||||
{item.codigo_ibge}
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
{/* UF */}
|
{/* Opção remover */}
|
||||||
<TableCell>
|
<DropdownMenuItem
|
||||||
{item.uf}
|
className="cursor-pointer"
|
||||||
</TableCell>
|
onSelect={() => onDelete(item, true)}
|
||||||
|
>
|
||||||
{/* Nome/descrição da cidade */}
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<TableCell>
|
Remover
|
||||||
{item.cidade_nome}
|
</DropdownMenuItem>
|
||||||
</TableCell>
|
</DropdownMenuGroup>
|
||||||
|
</DropdownMenuContent>
|
||||||
{/* Ações (menu dropdown) */}
|
</DropdownMenu>
|
||||||
<TableCell className="text-right">
|
</TableCell>
|
||||||
<DropdownMenu>
|
</TableRow>
|
||||||
{/* Botão de disparo do menu */}
|
))}
|
||||||
<DropdownMenuTrigger asChild>
|
</TableBody>
|
||||||
<Button
|
</Table>
|
||||||
variant="outline"
|
);
|
||||||
size="icon"
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<EllipsisIcon />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
|
|
||||||
{/* Conteúdo do menu */}
|
|
||||||
<DropdownMenuContent side="left" align="start">
|
|
||||||
<DropdownMenuGroup>
|
|
||||||
{/* Opção editar */}
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
{/* Opção remover */}
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -7,21 +7,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import LoadingButton from "@/app/_components/loadingButton/LoadingButton";
|
import LoadingButton from "@/app/_components/loadingButton/LoadingButton";
|
||||||
|
|
@ -31,95 +31,106 @@ import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface";
|
||||||
type FormValues = z.infer<typeof GMedidaTipoSchema>;
|
type FormValues = z.infer<typeof GMedidaTipoSchema>;
|
||||||
|
|
||||||
interface GMedidaTipoFormProps {
|
interface GMedidaTipoFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GMedidaTipoForm({ isOpen, data, onClose, onSave, buttonIsLoading }: GMedidaTipoFormProps) {
|
export default function GMedidaTipoForm({
|
||||||
// Inicializa o react-hook-form com o schema Zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(GMedidaTipoSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
medida_tipo_id: 0,
|
buttonIsLoading,
|
||||||
sigla: "",
|
}: GMedidaTipoFormProps) {
|
||||||
descricao: "",
|
// Inicializa o react-hook-form com o schema Zod
|
||||||
},
|
const form = useForm<FormValues>({
|
||||||
});
|
resolver: zodResolver(GMedidaTipoSchema),
|
||||||
|
defaultValues: {
|
||||||
|
medida_tipo_id: 0,
|
||||||
|
sigla: "",
|
||||||
|
descricao: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>Tipo de Medida</DialogTitle>
|
||||||
Tipo de Medida
|
<DialogDescription>Crie ou edite um tipo de medida</DialogDescription>
|
||||||
</DialogTitle>
|
</DialogHeader>
|
||||||
<DialogDescription>
|
|
||||||
Crie ou edite um tipo de medida
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Sigla */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="descricao"
|
name="sigla"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Descrição</FormLabel>
|
<FormLabel>Sigla</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
<Input {...field} placeholder="Digite a sigla" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Sigla */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="sigla"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Sigla</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input {...field} placeholder="Digite a sigla" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
{/* Botão de loading */}
|
||||||
/>
|
<LoadingButton
|
||||||
|
text="Salvar"
|
||||||
{/* Rodapé do Dialog */}
|
textLoading="Aguarde..."
|
||||||
<DialogFooter className="mt-4">
|
type="submit"
|
||||||
<DialogClose asChild>
|
loading={buttonIsLoading}
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
/>
|
||||||
Cancelar
|
</DialogFooter>
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
{/* Botão de loading */}
|
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
{/* Campo oculto */}
|
||||||
<input type="hidden" {...form.register("medida_tipo_id")} />
|
<input type="hidden" {...form.register("medida_tipo_id")} />
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,96 +1,91 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface";
|
import { GMedidaTipoInterface } from "../../_interfaces/GMedidaTipoInterface";
|
||||||
|
|
||||||
interface GMedidaTipoTableProps {
|
interface GMedidaTipoTableProps {
|
||||||
data: GMedidaTipoInterface[];
|
data: GMedidaTipoInterface[];
|
||||||
onEdit: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (item: GMedidaTipoInterface, isEditingFormStatus: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GMedidaTipoTable({
|
export default function GMedidaTipoTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GMedidaTipoTableProps) {
|
}: GMedidaTipoTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead>Sigla</TableHead>
|
<TableHead>Sigla</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.medida_tipo_id} className="cursor-pointer">
|
||||||
key={item.medida_tipo_id}
|
<TableCell className="font-medium">{item.medida_tipo_id}</TableCell>
|
||||||
className="cursor-pointer"
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
<TableCell>{item.sigla}</TableCell>
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.medida_tipo_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
<TableCell>{item.descricao}</TableCell>
|
|
||||||
<TableCell>{item.sigla}</TableCell>
|
|
||||||
<TableCell className="text-right">
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<EllipsisIcon />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
|
|
||||||
<DropdownMenuContent side="left" align="start">
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuGroup>
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<DropdownMenuItem
|
onSelect={() => onDelete(item, true)}
|
||||||
className="cursor-pointer"
|
>
|
||||||
onSelect={() => onDelete(item, true)}
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
>
|
Remover
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
</DropdownMenuItem>
|
||||||
Remover
|
</DropdownMenuGroup>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuContent>
|
||||||
</DropdownMenuGroup>
|
</DropdownMenu>
|
||||||
</DropdownMenuContent>
|
</TableCell>
|
||||||
</DropdownMenu>
|
</TableRow>
|
||||||
</TableCell>
|
))}
|
||||||
</TableRow>
|
</TableBody>
|
||||||
))}
|
</Table>
|
||||||
</TableBody>
|
);
|
||||||
</Table>
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
@ -8,21 +8,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -34,99 +34,113 @@ import { SituacoesEnum } from "@/enums/SituacoesEnum";
|
||||||
type FormValues = z.infer<typeof GTBBairroSchema>;
|
type FormValues = z.infer<typeof GTBBairroSchema>;
|
||||||
|
|
||||||
interface GTBBairroFormProps {
|
interface GTBBairroFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBBairroForm({ isOpen, data, onClose, onSave, buttonIsLoading }: GTBBairroFormProps) {
|
export default function GTBBairroForm({
|
||||||
|
isOpen,
|
||||||
|
data,
|
||||||
|
onClose,
|
||||||
|
onSave,
|
||||||
|
buttonIsLoading,
|
||||||
|
}: GTBBairroFormProps) {
|
||||||
|
// Inicializa o react-hook-form com o schema Zod
|
||||||
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(GTBBairroSchema),
|
||||||
|
defaultValues: {
|
||||||
|
sistema_id: null,
|
||||||
|
tb_bairro_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
situacao: SituacoesEnum.A,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Inicializa o react-hook-form com o schema Zod
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
const form = useForm<FormValues>({
|
useEffect(() => {
|
||||||
resolver: zodResolver(GTBBairroSchema),
|
if (data) form.reset(data);
|
||||||
defaultValues: {
|
}, [data, form]);
|
||||||
sistema_id: null,
|
|
||||||
tb_bairro_id: 0,
|
|
||||||
descricao: "",
|
|
||||||
situacao: SituacoesEnum.A,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
return (
|
||||||
useEffect(() => {
|
<Dialog
|
||||||
if (data) form.reset(data);
|
open={isOpen}
|
||||||
}, [data, form]);
|
onOpenChange={(open) => {
|
||||||
|
if (!open) onClose(null, false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Bairro</DialogTitle>
|
||||||
|
<DialogDescription>Crie ou edite um bairro</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
return (
|
<Form {...form}>
|
||||||
<Dialog
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
open={isOpen}
|
{/* Descrição */}
|
||||||
onOpenChange={(open) => {
|
<FormField
|
||||||
if (!open) onClose(null, false);
|
control={form.control}
|
||||||
}}
|
name="descricao"
|
||||||
>
|
render={({ field }) => (
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<FormItem>
|
||||||
<DialogHeader>
|
<FormLabel>Descrição</FormLabel>
|
||||||
<DialogTitle>
|
<FormControl>
|
||||||
Bairro
|
<Input
|
||||||
</DialogTitle>
|
{...field}
|
||||||
<DialogDescription>
|
placeholder="Digite a descrição do bairro"
|
||||||
Crie ou edite um bairro
|
/>
|
||||||
</DialogDescription>
|
</FormControl>
|
||||||
</DialogHeader>
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* Situação */}
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<Controller
|
||||||
|
name="situacao"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={field.value === "A"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label>Ativo</Label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="descricao"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Descrição</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input {...field} placeholder="Digite a descrição do bairro" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
{/* Botão de loading */}
|
||||||
/>
|
<LoadingButton
|
||||||
|
text="Salvar"
|
||||||
|
textLoading="Aguarde..."
|
||||||
|
type="submit"
|
||||||
|
loading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Campos ocultos */}
|
||||||
<Controller
|
<input type="hidden" {...form.register("tb_bairro_id")} />
|
||||||
name="situacao"
|
<input type="hidden" {...form.register("sistema_id")} />
|
||||||
control={form.control}
|
</form>
|
||||||
render={({ field }) => (
|
</Form>
|
||||||
<div className="flex items-center space-x-2">
|
</DialogContent>
|
||||||
<Checkbox
|
</Dialog>
|
||||||
checked={field.value === "A"}
|
);
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
}
|
||||||
/>
|
|
||||||
<Label>Ativo</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
|
||||||
<DialogFooter className="mt-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
{/* Botão de loading */}
|
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campos ocultos */}
|
|
||||||
<input type="hidden" {...form.register("tb_bairro_id")} />
|
|
||||||
<input type="hidden" {...form.register("sistema_id")} />
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,123 +1,119 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface";
|
import { GTBBairroInterface } from "../../_interfaces/GTBBairroInterface";
|
||||||
|
|
||||||
interface GTBBairroTableProps {
|
interface GTBBairroTableProps {
|
||||||
data: GTBBairroInterface[];
|
data: GTBBairroInterface[];
|
||||||
onEdit: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (item: GTBBairroInterface, isEditingFormStatus: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
function StatusBadge({ situacao }: { situacao: "A" | "I" }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBBairroTable({
|
export default function GTBBairroTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GTBBairroTableProps) {
|
}: GTBBairroTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_bairro_id} className="cursor-pointer">
|
||||||
key={item.tb_bairro_id}
|
<TableCell className="font-medium">{item.tb_bairro_id}</TableCell>
|
||||||
className="cursor-pointer"
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_bairro_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
}
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -9,21 +9,21 @@ import LoadingButton from "@/app/_components/loadingButton/LoadingButton";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -34,97 +34,116 @@ import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterfa
|
||||||
type FormValues = z.infer<typeof GTBEstadoCivilSchema>;
|
type FormValues = z.infer<typeof GTBEstadoCivilSchema>;
|
||||||
|
|
||||||
interface TBEstadoCivilFormProps {
|
interface TBEstadoCivilFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBEstadoCivilForm({ isOpen, data, onClose, onSave, buttonIsLoading }: TBEstadoCivilFormProps) {
|
export default function GTBEstadoCivilForm({
|
||||||
// Inicializa o react-hook-form com o schema Zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(GTBEstadoCivilSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
tb_estadocivil_id: 0,
|
buttonIsLoading,
|
||||||
sistema_id: 0,
|
}: TBEstadoCivilFormProps) {
|
||||||
descricao: "",
|
// Inicializa o react-hook-form com o schema Zod
|
||||||
situacao: "A",
|
const form = useForm<FormValues>({
|
||||||
},
|
resolver: zodResolver(GTBEstadoCivilSchema),
|
||||||
});
|
defaultValues: {
|
||||||
|
tb_estadocivil_id: 0,
|
||||||
|
sistema_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
situacao: "A",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>Estado Civil</DialogTitle>
|
||||||
Estado Civil
|
<DialogDescription>Crie ou edite um estado civil</DialogDescription>
|
||||||
</DialogTitle>
|
</DialogHeader>
|
||||||
<DialogDescription>
|
|
||||||
Crie ou edite um estado civil
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="descricao"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>Descrição</FormLabel>
|
<Checkbox
|
||||||
<FormControl>
|
checked={field.value === "A"}
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
onCheckedChange={(checked) =>
|
||||||
</FormControl>
|
field.onChange(checked ? "A" : "I")
|
||||||
<FormMessage />
|
}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<Label>Ativo</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Rodapé do Dialog */}
|
||||||
<Controller
|
<DialogFooter className="mt-4">
|
||||||
name="situacao"
|
<DialogClose asChild>
|
||||||
control={form.control}
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<div className="flex items-center space-x-2">
|
type="button"
|
||||||
<Checkbox
|
onClick={() => onClose(null, false)}
|
||||||
checked={field.value === "A"}
|
className="cursor-pointer"
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
>
|
||||||
/>
|
Cancelar
|
||||||
<Label>Ativo</Label>
|
</Button>
|
||||||
</div>
|
</DialogClose>
|
||||||
)}
|
{/* Botão de loading */}
|
||||||
/>
|
<LoadingButton
|
||||||
|
text="Salvar"
|
||||||
|
textLoading="Aguarde..."
|
||||||
|
type="submit"
|
||||||
|
loading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
{/* Campos ocultos */}
|
||||||
<DialogFooter className="mt-4">
|
<input
|
||||||
<DialogClose asChild>
|
type="hidden"
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
{...form.register("tb_estadocivil_id", { valueAsNumber: true })}
|
||||||
Cancelar
|
/>
|
||||||
</Button>
|
<input
|
||||||
</DialogClose>
|
type="hidden"
|
||||||
{/* Botão de loading */}
|
{...form.register("sistema_id", { valueAsNumber: true })}
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
/>
|
||||||
</DialogFooter>
|
</form>
|
||||||
|
</Form>
|
||||||
{/* Campos ocultos */}
|
</DialogContent>
|
||||||
<input type="hidden" {...form.register("tb_estadocivil_id", { valueAsNumber: true })} />
|
</Dialog>
|
||||||
<input type="hidden" {...form.register("sistema_id", { valueAsNumber: true })} />
|
);
|
||||||
</form>
|
}
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,123 +1,124 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface";
|
import { GTBEstadoCivilInterface } from "../../_interfaces/GTBEstadoCivilInterface";
|
||||||
|
|
||||||
interface TBEstadoCivilTableProps {
|
interface TBEstadoCivilTableProps {
|
||||||
data: GTBEstadoCivilInterface[];
|
data: GTBEstadoCivilInterface[];
|
||||||
onEdit: (item: GTBEstadoCivilInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: GTBEstadoCivilInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: GTBEstadoCivilInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (
|
||||||
|
item: GTBEstadoCivilInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
function StatusBadge({ situacao }: { situacao: "A" | "I" }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBEstadoCivilTable({
|
export default function GTBEstadoCivilTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: TBEstadoCivilTableProps) {
|
}: TBEstadoCivilTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_estadocivil_id} className="cursor-pointer">
|
||||||
key={item.tb_estadocivil_id}
|
<TableCell className="font-medium">
|
||||||
className="cursor-pointer"
|
{item.tb_estadocivil_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_estadocivil_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
}
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,21 +8,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -32,112 +32,126 @@ import { GTBProfissaoSchema } from "../../_schemas/GTBProfissaoSchema";
|
||||||
type FormValues = z.infer<typeof GTBProfissaoSchema>;
|
type FormValues = z.infer<typeof GTBProfissaoSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBProfissaoForm({ isOpen, data, onClose, onSave }: Props) {
|
export default function GTBProfissaoForm({
|
||||||
// Inicializa o react-hook-form com schema zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(GTBProfissaoSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
descricao: "",
|
}: Props) {
|
||||||
cod_cbo: "",
|
// Inicializa o react-hook-form com schema zod
|
||||||
situacao: "A",
|
const form = useForm<FormValues>({
|
||||||
tb_profissao_id: 0,
|
resolver: zodResolver(GTBProfissaoSchema),
|
||||||
},
|
defaultValues: {
|
||||||
});
|
descricao: "",
|
||||||
|
cod_cbo: "",
|
||||||
|
situacao: "A",
|
||||||
|
tb_profissao_id: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Profissões</DialogTitle>
|
||||||
|
<DialogDescription>Controle de profissões</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
<DialogHeader>
|
<Form {...form}>
|
||||||
<DialogTitle>
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
Profissões
|
{/* Descrição */}
|
||||||
</DialogTitle>
|
<FormField
|
||||||
<DialogDescription>
|
control={form.control}
|
||||||
Controle de profissões
|
name="descricao"
|
||||||
</DialogDescription>
|
render={({ field }) => (
|
||||||
</DialogHeader>
|
<FormItem>
|
||||||
|
<FormLabel>Descrição</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
{...field}
|
||||||
|
placeholder="Digite a descrição"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* CBO */}
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="cod_cbo"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>CBO</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="nubmer"
|
||||||
|
{...field}
|
||||||
|
placeholder="Digite o código"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="descricao"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>Descrição</FormLabel>
|
<Checkbox
|
||||||
<FormControl>
|
checked={field.value === "A"}
|
||||||
<Input type="text" {...field} placeholder="Digite a descrição" />
|
onCheckedChange={(checked) =>
|
||||||
</FormControl>
|
field.onChange(checked ? "A" : "I")
|
||||||
<FormMessage />
|
}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<Label>Ativo</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* CBO */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="cod_cbo"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>CBO</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input type="nubmer" {...field} placeholder="Digite o código" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
<Button type="submit" className="cursor-pointer">
|
||||||
/>
|
Salvar
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Campo oculto */}
|
||||||
<Controller
|
<input type="hidden" {...form.register("tb_profissao_id")} />
|
||||||
name="situacao"
|
</form>
|
||||||
control={form.control}
|
</Form>
|
||||||
render={({ field }) => (
|
</DialogContent>
|
||||||
<div className="flex items-center space-x-2">
|
</Dialog>
|
||||||
<Checkbox
|
);
|
||||||
checked={field.value === "A"}
|
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
|
||||||
/>
|
|
||||||
<Label>Ativo</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
|
||||||
<DialogFooter className="mt-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
<Button type="submit" className="cursor-pointer">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("tb_profissao_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,129 +1,125 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
||||||
|
|
||||||
interface GTBProfissaoTableProps {
|
interface GTBProfissaoTableProps {
|
||||||
data: GTBProfissaoInterface[];
|
data: GTBProfissaoInterface[];
|
||||||
onEdit: (item: GTBProfissaoInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: GTBProfissaoInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: GTBProfissaoInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (item: GTBProfissaoInterface, isEditingFormStatus: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBProfissaoTable({
|
export default function GTBProfissaoTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GTBProfissaoTableProps) {
|
}: GTBProfissaoTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>CBO</TableHead>
|
<TableHead>CBO</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_profissao_id} className="cursor-pointer">
|
||||||
key={item.tb_profissao_id}
|
<TableCell className="font-medium">
|
||||||
className="cursor-pointer"
|
{item.tb_profissao_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="font-medium">{item.cod_cbo}</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_profissao_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell className="font-medium">
|
<DropdownMenuItem
|
||||||
{item.cod_cbo}
|
className="cursor-pointer"
|
||||||
</TableCell>
|
onSelect={() => onDelete(item, true)}
|
||||||
|
>
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
|
Remover
|
||||||
<TableCell className="text-right">
|
</DropdownMenuItem>
|
||||||
<DropdownMenu>
|
</DropdownMenuGroup>
|
||||||
<DropdownMenuTrigger asChild>
|
</DropdownMenuContent>
|
||||||
<Button
|
</DropdownMenu>
|
||||||
variant="outline"
|
</TableCell>
|
||||||
size="icon"
|
</TableRow>
|
||||||
className="cursor-pointer"
|
))}
|
||||||
>
|
</TableBody>
|
||||||
<EllipsisIcon />
|
</Table>
|
||||||
</Button>
|
);
|
||||||
</DropdownMenuTrigger>
|
|
||||||
|
|
||||||
<DropdownMenuContent side="left" align="start">
|
|
||||||
<DropdownMenuGroup>
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
|
@ -7,21 +7,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -32,96 +32,102 @@ import { useEffect } from "react";
|
||||||
type FormValues = z.infer<typeof GTBRegimeBensSchema>;
|
type FormValues = z.infer<typeof GTBRegimeBensSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: Props) {
|
export default function GTBRegimeComunhaoForm({
|
||||||
|
isOpen,
|
||||||
|
data,
|
||||||
|
onClose,
|
||||||
|
onSave,
|
||||||
|
}: Props) {
|
||||||
|
// Inicializa o react-hook-form com schema zod
|
||||||
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(GTBRegimeBensSchema),
|
||||||
|
defaultValues: {
|
||||||
|
tb_regimebens_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
situacao: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Inicializa o react-hook-form com schema zod
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
const form = useForm<FormValues>({
|
useEffect(() => {
|
||||||
resolver: zodResolver(GTBRegimeBensSchema),
|
if (data) form.reset(data);
|
||||||
defaultValues: {
|
}, [data, form]);
|
||||||
tb_regimebens_id: 0,
|
|
||||||
descricao: "",
|
|
||||||
situacao: "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
return (
|
||||||
useEffect(() => {
|
<Dialog
|
||||||
if (data) form.reset(data);
|
open={isOpen}
|
||||||
}, [data, form]);
|
onOpenChange={(open) => {
|
||||||
|
if (!open) onClose(null, false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Regimes de Bens</DialogTitle>
|
||||||
|
<DialogDescription>Controle de Regimes de Vens</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
return (
|
<Form {...form}>
|
||||||
<Dialog
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
open={isOpen}
|
{/* Descrição */}
|
||||||
onOpenChange={(open) => {
|
<FormField
|
||||||
if (!open) onClose(null, false);
|
control={form.control}
|
||||||
}}
|
name="descricao"
|
||||||
>
|
render={({ field }) => (
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<FormItem>
|
||||||
<DialogHeader>
|
<FormLabel>Descrição</FormLabel>
|
||||||
<DialogTitle>
|
<FormControl>
|
||||||
Regimes de Bens
|
<Input {...field} placeholder="Digite a descrição" />
|
||||||
</DialogTitle>
|
</FormControl>
|
||||||
<DialogDescription>
|
<FormMessage />
|
||||||
Controle de Regimes de Vens
|
</FormItem>
|
||||||
</DialogDescription>
|
)}
|
||||||
</DialogHeader>
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* Situação */}
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<Controller
|
||||||
|
name="situacao"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={field.value === "A"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label>Ativo</Label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="descricao"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Descrição</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
<Button type="submit" className="cursor-pointer">
|
||||||
/>
|
Salvar
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Campo oculto */}
|
||||||
<Controller
|
<input type="hidden" {...form.register("tb_regimebens_id")} />
|
||||||
name="situacao"
|
</form>
|
||||||
control={form.control}
|
</Form>
|
||||||
render={({ field }) => (
|
</DialogContent>
|
||||||
<div className="flex items-center space-x-2">
|
</Dialog>
|
||||||
<Checkbox
|
);
|
||||||
checked={field.value === "A"}
|
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
|
||||||
/>
|
|
||||||
<Label>Ativo</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
|
||||||
<DialogFooter className="mt-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
<Button type="submit" className="cursor-pointer">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("tb_regimebens_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,126 +1,125 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface";
|
import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface";
|
||||||
|
|
||||||
interface GTBRegimeBensTableProps {
|
interface GTBRegimeBensTableProps {
|
||||||
data: GTBRegimeBensInterface[];
|
data: GTBRegimeBensInterface[];
|
||||||
onEdit: (item: GTBRegimeBensInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: GTBRegimeBensInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: GTBRegimeBensInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (
|
||||||
|
item: GTBRegimeBensInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBRegimeBensTable({
|
export default function GTBRegimeBensTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GTBRegimeBensTableProps) {
|
}: GTBRegimeBensTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_regimebens_id} className="cursor-pointer">
|
||||||
key={item.tb_regimebens_id}
|
<TableCell className="font-medium">
|
||||||
className="cursor-pointer"
|
{item.tb_regimebens_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_regimebens_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuItem
|
||||||
{item.descricao}
|
className="cursor-pointer"
|
||||||
</TableCell>
|
onSelect={() => onDelete(item, true)}
|
||||||
|
>
|
||||||
<TableCell className="text-right">
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<DropdownMenu>
|
Remover
|
||||||
<DropdownMenuTrigger asChild>
|
</DropdownMenuItem>
|
||||||
<Button
|
</DropdownMenuGroup>
|
||||||
variant="outline"
|
</DropdownMenuContent>
|
||||||
size="icon"
|
</DropdownMenu>
|
||||||
className="cursor-pointer"
|
</TableCell>
|
||||||
>
|
</TableRow>
|
||||||
<EllipsisIcon />
|
))}
|
||||||
</Button>
|
</TableBody>
|
||||||
</DropdownMenuTrigger>
|
</Table>
|
||||||
|
);
|
||||||
<DropdownMenuContent side="left" align="start">
|
|
||||||
<DropdownMenuGroup>
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,182 +8,195 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
import { GTBRegimeComunhaoSchema } from "../../_schemas/GTBRegimeComunhaoSchema";
|
import { GTBRegimeComunhaoSchema } from "../../_schemas/GTBRegimeComunhaoSchema";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook";
|
import { useGTBRegimeBensReadHook } from "../../_hooks/g_tb_regimebens/useGTBRegimeBensReadHook";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof GTBRegimeComunhaoSchema>;
|
type FormValues = z.infer<typeof GTBRegimeComunhaoSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBRegimeComunhaoForm({ isOpen, data, onClose, onSave }: Props) {
|
export default function GTBRegimeComunhaoForm({
|
||||||
|
isOpen,
|
||||||
|
data,
|
||||||
|
onClose,
|
||||||
|
onSave,
|
||||||
|
}: Props) {
|
||||||
|
const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook();
|
||||||
|
|
||||||
const { gTBRegimeBens, fetchGTBRegimeBens } = useGTBRegimeBensReadHook();
|
// Inicializa o react-hook-form com schema zod
|
||||||
|
const form = useForm<FormValues>({
|
||||||
|
resolver: zodResolver(GTBRegimeComunhaoSchema),
|
||||||
|
defaultValues: {
|
||||||
|
tb_regimecomunhao_id: 0,
|
||||||
|
tb_regimebens_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
texto: "",
|
||||||
|
situacao: "",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Inicializa o react-hook-form com schema zod
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
const form = useForm<FormValues>({
|
useEffect(() => {
|
||||||
resolver: zodResolver(GTBRegimeComunhaoSchema),
|
const loadData = async () => {
|
||||||
defaultValues: {
|
// Se existir dados, reseta o formulário com os dados informados
|
||||||
tb_regimecomunhao_id: 0,
|
if (data) form.reset(data);
|
||||||
tb_regimebens_id: 0,
|
|
||||||
descricao: "",
|
|
||||||
texto: "",
|
|
||||||
situacao: "",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Aguarda a busca terminar
|
||||||
useEffect(() => {
|
await fetchGTBRegimeBens();
|
||||||
|
};
|
||||||
|
|
||||||
const loadData = async () => {
|
// Dispara a função
|
||||||
// Se existir dados, reseta o formulário com os dados informados
|
loadData();
|
||||||
if (data) form.reset(data);
|
}, [data, form]);
|
||||||
|
|
||||||
// Aguarda a busca terminar
|
return (
|
||||||
await fetchGTBRegimeBens();
|
<Dialog
|
||||||
};
|
open={isOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
if (!open) onClose(null, false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Regimes de Comunhão</DialogTitle>
|
||||||
|
<DialogDescription>Controle de Regimes de Comunhão</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
// Dispara a função
|
<Form {...form}>
|
||||||
loadData();
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
}, [data, form]);
|
{/* Texto */}
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="texto"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Texto</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} placeholder="Digite o texto" />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
return (
|
{/* Tipo */}
|
||||||
<Dialog
|
<FormField
|
||||||
open={isOpen}
|
control={form.control}
|
||||||
onOpenChange={(open) => {
|
name="tb_regimebens_id"
|
||||||
if (!open) onClose(null, false);
|
render={({ field }) => (
|
||||||
}}
|
<FormItem>
|
||||||
>
|
<FormLabel>Tipo</FormLabel>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<Select
|
||||||
<DialogHeader>
|
value={String(field.value)}
|
||||||
<DialogTitle>
|
// Converter o valor inteiro para ser aceito pelo zod
|
||||||
Regimes de Comunhão
|
onValueChange={(val) => field.onChange(Number(val))}
|
||||||
</DialogTitle>
|
>
|
||||||
<DialogDescription>
|
<FormControl className="w-full">
|
||||||
Controle de Regimes de Comunhão
|
<SelectTrigger>
|
||||||
</DialogDescription>
|
<SelectValue placeholder="Escolha o tipo do andamento" />
|
||||||
</DialogHeader>
|
</SelectTrigger>
|
||||||
|
</FormControl>
|
||||||
|
<SelectContent>
|
||||||
|
{gTBRegimeBens.map((item) => (
|
||||||
|
<SelectItem
|
||||||
|
key={item.tb_regimebens_id}
|
||||||
|
value={String(item.tb_regimebens_id)}
|
||||||
|
>
|
||||||
|
{item.descricao}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* Situação */}
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<Controller
|
||||||
|
name="situacao"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={field.value === "A"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label>Ativo</Label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="descricao"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Descrição</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
<Button type="submit" className="cursor-pointer">
|
||||||
/>
|
Salvar
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Texto */}
|
{/* Campo oculto */}
|
||||||
<FormField
|
<input type="hidden" {...form.register("tb_regimecomunhao_id")} />
|
||||||
control={form.control}
|
</form>
|
||||||
name="texto"
|
</Form>
|
||||||
render={({ field }) => (
|
</DialogContent>
|
||||||
<FormItem>
|
</Dialog>
|
||||||
<FormLabel>Texto</FormLabel>
|
);
|
||||||
<FormControl>
|
|
||||||
<Input {...field} placeholder="Digite o texto" />
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Tipo */}
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="tb_regimebens_id"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Tipo</FormLabel>
|
|
||||||
<Select
|
|
||||||
value={String(field.value)}
|
|
||||||
// Converter o valor inteiro para ser aceito pelo zod
|
|
||||||
onValueChange={(val) => field.onChange(Number(val))}
|
|
||||||
>
|
|
||||||
<FormControl className="w-full">
|
|
||||||
<SelectTrigger>
|
|
||||||
<SelectValue placeholder="Escolha o tipo do andamento" />
|
|
||||||
</SelectTrigger>
|
|
||||||
</FormControl>
|
|
||||||
<SelectContent>
|
|
||||||
{gTBRegimeBens.map((item) => (
|
|
||||||
<SelectItem key={item.tb_regimebens_id} value={String(item.tb_regimebens_id)}>
|
|
||||||
{item.descricao}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Situação */}
|
|
||||||
<Controller
|
|
||||||
name="situacao"
|
|
||||||
control={form.control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<Checkbox
|
|
||||||
checked={field.value === "A"}
|
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
|
||||||
/>
|
|
||||||
<Label>Ativo</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
|
||||||
<DialogFooter className="mt-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
<Button type="submit" className="cursor-pointer">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("tb_regimecomunhao_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,126 +1,128 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||||
|
|
||||||
interface GTBRegimeComunhaoTableProps {
|
interface GTBRegimeComunhaoTableProps {
|
||||||
data: GTBRegimeComunhaoInterface[];
|
data: GTBRegimeComunhaoInterface[];
|
||||||
onEdit: (item: GTBRegimeComunhaoInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (
|
||||||
onDelete: (item: GTBRegimeComunhaoInterface, isEditingFormStatus: boolean) => void;
|
item: GTBRegimeComunhaoInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
|
onDelete: (
|
||||||
|
item: GTBRegimeComunhaoInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBRegimeComunhaoTable({
|
export default function GTBRegimeComunhaoTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GTBRegimeComunhaoTableProps) {
|
}: GTBRegimeComunhaoTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_regimecomunhao_id} className="cursor-pointer">
|
||||||
key={item.tb_regimecomunhao_id}
|
<TableCell className="font-medium">
|
||||||
className="cursor-pointer"
|
{item.tb_regimecomunhao_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_regimecomunhao_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuItem
|
||||||
{item.descricao}
|
className="cursor-pointer"
|
||||||
</TableCell>
|
onSelect={() => onDelete(item, true)}
|
||||||
|
>
|
||||||
<TableCell className="text-right">
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<DropdownMenu>
|
Remover
|
||||||
<DropdownMenuTrigger asChild>
|
</DropdownMenuItem>
|
||||||
<Button
|
</DropdownMenuGroup>
|
||||||
variant="outline"
|
</DropdownMenuContent>
|
||||||
size="icon"
|
</DropdownMenu>
|
||||||
className="cursor-pointer"
|
</TableCell>
|
||||||
>
|
</TableRow>
|
||||||
<EllipsisIcon />
|
))}
|
||||||
</Button>
|
</TableBody>
|
||||||
</DropdownMenuTrigger>
|
</Table>
|
||||||
|
);
|
||||||
<DropdownMenuContent side="left" align="start">
|
|
||||||
<DropdownMenuGroup>
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,21 +8,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -35,116 +35,131 @@ import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroI
|
||||||
type FormValues = z.infer<typeof GTBTipoLogradouroSchema>;
|
type FormValues = z.infer<typeof GTBTipoLogradouroSchema>;
|
||||||
|
|
||||||
interface GTBTipoLogradouroFormProps {
|
interface GTBTipoLogradouroFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBTipoLogradouroForm({ isOpen, data, onClose, onSave,buttonIsLoading }: GTBTipoLogradouroFormProps) {
|
export default function GTBTipoLogradouroForm({
|
||||||
// Inicializa o react-hook-form com schema zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(GTBTipoLogradouroSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
sistema_id: null,
|
buttonIsLoading,
|
||||||
tb_tipologradouro_id: 0,
|
}: GTBTipoLogradouroFormProps) {
|
||||||
situacao_id: null,
|
// Inicializa o react-hook-form com schema zod
|
||||||
descricao: "",
|
const form = useForm<FormValues>({
|
||||||
situacao: "A",
|
resolver: zodResolver(GTBTipoLogradouroSchema),
|
||||||
onr_tipo_logradouro_id: 0
|
defaultValues: {
|
||||||
},
|
sistema_id: null,
|
||||||
});
|
tb_tipologradouro_id: 0,
|
||||||
|
situacao_id: null,
|
||||||
|
descricao: "",
|
||||||
|
situacao: "A",
|
||||||
|
onr_tipo_logradouro_id: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>Tipo de Logradouro</DialogTitle>
|
||||||
Tipo de Logradouro
|
<DialogDescription>
|
||||||
</DialogTitle>
|
Crie ou edite um tipo de logradouro
|
||||||
<DialogDescription>
|
</DialogDescription>
|
||||||
Crie ou edite um tipo de logradouro
|
</DialogHeader>
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* ID do tipo logradouro na ONR */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="descricao"
|
name="onr_tipo_logradouro_id"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Descrição</FormLabel>
|
<FormLabel>ID do tipo logradouro na ONR</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
<Input {...field} placeholder="Digite o valor" />
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* ID do tipo logradouro na ONR */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="onr_tipo_logradouro_id"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>ID do tipo logradouro na ONR</FormLabel>
|
<Checkbox
|
||||||
<FormControl>
|
checked={field.value === "A"}
|
||||||
<Input {...field} placeholder="Digite o valor" />
|
onCheckedChange={(checked) =>
|
||||||
</FormControl>
|
field.onChange(checked ? "A" : "I")
|
||||||
<FormMessage />
|
}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<Label>Ativo</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Rodapé do Dialog */}
|
||||||
<Controller
|
<DialogFooter className="mt-4">
|
||||||
name="situacao"
|
<DialogClose asChild>
|
||||||
control={form.control}
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<div className="flex items-center space-x-2">
|
type="button"
|
||||||
<Checkbox
|
onClick={() => onClose(null, false)}
|
||||||
checked={field.value === "A"}
|
className="cursor-pointer"
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
>
|
||||||
/>
|
Cancelar
|
||||||
<Label>Ativo</Label>
|
</Button>
|
||||||
</div>
|
</DialogClose>
|
||||||
)}
|
{/* Botão de loading */}
|
||||||
/>
|
<LoadingButton
|
||||||
|
text="Salvar"
|
||||||
|
textLoading="Aguarde..."
|
||||||
|
type="submit"
|
||||||
|
loading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
{/* Campos ocultos */}
|
||||||
<DialogFooter className="mt-4">
|
<input type="hidden" {...form.register("tb_tipologradouro_id")} />
|
||||||
<DialogClose asChild>
|
<input type="hidden" {...form.register("sistema_id")} />
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
<input type="hidden" {...form.register("situacao_id")} />
|
||||||
Cancelar
|
<input type="hidden" {...form.register("onr_tipo_logradouro_id")} />
|
||||||
</Button>
|
</form>
|
||||||
</DialogClose>
|
</Form>
|
||||||
{/* Botão de loading */}
|
</DialogContent>
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
</Dialog>
|
||||||
</DialogFooter>
|
);
|
||||||
|
}
|
||||||
{/* Campos ocultos */}
|
|
||||||
<input type="hidden" {...form.register("tb_tipologradouro_id")} />
|
|
||||||
<input type="hidden" {...form.register("sistema_id")} />
|
|
||||||
<input type="hidden" {...form.register("situacao_id")} />
|
|
||||||
<input type="hidden" {...form.register("onr_tipo_logradouro_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,123 +1,127 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface";
|
import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroInterface";
|
||||||
|
|
||||||
interface GTBTipoLogradouroTableProps {
|
interface GTBTipoLogradouroTableProps {
|
||||||
data: GTBTipoLogradouroInterface[];
|
data: GTBTipoLogradouroInterface[];
|
||||||
onEdit: (item: GTBTipoLogradouroInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (
|
||||||
onDelete: (item: GTBTipoLogradouroInterface, isEditingFormStatus: boolean) => void;
|
item: GTBTipoLogradouroInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
|
onDelete: (
|
||||||
|
item: GTBTipoLogradouroInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
function StatusBadge({ situacao }: { situacao: "A" | "I" }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GTBTipoLogradouroTable({
|
export default function GTBTipoLogradouroTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: GTBTipoLogradouroTableProps) {
|
}: GTBTipoLogradouroTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.tb_tipologradouro_id} className="cursor-pointer">
|
||||||
key={item.tb_tipologradouro_id}
|
<TableCell className="font-medium">
|
||||||
className="cursor-pointer"
|
{item.tb_tipologradouro_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_tipologradouro_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,21 +8,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -34,96 +34,112 @@ import LoadingButton from "@/app/_components/loadingButton/LoadingButton";
|
||||||
type FormValues = z.infer<typeof TCensecSchema>;
|
type FormValues = z.infer<typeof TCensecSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TCensecForm({ isOpen, data, onClose, onSave, buttonIsLoading }: Props) {
|
export default function TCensecForm({
|
||||||
// Inicializa o react-hook-form com schema zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(TCensecSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
descricao: "",
|
buttonIsLoading,
|
||||||
situacao: SituacoesEnum.A,
|
}: Props) {
|
||||||
censec_id: 0,
|
// Inicializa o react-hook-form com schema zod
|
||||||
},
|
const form = useForm<FormValues>({
|
||||||
});
|
resolver: zodResolver(TCensecSchema),
|
||||||
|
defaultValues: {
|
||||||
|
descricao: "",
|
||||||
|
situacao: SituacoesEnum.A,
|
||||||
|
censec_id: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Censec</DialogTitle>
|
||||||
|
<DialogDescription>Tipos de Centrais</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
<DialogHeader>
|
<Form {...form}>
|
||||||
<DialogTitle>
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
Censec
|
{/* Descrição */}
|
||||||
</DialogTitle>
|
<FormField
|
||||||
<DialogDescription>
|
control={form.control}
|
||||||
Tipos de Centrais
|
name="descricao"
|
||||||
</DialogDescription>
|
render={({ field }) => (
|
||||||
</DialogHeader>
|
<FormItem>
|
||||||
|
<FormLabel>Descrição</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type="text"
|
||||||
|
{...field}
|
||||||
|
placeholder="Digite a descrição"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form {...form}>
|
{/* Situação */}
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<Controller
|
||||||
|
name="situacao"
|
||||||
|
control={form.control}
|
||||||
|
render={({ field }) => (
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={field.value === "A"}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Label>Ativo</Label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Rodapé do Dialog */}
|
||||||
<FormField
|
<DialogFooter className="mt-4">
|
||||||
control={form.control}
|
<DialogClose asChild>
|
||||||
name="descricao"
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<FormItem>
|
type="button"
|
||||||
<FormLabel>Descrição</FormLabel>
|
onClick={() => onClose(null, false)}
|
||||||
<FormControl>
|
className="cursor-pointer"
|
||||||
<Input type="text" {...field} placeholder="Digite a descrição" />
|
>
|
||||||
</FormControl>
|
Cancelar
|
||||||
<FormMessage />
|
</Button>
|
||||||
</FormItem>
|
</DialogClose>
|
||||||
)}
|
{/* Botão de loading */}
|
||||||
/>
|
<LoadingButton
|
||||||
|
text="Salvar"
|
||||||
|
textLoading="Aguarde..."
|
||||||
|
type="submit"
|
||||||
|
loading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Campo oculto */}
|
||||||
<Controller
|
<input type="hidden" {...form.register("censec_id")} />
|
||||||
name="situacao"
|
</form>
|
||||||
control={form.control}
|
</Form>
|
||||||
render={({ field }) => (
|
</DialogContent>
|
||||||
<div className="flex items-center space-x-2">
|
</Dialog>
|
||||||
<Checkbox
|
);
|
||||||
checked={field.value === "A"}
|
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
|
||||||
/>
|
|
||||||
<Label>Ativo</Label>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
|
||||||
<DialogFooter className="mt-4">
|
|
||||||
<DialogClose asChild>
|
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
|
||||||
Cancelar
|
|
||||||
</Button>
|
|
||||||
</DialogClose>
|
|
||||||
{/* Botão de loading */}
|
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("censec_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,125 +1,121 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import TCensecInterface from "../../_interfaces/TCensecInterface";
|
import TCensecInterface from "../../_interfaces/TCensecInterface";
|
||||||
|
|
||||||
interface TCensecTableProps {
|
interface TCensecTableProps {
|
||||||
data: TCensecInterface[];
|
data: TCensecInterface[];
|
||||||
onEdit: (item: TCensecInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (item: TCensecInterface, isEditingFormStatus: boolean) => void;
|
||||||
onDelete: (item: TCensecInterface, isEditingFormStatus: boolean) => void;
|
onDelete: (item: TCensecInterface, isEditingFormStatus: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TCensecTable({
|
export default function TCensecTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: TCensecTableProps) {
|
}: TCensecTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>CBO</TableHead>
|
<TableHead>CBO</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow key={item.censec_id} className="cursor-pointer">
|
||||||
key={item.censec_id}
|
<TableCell className="font-medium">{item.censec_id}</TableCell>
|
||||||
className="cursor-pointer"
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.censec_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,124 +1,142 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from 'zod';
|
import z from "zod";
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from "react";
|
||||||
import { useForm, Controller } from 'react-hook-form';
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import LoadingButton from '@/app/_components/loadingButton/LoadingButton';
|
import LoadingButton from "@/app/_components/loadingButton/LoadingButton";
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from "@/components/ui/form";
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
import { TCensecNaturezaLitigioSchema } from '../../_schemas/TCensecNaturezaLitigioSchema';
|
import { TCensecNaturezaLitigioSchema } from "../../_schemas/TCensecNaturezaLitigioSchema";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof TCensecNaturezaLitigioSchema>;
|
type FormValues = z.infer<typeof TCensecNaturezaLitigioSchema>;
|
||||||
|
|
||||||
interface TCensecNaturezaLitigioFormProps {
|
interface TCensecNaturezaLitigioFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
buttonIsLoading: boolean;
|
buttonIsLoading: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TCensecNaturezaLitigioForm({isOpen, data, onClose, onSave, buttonIsLoading}: TCensecNaturezaLitigioFormProps) {
|
export default function TCensecNaturezaLitigioForm({
|
||||||
const form = useForm<FormValues>({
|
isOpen,
|
||||||
resolver: zodResolver(TCensecNaturezaLitigioSchema),
|
data,
|
||||||
defaultValues: {
|
onClose,
|
||||||
censec_naturezalitigio_id: 0,
|
onSave,
|
||||||
descricao: "",
|
buttonIsLoading,
|
||||||
situacao: "A"
|
}: TCensecNaturezaLitigioFormProps) {
|
||||||
}
|
const form = useForm<FormValues>({
|
||||||
});
|
resolver: zodResolver(TCensecNaturezaLitigioSchema),
|
||||||
|
defaultValues: {
|
||||||
|
censec_naturezalitigio_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
situacao: "A",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Natureza do Litígio</DialogTitle>
|
<DialogTitle>Natureza do Litígio</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Crie ou edite uma natureza do litígio
|
Crie ou edite uma natureza do litígio
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="descricao"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>Descrição</FormLabel>
|
<Checkbox
|
||||||
<FormControl>
|
checked={field.value === "A"}
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
onCheckedChange={(checked) =>
|
||||||
</FormControl>
|
field.onChange(checked ? "A" : "I")
|
||||||
<FormMessage />
|
}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<Label>Ativo</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Rodapé */}
|
||||||
<Controller
|
<DialogFooter className="mt-4">
|
||||||
name="situacao"
|
<DialogClose asChild>
|
||||||
control={form.control}
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<div className="flex items-center space-x-2">
|
type="button"
|
||||||
<Checkbox
|
onClick={() => onClose(null, false)}
|
||||||
checked={field.value === "A"}
|
>
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
Cancelar
|
||||||
/>
|
</Button>
|
||||||
<Label>Ativo</Label>
|
</DialogClose>
|
||||||
</div>
|
{/* Botão de loading */}
|
||||||
)}
|
<LoadingButton
|
||||||
/>
|
text="Salvar"
|
||||||
|
textLoading="Aguarde..."
|
||||||
|
type="submit"
|
||||||
|
loading={buttonIsLoading}
|
||||||
|
/>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
|
{/* Campo oculto */}
|
||||||
{/* Rodapé */}
|
<input
|
||||||
<DialogFooter className="mt-4">
|
type="hidden"
|
||||||
<DialogClose asChild>
|
{...form.register("censec_naturezalitigio_id")}
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
/>
|
||||||
Cancelar
|
</form>
|
||||||
</Button>
|
</Form>
|
||||||
</DialogClose>
|
</DialogContent>
|
||||||
{/* Botão de loading */}
|
</Dialog>
|
||||||
<LoadingButton text="Salvar" textLoading="Aguarde..." type="submit" loading={buttonIsLoading} />
|
);
|
||||||
</DialogFooter>
|
}
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register('censec_naturezalitigio_id')} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
|
|
@ -7,7 +7,7 @@ import {
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
|
|
@ -15,25 +15,30 @@ import {
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface";
|
import { TCensecNaturezaLitigioInterface } from "../../_interfaces/TCensecNaturezaLitigioInterface";
|
||||||
|
|
||||||
interface TCensecNaturezaLitigioTableProps {
|
interface TCensecNaturezaLitigioTableProps {
|
||||||
data: TCensecNaturezaLitigioInterface[];
|
data: TCensecNaturezaLitigioInterface[];
|
||||||
onEdit: (item: TCensecNaturezaLitigioInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (
|
||||||
onDelete: (item: TCensecNaturezaLitigioInterface, isEditingFormStatus: boolean) => void;
|
item: TCensecNaturezaLitigioInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
|
onDelete: (
|
||||||
|
item: TCensecNaturezaLitigioInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
function StatusBadge({ situacao }: { situacao: "A" | "I" }) {
|
||||||
const isActive = situacao === 'A';
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
@ -42,7 +47,9 @@ function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
|
>
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
@ -51,7 +58,7 @@ function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
||||||
export default function TCensecNaturezaLitigioTable({
|
export default function TCensecNaturezaLitigioTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: TCensecNaturezaLitigioTableProps) {
|
}: TCensecNaturezaLitigioTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
|
|
@ -120,4 +127,4 @@ export default function TCensecNaturezaLitigioTable({
|
||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from 'zod';
|
import z from "zod";
|
||||||
import { useEffect } from 'react';
|
import { useEffect } from "react";
|
||||||
import { useForm, Controller } from 'react-hook-form';
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
|
|
@ -14,22 +14,22 @@ import {
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from "@/components/ui/form";
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
||||||
import MainEditor from '@/components/MainEditor';
|
import MainEditor from "@/components/MainEditor";
|
||||||
import { TMinutaInterface } from '../../_interfaces/TMinutaInterface';
|
import { TMinutaInterface } from "../../_interfaces/TMinutaInterface";
|
||||||
import { TMinutaSchema } from '../../_schemas/TMinutaSchema';
|
import { TMinutaSchema } from "../../_schemas/TMinutaSchema";
|
||||||
|
|
||||||
type FormValues = z.infer<typeof TMinutaSchema>;
|
type FormValues = z.infer<typeof TMinutaSchema>;
|
||||||
|
|
||||||
|
|
@ -44,18 +44,17 @@ export default function TMinutaForm({
|
||||||
isOpen,
|
isOpen,
|
||||||
data,
|
data,
|
||||||
onClose,
|
onClose,
|
||||||
onSave
|
onSave,
|
||||||
}: TMinutaFormProps) {
|
}: TMinutaFormProps) {
|
||||||
|
|
||||||
const form = useForm<FormValues>({
|
const form = useForm<FormValues>({
|
||||||
resolver: zodResolver(TMinutaSchema),
|
resolver: zodResolver(TMinutaSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
minuta_id: 0,
|
minuta_id: 0,
|
||||||
natureza_id: undefined,
|
natureza_id: undefined,
|
||||||
descricao: '',
|
descricao: "",
|
||||||
situacao: 'A',
|
situacao: "A",
|
||||||
texto: '',
|
texto: "",
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -69,17 +68,17 @@ export default function TMinutaForm({
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="mx-auto"> {/* tamanho maior para comportar o editor */}
|
<DialogContent className="mx-auto">
|
||||||
|
{" "}
|
||||||
|
{/* tamanho maior para comportar o editor */}
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Minuta</DialogTitle>
|
<DialogTitle>Minuta</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Crie ou edite uma minuta de ato notarial.
|
Crie ou edite uma minuta de ato notarial.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Descrição */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
|
|
@ -88,7 +87,10 @@ export default function TMinutaForm({
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Descrição</FormLabel>
|
<FormLabel>Descrição</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input {...field} placeholder="Digite a descrição da minuta" />
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="Digite a descrição da minuta"
|
||||||
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
@ -103,7 +105,9 @@ export default function TMinutaForm({
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={field.value === "A"}
|
checked={field.value === "A"}
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
onCheckedChange={(checked) =>
|
||||||
|
field.onChange(checked ? "A" : "I")
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
<Label>{field.value === "A" ? "Ativo" : "Inativo"}</Label>
|
<Label>{field.value === "A" ? "Ativo" : "Inativo"}</Label>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -119,7 +123,7 @@ export default function TMinutaForm({
|
||||||
<MainEditor
|
<MainEditor
|
||||||
initialValue={field.value || ""}
|
initialValue={field.value || ""}
|
||||||
onEditorChange={field.onChange}
|
onEditorChange={field.onChange}
|
||||||
margins={{ top: '2', bottom: '2', left: '3', right: '3' }}
|
margins={{ top: "2", bottom: "2", left: "3", right: "3" }}
|
||||||
size={{ width: 800, height: 500 }}
|
size={{ width: 800, height: 500 }}
|
||||||
/>
|
/>
|
||||||
{form.formState.errors.texto && (
|
{form.formState.errors.texto && (
|
||||||
|
|
@ -134,7 +138,11 @@ export default function TMinutaForm({
|
||||||
{/* Rodapé do Dialog */}
|
{/* Rodapé do Dialog */}
|
||||||
<DialogFooter className="mt-4">
|
<DialogFooter className="mt-4">
|
||||||
<DialogClose asChild>
|
<DialogClose asChild>
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)}>
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
type="button"
|
||||||
|
onClick={() => onClose(null, false)}
|
||||||
|
>
|
||||||
Cancelar
|
Cancelar
|
||||||
</Button>
|
</Button>
|
||||||
</DialogClose>
|
</DialogClose>
|
||||||
|
|
@ -146,7 +154,6 @@ export default function TMinutaForm({
|
||||||
{/* Campos ocultos */}
|
{/* Campos ocultos */}
|
||||||
<input type="hidden" {...form.register("minuta_id")} />
|
<input type="hidden" {...form.register("minuta_id")} />
|
||||||
<input type="hidden" {...form.register("natureza_id")} />
|
<input type="hidden" {...form.register("natureza_id")} />
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
@ -30,7 +30,7 @@ interface TMinutaTableProps {
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
function StatusBadge({ situacao }: { situacao: "A" | "I" }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm mr-2";
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm mr-2";
|
||||||
|
|
@ -42,15 +42,15 @@ function StatusBadge({ situacao }: { situacao: 'A' | 'I' }) {
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
|
>
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TMinutaTable({
|
export default function TMinutaTable({ data }: TMinutaTableProps) {
|
||||||
data,
|
|
||||||
}: TMinutaTableProps) {
|
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
|
|
@ -64,16 +64,17 @@ export default function TMinutaTable({
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.length === 0 ? (
|
{data.length === 0 ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={4} className="text-center text-muted-foreground">
|
<TableCell
|
||||||
|
colSpan={4}
|
||||||
|
className="text-center text-muted-foreground"
|
||||||
|
>
|
||||||
Nenhuma minuta encontrada.
|
Nenhuma minuta encontrada.
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
data.map((item) => (
|
data.map((item) => (
|
||||||
<TableRow key={item.t_minuta_id} className="cursor-pointer">
|
<TableRow key={item.t_minuta_id} className="cursor-pointer">
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">{item.t_minuta_id}</TableCell>
|
||||||
{item.t_minuta_id}
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<StatusBadge situacao={item.situacao} />
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,30 +8,30 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
SelectItem,
|
SelectItem,
|
||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue
|
SelectValue,
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
|
|
||||||
import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema";
|
import { TTBAndamentoServicoSchema } from "../../_schemas/TTBAndamentoServicoSchema";
|
||||||
|
|
@ -40,150 +40,164 @@ import { tipoEnum } from "../../_interfaces/TTBAndamentoServicoInterface";
|
||||||
type FormValues = z.infer<typeof TTBAndamentoServicoSchema>;
|
type FormValues = z.infer<typeof TTBAndamentoServicoSchema>;
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TTBAndamentoServicoForm({ isOpen, data, onClose, onSave }: Props) {
|
export default function TTBAndamentoServicoForm({
|
||||||
// Inicializa o react-hook-form com schema zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(TTBAndamentoServicoSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
descricao: "",
|
}: Props) {
|
||||||
tipo: tipoEnum.OUTROS,
|
// Inicializa o react-hook-form com schema zod
|
||||||
situacao: "A",
|
const form = useForm<FormValues>({
|
||||||
usa_email: "I",
|
resolver: zodResolver(TTBAndamentoServicoSchema),
|
||||||
tb_andamentoservico_id: 0,
|
defaultValues: {
|
||||||
},
|
descricao: "",
|
||||||
});
|
tipo: tipoEnum.OUTROS,
|
||||||
|
situacao: "A",
|
||||||
|
usa_email: "I",
|
||||||
|
tb_andamentoservico_id: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Opções do Select mapeadas a partir do enum
|
// Opções do Select mapeadas a partir do enum
|
||||||
const tipoOptions = Object.values(tipoEnum).map((value) => ({
|
const tipoOptions = Object.values(tipoEnum).map((value) => ({
|
||||||
value,
|
value,
|
||||||
label:
|
label:
|
||||||
value === "C" ? "Cancelado" :
|
value === "C"
|
||||||
value === "E" ? "Estornado" :
|
? "Cancelado"
|
||||||
value === "PT" ? "Protocolado" :
|
: value === "E"
|
||||||
value === "PD" ? "Pedido" :
|
? "Estornado"
|
||||||
value === "NC" ? "Não Consta" :
|
: value === "PT"
|
||||||
"Outros"
|
? "Protocolado"
|
||||||
}));
|
: value === "PD"
|
||||||
|
? "Pedido"
|
||||||
|
: value === "NC"
|
||||||
|
? "Não Consta"
|
||||||
|
: "Outros",
|
||||||
|
}));
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>Andamentos</DialogTitle>
|
||||||
Andamentos
|
<DialogDescription>Controle de andamentos de atos</DialogDescription>
|
||||||
</DialogTitle>
|
</DialogHeader>
|
||||||
<DialogDescription>
|
|
||||||
Controle de andamentos de atos
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Tipo */}
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="descricao"
|
name="tipo"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>Descrição</FormLabel>
|
<FormLabel>Tipo</FormLabel>
|
||||||
<FormControl>
|
<Select value={field.value} onValueChange={field.onChange}>
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
<FormControl className="w-full">
|
||||||
</FormControl>
|
<SelectTrigger>
|
||||||
<FormMessage />
|
<SelectValue placeholder="Escolha o tipo do andamento" />
|
||||||
</FormItem>
|
</SelectTrigger>
|
||||||
)}
|
</FormControl>
|
||||||
/>
|
<SelectContent>
|
||||||
|
{tipoOptions.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Tipo */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="tipo"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>Tipo</FormLabel>
|
<Checkbox
|
||||||
<Select value={field.value} onValueChange={field.onChange}>
|
checked={field.value === "A"}
|
||||||
<FormControl className="w-full">
|
onCheckedChange={(checked) =>
|
||||||
<SelectTrigger>
|
field.onChange(checked ? "A" : "I")
|
||||||
<SelectValue placeholder="Escolha o tipo do andamento" />
|
}
|
||||||
</SelectTrigger>
|
/>
|
||||||
</FormControl>
|
<Label>Ativo</Label>
|
||||||
<SelectContent>
|
</div>
|
||||||
{tipoOptions.map((option) => (
|
)}
|
||||||
<SelectItem key={option.value} value={option.value}>
|
/>
|
||||||
{option.label}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Usar e-mail */}
|
||||||
<Controller
|
<Controller
|
||||||
name="situacao"
|
name="usa_email"
|
||||||
control={form.control}
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<div className="flex items-center space-x-2">
|
<div className="flex items-center space-x-2">
|
||||||
<Checkbox
|
<Checkbox
|
||||||
checked={field.value === "A"}
|
checked={field.value === "A"}
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
onCheckedChange={(checked) =>
|
||||||
/>
|
field.onChange(checked ? "A" : "I")
|
||||||
<Label>Ativo</Label>
|
}
|
||||||
</div>
|
/>
|
||||||
)}
|
<Label>Usar e-mail</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Usar e-mail */}
|
{/* Rodapé do Dialog */}
|
||||||
<Controller
|
<DialogFooter className="mt-4">
|
||||||
name="usa_email"
|
<DialogClose asChild>
|
||||||
control={form.control}
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<div className="flex items-center space-x-2">
|
type="button"
|
||||||
<Checkbox
|
onClick={() => onClose(null, false)}
|
||||||
checked={field.value === "A"}
|
className="cursor-pointer"
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
>
|
||||||
/>
|
Cancelar
|
||||||
<Label>Usar e-mail</Label>
|
</Button>
|
||||||
</div>
|
</DialogClose>
|
||||||
)}
|
<Button type="submit" className="cursor-pointer">
|
||||||
/>
|
Salvar
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
{/* Campo oculto */}
|
||||||
<DialogFooter className="mt-4">
|
<input type="hidden" {...form.register("tb_andamentoservico_id")} />
|
||||||
<DialogClose asChild>
|
</form>
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
</Form>
|
||||||
Cancelar
|
</DialogContent>
|
||||||
</Button>
|
</Dialog>
|
||||||
</DialogClose>
|
);
|
||||||
<Button type="submit" className="cursor-pointer">
|
|
||||||
Salvar
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("tb_andamentoservico_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,124 +1,131 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface";
|
import TTBAndamentoServicoInteface from "../../_interfaces/TTBAndamentoServicoInterface";
|
||||||
|
|
||||||
interface TTBAndamentoServicoTableProps {
|
interface TTBAndamentoServicoTableProps {
|
||||||
data: TTBAndamentoServicoInteface[];
|
data: TTBAndamentoServicoInteface[];
|
||||||
onEdit: (item: TTBAndamentoServicoInteface, isEditingFormStatus: boolean) => void;
|
onEdit: (
|
||||||
onDelete: (item: TTBAndamentoServicoInteface, isEditingFormStatus: boolean) => void;
|
item: TTBAndamentoServicoInteface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
|
onDelete: (
|
||||||
|
item: TTBAndamentoServicoInteface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TTBAndamentoServicoTable({
|
export default function TTBAndamentoServicoTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: TTBAndamentoServicoTableProps) {
|
}: TTBAndamentoServicoTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={item.tb_andamentoservico_id}
|
key={item.tb_andamentoservico_id}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{item.tb_andamentoservico_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_andamentoservico_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
|
@ -8,21 +8,21 @@ import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Checkbox } from "@/components/ui/checkbox";
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogClose,
|
DialogClose,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle
|
DialogTitle,
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
|
|
@ -33,95 +33,105 @@ import { situacaoEnum } from "../../_interfaces/TTBReconhecimentoTipoInterface";
|
||||||
type FormValues = z.infer<typeof TTBReconhecimentoTipoSchema>;
|
type FormValues = z.infer<typeof TTBReconhecimentoTipoSchema>;
|
||||||
|
|
||||||
interface TTBReconhecimentoTipoFormProps {
|
interface TTBReconhecimentoTipoFormProps {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
data: FormValues | null;
|
data: FormValues | null;
|
||||||
onClose: (item: null, isFormStatus: boolean) => void;
|
onClose: (item: null, isFormStatus: boolean) => void;
|
||||||
onSave: (data: FormValues) => void;
|
onSave: (data: FormValues) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TTBReconhecimentoTipoForm({ isOpen, data, onClose, onSave }: TTBReconhecimentoTipoFormProps) {
|
export default function TTBReconhecimentoTipoForm({
|
||||||
// Inicializa o react-hook-form com schema zod
|
isOpen,
|
||||||
const form = useForm<FormValues>({
|
data,
|
||||||
resolver: zodResolver(TTBReconhecimentoTipoSchema),
|
onClose,
|
||||||
defaultValues: {
|
onSave,
|
||||||
tb_reconhecimentotipo_id: 0,
|
}: TTBReconhecimentoTipoFormProps) {
|
||||||
descricao: "",
|
// Inicializa o react-hook-form com schema zod
|
||||||
situacao: situacaoEnum.ATIVO,
|
const form = useForm<FormValues>({
|
||||||
},
|
resolver: zodResolver(TTBReconhecimentoTipoSchema),
|
||||||
});
|
defaultValues: {
|
||||||
|
tb_reconhecimentotipo_id: 0,
|
||||||
|
descricao: "",
|
||||||
|
situacao: situacaoEnum.ATIVO,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// Atualiza o formulário quando recebe dados para edição
|
// Atualiza o formulário quando recebe dados para edição
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) form.reset(data);
|
if (data) form.reset(data);
|
||||||
}, [data, form]);
|
}, [data, form]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) onClose(null, false);
|
if (!open) onClose(null, false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DialogContent className="sm:max-w-[425px]">
|
<DialogContent className="sm:max-w-[425px]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>
|
<DialogTitle>Reconhecimentos</DialogTitle>
|
||||||
Reconhecimentos
|
<DialogDescription>Tipos de Reconhecimentos</DialogDescription>
|
||||||
</DialogTitle>
|
</DialogHeader>
|
||||||
<DialogDescription>
|
|
||||||
Tipos de Reconhecimentos
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSave)} className="space-y-6">
|
<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>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Descrição */}
|
{/* Situação */}
|
||||||
<FormField
|
<Controller
|
||||||
control={form.control}
|
name="situacao"
|
||||||
name="descricao"
|
control={form.control}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<div className="flex items-center space-x-2">
|
||||||
<FormLabel>Descrição</FormLabel>
|
<Checkbox
|
||||||
<FormControl>
|
checked={field.value === "A"}
|
||||||
<Input {...field} placeholder="Digite a descrição" />
|
onCheckedChange={(checked) =>
|
||||||
</FormControl>
|
field.onChange(checked ? "A" : "I")
|
||||||
<FormMessage />
|
}
|
||||||
</FormItem>
|
/>
|
||||||
)}
|
<Label>Ativo</Label>
|
||||||
/>
|
</div>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
{/* Situação */}
|
{/* Rodapé do Dialog */}
|
||||||
<Controller
|
<DialogFooter className="mt-4">
|
||||||
name="situacao"
|
<DialogClose asChild>
|
||||||
control={form.control}
|
<Button
|
||||||
render={({ field }) => (
|
variant="outline"
|
||||||
<div className="flex items-center space-x-2">
|
type="button"
|
||||||
<Checkbox
|
onClick={() => onClose(null, false)}
|
||||||
checked={field.value === "A"}
|
className="cursor-pointer"
|
||||||
onCheckedChange={(checked) => field.onChange(checked ? "A" : "I")}
|
>
|
||||||
/>
|
Cancelar
|
||||||
<Label>Ativo</Label>
|
</Button>
|
||||||
</div>
|
</DialogClose>
|
||||||
)}
|
<Button type="submit" className="cursor-pointer">
|
||||||
/>
|
Salvar
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
|
||||||
{/* Rodapé do Dialog */}
|
{/* Campo oculto */}
|
||||||
<DialogFooter className="mt-4">
|
<input
|
||||||
<DialogClose asChild>
|
type="hidden"
|
||||||
<Button variant="outline" type="button" onClick={() => onClose(null, false)} className="cursor-pointer">
|
{...form.register("tb_reconhecimentotipo_id")}
|
||||||
Cancelar
|
/>
|
||||||
</Button>
|
</form>
|
||||||
</DialogClose>
|
</Form>
|
||||||
<Button type="submit" className="cursor-pointer">
|
</DialogContent>
|
||||||
Salvar
|
</Dialog>
|
||||||
</Button>
|
);
|
||||||
</DialogFooter>
|
|
||||||
|
|
||||||
{/* Campo oculto */}
|
|
||||||
<input type="hidden" {...form.register("tb_reconhecimentotipo_id")} />
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,124 +1,131 @@
|
||||||
'use client';
|
"use client";
|
||||||
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuGroup,
|
DropdownMenuGroup,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
TableCell,
|
TableCell,
|
||||||
TableHead,
|
TableHead,
|
||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
|
|
||||||
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
import { EllipsisIcon, PencilIcon, Trash2Icon } from "lucide-react";
|
||||||
import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface";
|
import TTBReconhecimentoTipoInterface from "../../_interfaces/TTBReconhecimentoTipoInterface";
|
||||||
|
|
||||||
interface TTBReconhecimentoTipoTableProps {
|
interface TTBReconhecimentoTipoTableProps {
|
||||||
data: TTBReconhecimentoTipoInterface[];
|
data: TTBReconhecimentoTipoInterface[];
|
||||||
onEdit: (item: TTBReconhecimentoTipoInterface, isEditingFormStatus: boolean) => void;
|
onEdit: (
|
||||||
onDelete: (item: TTBReconhecimentoTipoInterface, isEditingFormStatus: boolean) => void;
|
item: TTBReconhecimentoTipoInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
|
onDelete: (
|
||||||
|
item: TTBReconhecimentoTipoInterface,
|
||||||
|
isEditingFormStatus: boolean,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderiza o badge de situação
|
* Renderiza o badge de situação
|
||||||
*/
|
*/
|
||||||
function StatusBadge({ situacao }: { situacao: string }) {
|
function StatusBadge({ situacao }: { situacao: string }) {
|
||||||
const isActive = situacao === "A";
|
const isActive = situacao === "A";
|
||||||
|
|
||||||
const baseClasses =
|
const baseClasses = "text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
||||||
"text-xs font-medium px-2.5 py-0.5 rounded-sm me-2";
|
|
||||||
|
|
||||||
const activeClasses =
|
const activeClasses =
|
||||||
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300";
|
||||||
|
|
||||||
const inactiveClasses =
|
const inactiveClasses =
|
||||||
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-300";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}>
|
<span
|
||||||
{isActive ? "Ativo" : "Inativo"}
|
className={`${baseClasses} ${isActive ? activeClasses : inactiveClasses}`}
|
||||||
</span>
|
>
|
||||||
);
|
{isActive ? "Ativo" : "Inativo"}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function TTBReconhecimentoTipoTable({
|
export default function TTBReconhecimentoTipoTable({
|
||||||
data,
|
data,
|
||||||
onEdit,
|
onEdit,
|
||||||
onDelete
|
onDelete,
|
||||||
}: TTBReconhecimentoTipoTableProps) {
|
}: TTBReconhecimentoTipoTableProps) {
|
||||||
return (
|
return (
|
||||||
<Table>
|
<Table>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableHead>#</TableHead>
|
<TableHead>#</TableHead>
|
||||||
<TableHead>Situação</TableHead>
|
<TableHead>Situação</TableHead>
|
||||||
<TableHead>Descrição</TableHead>
|
<TableHead>Descrição</TableHead>
|
||||||
<TableHead className="text-right">Ações</TableHead>
|
<TableHead className="text-right">Ações</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
|
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{data.map((item) => (
|
{data.map((item) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={item.tb_reconhecimentotipo_id}
|
key={item.tb_reconhecimentotipo_id}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{item.tb_reconhecimentotipo_id}
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>
|
||||||
|
<StatusBadge situacao={item.situacao} />
|
||||||
|
</TableCell>
|
||||||
|
|
||||||
|
<TableCell>{item.descricao}</TableCell>
|
||||||
|
|
||||||
|
<TableCell className="text-right">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<EllipsisIcon />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
|
||||||
|
<DropdownMenuContent side="left" align="start">
|
||||||
|
<DropdownMenuGroup>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
|
onSelect={() => onEdit(item, true)}
|
||||||
>
|
>
|
||||||
<TableCell className="font-medium">
|
<PencilIcon className="mr-2 h-4 w-4" />
|
||||||
{item.tb_reconhecimentotipo_id}
|
Editar
|
||||||
</TableCell>
|
</DropdownMenuItem>
|
||||||
|
|
||||||
<TableCell>
|
<DropdownMenuSeparator />
|
||||||
<StatusBadge situacao={item.situacao} />
|
|
||||||
</TableCell>
|
|
||||||
|
|
||||||
<TableCell>{item.descricao}</TableCell>
|
<DropdownMenuItem
|
||||||
|
className="cursor-pointer"
|
||||||
<TableCell className="text-right">
|
onSelect={() => onDelete(item, true)}
|
||||||
<DropdownMenu>
|
>
|
||||||
<DropdownMenuTrigger asChild>
|
<Trash2Icon className="mr-2 h-4 w-4" />
|
||||||
<Button
|
Remover
|
||||||
variant="outline"
|
</DropdownMenuItem>
|
||||||
size="icon"
|
</DropdownMenuGroup>
|
||||||
className="cursor-pointer"
|
</DropdownMenuContent>
|
||||||
>
|
</DropdownMenu>
|
||||||
<EllipsisIcon />
|
</TableCell>
|
||||||
</Button>
|
</TableRow>
|
||||||
</DropdownMenuTrigger>
|
))}
|
||||||
|
</TableBody>
|
||||||
<DropdownMenuContent side="left" align="start">
|
</Table>
|
||||||
<DropdownMenuGroup>
|
);
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onEdit(item, true)}
|
|
||||||
>
|
|
||||||
<PencilIcon className="mr-2 h-4 w-4" />
|
|
||||||
Editar
|
|
||||||
</DropdownMenuItem>
|
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
|
||||||
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="cursor-pointer"
|
|
||||||
onSelect={() => onDelete(item, true)}
|
|
||||||
>
|
|
||||||
<Trash2Icon className="mr-2 h-4 w-4" />
|
|
||||||
Remover
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuGroup>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
))}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,85 +2,80 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GCidadeIndexData() {
|
export default async function GCidadeIndexData() {
|
||||||
|
return Promise.resolve({
|
||||||
return Promise.resolve({
|
status: 200,
|
||||||
status: 200,
|
message: "Dados localizados",
|
||||||
message: "Dados localizados",
|
data: [
|
||||||
data: [
|
{
|
||||||
{
|
cidade_id: 1,
|
||||||
"cidade_id": 1,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Acrelândia",
|
||||||
"cidade_nome": "Acrelândia",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 2,
|
||||||
"cidade_id": 2,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Assis Brasil",
|
||||||
"cidade_nome": "Assis Brasil",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 3,
|
||||||
"cidade_id": 3,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Brasiléia",
|
||||||
"cidade_nome": "Brasiléia",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 4,
|
||||||
"cidade_id": 4,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Bujari",
|
||||||
"cidade_nome": "Bujari",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 5,
|
||||||
"cidade_id": 5,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Capixaba",
|
||||||
"cidade_nome": "Capixaba",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 6,
|
||||||
"cidade_id": 6,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Cruzeiro do Sul",
|
||||||
"cidade_nome": "Cruzeiro do Sul",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 7,
|
||||||
"cidade_id": 7,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Epitaciolândia",
|
||||||
"cidade_nome": "Epitaciolândia",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 8,
|
||||||
"cidade_id": 8,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Feijó",
|
||||||
"cidade_nome": "Feijó",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 9,
|
||||||
"cidade_id": 9,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Jordão",
|
||||||
"cidade_nome": "Jordão",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
},
|
{
|
||||||
{
|
cidade_id: 10,
|
||||||
"cidade_id": 10,
|
uf: "AC",
|
||||||
"uf": "AC",
|
cidade_nome: "Mâncio Lima",
|
||||||
"cidade_nome": "Mâncio Lima",
|
codigo_ibge: null,
|
||||||
"codigo_ibge": null,
|
codigo_gyn: null,
|
||||||
"codigo_gyn": null
|
},
|
||||||
}
|
],
|
||||||
]
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,9 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import GCidadeInterface from "../../_interfaces/GCidadeInterface";
|
import GCidadeInterface from "../../_interfaces/GCidadeInterface";
|
||||||
|
|
||||||
export default async function GCidadeRemoveData(data: GCidadeInterface) {
|
export default async function GCidadeRemoveData(data: GCidadeInterface) {
|
||||||
|
return Promise.resolve({
|
||||||
return Promise.resolve({
|
status: 200,
|
||||||
status: 200,
|
message: "Dados removidos",
|
||||||
message: "Dados removidos",
|
data: null,
|
||||||
data: null
|
});
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,12 @@ import GCidadeInterface from "../../_interfaces/GCidadeInterface";
|
||||||
|
|
||||||
// Função assíncrona responsável por salvar dados de cidades
|
// Função assíncrona responsável por salvar dados de cidades
|
||||||
export default async function GCidadeSaveData(data: GCidadeInterface) {
|
export default async function GCidadeSaveData(data: GCidadeInterface) {
|
||||||
|
// Log para indicar que a função foi chamada
|
||||||
|
console.log("chegou");
|
||||||
|
|
||||||
// Log para indicar que a função foi chamada
|
// Retorna uma Promise resolvida simulando resposta da API
|
||||||
console.log("chegou");
|
return Promise.resolve({
|
||||||
|
status: 200, // Código de status fictício
|
||||||
// Retorna uma Promise resolvida simulando resposta da API
|
message: "Dados salvos", // Mensagem de sucesso
|
||||||
return Promise.resolve({
|
});
|
||||||
status: 200, // Código de status fictício
|
|
||||||
message: "Dados salvos" // Mensagem de sucesso
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,13 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
async function executeGMedidaTipoIndexData() {
|
async function executeGMedidaTipoIndexData() {
|
||||||
const api = new API();
|
const api = new API();
|
||||||
return await api.send({
|
return await api.send({
|
||||||
method: Methods.GET,
|
method: Methods.GET,
|
||||||
endpoint: `administrativo/g_medida_tipo/`
|
endpoint: `administrativo/g_medida_tipo/`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GMedidaTipoIndexData = withClientErrorHandler(executeGMedidaTipoIndexData)
|
export const GMedidaTipoIndexData = withClientErrorHandler(
|
||||||
|
executeGMedidaTipoIndexData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGMedidaTipoRemoveData(data: GMedidaTipoInterface) {
|
async function executeGMedidaTipoRemoveData(data: GMedidaTipoInterface) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id}`
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GMedidaTipoRemoveData = withClientErrorHandler(executeGMedidaTipoRemoveData)
|
export const GMedidaTipoRemoveData = withClientErrorHandler(
|
||||||
|
executeGMedidaTipoRemoveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGMedidaTipoSaveData(data: GMedidaTipoInterface) {
|
async function executeGMedidaTipoSaveData(data: GMedidaTipoInterface) {
|
||||||
|
const isUpdate = Boolean(data.medida_tipo_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.medida_tipo_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
return await api.send({
|
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
|
||||||
endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id || ''}`,
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
|
endpoint: `administrativo/g_medida_tipo/${data.medida_tipo_id || ""}`,
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GMedidaTipoSaveData = withClientErrorHandler(executeGMedidaTipoSaveData)
|
export const GMedidaTipoSaveData = withClientErrorHandler(
|
||||||
|
executeGMedidaTipoSaveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,16 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
async function executeGTBBairroIndexData() {
|
async function executeGTBBairroIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
const dados = await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
const dados = await api.send({
|
endpoint: `administrativo/g_tb_bairro/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_bairro/`
|
|
||||||
});
|
|
||||||
|
|
||||||
return dados
|
|
||||||
|
|
||||||
|
return dados;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBBairroIndexData = withClientErrorHandler(executeGTBBairroIndexData)
|
export const GTBBairroIndexData = withClientErrorHandler(
|
||||||
|
executeGTBBairroIndexData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBBairroRemoveData(data: GTBBairroInterface) {
|
async function executeGTBBairroRemoveData(data: GTBBairroInterface) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_bairro/${data.tb_bairro_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_tb_bairro/${data.tb_bairro_id}`
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBBairroRemoveData = withClientErrorHandler(executeGTBBairroRemoveData)
|
export const GTBBairroRemoveData = withClientErrorHandler(
|
||||||
|
executeGTBBairroRemoveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBBairroSaveData(data: GTBBairroInterface) {
|
async function executeGTBBairroSaveData(data: GTBBairroInterface) {
|
||||||
|
const isUpdate = Boolean(data.tb_bairro_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_bairro_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
return await api.send({
|
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
|
||||||
endpoint: `administrativo/g_tb_bairro/${data.tb_bairro_id || ''}`,
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
|
endpoint: `administrativo/g_tb_bairro/${data.tb_bairro_id || ""}`,
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBBairroSaveData = withClientErrorHandler(executeGTBBairroSaveData)
|
export const GTBBairroSaveData = withClientErrorHandler(
|
||||||
|
executeGTBBairroSaveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,15 @@ import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withCli
|
||||||
import API from "@/services/api/Api";
|
import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
|
|
||||||
async function executeGTBEstadoCivilIndexData() {
|
async function executeGTBEstadoCivilIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_estado_civil/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_estado_civil/`
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBEstadoCivilIndexData = withClientErrorHandler(executeGTBEstadoCivilIndexData)
|
export const GTBEstadoCivilIndexData = withClientErrorHandler(
|
||||||
|
executeGTBEstadoCivilIndexData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBEstadoCivilRemoveData(data: GTBEstadoCivilInterface) {
|
async function executeGTBEstadoCivilRemoveData(data: GTBEstadoCivilInterface) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id}`
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBEstadoCivilRemoveData = withClientErrorHandler(executeGTBEstadoCivilRemoveData)
|
export const GTBEstadoCivilRemoveData = withClientErrorHandler(
|
||||||
|
executeGTBEstadoCivilRemoveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBEstadoCivilSaveData(data: GTBEstadoCivilInterface) {
|
async function executeGTBEstadoCivilSaveData(data: GTBEstadoCivilInterface) {
|
||||||
|
const isUpdate = Boolean(data.tb_estadocivil_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_estadocivil_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
return await api.send({
|
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
|
||||||
endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id || ''}`,
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
|
endpoint: `administrativo/g_tb_bairro/${data.tb_estadocivil_id || ""}`,
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBEstadoCivilSaveData = withClientErrorHandler(executeGTBEstadoCivilSaveData)
|
export const GTBEstadoCivilSaveData = withClientErrorHandler(
|
||||||
|
executeGTBEstadoCivilSaveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBProfissoesIndexData() {
|
export default async function GTBProfissoesIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_profissao/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_profissao/`
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import API from "@/services/api/Api";
|
||||||
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBProfissaoRemoveData(data: GTBProfissaoInterface) {
|
export default async function GTBProfissaoRemoveData(
|
||||||
|
data: GTBProfissaoInterface,
|
||||||
|
) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id}`
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,16 @@ import API from "@/services/api/Api";
|
||||||
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
import GTBProfissaoInterface from "../../_interfaces/GTBProfissaoInterface";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBProfissaoSaveData(data: GTBProfissaoInterface) {
|
export default async function GTBProfissaoSaveData(
|
||||||
|
data: GTBProfissaoInterface,
|
||||||
|
) {
|
||||||
|
const isUpdate = Boolean(data.tb_profissao_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_profissao_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id || ""}`,
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
body: data,
|
||||||
endpoint: `administrativo/g_tb_profissao/${data.tb_profissao_id || ''}`,
|
});
|
||||||
body: data
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBRegimeBensIndexData() {
|
export default async function GTBRegimeBensIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimebens/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_regimebens/`
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface";
|
import GTBRegimeBensInterface from "../../_interfaces/GTBRegimeBensInterface";
|
||||||
|
|
||||||
export default async function GTBRegimeBensRemoveData(data: GTBRegimeBensInterface) {
|
export default async function GTBRegimeBensRemoveData(
|
||||||
|
data: GTBRegimeBensInterface,
|
||||||
|
) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id}`
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,19 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBRegimeBensSaveData(data: GTBRegimeBensInterface) {
|
async function executeGTBRegimeBensSaveData(data: GTBRegimeBensInterface) {
|
||||||
|
throw new Error("Nome e email são obrigatórios");
|
||||||
|
|
||||||
throw new Error("Nome e email são obrigatórios");
|
const isUpdate = Boolean(data.tb_regimebens_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_regimebens_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id || ""}`,
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
body: data,
|
||||||
endpoint: `administrativo/g_tb_regimebens/${data.tb_regimebens_id || ''}`,
|
});
|
||||||
body: data
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBRegimeBensSaveData = withClientErrorHandler(executeGTBRegimeBensSaveData);
|
export const GTBRegimeBensSaveData = withClientErrorHandler(
|
||||||
|
executeGTBRegimeBensSaveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
async function executeGTBTipoLogradouroIndexData() {
|
async function executeGTBTipoLogradouroIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_tipologradouro/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_tipologradouro/`
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBTipoLogradouroIndexData = withClientErrorHandler(executeGTBTipoLogradouroIndexData)
|
export const GTBTipoLogradouroIndexData = withClientErrorHandler(
|
||||||
|
executeGTBTipoLogradouroIndexData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,17 @@ import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroI
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBTipoLogradouroRemoveData(data: GTBTipoLogradouroInterface) {
|
async function executeGTBTipoLogradouroRemoveData(
|
||||||
|
data: GTBTipoLogradouroInterface,
|
||||||
const api = new API();
|
) {
|
||||||
|
const api = new API();
|
||||||
return await api.send({
|
|
||||||
method: Methods.DELETE,
|
|
||||||
endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id}`
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
|
endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id}`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBTipoLogradouroRemoveData = withClientErrorHandler(executeGTBTipoLogradouroRemoveData)
|
export const GTBTipoLogradouroRemoveData = withClientErrorHandler(
|
||||||
|
executeGTBTipoLogradouroRemoveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,20 @@ import { GTBTipoLogradouroInterface } from "../../_interfaces/GTBTipoLogradouroI
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeGTBTipoLogradouroSaveData(data: GTBTipoLogradouroInterface) {
|
async function executeGTBTipoLogradouroSaveData(
|
||||||
|
data: GTBTipoLogradouroInterface,
|
||||||
|
) {
|
||||||
|
const isUpdate = Boolean(data.tb_tipologradouro_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_tipologradouro_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
|
||||||
|
|
||||||
return await api.send({
|
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
|
||||||
endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id || ''}`,
|
|
||||||
body: data
|
|
||||||
});
|
|
||||||
|
|
||||||
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
|
endpoint: `administrativo/g_tb_tipologradouro/${data.tb_tipologradouro_id || ""}`,
|
||||||
|
body: data,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GTBTipoLogradouroSaveData = withClientErrorHandler(executeGTBTipoLogradouroSaveData)
|
export const GTBTipoLogradouroSaveData = withClientErrorHandler(
|
||||||
|
executeGTBTipoLogradouroSaveData,
|
||||||
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,10 @@ import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInter
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBRegimeComunhaoIndexData() {
|
export default async function GTBRegimeComunhaoIndexData() {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.GET,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimecomunhao/`,
|
||||||
method: Methods.GET,
|
});
|
||||||
endpoint: `administrativo/g_tb_regimecomunhao/`
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ import API from "@/services/api/Api";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||||
|
|
||||||
export default async function GTBRegimeComunhaoRemoveData(data: GTBRegimeComunhaoInterface) {
|
export default async function GTBRegimeComunhaoRemoveData(
|
||||||
|
data: GTBRegimeComunhaoInterface,
|
||||||
|
) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id}`
|
}
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,16 @@ import API from "@/services/api/Api";
|
||||||
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
import GTBRegimeComunhaoInterface from "../../_interfaces/GTBRegimeComunhaoInterface";
|
||||||
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
|
|
||||||
export default async function GTBRegimeComunhaoSaveData(data: GTBRegimeComunhaoInterface) {
|
export default async function GTBRegimeComunhaoSaveData(
|
||||||
|
data: GTBRegimeComunhaoInterface,
|
||||||
|
) {
|
||||||
|
const isUpdate = Boolean(data.tb_regimecomunhao_id);
|
||||||
|
|
||||||
const isUpdate = Boolean(data.tb_regimecomunhao_id);
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: isUpdate ? Methods.PUT : Methods.POST,
|
||||||
return await api.send({
|
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id || ""}`,
|
||||||
method: isUpdate ? Methods.PUT : Methods.POST,
|
body: data,
|
||||||
endpoint: `administrativo/g_tb_regimecomunhao/${data.tb_regimecomunhao_id || ''}`,
|
});
|
||||||
body: data
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import { Methods } from "@/services/api/enums/ApiMethodEnum";
|
||||||
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
import { withClientErrorHandler } from "@/actions/withClientErrorHandler/withClientErrorHandler";
|
||||||
|
|
||||||
async function executeTCensecDeleteData(data: TCensecInterface) {
|
async function executeTCensecDeleteData(data: TCensecInterface) {
|
||||||
|
const api = new API();
|
||||||
|
|
||||||
const api = new API();
|
return await api.send({
|
||||||
|
method: Methods.DELETE,
|
||||||
return await api.send({
|
endpoint: `administrativo/t_censec/${data.censec_id}`,
|
||||||
method: Methods.DELETE,
|
});
|
||||||
endpoint: `administrativo/t_censec/${data.censec_id}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TCensecDeleteData = withClientErrorHandler(executeTCensecDeleteData);
|
export const TCensecDeleteData = withClientErrorHandler(
|
||||||
|
executeTCensecDeleteData,
|
||||||
|
);
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue