@innertia-solutions/innertia-nuxt 0.1.89 → 0.1.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/app.config.ts +8 -0
- package/components/App/NotificationBell.vue +4 -1
- package/components/App/NotificationHistory.vue +4 -2
- package/components/Mail/BrandingPreview.vue +60 -0
- package/components/Mail/BrandingSettings.vue +141 -0
- package/components/Notifications/Preferences.vue +98 -0
- package/components/Notifications/__tests__/sfc-compile.test.ts +34 -0
- package/components/Platform/Emails.vue +133 -0
- package/components/Platform/MailSettings.vue +213 -0
- package/composables/__tests__/useNotifications.test.ts +32 -0
- package/composables/internal/__tests__/forcePassword.test.ts +37 -0
- package/composables/internal/__tests__/mailBranding.test.ts +35 -0
- package/composables/internal/forcePassword.ts +39 -0
- package/composables/internal/mailBranding.ts +62 -0
- package/composables/useNotificationHistory/index.ts +8 -7
- package/composables/useNotificationPreferences/index.ts +28 -0
- package/composables/useNotificationPreferences/internal/__tests__/preferences.test.ts +39 -0
- package/composables/useNotificationPreferences/internal/preferences.ts +66 -0
- package/composables/useNotifications.js +10 -5
- package/docs/correos-notificaciones.md +101 -0
- package/middleware/06.force-password.global.ts +14 -0
- package/middleware/platform-owner.ts +12 -0
- package/nuxt.config.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,8 @@ All notable changes to `@innertia-solutions/innertia-nuxt` are documented here.
|
|
|
6
6
|
|
|
7
7
|
### Added
|
|
8
8
|
|
|
9
|
+
- Correos y notificaciones con marca (opt-in): `Notifications.Preferences` + `useNotificationPreferences()`, `Platform.Emails` (filtros por tipo, espacio y estado; motivo de los fallidos), `Platform.MailSettings` (versión pulida: validación por campo, cambios sin guardar, confirmar borrar key, prueba con vista previa), `Mail.BrandingPreview` y `Mail.BrandingSettings` (marca del espacio). Campanita e historial en platform con la prop `endpoint` (`useNotifications({ base })`, `useNotificationHistory({ base })`). Middleware `platform-owner` y `06.force-password.global` (apagado hasta `appConfig.innertia.forcePassword.enabled`). Ver `docs/correos-notificaciones.md`.
|
|
10
|
+
|
|
9
11
|
- Passkeys (WebAuthn): composable `usePasskeys()`, componentes `Auth.PasskeyButton` (login tenant y `/platform`, con autocompletado), `Auth.PasskeyInvite`, `Auth.PasskeyManager` y `Auth.UserPasskeys`, y rutas BFF `/_auth/passkey/login` y `/_auth/platform/passkey/login` que sellan la sesión solo si hay token. Se activa y desactiva desde `/platform` con `Auth.PasskeySettings` (sin variables de entorno). Ver `docs/passkeys.md`.
|
|
10
12
|
- `Kanban.Standard`: reordenamiento intra-columna con drag&drop (prop `reorderEndpoint`); orden por `position`, placeholder de inserción, y persistencia vía POST. Retrocompatible: sin la prop se comporta igual que antes (solo cross-column).
|
|
11
13
|
|
package/app.config.ts
CHANGED
|
@@ -36,6 +36,14 @@ export default defineAppConfig({
|
|
|
36
36
|
version: '1.0.0',
|
|
37
37
|
},
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Cambio de contraseña forzado (middleware 06.force-password.global). Opt-in:
|
|
41
|
+
* forcePassword: { enabled: true, routes: { '/backoffice': '/backoffice/auth/change-password' } }
|
|
42
|
+
* `allow` (opcional): prefijos que siempre pasan (default: '<prefijo>/auth/').
|
|
43
|
+
* `undefined` a propósito (ver nota de `mode`): el producto lo define en su nuxt.config.
|
|
44
|
+
*/
|
|
45
|
+
forcePassword: undefined as { enabled?: boolean; routes?: Record<string, string>; allow?: string[] } | undefined,
|
|
46
|
+
|
|
39
47
|
/**
|
|
40
48
|
* Tema Preline. Cada tema define el "feel" completo (paleta neutral, fondos,
|
|
41
49
|
* bordes, sombras) tanto en light como en dark mode. Es el equivalente a
|
|
@@ -8,12 +8,15 @@ import { IconBell, IconChecks, IconBellOff } from '@tabler/icons-vue'
|
|
|
8
8
|
*
|
|
9
9
|
* Backend: notification center de innertia-laravel (vía useNotifications).
|
|
10
10
|
* `allRoute`: ruta de la vista "ver todas" (cada producto monta la suya).
|
|
11
|
+
* `endpoint`: prefijo de la API. En el layout de platform:
|
|
12
|
+
* <App.NotificationBell endpoint="platform/notifications" all-route="/platform/notifications" />
|
|
11
13
|
*/
|
|
12
14
|
const props = defineProps({
|
|
13
15
|
allRoute: { type: String, default: '/backoffice/notifications' },
|
|
16
|
+
endpoint: { type: String, default: 'notifications' },
|
|
14
17
|
})
|
|
15
18
|
|
|
16
|
-
const { fetchNotifications, markAsRead, markAllAsRead } = useNotifications()
|
|
19
|
+
const { fetchNotifications, markAsRead, markAllAsRead } = useNotifications({ base: props.endpoint })
|
|
17
20
|
const store = useNotificationsStore()
|
|
18
21
|
|
|
19
22
|
const tab = ref('all') // all | unread
|
|
@@ -17,7 +17,9 @@ const props = withDefaults(defineProps<{
|
|
|
17
17
|
perPage?: number
|
|
18
18
|
/** Ruta destino al abrir una notificación; null = no navega. Default: data.link → data.url. */
|
|
19
19
|
resolveLink?: (n: NotificationItem) => string | null | undefined
|
|
20
|
-
|
|
20
|
+
/** Prefijo de la API (en /platform: 'platform/notifications'). */
|
|
21
|
+
endpoint?: string
|
|
22
|
+
}>(), { perPage: 20, resolveLink: undefined, endpoint: 'notifications' })
|
|
21
23
|
|
|
22
24
|
const emit = defineEmits<{ (e: 'open', n: NotificationItem): void }>()
|
|
23
25
|
|
|
@@ -25,7 +27,7 @@ const filter = ref<HistoryFilter>('all')
|
|
|
25
27
|
const page = ref(1)
|
|
26
28
|
watch(filter, () => { page.value = 1 })
|
|
27
29
|
|
|
28
|
-
const { list, markRead, markAllRead, remove, removeRead } = useNotificationHistory()
|
|
30
|
+
const { list, markRead, markAllRead, remove, removeRead } = useNotificationHistory({ base: props.endpoint })
|
|
29
31
|
const { data, isLoading, isError, refetch } = list(() => ({ filter: filter.value, page: page.value, perPage: props.perPage }))
|
|
30
32
|
const { mutateAsync: doMarkRead } = markRead()
|
|
31
33
|
const { mutate: doMarkAll, isPending: markingAll } = markAllRead()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
import { resolveBrandingPreview, type BrandingFields, type ResolvedBranding } from '../../composables/internal/mailBranding'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Mail.BrandingPreview — vista previa en vivo de un correo con la marca (logo/nombre, color del
|
|
7
|
+
* botón, pie y "Enviado vía …"). Misma resolución que \Innertia\Mail\Branding::for().
|
|
8
|
+
*
|
|
9
|
+
* <Mail.BrandingPreview :branding="form" :platform="data.platform" /> // marca del espacio
|
|
10
|
+
* <Mail.BrandingPreview :platform="{ name, logo_url, color }" /> // marca de plataforma
|
|
11
|
+
*
|
|
12
|
+
* Un logo que no carga se reemplaza por el nombre (como en el correo real).
|
|
13
|
+
*/
|
|
14
|
+
const props = withDefaults(defineProps<{
|
|
15
|
+
branding?: BrandingFields | null
|
|
16
|
+
platform?: Partial<ResolvedBranding> | null
|
|
17
|
+
title?: string
|
|
18
|
+
body?: string
|
|
19
|
+
action?: string
|
|
20
|
+
}>(), {
|
|
21
|
+
branding: null,
|
|
22
|
+
platform: null,
|
|
23
|
+
title: 'Nuevo mensaje de voz',
|
|
24
|
+
body: 'Tienes un mensaje nuevo en tu buzón. Escúchalo desde la plataforma.',
|
|
25
|
+
action: 'Ver detalle',
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const resolved = computed(() => resolveBrandingPreview(props.branding, props.platform))
|
|
29
|
+
const logoFailed = ref(false)
|
|
30
|
+
watch(() => resolved.value.logo_url, () => { logoFailed.value = false })
|
|
31
|
+
const footer = computed(() => [resolved.value.footer_address, resolved.value.footer_phone].filter(Boolean).join(' · '))
|
|
32
|
+
const year = new Date().getFullYear()
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<div class="rounded-card border border-card-line bg-[#f4f4f5] p-5 text-left" data-testid="branding-preview">
|
|
37
|
+
<div class="flex justify-center pb-4">
|
|
38
|
+
<img
|
|
39
|
+
v-if="resolved.logo_url && !logoFailed"
|
|
40
|
+
:src="resolved.logo_url"
|
|
41
|
+
:alt="resolved.name"
|
|
42
|
+
class="h-10 w-auto max-w-full object-contain"
|
|
43
|
+
@error="logoFailed = true"
|
|
44
|
+
/>
|
|
45
|
+
<span v-else class="text-xl font-bold" :style="{ color: resolved.color }">{{ resolved.name }}</span>
|
|
46
|
+
</div>
|
|
47
|
+
<div class="rounded-lg bg-white px-6 py-6 shadow-sm">
|
|
48
|
+
<p class="text-lg font-bold text-zinc-900">{{ title }}</p>
|
|
49
|
+
<p class="mt-2 text-sm text-zinc-500">{{ body }}</p>
|
|
50
|
+
<div class="mt-5 flex justify-center">
|
|
51
|
+
<span class="inline-block rounded-md px-5 py-2.5 text-sm font-semibold text-white" :style="{ backgroundColor: resolved.color }">{{ action }}</span>
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
<p class="pt-4 text-center text-[11px] leading-relaxed text-zinc-400">
|
|
55
|
+
<template v-if="footer">{{ footer }}<br></template>
|
|
56
|
+
© {{ year }} {{ resolved.name }}. Todos los derechos reservados.
|
|
57
|
+
<template v-if="resolved.via"><br>Enviado vía {{ resolved.via }}</template>
|
|
58
|
+
</p>
|
|
59
|
+
</div>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { IconSend, IconPalette } from '@tabler/icons-vue'
|
|
3
|
+
import { DEFAULT_BRAND_COLOR, validateBranding } from '../../composables/internal/mailBranding'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Mail.BrandingSettings — marca del espacio para los correos de negocio ("Sistema › Marca").
|
|
7
|
+
* Backend: \Innertia\Mail\Routes::tenantBranding('settings/branding') → GET|PUT, POST /test.
|
|
8
|
+
*
|
|
9
|
+
* <Mail.BrandingSettings />
|
|
10
|
+
* <Mail.BrandingSettings>
|
|
11
|
+
* <template #logo-picker="{ set }"><MiSelectorDeArchivos @picked="(f) => set({ logo_file_id: f.id })" /></template>
|
|
12
|
+
* </Mail.BrandingSettings>
|
|
13
|
+
*
|
|
14
|
+
* Vista previa en vivo, aviso de cambios sin guardar y "Enviarme un correo de prueba" (usa lo guardado).
|
|
15
|
+
*/
|
|
16
|
+
const props = withDefaults(defineProps<{ endpoint?: string }>(), { endpoint: 'settings/branding' })
|
|
17
|
+
|
|
18
|
+
const api = useApi()
|
|
19
|
+
const toast = useToast()
|
|
20
|
+
const queryClient = useQueryClient()
|
|
21
|
+
const base = props.endpoint.replace(/^\/+|\/+$/g, '')
|
|
22
|
+
|
|
23
|
+
const { data, isPending } = useQuery({ queryKey: ['mail', 'branding', base], queryFn: () => api.get(base) })
|
|
24
|
+
|
|
25
|
+
const FIELDS = ['display_name', 'logo_url', 'logo_file_id', 'color', 'footer_address', 'footer_phone'] as const
|
|
26
|
+
type Field = typeof FIELDS[number]
|
|
27
|
+
const form = reactive<Record<Field, string>>(Object.fromEntries(FIELDS.map(f => [f, ''])) as any)
|
|
28
|
+
const errors = reactive<Record<string, string | null>>({})
|
|
29
|
+
FIELDS.forEach(f => watch(() => form[f], () => { errors[f] = null }))
|
|
30
|
+
|
|
31
|
+
const saved = ref('')
|
|
32
|
+
const snapshot = () => JSON.stringify(form)
|
|
33
|
+
const isDirty = computed(() => snapshot() !== saved.value)
|
|
34
|
+
const platform = computed(() => (data.value as any)?.platform ?? null)
|
|
35
|
+
const previewFields = computed(() => ({
|
|
36
|
+
...form,
|
|
37
|
+
// Un logo desde Archivos se ve con la URL resuelta por el servidor (una vez guardado).
|
|
38
|
+
logo_url: form.logo_url || (form.logo_file_id && !isDirty.value ? (data.value as any)?.resolved?.logo_url : '') || '',
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
watch(data, (v: any) => {
|
|
42
|
+
if (!v) return
|
|
43
|
+
FIELDS.forEach((f) => { form[f] = v.branding?.[f] ?? '' })
|
|
44
|
+
saved.value = snapshot()
|
|
45
|
+
}, { immediate: true })
|
|
46
|
+
|
|
47
|
+
function set(values: Partial<Record<Field, string | null>>) {
|
|
48
|
+
for (const [k, v] of Object.entries(values)) {
|
|
49
|
+
if ((FIELDS as readonly string[]).includes(k)) form[k as Field] = v ?? ''
|
|
50
|
+
}
|
|
51
|
+
if (values.logo_file_id) form.logo_url = ''
|
|
52
|
+
if (values.logo_url) form.logo_file_id = ''
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const saving = ref(false)
|
|
56
|
+
async function save() {
|
|
57
|
+
Object.assign(errors, validateBranding(form))
|
|
58
|
+
if (Object.values(errors).some(Boolean)) return
|
|
59
|
+
saving.value = true
|
|
60
|
+
try {
|
|
61
|
+
const payload = Object.fromEntries(FIELDS.map(f => [f, form[f].trim() || null]))
|
|
62
|
+
const res = await api.put(base, payload)
|
|
63
|
+
queryClient.setQueryData(['mail', 'branding', base], { ...(data.value as any), ...res })
|
|
64
|
+
saved.value = snapshot()
|
|
65
|
+
toast.success('Marca guardada.')
|
|
66
|
+
} catch (e: any) {
|
|
67
|
+
const fieldErrors = e?.data?.errors ?? {}
|
|
68
|
+
FIELDS.forEach((f) => { errors[f] = fieldErrors[f]?.[0] ?? null })
|
|
69
|
+
if (!FIELDS.some(f => errors[f])) toast.error(e?.data?.message ?? 'No se pudo guardar.')
|
|
70
|
+
} finally {
|
|
71
|
+
saving.value = false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function discard() {
|
|
76
|
+
const v: any = data.value
|
|
77
|
+
FIELDS.forEach((f) => { form[f] = v?.branding?.[f] ?? '' })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const testing = ref(false)
|
|
81
|
+
async function sendTest() {
|
|
82
|
+
if (isDirty.value) { toast.error('Guarda los cambios antes de probar: la prueba usa la marca guardada.'); return }
|
|
83
|
+
testing.value = true
|
|
84
|
+
try {
|
|
85
|
+
const res: any = await api.post(`${base}/test`, {})
|
|
86
|
+
toast.success(`Correo de prueba enviado a ${res?.sent_to ?? 'tu correo'}.`)
|
|
87
|
+
} catch (e: any) {
|
|
88
|
+
toast.error(e?.data?.message ?? 'No se pudo enviar la prueba.')
|
|
89
|
+
} finally {
|
|
90
|
+
testing.value = false
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onBeforeRouteLeave(() => {
|
|
95
|
+
if (isDirty.value && import.meta.client) return window.confirm('Tienes cambios sin guardar. ¿Salir igual?')
|
|
96
|
+
})
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<template>
|
|
100
|
+
<div class="space-y-5">
|
|
101
|
+
<div v-if="isPending" class="p-8 text-center text-sm text-muted-foreground">Cargando…</div>
|
|
102
|
+
<div v-else class="grid lg:grid-cols-2 gap-5 items-start">
|
|
103
|
+
<div class="space-y-4">
|
|
104
|
+
<div class="bg-card border border-card-line rounded-card p-5 space-y-4">
|
|
105
|
+
<Forms.Input v-model="form.display_name" label="Nombre visible" :placeholder="platform?.name ?? ''" :error="errors.display_name" hint="Aparece en el encabezado de los correos si no hay logo." />
|
|
106
|
+
<div class="space-y-2">
|
|
107
|
+
<Forms.Input v-model="form.logo_url" label="URL del logo" placeholder="https://…/logo.png" :error="errors.logo_url" hint="Imagen pública (PNG o SVG). Si no carga, el correo muestra el nombre." />
|
|
108
|
+
<slot name="logo-picker" :set="set" />
|
|
109
|
+
<p v-if="form.logo_file_id" class="text-xs text-muted-foreground">
|
|
110
|
+
Logo desde Documentos seleccionado.
|
|
111
|
+
<button type="button" class="text-red-500 hover:underline" @click="form.logo_file_id = ''">Quitar</button>
|
|
112
|
+
</p>
|
|
113
|
+
</div>
|
|
114
|
+
<div>
|
|
115
|
+
<label class="block text-sm font-medium text-foreground mb-1">Color</label>
|
|
116
|
+
<div class="flex items-start gap-3">
|
|
117
|
+
<input v-model="form.color" type="color" class="h-9 w-14 rounded-control border border-card-line bg-transparent p-1 cursor-pointer" />
|
|
118
|
+
<Forms.Input v-model="form.color" class="w-40" :placeholder="platform?.color ?? DEFAULT_BRAND_COLOR" :error="errors.color" />
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="grid sm:grid-cols-2 gap-4">
|
|
122
|
+
<Forms.Input v-model="form.footer_address" label="Dirección (pie)" placeholder="Av. Principal 123, Ciudad" :error="errors.footer_address" />
|
|
123
|
+
<Forms.Input v-model="form.footer_phone" label="Teléfono (pie)" placeholder="+56 72 000 0000" :error="errors.footer_phone" />
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<div class="flex flex-wrap items-center justify-end gap-2">
|
|
128
|
+
<span v-if="isDirty" class="text-xs text-amber-600 dark:text-amber-400 mr-auto">Tienes cambios sin guardar.</span>
|
|
129
|
+
<App.Button v-if="isDirty" text="Descartar" severity="secondary" size="sm" @click="discard" />
|
|
130
|
+
<App.Button text="Enviarme un correo de prueba" :icon="IconSend" severity="secondary" size="sm" :disabled="isDirty" :loading="testing" @click="sendTest" />
|
|
131
|
+
<App.Button text="Guardar" severity="primary" size="sm" :disabled="!isDirty" :loading="saving" @click="save" />
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div class="space-y-2">
|
|
136
|
+
<p class="text-sm font-medium text-foreground flex items-center gap-1.5"><IconPalette class="size-4" :stroke-width="1.5" /> Vista previa</p>
|
|
137
|
+
<Mail.BrandingPreview :branding="previewFields" :platform="platform" />
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</template>
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { IconBell, IconMail, IconLock } from '@tabler/icons-vue'
|
|
3
|
+
import {
|
|
4
|
+
CHANNELS, CHANNEL_LABELS, clonePreferences, diffPreferences, groupByCategory, togglePreference,
|
|
5
|
+
type Channel, type NoticeTypePreference,
|
|
6
|
+
} from '../../composables/useNotificationPreferences/internal/preferences'
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* Notifications.Preferences — qué avisos recibe el usuario y por qué canal (campanita/correo).
|
|
10
|
+
* Los avisos críticos de cuenta se muestran bloqueados (el servidor ignora apagarlos).
|
|
11
|
+
* Backend: \Innertia\Notifications\Routes::preferences() (GET|PUT me/notification-preferences).
|
|
12
|
+
*
|
|
13
|
+
* <Notifications.Preferences /> // backoffice
|
|
14
|
+
* <Notifications.Preferences endpoint="platform/me/notification-preferences" />
|
|
15
|
+
*/
|
|
16
|
+
const props = withDefaults(defineProps<{ endpoint?: string }>(), { endpoint: 'me/notification-preferences' })
|
|
17
|
+
|
|
18
|
+
const toast = useToast()
|
|
19
|
+
const { query, save } = useNotificationPreferences({ base: props.endpoint })
|
|
20
|
+
|
|
21
|
+
const original = computed<NoticeTypePreference[]>(() => (query.data.value as any)?.data ?? [])
|
|
22
|
+
const items = ref<NoticeTypePreference[]>([])
|
|
23
|
+
watch(original, (v) => { items.value = clonePreferences(v) }, { immediate: true })
|
|
24
|
+
|
|
25
|
+
const changes = computed(() => diffPreferences(original.value, items.value))
|
|
26
|
+
const groups = computed(() => groupByCategory(items.value))
|
|
27
|
+
const icons: Record<Channel, any> = { bell: IconBell, mail: IconMail }
|
|
28
|
+
|
|
29
|
+
function set(key: string, channel: Channel, enabled: boolean) {
|
|
30
|
+
items.value = togglePreference(items.value, key, channel, enabled)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function submit() {
|
|
34
|
+
if (!changes.value.length) return
|
|
35
|
+
try {
|
|
36
|
+
await save.mutateAsync(changes.value)
|
|
37
|
+
toast.success('Preferencias guardadas.')
|
|
38
|
+
} catch (e: any) {
|
|
39
|
+
toast.error(e?.data?.message ?? 'No se pudieron guardar las preferencias.')
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function discard() {
|
|
44
|
+
items.value = clonePreferences(original.value)
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<div class="space-y-4">
|
|
50
|
+
<div v-if="query.isPending.value" class="p-8 text-center text-sm text-muted-foreground">Cargando…</div>
|
|
51
|
+
<div v-else-if="query.isError.value" class="p-8 text-center text-sm text-muted-foreground">
|
|
52
|
+
No se pudieron cargar tus preferencias.
|
|
53
|
+
<button type="button" class="text-primary hover:underline" @click="query.refetch()">Reintentar</button>
|
|
54
|
+
</div>
|
|
55
|
+
<div v-else-if="!items.length" class="p-8 text-center text-sm text-muted-foreground">No hay avisos configurables.</div>
|
|
56
|
+
|
|
57
|
+
<template v-else>
|
|
58
|
+
<div v-for="g in groups" :key="g.category" class="bg-card border border-card-line rounded-card overflow-hidden">
|
|
59
|
+
<div class="flex items-center gap-3 px-5 py-3 border-b border-card-line bg-muted/30">
|
|
60
|
+
<p class="flex-1 text-sm font-semibold text-foreground">{{ g.label }}</p>
|
|
61
|
+
<span v-for="c in CHANNELS" :key="c" class="w-20 text-center text-xs font-medium text-muted-foreground inline-flex items-center justify-center gap-1">
|
|
62
|
+
<component :is="icons[c]" class="size-3.5" :stroke-width="1.75" />{{ CHANNEL_LABELS[c] }}
|
|
63
|
+
</span>
|
|
64
|
+
</div>
|
|
65
|
+
<ul class="divide-y divide-card-line">
|
|
66
|
+
<li v-for="t in g.items" :key="t.key" class="flex items-center gap-3 px-5 py-3">
|
|
67
|
+
<div class="flex-1 min-w-0">
|
|
68
|
+
<p class="text-sm font-medium text-foreground flex items-center gap-1.5">
|
|
69
|
+
{{ t.label }}
|
|
70
|
+
<IconLock v-if="t.critical" class="size-3.5 text-muted-foreground" :stroke-width="1.75" title="Aviso de seguridad: no se puede desactivar" />
|
|
71
|
+
</p>
|
|
72
|
+
<p v-if="t.description" class="text-xs text-muted-foreground">{{ t.description }}</p>
|
|
73
|
+
</div>
|
|
74
|
+
<label v-for="c in CHANNELS" :key="c" class="w-20 flex justify-center">
|
|
75
|
+
<input
|
|
76
|
+
type="checkbox"
|
|
77
|
+
class="size-4 rounded border-card-line text-primary focus:ring-primary/30 disabled:opacity-50 disabled:cursor-not-allowed"
|
|
78
|
+
:checked="t.preferences[c]?.enabled"
|
|
79
|
+
:disabled="t.preferences[c]?.locked || !t.preferences[c]?.available"
|
|
80
|
+
:aria-label="`${t.label}: ${CHANNEL_LABELS[c]}`"
|
|
81
|
+
@change="set(t.key, c, ($event.target as HTMLInputElement).checked)"
|
|
82
|
+
/>
|
|
83
|
+
</label>
|
|
84
|
+
</li>
|
|
85
|
+
</ul>
|
|
86
|
+
</div>
|
|
87
|
+
|
|
88
|
+
<p class="text-xs text-muted-foreground flex items-center gap-1">
|
|
89
|
+
<IconLock class="size-3.5" :stroke-width="1.75" /> Los avisos de seguridad de tu cuenta siempre se envían.
|
|
90
|
+
</p>
|
|
91
|
+
|
|
92
|
+
<div class="flex justify-end gap-2">
|
|
93
|
+
<App.Button v-if="changes.length" text="Descartar" severity="secondary" size="sm" @click="discard" />
|
|
94
|
+
<App.Button text="Guardar" severity="primary" size="sm" :disabled="!changes.length" :loading="save.isPending.value" @click="submit" />
|
|
95
|
+
</div>
|
|
96
|
+
</template>
|
|
97
|
+
</div>
|
|
98
|
+
</template>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { resolve } from 'node:path'
|
|
4
|
+
import { parse, compileScript, compileTemplate } from 'vue/compiler-sfc'
|
|
5
|
+
|
|
6
|
+
// Componentes de avisos, correo y marca: compilan (script + template) sin errores.
|
|
7
|
+
const COMPONENTS = [
|
|
8
|
+
'../Preferences.vue',
|
|
9
|
+
'../../Platform/Emails.vue',
|
|
10
|
+
'../../Platform/MailSettings.vue',
|
|
11
|
+
'../../Mail/BrandingPreview.vue',
|
|
12
|
+
'../../Mail/BrandingSettings.vue',
|
|
13
|
+
'../../App/NotificationBell.vue',
|
|
14
|
+
'../../App/NotificationHistory.vue',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
describe('SFC de avisos y correo compilan', () => {
|
|
18
|
+
for (const rel of COMPONENTS) {
|
|
19
|
+
it(rel, () => {
|
|
20
|
+
const filename = resolve(__dirname, rel)
|
|
21
|
+
const { descriptor, errors } = parse(readFileSync(filename, 'utf8'), { filename })
|
|
22
|
+
expect(errors).toEqual([])
|
|
23
|
+
|
|
24
|
+
const script = compileScript(descriptor, { id: rel })
|
|
25
|
+
const tpl = compileTemplate({
|
|
26
|
+
source: descriptor.template!.content,
|
|
27
|
+
filename,
|
|
28
|
+
id: rel,
|
|
29
|
+
compilerOptions: { bindingMetadata: script.bindings },
|
|
30
|
+
})
|
|
31
|
+
expect(tpl.errors).toEqual([])
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
})
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { IconSend, IconSearch } from '@tabler/icons-vue'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Platform.Emails — registro de correos enviados (/platform/emails).
|
|
6
|
+
* Backend: \Innertia\Mail\Routes::platform('') → GET emails, GET emails/types.
|
|
7
|
+
* Filtros: búsqueda (destinatario/asunto), estado, tipo y espacio. Los fallidos muestran el motivo.
|
|
8
|
+
*
|
|
9
|
+
* <Platform.Emails />
|
|
10
|
+
* <Platform.Emails :tenants="[{ value: 'uuid', label: 'Rancagua' }]" />
|
|
11
|
+
*/
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
endpoint?: string
|
|
14
|
+
tenants?: { value: string; label: string }[]
|
|
15
|
+
}>(), { endpoint: 'platform/emails', tenants: () => [] })
|
|
16
|
+
|
|
17
|
+
const api = useApi()
|
|
18
|
+
const base = props.endpoint.replace(/^\/+|\/+$/g, '')
|
|
19
|
+
|
|
20
|
+
const search = ref('')
|
|
21
|
+
const status = ref<string | null>('')
|
|
22
|
+
const type = ref<string | null>('')
|
|
23
|
+
const tenant = ref<string | null>('')
|
|
24
|
+
const page = ref(1)
|
|
25
|
+
const expanded = ref<string | null>(null)
|
|
26
|
+
|
|
27
|
+
const params = computed(() => ({
|
|
28
|
+
page: page.value,
|
|
29
|
+
...(search.value ? { search: search.value } : {}),
|
|
30
|
+
...(status.value ? { status: status.value } : {}),
|
|
31
|
+
...(type.value ? { type: type.value } : {}),
|
|
32
|
+
...(tenant.value ? { tenant_id: tenant.value } : {}),
|
|
33
|
+
}))
|
|
34
|
+
|
|
35
|
+
const { data, isPending } = useQuery({
|
|
36
|
+
queryKey: computed(() => ['platform', 'emails', base, params.value]),
|
|
37
|
+
queryFn: () => api.get(base, { params: params.value }),
|
|
38
|
+
placeholderData: (prev: any) => prev,
|
|
39
|
+
})
|
|
40
|
+
const { data: typesData } = useQuery({ queryKey: ['platform', 'emails', base, 'types'], queryFn: () => api.get(`${base}/types`) })
|
|
41
|
+
|
|
42
|
+
const rows = computed<any[]>(() => (data.value as any)?.data ?? [])
|
|
43
|
+
const lastPage = computed(() => (data.value as any)?.last_page ?? 1)
|
|
44
|
+
const typeOptions = computed(() => ((typesData.value as any)?.data ?? []).map((t: string) => ({ value: t, label: t })))
|
|
45
|
+
|
|
46
|
+
watch([search, status, type, tenant], () => { page.value = 1 })
|
|
47
|
+
|
|
48
|
+
const STATUS: Record<string, { label: string; class: string }> = {
|
|
49
|
+
queued: { label: 'En cola', class: 'bg-amber-100 text-amber-700 dark:bg-amber-500/15 dark:text-amber-400' },
|
|
50
|
+
sent: { label: 'Enviado', class: 'bg-emerald-100 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-400' },
|
|
51
|
+
failed: { label: 'Fallido', class: 'bg-red-100 text-red-700 dark:bg-red-500/15 dark:text-red-400' },
|
|
52
|
+
pending: { label: 'Pendiente', class: 'bg-slate-100 text-slate-600 dark:bg-slate-700/40 dark:text-slate-300' },
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function fmtDate(v?: string | null) {
|
|
56
|
+
return v ? new Date(v).toLocaleString('es-CL', { dateStyle: 'medium', timeStyle: 'short' }) : '—'
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<template>
|
|
61
|
+
<div class="space-y-5">
|
|
62
|
+
<div class="flex items-center gap-3">
|
|
63
|
+
<div class="size-10 rounded-xl bg-primary/10 text-primary flex items-center justify-center shrink-0">
|
|
64
|
+
<IconSend class="size-5" :stroke-width="1.5" />
|
|
65
|
+
</div>
|
|
66
|
+
<div>
|
|
67
|
+
<h1 class="text-lg font-semibold text-foreground">Correos enviados</h1>
|
|
68
|
+
<p class="text-sm text-muted-foreground">Registro de los correos que envía la plataforma.</p>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div class="flex flex-wrap items-end gap-3">
|
|
73
|
+
<div class="relative flex-1 min-w-56">
|
|
74
|
+
<IconSearch class="absolute left-3 top-1/2 -translate-y-1/2 size-4 text-muted-foreground" />
|
|
75
|
+
<input
|
|
76
|
+
v-model="search"
|
|
77
|
+
type="search"
|
|
78
|
+
placeholder="Buscar por destinatario o asunto…"
|
|
79
|
+
class="w-full pl-9 pr-3 h-9 rounded-control border border-card-line bg-card text-sm text-foreground focus:outline-hidden focus:ring-2 focus:ring-primary/30"
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
<div class="w-44"><Forms.Select v-model="status" placeholder="Todos los estados" :options="[{ value: 'sent', label: 'Enviado' }, { value: 'queued', label: 'En cola' }, { value: 'failed', label: 'Fallido' }]" /></div>
|
|
83
|
+
<div class="w-56"><Forms.Select :key="typeOptions.length" v-model="type" placeholder="Todos los tipos" :options="typeOptions" /></div>
|
|
84
|
+
<div v-if="tenants.length" class="w-56"><Forms.Select v-model="tenant" placeholder="Todos los espacios" :options="tenants" /></div>
|
|
85
|
+
</div>
|
|
86
|
+
|
|
87
|
+
<div class="bg-card border border-card-line rounded-card overflow-hidden">
|
|
88
|
+
<div v-if="isPending" class="p-8 text-center text-sm text-muted-foreground">Cargando…</div>
|
|
89
|
+
<div v-else-if="!rows.length" class="p-10 text-center text-sm text-muted-foreground">Sin correos registrados.</div>
|
|
90
|
+
<div v-else class="overflow-x-auto">
|
|
91
|
+
<table class="w-full min-w-[720px] text-sm">
|
|
92
|
+
<thead class="bg-muted/40 text-muted-foreground">
|
|
93
|
+
<tr class="text-left">
|
|
94
|
+
<th class="font-medium px-4 py-2.5">Fecha</th>
|
|
95
|
+
<th class="font-medium px-4 py-2.5">Destinatario</th>
|
|
96
|
+
<th class="font-medium px-4 py-2.5">Asunto</th>
|
|
97
|
+
<th class="font-medium px-4 py-2.5">Tipo</th>
|
|
98
|
+
<th class="font-medium px-4 py-2.5">Espacio</th>
|
|
99
|
+
<th class="font-medium px-4 py-2.5">Estado</th>
|
|
100
|
+
</tr>
|
|
101
|
+
</thead>
|
|
102
|
+
<tbody class="divide-y divide-card-line">
|
|
103
|
+
<template v-for="r in rows" :key="r.id">
|
|
104
|
+
<tr class="hover:bg-muted/30" :class="{ 'cursor-pointer': r.exception }" @click="r.exception && (expanded = expanded === r.id ? null : r.id)">
|
|
105
|
+
<td class="px-4 py-2.5 text-muted-foreground whitespace-nowrap">{{ fmtDate(r.sent_at ?? r.created_at) }}</td>
|
|
106
|
+
<td class="px-4 py-2.5 text-foreground break-all">{{ r.to }}</td>
|
|
107
|
+
<td class="px-4 py-2.5 text-foreground">{{ r.subject }}</td>
|
|
108
|
+
<td class="px-4 py-2.5 text-muted-foreground font-mono text-xs">{{ r.type ?? '—' }}</td>
|
|
109
|
+
<td class="px-4 py-2.5 text-muted-foreground">{{ r.tenant_name ?? (r.tenant_id ? r.tenant_id : 'Plataforma') }}</td>
|
|
110
|
+
<td class="px-4 py-2.5">
|
|
111
|
+
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium" :class="STATUS[r.status]?.class ?? STATUS.pending.class">
|
|
112
|
+
{{ STATUS[r.status]?.label ?? r.status }}
|
|
113
|
+
</span>
|
|
114
|
+
</td>
|
|
115
|
+
</tr>
|
|
116
|
+
<tr v-if="expanded === r.id && r.exception">
|
|
117
|
+
<td colspan="6" class="px-4 py-3 bg-red-50 dark:bg-red-500/10 text-xs text-red-700 dark:text-red-300 break-all">
|
|
118
|
+
<span class="font-medium">Motivo:</span> {{ r.exception }}
|
|
119
|
+
</td>
|
|
120
|
+
</tr>
|
|
121
|
+
</template>
|
|
122
|
+
</tbody>
|
|
123
|
+
</table>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<div v-if="lastPage > 1" class="flex items-center justify-end gap-2">
|
|
128
|
+
<App.Button text="Anterior" severity="secondary" size="sm" :disabled="page <= 1" @click="page--" />
|
|
129
|
+
<span class="text-xs text-muted-foreground">Página {{ page }} de {{ lastPage }}</span>
|
|
130
|
+
<App.Button text="Siguiente" severity="secondary" size="sm" :disabled="page >= lastPage" @click="page++" />
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
</template>
|