Fix usuarios page #6

Merged
killer-cf merged 28 commits from fix-usuarios-page into master 2025-11-04 17:42:21 +00:00
75 changed files with 13608 additions and 7454 deletions
Showing only changes of commit 6d613fe618 - Show all commits

View File

@@ -0,0 +1,54 @@
<script lang="ts">
interface Props {
open: boolean;
title?: string;
message: string;
details?: string;
onClose: () => void;
}
let {
open = $bindable(false),
title = "Erro",
message,
details,
onClose,
}: Props = $props();
</script>
{#if open}
<div class="modal modal-open">
<div class="modal-box">
<h3 class="font-bold text-lg text-error mb-4 flex items-center gap-2">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-6 w-6"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
{title}
</h3>
<p class="py-4 text-base-content">{message}</p>
{#if details}
<div class="bg-base-200 rounded-lg p-3 mb-4">
<p class="text-sm text-base-content/70 font-mono">{details}</p>
</div>
{/if}
<div class="modal-action">
<button class="btn btn-primary" onclick={() => { open = false; onClose(); }}>
Fechar
</button>
</div>
</div>
<div class="modal-backdrop" onclick={() => { open = false; onClose(); }}></div>
</div>
{/if}

View File

@@ -1,274 +1,279 @@
<script lang="ts"> <script lang="ts">
import { useConvexClient } from "convex-svelte"; import { useConvexClient } from "convex-svelte";
interface Props { interface Props {
label: string; label: string;
helpUrl?: string; helpUrl?: string;
value?: string; // storageId value?: string; // storageId
disabled?: boolean; disabled?: boolean;
onUpload: (file: File) => Promise<void>; required?: boolean;
onRemove: () => Promise<void>; onUpload: (file: File) => Promise<void>;
} onRemove: () => Promise<void>;
}
let {
label, let {
helpUrl, label,
value = $bindable(), helpUrl,
disabled = false, value = $bindable(),
onUpload, disabled = false,
onRemove, required = false,
}: Props = $props(); onUpload,
onRemove,
const client = useConvexClient(); }: Props = $props();
let fileInput: HTMLInputElement; const client = useConvexClient();
let uploading = $state(false);
let error = $state<string | null>(null); let fileInput: HTMLInputElement;
let fileName = $state<string>(""); let uploading = $state(false);
let fileType = $state<string>(""); let error = $state<string | null>(null);
let previewUrl = $state<string | null>(null); let fileName = $state<string>("");
let fileUrl = $state<string | null>(null); let fileType = $state<string>("");
let previewUrl = $state<string | null>(null);
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB let fileUrl = $state<string | null>(null);
const ALLOWED_TYPES = [
"application/pdf", const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
"image/jpeg", const ALLOWED_TYPES = [
"image/jpg", "application/pdf",
"image/png", "image/jpeg",
]; "image/jpg",
"image/png",
// Buscar URL do arquivo quando houver um storageId ];
$effect(() => {
if (value && !fileName) { // Buscar URL do arquivo quando houver um storageId
// Tem storageId mas não é um upload recente $effect(() => {
loadExistingFile(value); if (value && !fileName) {
} // Tem storageId mas não é um upload recente
}); loadExistingFile(value);
}
async function loadExistingFile(storageId: string) { });
try {
const url = await client.storage.getUrl(storageId as any); async function loadExistingFile(storageId: string) {
if (url) { try {
fileUrl = url; const url = await client.storage.getUrl(storageId as any);
fileName = "Documento anexado"; if (url) {
// Detectar tipo pelo URL ou assumir PDF fileUrl = url;
if (url.includes(".pdf") || url.includes("application/pdf")) { fileName = "Documento anexado";
fileType = "application/pdf"; // Detectar tipo pelo URL ou assumir PDF
} else { if (url.includes(".pdf") || url.includes("application/pdf")) {
fileType = "image/jpeg"; fileType = "application/pdf";
previewUrl = url; // Para imagens, a URL serve como preview } else {
} fileType = "image/jpeg";
} previewUrl = url; // Para imagens, a URL serve como preview
} catch (err) { }
console.error("Erro ao carregar arquivo existente:", err); }
} } catch (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]; async function handleFileSelect(event: Event) {
const target = event.target as HTMLInputElement;
if (!file) return; const file = target.files?.[0];
error = null; if (!file) return;
// Validate file size error = null;
if (file.size > MAX_FILE_SIZE) {
error = "Arquivo muito grande. Tamanho máximo: 10MB"; // Validate file size
target.value = ""; if (file.size > MAX_FILE_SIZE) {
return; error = "Arquivo muito grande. Tamanho máximo: 10MB";
} target.value = "";
return;
// Validate file type }
if (!ALLOWED_TYPES.includes(file.type)) {
error = "Tipo de arquivo não permitido. Use PDF ou imagens (JPG, PNG)"; // Validate file type
target.value = ""; if (!ALLOWED_TYPES.includes(file.type)) {
return; error = "Tipo de arquivo não permitido. Use PDF ou imagens (JPG, PNG)";
} target.value = "";
return;
try { }
uploading = true;
fileName = file.name; try {
fileType = file.type; uploading = true;
fileName = file.name;
// Create preview for images fileType = file.type;
if (file.type.startsWith("image/")) {
const reader = new FileReader(); // Create preview for images
reader.onload = (e) => { if (file.type.startsWith("image/")) {
previewUrl = e.target?.result as string; const reader = new FileReader();
}; reader.onload = (e) => {
reader.readAsDataURL(file); previewUrl = e.target?.result as string;
} };
reader.readAsDataURL(file);
await onUpload(file); }
} catch (err: any) { await onUpload(file);
error = err?.message || "Erro ao fazer upload do arquivo";
previewUrl = null; } catch (err: any) {
} finally { error = err?.message || "Erro ao fazer upload do arquivo";
uploading = false; previewUrl = null;
target.value = ""; } finally {
} uploading = false;
} target.value = "";
}
async function handleRemove() { }
if (!confirm("Tem certeza que deseja remover este arquivo?")) {
return; async function handleRemove() {
} if (!confirm("Tem certeza que deseja remover este arquivo?")) {
return;
try { }
uploading = true;
await onRemove(); try {
fileName = ""; uploading = true;
fileType = ""; await onRemove();
previewUrl = null; fileName = "";
fileUrl = null; fileType = "";
} catch (err: any) { previewUrl = null;
error = err?.message || "Erro ao remover arquivo"; fileUrl = null;
} finally { } catch (err: any) {
uploading = false; error = err?.message || "Erro ao remover arquivo";
} } finally {
} uploading = false;
}
function handleView() { }
if (fileUrl) {
window.open(fileUrl, '_blank'); function handleView() {
} if (fileUrl) {
} window.open(fileUrl, '_blank');
}
function openFileDialog() { }
fileInput?.click();
} function openFileDialog() {
</script> fileInput?.click();
}
<div class="form-control w-full"> </script>
<label class="label" for="file-upload-input">
<span class="label-text font-medium flex items-center gap-2"> <div class="form-control w-full">
{label} <label class="label" for="file-upload-input">
{#if helpUrl} <span class="label-text font-medium flex items-center gap-2">
<div class="tooltip tooltip-right" data-tip="Clique para acessar o link"> {label}
<a {#if required}
href={helpUrl} <span class="text-error">*</span>
target="_blank" {/if}
rel="noopener noreferrer" {#if helpUrl}
class="text-primary hover:text-primary-focus transition-colors" <div class="tooltip tooltip-right" data-tip="Clique para acessar o link">
aria-label="Acessar link" <a
> href={helpUrl}
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> target="_blank"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" /> rel="noopener noreferrer"
</svg> class="text-primary hover:text-primary-focus transition-colors"
</a> aria-label="Acessar link"
</div> >
{/if} <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
</span> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" />
</label> </svg>
</a>
<input </div>
id="file-upload-input" {/if}
type="file" </span>
bind:this={fileInput} </label>
onchange={handleFileSelect}
accept=".pdf,.jpg,.jpeg,.png" <input
class="hidden" id="file-upload-input"
{disabled} type="file"
/> bind:this={fileInput}
onchange={handleFileSelect}
{#if value || fileName} accept=".pdf,.jpg,.jpeg,.png"
<div class="flex items-center gap-2 p-3 border border-base-300 rounded-lg bg-base-100"> class="hidden"
<!-- Preview --> {disabled}
<div class="flex-shrink-0"> />
{#if previewUrl}
<img src={previewUrl} alt="Preview" class="w-12 h-12 object-cover rounded" /> {#if value || fileName}
{:else if fileType === "application/pdf" || fileName.endsWith(".pdf")} <div class="flex items-center gap-2 p-3 border border-base-300 rounded-lg bg-base-100">
<div class="w-12 h-12 bg-error/10 rounded flex items-center justify-center"> <!-- Preview -->
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-error" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <div class="flex-shrink-0">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" /> {#if previewUrl}
</svg> <img src={previewUrl} alt="Preview" class="w-12 h-12 object-cover rounded" />
</div> {:else if fileType === "application/pdf" || fileName.endsWith(".pdf")}
{:else} <div class="w-12 h-12 bg-error/10 rounded flex items-center justify-center">
<div class="w-12 h-12 bg-success/10 rounded flex items-center justify-center"> <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-error" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-success" fill="none" viewBox="0 0 24 24" stroke="currentColor"> <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" />
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" /> </svg>
</svg> </div>
</div> {:else}
{/if} <div class="w-12 h-12 bg-success/10 rounded flex items-center justify-center">
</div> <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-success" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
<!-- File info --> </svg>
<div class="flex-1 min-w-0"> </div>
<p class="text-sm font-medium truncate">{fileName || "Arquivo anexado"}</p> {/if}
<p class="text-xs text-base-content/60"> </div>
{#if uploading}
Carregando... <!-- File info -->
{:else} <div class="flex-1 min-w-0">
Enviado com sucesso <p class="text-sm font-medium truncate">{fileName || "Arquivo anexado"}</p>
{/if} <p class="text-xs text-base-content/60">
</p> {#if uploading}
</div> Carregando...
{:else}
<!-- Actions --> Enviado com sucesso
<div class="flex gap-2"> {/if}
{#if fileUrl} </p>
<button </div>
type="button"
onclick={handleView} <!-- Actions -->
class="btn btn-sm btn-ghost text-info" <div class="flex gap-2">
disabled={uploading || disabled} {#if fileUrl}
title="Visualizar arquivo" <button
> type="button"
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> onclick={handleView}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> class="btn btn-sm btn-ghost text-info"
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" /> disabled={uploading || disabled}
</svg> title="Visualizar arquivo"
</button> >
{/if} <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<button <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
type="button" <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z" />
onclick={openFileDialog} </svg>
class="btn btn-sm btn-ghost" </button>
disabled={uploading || disabled} {/if}
title="Substituir arquivo" <button
> type="button"
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> onclick={openFileDialog}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" /> class="btn btn-sm btn-ghost"
</svg> disabled={uploading || disabled}
</button> title="Substituir arquivo"
<button >
type="button" <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
onclick={handleRemove} <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12" />
class="btn btn-sm btn-ghost text-error" </svg>
disabled={uploading || disabled} </button>
title="Remover arquivo" <button
> type="button"
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor"> onclick={handleRemove}
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /> class="btn btn-sm btn-ghost text-error"
</svg> disabled={uploading || disabled}
</button> title="Remover arquivo"
</div> >
</div> <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
{:else} <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
<button </svg>
type="button" </button>
onclick={openFileDialog} </div>
class="btn btn-outline btn-block justify-start gap-2" </div>
disabled={uploading || disabled} {:else}
> <button
{#if uploading} type="button"
<span class="loading loading-spinner loading-sm"></span> onclick={openFileDialog}
Carregando... class="btn btn-outline btn-block justify-start gap-2"
{:else} disabled={uploading || disabled}
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> >
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" /> {#if uploading}
</svg> <span class="loading loading-spinner loading-sm"></span>
Selecionar arquivo (PDF ou imagem, máx. 10MB) Carregando...
{/if} {:else}
</button> <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
{/if} <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12" />
</svg>
{#if error} Selecionar arquivo (PDF ou imagem, máx. 10MB)
<div class="label"> {/if}
<span class="label-text-alt text-error">{error}</span> </button>
</div> {/if}
{/if}
</div> {#if error}
<div class="label">
<span class="label-text-alt text-error">{error}</span>
</div>
{/if}
</div>

View File

@@ -5,6 +5,7 @@
import { toast } from "svelte-sonner"; import { toast } from "svelte-sonner";
import FuncionarioSelect from "$lib/components/FuncionarioSelect.svelte"; import FuncionarioSelect from "$lib/components/FuncionarioSelect.svelte";
import FileUpload from "$lib/components/FileUpload.svelte"; import FileUpload from "$lib/components/FileUpload.svelte";
import ErrorModal from "$lib/components/ErrorModal.svelte";
import type { Id } from "@sgse-app/backend/convex/_generated/dataModel"; import type { Id } from "@sgse-app/backend/convex/_generated/dataModel";
const client = useConvexClient(); const client = useConvexClient();
@@ -74,6 +75,14 @@
let salvandoMaternidade = $state(false); let salvandoMaternidade = $state(false);
let salvandoPaternidade = $state(false); let salvandoPaternidade = $state(false);
// Modal de erro
let erroModal = $state({
aberto: false,
titulo: "",
mensagem: "",
detalhes: "",
});
// Licenças maternidade para prorrogação (derivar dos dados já carregados) // Licenças maternidade para prorrogação (derivar dos dados já carregados)
const licencasMaternidade = $derived.by(() => { const licencasMaternidade = $derived.by(() => {
const dados = dadosQuery?.data; const dados = dadosQuery?.data;
@@ -114,10 +123,33 @@
} }
} }
// Função para mostrar erro em modal
function mostrarErro(titulo: string, mensagem: string, detalhes?: string) {
erroModal = {
aberto: true,
titulo,
mensagem,
detalhes: detalhes || "",
};
}
// Salvar Atestado Médico // Salvar Atestado Médico
async function salvarAtestadoMedico() { async function salvarAtestadoMedico() {
if (!atestadoMedico.funcionarioId || !atestadoMedico.dataInicio || !atestadoMedico.dataFim || !atestadoMedico.cid) { if (!atestadoMedico.funcionarioId || !atestadoMedico.dataInicio || !atestadoMedico.dataFim || !atestadoMedico.cid) {
toast.error("Preencha todos os campos obrigatórios"); mostrarErro(
"Campos obrigatórios",
"Preencha todos os campos obrigatórios antes de salvar.",
"Campos obrigatórios: Funcionário, Data Início, Data Fim e CID"
);
return;
}
if (!atestadoMedico.documentoId) {
mostrarErro(
"Documento obrigatório",
"É necessário anexar o documento do atestado médico.",
"Por favor, faça o upload do arquivo PDF ou imagem do atestado antes de salvar."
);
return; return;
} }
@@ -129,14 +161,16 @@
dataFim: atestadoMedico.dataFim, dataFim: atestadoMedico.dataFim,
cid: atestadoMedico.cid, cid: atestadoMedico.cid,
observacoes: atestadoMedico.observacoes || undefined, observacoes: atestadoMedico.observacoes || undefined,
documentoId: atestadoMedico.documentoId as Id<"_storage"> | undefined, documentoId: atestadoMedico.documentoId as Id<"_storage">,
}); });
toast.success("Atestado médico registrado com sucesso!"); toast.success("Atestado médico registrado com sucesso!");
resetarFormularioAtestado(); resetarFormularioAtestado();
abaAtiva = "dashboard"; abaAtiva = "dashboard";
} catch (error: any) { } catch (error: any) {
toast.error(error?.message || "Erro ao registrar atestado"); const mensagemErro = error?.message || "Erro ao registrar atestado";
const detalhesErro = error?.data?.message || error?.toString() || "";
mostrarErro("Erro ao registrar", mensagemErro, detalhesErro);
} finally { } finally {
salvandoAtestado = false; salvandoAtestado = false;
} }
@@ -145,7 +179,20 @@
// Salvar Declaração // Salvar Declaração
async function salvarDeclaracao() { async function salvarDeclaracao() {
if (!declaracao.funcionarioId || !declaracao.dataInicio || !declaracao.dataFim) { if (!declaracao.funcionarioId || !declaracao.dataInicio || !declaracao.dataFim) {
toast.error("Preencha todos os campos obrigatórios"); mostrarErro(
"Campos obrigatórios",
"Preencha todos os campos obrigatórios antes de salvar.",
"Campos obrigatórios: Funcionário, Data Início e Data Fim"
);
return;
}
if (!declaracao.documentoId) {
mostrarErro(
"Documento obrigatório",
"É necessário anexar o documento da declaração.",
"Por favor, faça o upload do arquivo PDF ou imagem da declaração antes de salvar."
);
return; return;
} }
@@ -156,14 +203,16 @@
dataInicio: declaracao.dataInicio, dataInicio: declaracao.dataInicio,
dataFim: declaracao.dataFim, dataFim: declaracao.dataFim,
observacoes: declaracao.observacoes || undefined, observacoes: declaracao.observacoes || undefined,
documentoId: declaracao.documentoId as Id<"_storage"> | undefined, documentoId: declaracao.documentoId as Id<"_storage">,
}); });
toast.success("Declaração registrada com sucesso!"); toast.success("Declaração registrada com sucesso!");
resetarFormularioDeclaracao(); resetarFormularioDeclaracao();
abaAtiva = "dashboard"; abaAtiva = "dashboard";
} catch (error: any) { } catch (error: any) {
toast.error(error?.message || "Erro ao registrar declaração"); const mensagemErro = error?.message || "Erro ao registrar declaração";
const detalhesErro = error?.data?.message || error?.toString() || "";
mostrarErro("Erro ao registrar", mensagemErro, detalhesErro);
} finally { } finally {
salvandoDeclaracao = false; salvandoDeclaracao = false;
} }
@@ -172,12 +221,29 @@
// Salvar Licença Maternidade // Salvar Licença Maternidade
async function salvarLicencaMaternidade() { async function salvarLicencaMaternidade() {
if (!licencaMaternidade.funcionarioId || !licencaMaternidade.dataInicio || !licencaMaternidade.dataFim) { if (!licencaMaternidade.funcionarioId || !licencaMaternidade.dataInicio || !licencaMaternidade.dataFim) {
toast.error("Preencha todos os campos obrigatórios"); mostrarErro(
"Campos obrigatórios",
"Preencha todos os campos obrigatórios antes de salvar.",
"Campos obrigatórios: Funcionário, Data Início e Data Fim"
);
return; return;
} }
if (licencaMaternidade.ehProrrogacao && !licencaMaternidade.licencaOriginalId) { if (licencaMaternidade.ehProrrogacao && !licencaMaternidade.licencaOriginalId) {
toast.error("Selecione a licença original para prorrogação"); mostrarErro(
"Licença original obrigatória",
"Para prorrogações, é necessário selecionar a licença original.",
"Selecione a licença de maternidade original no campo 'Licença Original'."
);
return;
}
if (!licencaMaternidade.documentoId) {
mostrarErro(
"Documento obrigatório",
"É necessário anexar o documento da licença de maternidade.",
"Por favor, faça o upload do arquivo PDF ou imagem da licença antes de salvar."
);
return; return;
} }
@@ -188,7 +254,7 @@
dataInicio: licencaMaternidade.dataInicio, dataInicio: licencaMaternidade.dataInicio,
dataFim: licencaMaternidade.dataFim, dataFim: licencaMaternidade.dataFim,
observacoes: licencaMaternidade.observacoes || undefined, observacoes: licencaMaternidade.observacoes || undefined,
documentoId: licencaMaternidade.documentoId as Id<"_storage"> | undefined, documentoId: licencaMaternidade.documentoId as Id<"_storage">,
licencaOriginalId: licencaMaternidade.licencaOriginalId as Id<"licencas"> | undefined, licencaOriginalId: licencaMaternidade.licencaOriginalId as Id<"licencas"> | undefined,
}); });
@@ -196,7 +262,9 @@
resetarFormularioMaternidade(); resetarFormularioMaternidade();
abaAtiva = "dashboard"; abaAtiva = "dashboard";
} catch (error: any) { } catch (error: any) {
toast.error(error?.message || "Erro ao registrar licença"); const mensagemErro = error?.message || "Erro ao registrar licença";
const detalhesErro = error?.data?.message || error?.toString() || "";
mostrarErro("Erro ao registrar", mensagemErro, detalhesErro);
} finally { } finally {
salvandoMaternidade = false; salvandoMaternidade = false;
} }
@@ -205,7 +273,20 @@
// Salvar Licença Paternidade // Salvar Licença Paternidade
async function salvarLicencaPaternidade() { async function salvarLicencaPaternidade() {
if (!licencaPaternidade.funcionarioId || !licencaPaternidade.dataInicio || !licencaPaternidade.dataFim) { if (!licencaPaternidade.funcionarioId || !licencaPaternidade.dataInicio || !licencaPaternidade.dataFim) {
toast.error("Preencha todos os campos obrigatórios"); mostrarErro(
"Campos obrigatórios",
"Preencha todos os campos obrigatórios antes de salvar.",
"Campos obrigatórios: Funcionário, Data Início e Data Fim"
);
return;
}
if (!licencaPaternidade.documentoId) {
mostrarErro(
"Documento obrigatório",
"É necessário anexar o documento da licença de paternidade.",
"Por favor, faça o upload do arquivo PDF ou imagem da licença antes de salvar."
);
return; return;
} }
@@ -216,14 +297,16 @@
dataInicio: licencaPaternidade.dataInicio, dataInicio: licencaPaternidade.dataInicio,
dataFim: licencaPaternidade.dataFim, dataFim: licencaPaternidade.dataFim,
observacoes: licencaPaternidade.observacoes || undefined, observacoes: licencaPaternidade.observacoes || undefined,
documentoId: licencaPaternidade.documentoId as Id<"_storage"> | undefined, documentoId: licencaPaternidade.documentoId as Id<"_storage">,
}); });
toast.success("Licença paternidade registrada com sucesso!"); toast.success("Licença paternidade registrada com sucesso!");
resetarFormularioPaternidade(); resetarFormularioPaternidade();
abaAtiva = "dashboard"; abaAtiva = "dashboard";
} catch (error: any) { } catch (error: any) {
toast.error(error?.message || "Erro ao registrar licença"); const mensagemErro = error?.message || "Erro ao registrar licença";
const detalhesErro = error?.data?.message || error?.toString() || "";
mostrarErro("Erro ao registrar", mensagemErro, detalhesErro);
} finally { } finally {
salvandoPaternidade = false; salvandoPaternidade = false;
} }
@@ -1220,6 +1303,7 @@
<FileUpload <FileUpload
label="Anexar Atestado (PDF ou Imagem)" label="Anexar Atestado (PDF ou Imagem)"
bind:value={atestadoMedico.documentoId} bind:value={atestadoMedico.documentoId}
required={true}
onUpload={async (file) => { onUpload={async (file) => {
atestadoMedico.documentoId = await handleDocumentoUpload( atestadoMedico.documentoId = await handleDocumentoUpload(
file file
@@ -1305,6 +1389,7 @@
<FileUpload <FileUpload
label="Anexar Documento (PDF ou Imagem)" label="Anexar Documento (PDF ou Imagem)"
bind:value={declaracao.documentoId} bind:value={declaracao.documentoId}
required={true}
onUpload={async (file) => { onUpload={async (file) => {
declaracao.documentoId = await handleDocumentoUpload(file); declaracao.documentoId = await handleDocumentoUpload(file);
}} }}
@@ -1424,6 +1509,7 @@
<FileUpload <FileUpload
label="Anexar Documento (PDF ou Imagem)" label="Anexar Documento (PDF ou Imagem)"
bind:value={licencaMaternidade.documentoId} bind:value={licencaMaternidade.documentoId}
required={true}
onUpload={async (file) => { onUpload={async (file) => {
licencaMaternidade.documentoId = await handleDocumentoUpload( licencaMaternidade.documentoId = await handleDocumentoUpload(
file file
@@ -1512,6 +1598,7 @@
<FileUpload <FileUpload
label="Anexar Documento (PDF ou Imagem)" label="Anexar Documento (PDF ou Imagem)"
bind:value={licencaPaternidade.documentoId} bind:value={licencaPaternidade.documentoId}
required={true}
onUpload={async (file) => { onUpload={async (file) => {
licencaPaternidade.documentoId = await handleDocumentoUpload( licencaPaternidade.documentoId = await handleDocumentoUpload(
file file
@@ -1560,3 +1647,14 @@
{/if} {/if}
</main> </main>
<!-- Modal de Erro -->
<ErrorModal
bind:open={erroModal.aberto}
title={erroModal.titulo}
message={erroModal.mensagem}
details={erroModal.detalhes}
onClose={() => {
erroModal.aberto = false;
}}
/>