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

@@ -5,7 +5,6 @@
import { formatDistanceToNow } from "date-fns";
import { ptBR } from "date-fns/locale";
import { onMount } from "svelte";
import { authStore } from "$lib/stores/auth.svelte";
import {
Bell,
Mail,
@@ -26,6 +25,8 @@
const todasNotificacoesQuery = useQuery(api.chat.obterNotificacoes, {
apenasPendentes: false,
});
// Usuário atual
const currentUser = useQuery(api.auth.getCurrentUser, {});
let modalOpen = $state(false);
let notificacoesFerias = $state<
@@ -74,13 +75,12 @@
// Buscar notificações de férias
async function buscarNotificacoesFerias() {
try {
const usuarioStore = authStore;
if (usuarioStore.usuario?._id) {
const usuarioId = currentUser?.data?._id;
if (usuarioId) {
const notifsFerias = await client.query(
api.ferias.obterNotificacoesNaoLidas,
{
usuarioId: usuarioStore.usuario._id,
usuarioId,
},
);
notificacoesFerias = notifsFerias || [];
@@ -93,14 +93,13 @@
// Buscar notificações de ausências
async function buscarNotificacoesAusencias() {
try {
const usuarioStore = authStore;
if (usuarioStore.usuario?._id) {
const usuarioId = currentUser?.data?._id;
if (usuarioId) {
try {
const notifsAusencias = await client.query(
api.ausencias.obterNotificacoesNaoLidas,
{
usuarioId: usuarioStore.usuario._id,
usuarioId,
},
);
notificacoesAusencias = notifsAusencias || [];
@@ -366,7 +365,7 @@
>
<div class="flex items-start gap-3">
<!-- Ícone -->
<div class="flex-shrink-0 mt-1">
<div class="shrink-0 mt-1">
{#if notificacao.tipo === "nova_mensagem"}
<Mail class="w-5 h-5 text-primary" strokeWidth={1.5} />
{:else if notificacao.tipo === "mencao"}
@@ -415,7 +414,7 @@
</div>
<!-- Indicador de não lida -->
<div class="flex-shrink-0">
<div class="shrink-0">
<div class="w-2 h-2 rounded-full bg-primary"></div>
</div>
</div>
@@ -438,7 +437,7 @@
>
<div class="flex items-start gap-3">
<!-- Ícone -->
<div class="flex-shrink-0 mt-1">
<div class="shrink-0 mt-1">
{#if notificacao.tipo === "nova_mensagem"}
<Mail
class="w-5 h-5 text-primary/60"
@@ -508,7 +507,7 @@
>
<div class="flex items-start gap-3">
<!-- Ícone -->
<div class="flex-shrink-0 mt-1">
<div class="shrink-0 mt-1">
<Calendar
class="w-5 h-5 text-purple-600"
strokeWidth={2}
@@ -526,7 +525,7 @@
</div>
<!-- Badge -->
<div class="flex-shrink-0">
<div class="shrink-0">
<div class="badge badge-primary badge-xs"></div>
</div>
</div>
@@ -550,7 +549,7 @@
>
<div class="flex items-start gap-3">
<!-- Ícone -->
<div class="flex-shrink-0 mt-1">
<div class="shrink-0 mt-1">
<Clock class="w-5 h-5 text-orange-600" strokeWidth={2} />
</div>
@@ -565,7 +564,7 @@
</div>
<!-- Badge -->
<div class="flex-shrink-0">
<div class="shrink-0">
<div class="badge badge-warning badge-xs"></div>
</div>
</div>