Lint errors
Signed-off-by: Rodrigo Martins <rodrigo.sousa.577@gmail.com>
This commit is contained in:
1 parent
9742d62ba2
commit
5acec6b71e
196 files changed
+10885
-6655
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { api } from '../../lib/api';
|
||||
import { toast } from 'react-toastify';
|
||||
import { Dialog } from '@headlessui/react';
|
||||
import { DocumentArrowUpIcon } from '@heroicons/react/24/outline';
|
||||
import { Editor } from '@tinymce/tinymce-react';
|
||||
import { DOCUMENT_VARIABLES } from '../../utils/documentVariables';
|
||||
import { Dialog } from "@headlessui/react";
|
||||
import { DocumentArrowUpIcon } from "@heroicons/react/24/outline";
|
||||
import { Editor } from "@tinymce/tinymce-react";
|
||||
import { useState, useEffect } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
import { api } from "../../lib/api";
|
||||
import { DOCUMENT_VARIABLES } from "../../utils/documentVariables";
|
||||
|
||||
// Definir interface para o estado
|
||||
interface ConfigState {
|
||||
@@ -24,18 +25,18 @@ interface ConfigState {
|
||||
|
||||
export function ConfiguracaoDocumento() {
|
||||
const [config, setConfig] = useState<ConfigState>({
|
||||
timbradoUrl: '',
|
||||
timbradoUrl: "",
|
||||
timbradoMarginTop: 100,
|
||||
timbradoMarginBottom: 50,
|
||||
timbradoMarginLeft: 50,
|
||||
timbradoMarginRight: 50,
|
||||
templatePadrao: '',
|
||||
templatePadrao: "",
|
||||
margensTemplate: {
|
||||
top: 35,
|
||||
bottom: 29,
|
||||
left: 25,
|
||||
right: 25
|
||||
}
|
||||
right: 25,
|
||||
},
|
||||
});
|
||||
|
||||
const [isPreviewOpen, setPreviewOpen] = useState(false);
|
||||
@@ -47,27 +48,27 @@ export function ConfiguracaoDocumento() {
|
||||
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
const response = await api.get('/documentos/configuracoes');
|
||||
console.log('Configurações carregadas:', response.data); // Debug
|
||||
const response = await api.get("/documentos/configuracoes");
|
||||
console.log("Configurações carregadas:", response.data); // Debug
|
||||
if (response.data) {
|
||||
setConfig({
|
||||
timbradoUrl: response.data.timbradoUrl || '',
|
||||
timbradoUrl: response.data.timbradoUrl || "",
|
||||
timbradoMarginTop: response.data.timbradoMarginTop || 100,
|
||||
timbradoMarginBottom: response.data.timbradoMarginBottom || 50,
|
||||
timbradoMarginLeft: response.data.timbradoMarginLeft || 50,
|
||||
timbradoMarginRight: response.data.timbradoMarginRight || 50,
|
||||
templatePadrao: response.data.templatePadrao || '',
|
||||
templatePadrao: response.data.templatePadrao || "",
|
||||
margensTemplate: {
|
||||
top: response.data.margensTemplate?.top || 35,
|
||||
bottom: response.data.margensTemplate?.bottom || 29,
|
||||
left: response.data.margensTemplate?.left || 25,
|
||||
right: response.data.margensTemplate?.right || 25
|
||||
}
|
||||
right: response.data.margensTemplate?.right || 25,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erro ao carregar configurações:', error);
|
||||
toast.error('Erro ao carregar configurações');
|
||||
console.error("Erro ao carregar configurações:", error);
|
||||
toast.error("Erro ao carregar configurações");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -76,53 +77,57 @@ export function ConfiguracaoDocumento() {
|
||||
if (!file) return;
|
||||
|
||||
// Atualizado para aceitar PDF
|
||||
if (!['image/png', 'image/svg+xml', 'application/pdf'].includes(file.type)) {
|
||||
toast.error('Por favor, use apenas arquivos PDF, PNG ou SVG');
|
||||
if (
|
||||
!["image/png", "image/svg+xml", "application/pdf"].includes(file.type)
|
||||
) {
|
||||
toast.error("Por favor, use apenas arquivos PDF, PNG ou SVG");
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > 5 * 1024 * 1024) { // Aumentado para 5MB para acomodar PDFs
|
||||
toast.error('O arquivo deve ter no máximo 5MB');
|
||||
if (file.size > 5 * 1024 * 1024) {
|
||||
// Aumentado para 5MB para acomodar PDFs
|
||||
toast.error("O arquivo deve ter no máximo 5MB");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('timbrado', file);
|
||||
formData.append("timbrado", file);
|
||||
|
||||
const response = await api.post('/documentos/upload-timbrado', formData);
|
||||
setConfig(prev => ({ ...prev, timbradoUrl: response.data.url }));
|
||||
toast.success('Timbrado atualizado com sucesso');
|
||||
const response = await api.post("/documentos/upload-timbrado", formData);
|
||||
setConfig((prev) => ({ ...prev, timbradoUrl: response.data.url }));
|
||||
toast.success("Timbrado atualizado com sucesso");
|
||||
} catch (error) {
|
||||
toast.error('Erro ao fazer upload do timbrado');
|
||||
toast.error("Erro ao fazer upload do timbrado");
|
||||
}
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
try {
|
||||
setIsSaving(true);
|
||||
await api.post('/documentos/configuracoes', config);
|
||||
toast.success('Configurações salvas com sucesso');
|
||||
await api.post("/documentos/configuracoes", config);
|
||||
toast.success("Configurações salvas com sucesso");
|
||||
} catch (error) {
|
||||
toast.error('Erro ao salvar configurações');
|
||||
toast.error("Erro ao salvar configurações");
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEditorSetup = (editor: any) => {
|
||||
editor.ui.registry.addMenuButton('variables', {
|
||||
text: 'Variáveis',
|
||||
editor.ui.registry.addMenuButton("variables", {
|
||||
text: "Variáveis",
|
||||
fetch: (callback: Function) => {
|
||||
const items = Object.entries(DOCUMENT_VARIABLES).flatMap(([category, vars]) =>
|
||||
Object.entries(vars).map(([name, value]) => ({
|
||||
type: 'menuitem',
|
||||
text: `${category} - ${name.replace(/_/g, ' ')}`,
|
||||
onAction: () => editor.insertContent(value as string)
|
||||
}))
|
||||
const items = Object.entries(DOCUMENT_VARIABLES).flatMap(
|
||||
([category, vars]) =>
|
||||
Object.entries(vars).map(([name, value]) => ({
|
||||
type: "menuitem",
|
||||
text: `${category} - ${name.replace(/_/g, " ")}`,
|
||||
onAction: () => editor.insertContent(value as string),
|
||||
})),
|
||||
);
|
||||
callback(items);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -131,12 +136,14 @@ export function ConfiguracaoDocumento() {
|
||||
height: 400,
|
||||
menubar: true,
|
||||
plugins: [
|
||||
'code', 'preview' // Removido 'template'
|
||||
"code",
|
||||
"preview", // Removido 'template'
|
||||
],
|
||||
toolbar: 'variables | undo redo | formatselect | ' +
|
||||
'bold italic | alignleft aligncenter alignright | ' +
|
||||
'code preview',
|
||||
setup: handleEditorSetup
|
||||
toolbar:
|
||||
"variables | undo redo | formatselect | " +
|
||||
"bold italic | alignleft aligncenter alignright | " +
|
||||
"code preview",
|
||||
setup: handleEditorSetup,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -179,7 +186,12 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.timbradoMarginTop}
|
||||
onChange={e => setConfig(prev => ({ ...prev, timbradoMarginTop: Number(e.target.value) }))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
timbradoMarginTop: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -188,7 +200,12 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.timbradoMarginBottom}
|
||||
onChange={e => setConfig(prev => ({ ...prev, timbradoMarginBottom: Number(e.target.value) }))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
timbradoMarginBottom: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -197,7 +214,12 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.timbradoMarginLeft}
|
||||
onChange={e => setConfig(prev => ({ ...prev, timbradoMarginLeft: Number(e.target.value) }))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
timbradoMarginLeft: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -206,7 +228,12 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.timbradoMarginRight}
|
||||
onChange={e => setConfig(prev => ({ ...prev, timbradoMarginRight: Number(e.target.value) }))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
timbradoMarginRight: Number(e.target.value),
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -218,7 +245,9 @@ export function ConfiguracaoDocumento() {
|
||||
<Editor
|
||||
apiKey={import.meta.env.VITE_TINYMCE_API_KEY}
|
||||
value={config.templatePadrao}
|
||||
onEditorChange={(content) => setConfig(prev => ({ ...prev, templatePadrao: content }))}
|
||||
onEditorChange={(content) =>
|
||||
setConfig((prev) => ({ ...prev, templatePadrao: content }))
|
||||
}
|
||||
init={editorConfig}
|
||||
/>
|
||||
<div className="mt-2 p-4 bg-gray-50 rounded border">
|
||||
@@ -226,7 +255,9 @@ export function ConfiguracaoDocumento() {
|
||||
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
|
||||
{Object.entries(DOCUMENT_VARIABLES).map(([category, vars]) => (
|
||||
<div key={category}>
|
||||
<h5 className="font-medium text-sm text-gray-700">{category}</h5>
|
||||
<h5 className="font-medium text-sm text-gray-700">
|
||||
{category}
|
||||
</h5>
|
||||
<ul className="mt-1 space-y-1">
|
||||
{Object.entries(vars).map(([name, value]) => (
|
||||
<li key={name} className="text-xs text-gray-600">
|
||||
@@ -247,13 +278,15 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.margensTemplate.top}
|
||||
onChange={e => setConfig(prev => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
top: Number(e.target.value)
|
||||
}
|
||||
}))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
top: Number(e.target.value),
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -262,13 +295,15 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.margensTemplate.bottom}
|
||||
onChange={e => setConfig(prev => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
bottom: Number(e.target.value)
|
||||
}
|
||||
}))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
bottom: Number(e.target.value),
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -277,13 +312,15 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.margensTemplate.left}
|
||||
onChange={e => setConfig(prev => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
left: Number(e.target.value)
|
||||
}
|
||||
}))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
left: Number(e.target.value),
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -292,13 +329,15 @@ export function ConfiguracaoDocumento() {
|
||||
<input
|
||||
type="number"
|
||||
value={config.margensTemplate.right}
|
||||
onChange={e => setConfig(prev => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
right: Number(e.target.value)
|
||||
}
|
||||
}))}
|
||||
onChange={(e) =>
|
||||
setConfig((prev) => ({
|
||||
...prev,
|
||||
margensTemplate: {
|
||||
...prev.margensTemplate,
|
||||
right: Number(e.target.value),
|
||||
},
|
||||
}))
|
||||
}
|
||||
className="w-full p-2 border rounded"
|
||||
/>
|
||||
</div>
|
||||
@@ -309,11 +348,11 @@ export function ConfiguracaoDocumento() {
|
||||
disabled={isSaving}
|
||||
className={`px-4 py-2 ${
|
||||
isSaving
|
||||
? 'bg-gray-400 cursor-not-allowed'
|
||||
: 'bg-blue-600 hover:bg-blue-700'
|
||||
? "bg-gray-400 cursor-not-allowed"
|
||||
: "bg-blue-600 hover:bg-blue-700"
|
||||
} text-white rounded`}
|
||||
>
|
||||
{isSaving ? 'Salvando...' : 'Salvar Configurações'}
|
||||
{isSaving ? "Salvando..." : "Salvar Configurações"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user