diff --git a/ui/src/App.vue b/ui/src/App.vue index dd4e2d8..56c4abf 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -2,6 +2,7 @@ import { watchEffect, computed } from 'vue' // Added computed import TopBar from '@/components/ui/TopBar.vue' import NavBar from '@/components/ui/NavBar.vue' +import SnackbarContainer from '@/components/ui/SnackbarContainer.vue' import { useUi } from '@/stores/useUi' const ui = useUi() @@ -80,6 +81,7 @@ const transitionDurationStyle = computed(() => { + diff --git a/ui/src/components/ui/NavBar.vue b/ui/src/components/ui/NavBar.vue index 2582ec7..18bbe8f 100644 --- a/ui/src/components/ui/NavBar.vue +++ b/ui/src/components/ui/NavBar.vue @@ -3,6 +3,7 @@ import { ref, watch, computed, onMounted } from 'vue' import { useRoute } from 'vue-router' import { useUi } from '@/stores/useUi' import { useRealtimeStore } from '@/stores/useRealtime' +import { moduleInfo } from '@/constants/moduleInfo' const ui = useUi() const realtime = useRealtimeStore() @@ -10,10 +11,10 @@ const realtime = useRealtimeStore() // enlaces de la app const links = [ { to: '/', label: 'Chat', icon: '💬' }, - { to: '/empleados', label: 'Empleados', icon: '👥' }, - { to: '/tareas', label: 'Tareas', icon: '📋' }, - { to: '/planillas', label: 'Planillas', icon: '📂' }, - { to: '/asistencias', label: 'Asistencias', icon: '⏰' }, + { to: '/empleados', label: 'Empleados', icon: moduleInfo.Cliente.icon }, + { to: '/tareas', label: 'Tareas', icon: moduleInfo.TareaRealizada.icon }, + { to: '/planillas', label: 'Planillas', icon: moduleInfo.Planilla.icon }, + { to: '/asistencias', label: 'Asistencias', icon: moduleInfo.Asistencia.icon }, { to: '/feed', label: 'Feed', icon: '📰' }, { to: '/config', label: 'Config', icon: '⚙️' }, ] diff --git a/ui/src/components/ui/SnackbarContainer.vue b/ui/src/components/ui/SnackbarContainer.vue new file mode 100644 index 0000000..be3b66c --- /dev/null +++ b/ui/src/components/ui/SnackbarContainer.vue @@ -0,0 +1,80 @@ + + + + + + + {{ snack.icon }} + {{ snack.header }} + + {{ snack.text }} + + × + + + + + + + + diff --git a/ui/src/constants/moduleInfo.js b/ui/src/constants/moduleInfo.js new file mode 100644 index 0000000..5d8aa30 --- /dev/null +++ b/ui/src/constants/moduleInfo.js @@ -0,0 +1,6 @@ +export const moduleInfo = { + Cliente: { label: 'Empleados', icon: '👥' }, + TareaRealizada: { label: 'Tareas', icon: '📋' }, + Planilla: { label: 'Planillas', icon: '📂' }, + Asistencia: { label: 'Asistencias', icon: '⏰' } +} diff --git a/ui/src/stores/useRealtime.js b/ui/src/stores/useRealtime.js index cf34662..9992412 100644 --- a/ui/src/stores/useRealtime.js +++ b/ui/src/stores/useRealtime.js @@ -3,6 +3,8 @@ import { usePlanillasStore } from './usePlanillas' import { useEmpleadosStore } from './useEmpleados' import { useTareasStore } from './useTareas' import { useAsistenciasStore } from './useAsistencias' +import { useSnackbarStore } from './useSnackbar' +import { moduleInfo } from '@/constants/moduleInfo' export const useRealtimeStore = defineStore('realtime', { state: () => ({ @@ -55,6 +57,19 @@ export const useRealtimeStore = defineStore('realtime', { addEvent(); } + const snackbar = useSnackbarStore(); + const idPart = payload.new?.id || payload.old?.id; + const message = `${payload.operation} ${payload.table}${idPart ? ' #' + idPart : ''}`; + const type = payload.operation === 'DELETE' ? 'error' : + payload.operation === 'INSERT' ? 'success' : 'info'; + const info = moduleInfo[payload.table] || {}; + snackbar.push({ + text: message, + type, + icon: info.icon, + header: info.label + }); + // mark badge for module and operation if (this.badges[payload.table]) { this.badges[payload.table][payload.operation] = true; diff --git a/ui/src/stores/useSnackbar.js b/ui/src/stores/useSnackbar.js new file mode 100644 index 0000000..1689eb6 --- /dev/null +++ b/ui/src/stores/useSnackbar.js @@ -0,0 +1,26 @@ +import { defineStore } from 'pinia' + +export const useSnackbarStore = defineStore('snackbar', { + state: () => ({ + snacks: [], + maxSnacks: 5 + }), + actions: { + push({ text, type = 'info', icon = '', header = '', duration = 6000 }) { + const id = crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).slice(2) + const snack = { id, text, type, icon, header } + if (this.snacks.length >= this.maxSnacks) { + this.snacks.shift() + } + this.snacks.push(snack) + if (duration > 0) { + setTimeout(() => this.remove(id), duration) + } + return id + }, + remove(id) { + const index = this.snacks.findIndex(s => s.id === id) + if (index !== -1) this.snacks.splice(index, 1) + } + } +})