Fix page with lint errors #18
@@ -3,7 +3,7 @@
|
||||
import {
|
||||
ExternalLink,
|
||||
FileText,
|
||||
File,
|
||||
File as FileIcon,
|
||||
Upload,
|
||||
Trash2,
|
||||
Eye,
|
||||
@@ -16,7 +16,7 @@
|
||||
value?: string; // storageId
|
||||
disabled?: boolean;
|
||||
required?: boolean;
|
||||
onUpload: (file: File) => Promise<void>;
|
||||
onUpload: (file: globalThis.File) => Promise<void>;
|
||||
onRemove: () => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -60,27 +60,22 @@
|
||||
try {
|
||||
const url = await client.storage.getUrl(storageId as any);
|
||||
if (url) {
|
||||
fileUrl = url;
|
||||
fileName = "Documento anexado";
|
||||
async function handleFileSelect(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const file = target.files?.[0];
|
||||
// Detectar tipo pelo URL ou assumir PDF
|
||||
if (url.includes(".pdf") || url.includes("application/pdf")) {
|
||||
fileType = "application/pdf";
|
||||
if (url.includes('.pdf') || url.includes('application/pdf')) {
|
||||
fileType = 'application/pdf';
|
||||
} else {
|
||||
fileType = "image/jpeg";
|
||||
fileType = 'image/jpeg';
|
||||
previewUrl = url; // Para imagens, a URL serve como preview
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Erro ao carregar arquivo existente:", err);
|
||||
console.error('Erro ao carregar arquivo existente:', err);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFileSelect(event: Event) {
|
||||
const target = event.target as HTMLInputElement;
|
||||
const file = target.files?.[0];
|
||||
|
||||
if (!file) return;
|
||||
|
||||
error = null;
|
||||
|
||||
// Validate file size
|
||||
@@ -188,28 +183,18 @@
|
||||
/>
|
||||
|
||||
{#if value || fileName}
|
||||
<div
|
||||
class="flex items-center gap-2 p-3 border border-base-300 rounded-lg bg-base-100"
|
||||
>
|
||||
<div class="border-base-300 bg-base-100 flex items-center gap-2 rounded-lg border p-3">
|
||||
<!-- Preview -->
|
||||
<div class="shrink-0">
|
||||
{#if previewUrl}
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt="Preview"
|
||||
class="w-12 h-12 object-cover rounded"
|
||||
/>
|
||||
{:else if fileType === "application/pdf" || fileName.endsWith(".pdf")}
|
||||
<div
|
||||
class="w-12 h-12 bg-error/10 rounded flex items-center justify-center"
|
||||
>
|
||||
<FileText class="h-6 w-6 text-error" strokeWidth={2} />
|
||||
<img src={previewUrl} alt="Preview" class="h-12 w-12 rounded object-cover" />
|
||||
{:else if fileType === 'application/pdf' || fileName.endsWith('.pdf')}
|
||||
<div class="bg-error/10 flex h-12 w-12 items-center justify-center rounded">
|
||||
<FileText class="text-error h-6 w-6" strokeWidth={2} />
|
||||
</div>
|
||||
{:else}
|
||||
<div
|
||||
class="w-12 h-12 bg-success/10 rounded flex items-center justify-center"
|
||||
>
|
||||
<File class="h-6 w-6 text-success" strokeWidth={2} />
|
||||
<div class="bg-success/10 flex h-12 w-12 items-center justify-center rounded">
|
||||
<File class="text-success h-6 w-6" strokeWidth={2} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -11,15 +11,16 @@
|
||||
categoriasDocumentos,
|
||||
getDocumentosByCategoria
|
||||
} from '$lib/utils/documentos';
|
||||
import type { Id, Doc } from '@sgse-app/backend/convex/_generated/dataModel';
|
||||
|
||||
const client = useConvexClient();
|
||||
|
||||
let funcionarioId = $derived($page.params.funcionarioId as string);
|
||||
let funcionarioId = $derived($page.params.funcionarioId as Id<'funcionarios'>);
|
||||
|
||||
let funcionario = $state<any>(null);
|
||||
let funcionario = $state<Doc<'funcionarios'> | null>(null);
|
||||
let documentosStorage = $state<Record<string, string | undefined>>({});
|
||||
let loading = $state(true);
|
||||
let filtro = $state<string>('todos'); // todos, enviados, pendentes
|
||||
let filtro = $state<'todos' | 'enviados' | 'pendentes'>('todos'); // todos, enviados, pendentes
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
@@ -27,7 +28,7 @@
|
||||
|
||||
// Carregar dados do funcionário
|
||||
const data = await client.query(api.funcionarios.getById, {
|
||||
id: funcionarioId as any
|
||||
id: funcionarioId
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
@@ -39,8 +40,10 @@
|
||||
|
||||
// Mapear storage IDs dos documentos
|
||||
documentos.forEach((doc) => {
|
||||
if ((data as any)[doc.campo]) {
|
||||
documentosStorage[doc.campo] = (data as any)[doc.campo];
|
||||
const campo = doc.campo as keyof Doc<'funcionarios'>;
|
||||
const valor = data[campo];
|
||||
if (typeof valor === 'string') {
|
||||
documentosStorage[doc.campo] = valor;
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -63,13 +66,23 @@
|
||||
body: file
|
||||
});
|
||||
|
||||
const { storageId } = await result.json();
|
||||
const uploadResponse = await result.json();
|
||||
if (
|
||||
!uploadResponse ||
|
||||
typeof uploadResponse !== 'object' ||
|
||||
!('storageId' in uploadResponse) ||
|
||||
typeof uploadResponse.storageId !== 'string'
|
||||
) {
|
||||
throw new Error('Resposta inválida ao fazer upload');
|
||||
}
|
||||
|
||||
const storageId = uploadResponse.storageId;
|
||||
|
||||
// Atualizar documento no funcionário
|
||||
await client.mutation(api.documentos.updateDocumento, {
|
||||
funcionarioId: funcionarioId as any,
|
||||
funcionarioId,
|
||||
campo,
|
||||
storageId: storageId as any
|
||||
storageId: storageId as Id<'_storage'>
|
||||
});
|
||||
|
||||
// Atualizar localmente
|
||||
@@ -77,8 +90,11 @@
|
||||
|
||||
// Recarregar
|
||||
await load();
|
||||
} catch (err: any) {
|
||||
throw new Error(err?.message || 'Erro ao fazer upload');
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err.message) {
|
||||
throw err;
|
||||
}
|
||||
throw new Error('Erro ao fazer upload');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +102,7 @@
|
||||
try {
|
||||
// Atualizar documento no funcionário (set to null)
|
||||
await client.mutation(api.documentos.updateDocumento, {
|
||||
funcionarioId: funcionarioId as any,
|
||||
funcionarioId,
|
||||
campo,
|
||||
storageId: null
|
||||
});
|
||||
@@ -96,8 +112,10 @@
|
||||
|
||||
// Recarregar
|
||||
await load();
|
||||
} catch (err: any) {
|
||||
alert('Erro ao remover documento: ' + (err?.message || ''));
|
||||
} catch (err) {
|
||||
const mensagem =
|
||||
err instanceof Error && err.message ? err.message : 'Erro ao remover documento';
|
||||
alert('Erro ao remover documento: ' + mensagem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +148,9 @@
|
||||
<div class="breadcrumbs mb-4 text-sm">
|
||||
<ul>
|
||||
<li>
|
||||
<a href={resolve('/recursos-humanos')} class="text-primary hover:underline">Recursos Humanos</a>
|
||||
<a href={resolve('/recursos-humanos')} class="text-primary hover:underline"
|
||||
>Recursos Humanos</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href={resolve('/recursos-humanos/funcionarios')} class="text-primary hover:underline"
|
||||
@@ -305,7 +325,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Documentos por Categoria -->
|
||||
{#each categoriasDocumentos as categoria}
|
||||
{#each categoriasDocumentos as categoria (categoria)}
|
||||
{@const docsCategoria = getDocumentosByCategoria(categoria).filter((doc) => {
|
||||
const temDocumento = !!documentosStorage[doc.campo];
|
||||
if (filtro === 'enviados') return temDocumento;
|
||||
@@ -322,7 +342,7 @@
|
||||
</h2>
|
||||
|
||||
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
|
||||
{#each docsCategoria as doc}
|
||||
{#each docsCategoria as doc (doc.campo)}
|
||||
<FileUpload
|
||||
label={doc.nome}
|
||||
helpUrl={doc.helpUrl}
|
||||
|
||||
@@ -483,7 +483,9 @@
|
||||
<div class="breadcrumbs mb-4 text-sm">
|
||||
<ul>
|
||||
<li>
|
||||
<a href={resolve('/recursos-humanos')} class="text-primary hover:underline">Recursos Humanos</a>
|
||||
<a href={resolve('/recursos-humanos')} class="text-primary hover:underline"
|
||||
>Recursos Humanos</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a href={resolve('/recursos-humanos/funcionarios')} class="text-primary hover:underline"
|
||||
|
||||
Reference in New Issue
Block a user