feat: implement absence management features in the dashboard

- Added functionality for managing absence requests, including listing, approving, and rejecting requests.
- Enhanced the user interface to display statistics and pending requests for better oversight.
- Updated backend schema to support absence requests and notifications, ensuring data integrity and efficient handling.
- Integrated new components for absence request forms and approval workflows, improving user experience and administrative efficiency.
This commit is contained in:
2025-11-04 14:23:46 -03:00
parent f02eb473ca
commit a93d55f02b
13 changed files with 3837 additions and 497 deletions

View File

@@ -1,48 +1,218 @@
<script lang="ts">
</script>
<main class="container mx-auto px-4 py-4">
<div class="text-sm breadcrumbs mb-4">
<ul>
<li><a href="/" class="text-primary hover:underline">Dashboard</a></li>
<li>Secretaria de Gestão de Pessoas</li>
</ul>
</div>
<div class="mb-6">
<div class="flex items-center gap-4 mb-2">
<div class="p-3 bg-teal-500/20 rounded-xl">
<svg xmlns="http://www.w3.org/2000/svg" class="h-8 w-8 text-teal-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
</div>
<div>
<h1 class="text-3xl font-bold text-primary">Secretaria de Gestão de Pessoas</h1>
<p class="text-base-content/70">Gestão estratégica de pessoas</p>
</div>
</div>
</div>
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<div class="flex flex-col items-center justify-center py-12 text-center">
<div class="mb-6">
<svg xmlns="http://www.w3.org/2000/svg" class="h-24 w-24 text-base-content/20" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
</svg>
</div>
<h2 class="text-2xl font-bold mb-2">Módulo em Desenvolvimento</h2>
<p class="text-base-content/70 max-w-md mb-6">
O módulo da Secretaria de Gestão de Pessoas está sendo desenvolvido e em breve estará disponível com funcionalidades completas de gestão estratégica de pessoas.
</p>
<div class="badge badge-warning badge-lg gap-2">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6" />
</svg>
Em Desenvolvimento
</div>
</div>
</div>
</div>
</main>
<script lang="ts">
import { useQuery, useConvexClient } from "convex-svelte";
import { api } from "@sgse-app/backend/convex/_generated/api";
import { goto } from "$app/navigation";
const client = useConvexClient();
// Buscar todas as solicitações de ausências
const ausenciasQuery = useQuery(api.ausencias.listarTodas, {});
const ausencias = $derived(ausenciasQuery?.data || []);
// Estatísticas
const stats = $derived({
total: ausencias.length,
pendentes: ausencias.filter((a) => a.status === "aguardando_aprovacao").length,
aprovadas: ausencias.filter((a) => a.status === "aprovado").length,
reprovadas: ausencias.filter((a) => a.status === "reprovado").length,
});
// Solicitações pendentes (últimas 5)
const pendentes = $derived(
ausencias
.filter((a) => a.status === "aguardando_aprovacao")
.slice(0, 5)
);
function calcularDias(dataInicio: string, dataFim: string): number {
const inicio = new Date(dataInicio);
const fim = new Date(dataFim);
const diff = fim.getTime() - inicio.getTime();
return Math.ceil(diff / (1000 * 60 * 60 * 24)) + 1;
}
function getStatusBadge(status: string) {
const badges: Record<string, string> = {
aguardando_aprovacao: "badge-warning",
aprovado: "badge-success",
reprovado: "badge-error",
};
return badges[status] || "badge-neutral";
}
function getStatusTexto(status: string) {
const textos: Record<string, string> = {
aguardando_aprovacao: "Aguardando",
aprovado: "Aprovado",
reprovado: "Reprovado",
};
return textos[status] || status;
}
</script>
<main class="container mx-auto px-4 py-4">
<div class="text-sm breadcrumbs mb-4">
<ul>
<li><a href="/" class="text-primary hover:underline">Dashboard</a></li>
<li>Secretaria de Gestão de Pessoas</li>
</ul>
</div>
<div class="mb-6">
<div class="flex items-center gap-4 mb-2">
<div class="p-3 bg-teal-500/20 rounded-xl">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-8 w-8 text-teal-600"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"
/>
</svg>
</div>
<div>
<h1 class="text-3xl font-bold text-primary">
Secretaria de Gestão de Pessoas
</h1>
<p class="text-base-content/70">Gestão estratégica de pessoas</p>
</div>
</div>
</div>
<!-- Card: Gestão de Ausências -->
<div class="card bg-base-100 shadow-xl mb-6 border-t-4 border-orange-500">
<div class="card-body">
<div class="flex items-center justify-between mb-4">
<h2 class="card-title text-2xl">
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-7 w-7 text-orange-600"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
Gestão de Ausências
</h2>
<button
type="button"
class="btn btn-sm btn-outline btn-primary"
onclick={() => goto("/recursos-humanos/ausencias")}
>
Ver Todas
</button>
</div>
<!-- Estatísticas -->
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-6">
<div class="stat bg-base-200 rounded-lg">
<div class="stat-title">Total</div>
<div class="stat-value text-orange-600">{stats.total}</div>
<div class="stat-desc">Solicitações</div>
</div>
<div class="stat bg-warning/10 rounded-lg">
<div class="stat-title">Pendentes</div>
<div class="stat-value text-warning">{stats.pendentes}</div>
<div class="stat-desc">Aguardando</div>
</div>
<div class="stat bg-success/10 rounded-lg">
<div class="stat-title">Aprovadas</div>
<div class="stat-value text-success">{stats.aprovadas}</div>
<div class="stat-desc">Deferidas</div>
</div>
<div class="stat bg-error/10 rounded-lg">
<div class="stat-title">Reprovadas</div>
<div class="stat-value text-error">{stats.reprovadas}</div>
<div class="stat-desc">Indeferidas</div>
</div>
</div>
<!-- Lista de Pendentes -->
<div>
<h3 class="font-bold text-lg mb-3">
Solicitações Pendentes de Aprovação
</h3>
{#if pendentes.length === 0}
<div class="alert alert-success">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
class="stroke-current shrink-0 w-6 h-6"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"
></path>
</svg>
<span>Nenhuma solicitação pendente no momento.</span>
</div>
{:else}
<div class="overflow-x-auto">
<table class="table table-zebra">
<thead>
<tr>
<th>Funcionário</th>
<th>Período</th>
<th>Dias</th>
<th>Status</th>
<th>Solicitado em</th>
</tr>
</thead>
<tbody>
{#each pendentes as ausencia}
<tr>
<td class="font-semibold">
{ausencia.funcionario?.nome || "N/A"}
</td>
<td>
{new Date(ausencia.dataInicio).toLocaleDateString("pt-BR")} até{" "}
{new Date(ausencia.dataFim).toLocaleDateString("pt-BR")}
</td>
<td class="font-bold">
{calcularDias(ausencia.dataInicio, ausencia.dataFim)} dias
</td>
<td>
<div class={`badge ${getStatusBadge(ausencia.status)}`}>
{getStatusTexto(ausencia.status)}
</div>
</td>
<td class="text-xs">
{new Date(ausencia.criadoEm).toLocaleDateString("pt-BR")}
</td>
</tr>
{/each}
</tbody>
</table>
</div>
{#if stats.pendentes > 5}
<div class="mt-4 text-center">
<button
type="button"
class="btn btn-sm btn-outline"
onclick={() => goto("/recursos-humanos/ausencias")}
>
Ver todas as {stats.pendentes} pendentes
</button>
</div>
{/if}
{/if}
</div>
</div>
</div>
</main>