refactor: integrate current user data across components

- Replaced instances of `authStore` with `currentUser` to streamline user authentication handling.
- Updated permission checks and user-related data retrieval to utilize the new `useQuery` for better performance and clarity.
- Cleaned up component structures and improved formatting for consistency and readability.
- Enhanced error handling and user feedback mechanisms in various components to improve user experience.
This commit is contained in:
2025-11-08 10:52:33 -03:00
parent 01138b3e1c
commit 9a5f2b294d
28 changed files with 2312 additions and 1235 deletions

View File

@@ -2,11 +2,11 @@
import { goto } from "$app/navigation";
import { useQuery, useConvexClient } from "convex-svelte";
import { api } from "@sgse-app/backend/convex/_generated/api";
import { authStore } from "$lib/stores/auth.svelte";
import AprovarAusencias from "$lib/components/AprovarAusencias.svelte";
import type { Id } from "@sgse-app/backend/convex/_generated/dataModel";
const client = useConvexClient();
const currentUser = useQuery(api.auth.getCurrentUser, {});
// Buscar TODAS as solicitações de ausências
const todasAusenciasQuery = useQuery(api.ausencias.listarTodas, {});
@@ -22,13 +22,14 @@
// Filtro de status
if (filtroStatus !== "todos" && a.status !== filtroStatus) return false;
return true;
})
}),
);
// Estatísticas gerais
const stats = $derived({
total: ausencias.length,
aguardando: ausencias.filter((a) => a.status === "aguardando_aprovacao").length,
aguardando: ausencias.filter((a) => a.status === "aguardando_aprovacao")
.length,
aprovadas: ausencias.filter((a) => a.status === "aprovado").length,
reprovadas: ausencias.filter((a) => a.status === "reprovado").length,
});
@@ -58,7 +59,9 @@
return Math.ceil(diff / (1000 * 60 * 60 * 24)) + 1;
}
async function selecionarSolicitacao(solicitacaoId: Id<"solicitacoesAusencias">) {
async function selecionarSolicitacao(
solicitacaoId: Id<"solicitacoesAusencias">,
) {
solicitacaoSelecionada = solicitacaoId;
}
@@ -154,7 +157,9 @@
<div class="stat-desc">Solicitações</div>
</div>
<div class="stat bg-base-100 shadow-lg rounded-box border border-warning/30">
<div
class="stat bg-base-100 shadow-lg rounded-box border border-warning/30"
>
<div class="stat-figure text-warning">
<svg
xmlns="http://www.w3.org/2000/svg"
@@ -176,7 +181,9 @@
<div class="stat-desc">Aguardando</div>
</div>
<div class="stat bg-base-100 shadow-lg rounded-box border border-success/30">
<div
class="stat bg-base-100 shadow-lg rounded-box border border-success/30"
>
<div class="stat-figure text-success">
<svg
xmlns="http://www.w3.org/2000/svg"
@@ -294,7 +301,9 @@
{#if ausencia.time}
<div
class="badge badge-sm font-semibold"
style="background-color: {ausencia.time.cor}20; border-color: {ausencia.time.cor}; color: {ausencia.time.cor}"
style="background-color: {ausencia.time
.cor}20; border-color: {ausencia.time
.cor}; color: {ausencia.time.cor}"
>
{ausencia.time.nome}
</div>
@@ -390,16 +399,14 @@
</main>
<!-- Modal de Aprovação -->
{#if solicitacaoSelecionada && authStore.usuario}
{#await client.query(api.ausencias.obterDetalhes, {
solicitacaoId: solicitacaoSelecionada,
}) then detalhes}
{#if solicitacaoSelecionada && currentUser.data}
{#await client.query( api.ausencias.obterDetalhes, { solicitacaoId: solicitacaoSelecionada }, ) then detalhes}
{#if detalhes}
<dialog class="modal modal-open">
<div class="modal-box max-w-4xl">
<AprovarAusencias
solicitacao={detalhes}
gestorId={authStore.usuario._id}
gestorId={currentUser.data._id}
onSucesso={recarregar}
onCancelar={() => (solicitacaoSelecionada = null)}
/>
@@ -408,12 +415,10 @@
<button
type="button"
onclick={() => (solicitacaoSelecionada = null)}
aria-label="Fechar modal"
>Fechar</button
aria-label="Fechar modal">Fechar</button
>
</form>
</dialog>
{/if}
{/await}
{/if}