@asteby/metacore-runtime-react 53.2.0 → 53.4.0
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 +12 -0
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +26 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/license/index.d.ts +3 -1
- package/dist/license/index.d.ts.map +1 -1
- package/dist/license/index.js +3 -1
- package/dist/license/license-expiry-banner.d.ts +8 -1
- package/dist/license/license-expiry-banner.d.ts.map +1 -1
- package/dist/license/license-expiry-banner.js +96 -54
- package/dist/license/license-gate.d.ts +14 -4
- package/dist/license/license-gate.d.ts.map +1 -1
- package/dist/license/license-gate.js +75 -63
- package/dist/license/license-status-badge.d.ts.map +1 -1
- package/dist/license/license-status-badge.js +8 -9
- package/dist/license/messages.d.ts +29 -0
- package/dist/license/messages.d.ts.map +1 -0
- package/dist/license/messages.js +159 -0
- package/dist/license/types.d.ts +30 -7
- package/dist/license/types.d.ts.map +1 -1
- package/dist/license/types.js +20 -6
- package/dist/license/use-license-t.d.ts +11 -0
- package/dist/license/use-license-t.d.ts.map +1 -0
- package/dist/license/use-license-t.js +18 -0
- package/dist/license/view.d.ts +40 -0
- package/dist/license/view.d.ts.map +1 -0
- package/dist/license/view.js +62 -0
- package/dist/relative-date.d.ts +37 -0
- package/dist/relative-date.d.ts.map +1 -0
- package/dist/relative-date.js +110 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/license-states.test.tsx +381 -0
- package/src/__tests__/relative-date-brand-avatar.test.tsx +154 -0
- package/src/dynamic-columns.tsx +48 -6
- package/src/index.ts +13 -0
- package/src/license/index.ts +19 -0
- package/src/license/license-expiry-banner.tsx +155 -94
- package/src/license/license-gate.tsx +210 -147
- package/src/license/license-status-badge.tsx +8 -10
- package/src/license/messages.ts +185 -0
- package/src/license/types.ts +38 -6
- package/src/license/use-license-t.ts +23 -0
- package/src/license/view.ts +93 -0
- package/src/relative-date.tsx +142 -0
- package/src/types.ts +2 -0
|
@@ -6,12 +6,20 @@
|
|
|
6
6
|
* <AppShell />
|
|
7
7
|
* </LicenseGate>
|
|
8
8
|
*
|
|
9
|
-
* Comportamiento según el estado (resuelto por el backend del host
|
|
9
|
+
* Comportamiento según el estado (resuelto por el backend del host; la lógica de
|
|
10
|
+
* qué significa cada estado vive en `deriveLicenseView`):
|
|
10
11
|
* - Sin enforcement, o estado operable (valid/stale/grace) → renderiza children.
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Los estados que piden atención montan el <LicenseExpiryBanner> por encima:
|
|
13
|
+
* por vencer, gracia, hub caído (solo dueño), clonada (solo dueño) y las
|
|
14
|
+
* licencias en solo lectura (vencida o desactivada con plazo), que además
|
|
15
|
+
* ofrecen exportar los datos si el host pasa `onExport`.
|
|
16
|
+
* - Sin licencia, no válida, desactivada o vencida sin solo lectura → modal
|
|
17
|
+
* BLOQUEANTE full-screen, no descartable, con el formulario de activación
|
|
18
|
+
* (enlace, código o clave) y el contacto del vendedor si la licencia lo trae.
|
|
19
|
+
* Al activar con éxito el host refresca el estado y el gate se abre sin recargar.
|
|
20
|
+
*
|
|
21
|
+
* El modal es un diálogo con encabezado y pie fijos: solo el cuerpo se desplaza,
|
|
22
|
+
* así el botón de activar nunca queda fuera de pantalla en un teléfono.
|
|
15
23
|
*
|
|
16
24
|
* Es branding-aware si el host pasa `branding` (logo/nombre desde el
|
|
17
25
|
* PlatformConfig del SDK); si no, cae a un encabezado neutro.
|
|
@@ -21,15 +29,12 @@
|
|
|
21
29
|
*/
|
|
22
30
|
import { createPortal } from 'react-dom'
|
|
23
31
|
import { useState, type ReactNode } from 'react'
|
|
24
|
-
import { useTranslation } from 'react-i18next'
|
|
25
32
|
import { ShieldAlert, Clock, Loader2 } from 'lucide-react'
|
|
26
33
|
import { Button, Input } from '@asteby/metacore-ui'
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
type LicenseBranding,
|
|
32
|
-
} from './types'
|
|
34
|
+
import { type LicenseState, type LicenseBranding } from './types'
|
|
35
|
+
import { deriveLicenseView, sellerContactLine } from './view'
|
|
36
|
+
import { formatLicenseDate } from './messages'
|
|
37
|
+
import { useLicenseT } from './use-license-t'
|
|
33
38
|
import { LicenseStatusBadge } from './license-status-badge'
|
|
34
39
|
import { LicenseExpiryBanner } from './license-expiry-banner'
|
|
35
40
|
|
|
@@ -41,15 +46,25 @@ export interface LicenseGateProps {
|
|
|
41
46
|
/** Estado actual, resuelto por el backend del host. `undefined` mientras
|
|
42
47
|
* carga → fail-open (renderiza children, nunca destella el candado). */
|
|
43
48
|
state: LicenseState | undefined
|
|
44
|
-
/** Activa una licencia con el código
|
|
45
|
-
* refresca `state` y el gate se abre. Rechaza con un Error cuyo
|
|
46
|
-
* se muestra al usuario
|
|
49
|
+
/** Activa una licencia con el enlace, código o clave pegados. Resuelve → el
|
|
50
|
+
* host refresca `state` y el gate se abre. Rechaza con un Error cuyo
|
|
51
|
+
* `message` se muestra al usuario; si el Error trae `code` (el código estable
|
|
52
|
+
* del hub, p. ej. `activation_used`) se muestra el texto localizado de ese caso. */
|
|
47
53
|
onActivate: (code: string) => Promise<void>
|
|
48
54
|
children: ReactNode
|
|
49
55
|
/** Branding opcional (logo/nombre) para el encabezado del modal. */
|
|
50
56
|
branding?: LicenseBranding
|
|
51
57
|
/** Acción "Gestionar licencia" del banner degradado (opcional). */
|
|
52
58
|
onManage?: () => void
|
|
59
|
+
/** Exportar los datos: se ofrece en el banner de solo lectura y en el pie del
|
|
60
|
+
* modal de una licencia vencida. Sin él no se muestra el botón. */
|
|
61
|
+
onExport?: () => void
|
|
62
|
+
/** El usuario actual es el dueño/superadmin. Los avisos de hub caído y de
|
|
63
|
+
* clonado son solo para él. Default false (un host que no informa el rol nunca los muestra). */
|
|
64
|
+
isOwner?: boolean
|
|
65
|
+
/** El host acepta enlaces de activación (acs_…) además de lic_…: cambia la
|
|
66
|
+
* etiqueta y el ejemplo del campo. Default false (texto clásico). */
|
|
67
|
+
acceptsActivationLink?: boolean
|
|
53
68
|
/** Si el usuario actual puede activar la licencia (p. ej. Platform Root /
|
|
54
69
|
* superadmin). Default true — backward-compatible. Cuando es false, el modal
|
|
55
70
|
* bloqueante se muestra SIN el formulario de activación y en su lugar
|
|
@@ -66,18 +81,27 @@ export function LicenseGate({
|
|
|
66
81
|
children,
|
|
67
82
|
branding,
|
|
68
83
|
onManage,
|
|
84
|
+
onExport,
|
|
85
|
+
isOwner = false,
|
|
86
|
+
acceptsActivationLink = false,
|
|
69
87
|
canActivate = true,
|
|
70
88
|
readOnlyMessage,
|
|
71
89
|
className,
|
|
72
90
|
}: LicenseGateProps) {
|
|
73
|
-
const
|
|
91
|
+
const view = deriveLicenseView(state)
|
|
92
|
+
const blocking = !!view?.blocking
|
|
74
93
|
|
|
75
94
|
return (
|
|
76
95
|
<>
|
|
77
|
-
{/*
|
|
96
|
+
{/* Los estados que no bloquean degradan con banner; el propio banner
|
|
78
97
|
decide si mostrarse. Bloqueado → no hace falta, el modal manda. */}
|
|
79
98
|
{!blocking && (
|
|
80
|
-
<LicenseExpiryBanner
|
|
99
|
+
<LicenseExpiryBanner
|
|
100
|
+
state={state}
|
|
101
|
+
onManage={onManage}
|
|
102
|
+
onExport={onExport}
|
|
103
|
+
isOwner={isOwner}
|
|
104
|
+
/>
|
|
81
105
|
)}
|
|
82
106
|
{children}
|
|
83
107
|
{blocking && state && (
|
|
@@ -87,6 +111,8 @@ export function LicenseGate({
|
|
|
87
111
|
branding={branding}
|
|
88
112
|
canActivate={canActivate}
|
|
89
113
|
readOnlyMessage={readOnlyMessage}
|
|
114
|
+
acceptsActivationLink={acceptsActivationLink}
|
|
115
|
+
onExport={onExport}
|
|
90
116
|
className={className}
|
|
91
117
|
/>
|
|
92
118
|
)}
|
|
@@ -100,49 +126,56 @@ interface LicenseGateModalProps {
|
|
|
100
126
|
branding?: LicenseBranding
|
|
101
127
|
canActivate: boolean
|
|
102
128
|
readOnlyMessage?: string
|
|
129
|
+
acceptsActivationLink: boolean
|
|
130
|
+
onExport?: () => void
|
|
103
131
|
className?: string
|
|
104
132
|
}
|
|
105
133
|
|
|
134
|
+
const FORM_ID = 'license-gate-form'
|
|
135
|
+
|
|
106
136
|
function LicenseGateModal({
|
|
107
137
|
state,
|
|
108
138
|
onActivate,
|
|
109
139
|
branding,
|
|
110
140
|
canActivate,
|
|
111
141
|
readOnlyMessage,
|
|
142
|
+
acceptsActivationLink,
|
|
143
|
+
onExport,
|
|
112
144
|
className,
|
|
113
145
|
}: LicenseGateModalProps) {
|
|
114
|
-
const { t } =
|
|
146
|
+
const { t, lang } = useLicenseT()
|
|
115
147
|
const [code, setCode] = useState('')
|
|
116
148
|
const [submitting, setSubmitting] = useState(false)
|
|
117
149
|
const [error, setError] = useState<string | null>(null)
|
|
118
150
|
|
|
119
|
-
const
|
|
151
|
+
const view = deriveLicenseView(state)
|
|
152
|
+
const trialExpired = !!view?.trialExpired
|
|
153
|
+
const revoked = state.status === 'revoked'
|
|
154
|
+
const expired = state.status === 'expired'
|
|
155
|
+
const provider = t('license.gate.provider')
|
|
156
|
+
const who = state.seller?.name?.trim() || provider
|
|
157
|
+
const expiredOn = formatLicenseDate(state.expires_at, lang)
|
|
158
|
+
const contact = sellerContactLine(state)
|
|
120
159
|
|
|
121
160
|
const title = trialExpired
|
|
122
|
-
? t('license.gate.trial_title'
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
161
|
+
? t('license.gate.trial_title')
|
|
162
|
+
: revoked
|
|
163
|
+
? t('license.gate.revoked_title')
|
|
164
|
+
: expired
|
|
165
|
+
? t('license.gate.expired_title')
|
|
166
|
+
: t('license.gate.title')
|
|
126
167
|
|
|
127
168
|
const description = trialExpired
|
|
128
|
-
? t('license.gate.trial_description'
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
? t('license.gate.invalid_description', {
|
|
139
|
-
defaultValue:
|
|
140
|
-
'La licencia de esta instancia no es válida. Pega una clave (lic_…) o el token firmado que te entregó tu proveedor para reactivarla.',
|
|
141
|
-
})
|
|
142
|
-
: t('license.gate.missing_description', {
|
|
143
|
-
defaultValue:
|
|
144
|
-
'Esta instancia necesita una licencia activa para operar. Pega tu clave (lic_…) o el token firmado para activarla.',
|
|
145
|
-
})
|
|
169
|
+
? t('license.gate.trial_description')
|
|
170
|
+
: revoked
|
|
171
|
+
? t('license.gate.revoked_description', { who })
|
|
172
|
+
: expired
|
|
173
|
+
? expiredOn
|
|
174
|
+
? t('license.gate.expired_description', { date: expiredOn })
|
|
175
|
+
: t('license.gate.expired_description_nodate')
|
|
176
|
+
: state.status === 'invalid'
|
|
177
|
+
? t('license.gate.invalid_description')
|
|
178
|
+
: t('license.gate.missing_description')
|
|
146
179
|
|
|
147
180
|
const canSubmit = code.trim().length > 0 && !submitting
|
|
148
181
|
|
|
@@ -155,12 +188,11 @@ function LicenseGateModal({
|
|
|
155
188
|
// Éxito → el host refresca `state`; el gate se re-renderiza y este
|
|
156
189
|
// modal se desmonta solo. No recargamos.
|
|
157
190
|
} catch (e) {
|
|
191
|
+
const hubCode = (e as { code?: string } | null)?.code
|
|
192
|
+
const known = hubCode && LICENSE_LINK_CODES.has(hubCode) ? t(`license.link.${hubCode}`) : null
|
|
158
193
|
const message =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
: t('license.gate.activate_error', {
|
|
162
|
-
defaultValue: 'No se pudo activar la licencia.',
|
|
163
|
-
})
|
|
194
|
+
known ??
|
|
195
|
+
(e instanceof Error && e.message ? e.message : t('license.gate.activate_error'))
|
|
164
196
|
setError(message)
|
|
165
197
|
setSubmitting(false)
|
|
166
198
|
}
|
|
@@ -179,51 +211,51 @@ function LicenseGateModal({
|
|
|
179
211
|
className,
|
|
180
212
|
)}
|
|
181
213
|
>
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
: t('license.gate.instance', {
|
|
220
|
-
defaultValue: 'Esta instancia',
|
|
221
|
-
})}
|
|
222
|
-
</span>
|
|
223
|
-
</div>
|
|
214
|
+
{/* Encabezado y pie fijos; solo el cuerpo se desplaza. */}
|
|
215
|
+
<div className="bg-card text-card-foreground flex max-h-[calc(100dvh-2rem)] w-full max-w-lg flex-col overflow-hidden rounded-2xl border shadow-2xl">
|
|
216
|
+
<header
|
|
217
|
+
data-license-part="header"
|
|
218
|
+
className="flex shrink-0 items-start gap-3 border-b p-6 pb-4"
|
|
219
|
+
>
|
|
220
|
+
{branding?.logo ? (
|
|
221
|
+
<img
|
|
222
|
+
src={branding.logo}
|
|
223
|
+
alt={branding.name ?? ''}
|
|
224
|
+
className="h-10 w-10 shrink-0 rounded-xl object-contain"
|
|
225
|
+
/>
|
|
226
|
+
) : (
|
|
227
|
+
<div
|
|
228
|
+
className={cx(
|
|
229
|
+
'flex h-10 w-10 shrink-0 items-center justify-center rounded-xl',
|
|
230
|
+
trialExpired
|
|
231
|
+
? 'bg-primary/10 text-primary'
|
|
232
|
+
: 'bg-destructive/10 text-destructive',
|
|
233
|
+
)}
|
|
234
|
+
>
|
|
235
|
+
{trialExpired ? (
|
|
236
|
+
<Clock className="h-5 w-5" aria-hidden />
|
|
237
|
+
) : (
|
|
238
|
+
<ShieldAlert className="h-5 w-5" aria-hidden />
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
)}
|
|
242
|
+
<div className="flex min-w-0 flex-col gap-1">
|
|
243
|
+
<h2 id="license-gate-title" className="text-lg leading-tight font-semibold">
|
|
244
|
+
{title}
|
|
245
|
+
</h2>
|
|
246
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
247
|
+
<LicenseStatusBadge status={state.status} />
|
|
248
|
+
<span className="text-muted-foreground text-xs">
|
|
249
|
+
{branding?.name ? branding.name : t('license.gate.instance')}
|
|
250
|
+
</span>
|
|
224
251
|
</div>
|
|
225
252
|
</div>
|
|
253
|
+
</header>
|
|
226
254
|
|
|
255
|
+
<div
|
|
256
|
+
data-license-part="body"
|
|
257
|
+
className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-6"
|
|
258
|
+
>
|
|
227
259
|
<p className="text-muted-foreground text-sm">{description}</p>
|
|
228
260
|
|
|
229
261
|
{state.reason && (
|
|
@@ -232,78 +264,109 @@ function LicenseGateModal({
|
|
|
232
264
|
</p>
|
|
233
265
|
)}
|
|
234
266
|
|
|
267
|
+
{contact && (
|
|
268
|
+
<p
|
|
269
|
+
data-license-part="seller"
|
|
270
|
+
className="border-border bg-muted/40 rounded-md border px-3 py-2 text-sm"
|
|
271
|
+
>
|
|
272
|
+
<span className="text-muted-foreground">
|
|
273
|
+
{t('license.gate.contact_label')}:{' '}
|
|
274
|
+
</span>
|
|
275
|
+
{state.seller?.name ? <strong>{state.seller.name}</strong> : null}
|
|
276
|
+
{state.seller?.name ? ' · ' : null}
|
|
277
|
+
{contact}
|
|
278
|
+
</p>
|
|
279
|
+
)}
|
|
280
|
+
|
|
235
281
|
{!canActivate ? (
|
|
236
282
|
<p
|
|
237
283
|
role="note"
|
|
238
284
|
className="border-border bg-muted/40 text-muted-foreground rounded-md border px-3 py-3 text-sm"
|
|
239
285
|
>
|
|
240
|
-
{readOnlyMessage ??
|
|
241
|
-
t('license.gate.read_only', {
|
|
242
|
-
defaultValue:
|
|
243
|
-
'Contacta al administrador de la plataforma para activar la licencia.',
|
|
244
|
-
})}
|
|
286
|
+
{readOnlyMessage ?? t('license.gate.read_only')}
|
|
245
287
|
</p>
|
|
246
288
|
) : (
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
e
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
>
|
|
254
|
-
<label
|
|
255
|
-
htmlFor="license-gate-code"
|
|
256
|
-
className="text-sm font-medium"
|
|
257
|
-
>
|
|
258
|
-
{t('license.gate.code_label', {
|
|
259
|
-
defaultValue: 'Clave o token de licencia',
|
|
260
|
-
})}
|
|
261
|
-
</label>
|
|
262
|
-
<Input
|
|
263
|
-
id="license-gate-code"
|
|
264
|
-
autoFocus
|
|
265
|
-
autoComplete="off"
|
|
266
|
-
spellCheck={false}
|
|
267
|
-
placeholder={t('license.gate.code_placeholder', {
|
|
268
|
-
defaultValue: 'lic_… o pega el token firmado',
|
|
269
|
-
})}
|
|
270
|
-
value={code}
|
|
271
|
-
disabled={submitting}
|
|
272
|
-
aria-invalid={error ? true : undefined}
|
|
273
|
-
onChange={(e) => {
|
|
274
|
-
setCode(e.target.value)
|
|
275
|
-
if (error) setError(null)
|
|
289
|
+
<form
|
|
290
|
+
id={FORM_ID}
|
|
291
|
+
className="flex flex-col gap-2"
|
|
292
|
+
onSubmit={(e) => {
|
|
293
|
+
e.preventDefault()
|
|
294
|
+
void submit()
|
|
276
295
|
}}
|
|
277
|
-
/>
|
|
278
|
-
{error && (
|
|
279
|
-
<p role="alert" className="text-destructive text-sm">
|
|
280
|
-
{error}
|
|
281
|
-
</p>
|
|
282
|
-
)}
|
|
283
|
-
<Button
|
|
284
|
-
type="submit"
|
|
285
|
-
className="mt-1 w-full"
|
|
286
|
-
disabled={!canSubmit}
|
|
287
296
|
>
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
297
|
+
<label htmlFor="license-gate-code" className="text-sm font-medium">
|
|
298
|
+
{acceptsActivationLink
|
|
299
|
+
? t('license.gate.code_label_link')
|
|
300
|
+
: t('license.gate.code_label')}
|
|
301
|
+
</label>
|
|
302
|
+
<Input
|
|
303
|
+
id="license-gate-code"
|
|
304
|
+
autoFocus
|
|
305
|
+
autoComplete="off"
|
|
306
|
+
spellCheck={false}
|
|
307
|
+
placeholder={
|
|
308
|
+
acceptsActivationLink
|
|
309
|
+
? t('license.gate.code_placeholder_link')
|
|
310
|
+
: t('license.gate.code_placeholder')
|
|
311
|
+
}
|
|
312
|
+
value={code}
|
|
313
|
+
disabled={submitting}
|
|
314
|
+
aria-invalid={error ? true : undefined}
|
|
315
|
+
onChange={(e) => {
|
|
316
|
+
setCode(e.target.value)
|
|
317
|
+
if (error) setError(null)
|
|
318
|
+
}}
|
|
319
|
+
/>
|
|
320
|
+
{error && (
|
|
321
|
+
<p role="alert" className="text-destructive text-sm">
|
|
322
|
+
{error}
|
|
323
|
+
</p>
|
|
293
324
|
)}
|
|
294
|
-
|
|
295
|
-
? t('license.gate.activating', {
|
|
296
|
-
defaultValue: 'Activando…',
|
|
297
|
-
})
|
|
298
|
-
: t('license.gate.activate', {
|
|
299
|
-
defaultValue: 'Activar licencia',
|
|
300
|
-
})}
|
|
301
|
-
</Button>
|
|
302
|
-
</form>
|
|
325
|
+
</form>
|
|
303
326
|
)}
|
|
304
327
|
</div>
|
|
328
|
+
|
|
329
|
+
{(canActivate || (expired && onExport)) && (
|
|
330
|
+
<footer
|
|
331
|
+
data-license-part="footer"
|
|
332
|
+
className="flex shrink-0 flex-col gap-2 border-t p-6 pt-4 sm:flex-row-reverse"
|
|
333
|
+
>
|
|
334
|
+
{canActivate && (
|
|
335
|
+
<Button
|
|
336
|
+
type="submit"
|
|
337
|
+
form={FORM_ID}
|
|
338
|
+
className="w-full sm:w-auto"
|
|
339
|
+
disabled={!canSubmit}
|
|
340
|
+
>
|
|
341
|
+
{submitting && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
|
342
|
+
{submitting ? t('license.gate.activating') : t('license.gate.activate')}
|
|
343
|
+
</Button>
|
|
344
|
+
)}
|
|
345
|
+
{expired && onExport && (
|
|
346
|
+
<Button
|
|
347
|
+
type="button"
|
|
348
|
+
variant="outline"
|
|
349
|
+
className="w-full sm:w-auto"
|
|
350
|
+
onClick={onExport}
|
|
351
|
+
>
|
|
352
|
+
{t('license.gate.export')}
|
|
353
|
+
</Button>
|
|
354
|
+
)}
|
|
355
|
+
</footer>
|
|
356
|
+
)}
|
|
305
357
|
</div>
|
|
306
358
|
</div>,
|
|
307
359
|
document.body,
|
|
308
360
|
)
|
|
309
361
|
}
|
|
362
|
+
|
|
363
|
+
const LICENSE_LINK_CODES = new Set([
|
|
364
|
+
'activation_not_found',
|
|
365
|
+
'activation_used',
|
|
366
|
+
'activation_conflict',
|
|
367
|
+
'activation_expired',
|
|
368
|
+
'activation_revoked',
|
|
369
|
+
'license_revoked',
|
|
370
|
+
'license_expired',
|
|
371
|
+
'rate_limited',
|
|
372
|
+
])
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* color + etiqueta legible. Reutilizable suelto (p. ej. en Ajustes de licencia)
|
|
4
4
|
* o embebido en el encabezado del <LicenseGate>.
|
|
5
5
|
*/
|
|
6
|
-
import { useTranslation } from 'react-i18next'
|
|
7
6
|
import {
|
|
8
7
|
ShieldCheck,
|
|
9
8
|
ShieldAlert,
|
|
@@ -13,6 +12,7 @@ import {
|
|
|
13
12
|
} from 'lucide-react'
|
|
14
13
|
import { Badge } from '@asteby/metacore-ui'
|
|
15
14
|
import type { LicenseStatus } from './types'
|
|
15
|
+
import { useLicenseT } from './use-license-t'
|
|
16
16
|
|
|
17
17
|
type BadgeVariant = 'default' | 'secondary' | 'destructive' | 'outline'
|
|
18
18
|
|
|
@@ -20,7 +20,6 @@ interface StatusMeta {
|
|
|
20
20
|
variant: BadgeVariant
|
|
21
21
|
Icon: typeof ShieldCheck
|
|
22
22
|
key: string
|
|
23
|
-
defaultValue: string
|
|
24
23
|
/** Tinte amarillo para posturas degradadas (grace/stale) que `variant` no
|
|
25
24
|
* cubre — el sistema de badges no tiene "warning". */
|
|
26
25
|
warn?: boolean
|
|
@@ -31,39 +30,38 @@ const STATUS_META: Record<LicenseStatus, StatusMeta> = {
|
|
|
31
30
|
variant: 'default',
|
|
32
31
|
Icon: ShieldCheck,
|
|
33
32
|
key: 'license.status.valid',
|
|
34
|
-
defaultValue: 'Activa',
|
|
35
33
|
},
|
|
36
34
|
stale: {
|
|
37
35
|
variant: 'outline',
|
|
38
36
|
Icon: CloudOff,
|
|
39
37
|
key: 'license.status.stale',
|
|
40
|
-
defaultValue: 'Sin verificar',
|
|
41
38
|
warn: true,
|
|
42
39
|
},
|
|
43
40
|
grace: {
|
|
44
41
|
variant: 'outline',
|
|
45
42
|
Icon: Clock,
|
|
46
43
|
key: 'license.status.grace',
|
|
47
|
-
defaultValue: 'En gracia',
|
|
48
44
|
warn: true,
|
|
49
45
|
},
|
|
50
46
|
expired: {
|
|
51
47
|
variant: 'destructive',
|
|
52
48
|
Icon: ShieldAlert,
|
|
53
49
|
key: 'license.status.expired',
|
|
54
|
-
defaultValue: 'Vencida',
|
|
55
50
|
},
|
|
56
51
|
missing: {
|
|
57
52
|
variant: 'secondary',
|
|
58
53
|
Icon: ShieldQuestion,
|
|
59
54
|
key: 'license.status.missing',
|
|
60
|
-
defaultValue: 'Sin licencia',
|
|
61
55
|
},
|
|
62
56
|
invalid: {
|
|
63
57
|
variant: 'destructive',
|
|
64
58
|
Icon: ShieldAlert,
|
|
65
59
|
key: 'license.status.invalid',
|
|
66
|
-
|
|
60
|
+
},
|
|
61
|
+
revoked: {
|
|
62
|
+
variant: 'destructive',
|
|
63
|
+
Icon: ShieldAlert,
|
|
64
|
+
key: 'license.status.revoked',
|
|
67
65
|
},
|
|
68
66
|
}
|
|
69
67
|
|
|
@@ -73,7 +71,7 @@ export interface LicenseStatusBadgeProps {
|
|
|
73
71
|
}
|
|
74
72
|
|
|
75
73
|
export function LicenseStatusBadge({ status, className }: LicenseStatusBadgeProps) {
|
|
76
|
-
const { t } =
|
|
74
|
+
const { t } = useLicenseT()
|
|
77
75
|
const meta = STATUS_META[status] ?? STATUS_META.missing
|
|
78
76
|
const { Icon } = meta
|
|
79
77
|
|
|
@@ -87,7 +85,7 @@ export function LicenseStatusBadge({ status, className }: LicenseStatusBadgeProp
|
|
|
87
85
|
}
|
|
88
86
|
>
|
|
89
87
|
<Icon aria-hidden />
|
|
90
|
-
{t(meta.key
|
|
88
|
+
{t(meta.key)}
|
|
91
89
|
</Badge>
|
|
92
90
|
)
|
|
93
91
|
}
|