@xk2800/nextjs-template 0.7.2-beta.0 → 0.7.2-beta.10
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/README.md +1 -0
- package/components/auth/{loginErrorRecovery.tsx → forms/login-error-recovery.tsx} +1 -1
- package/components/auth/{emailPasswordLogin.tsx → forms/login-form.tsx} +8 -8
- package/components/auth/{emailPasswordSignup.tsx → forms/signup-form.tsx} +11 -8
- package/components/auth/{authCard.tsx → layout/auth-card.tsx} +5 -5
- package/components/auth/{authShell.tsx → layout/auth-shell.tsx} +17 -5
- package/components/auth/{oneTap.tsx → methods/one-tap.tsx} +2 -2
- package/components/auth/{passkeyLogin.tsx → methods/passkey-login.tsx} +2 -2
- package/components/auth/{socialLogin.tsx → methods/social-login.tsx} +3 -3
- package/components/auth/{twoFactorVerifyForm.tsx → mfa/two-factor-verify-form.tsx} +5 -5
- package/components/auth/{forgotPasswordForm.tsx → recovery/forgot-password-form.tsx} +4 -4
- package/components/auth/{resetPasswordForm.tsx → recovery/reset-password-form.tsx} +4 -4
- package/components/auth/{deviceCheck.tsx → session/device-check.tsx} +3 -3
- package/components/auth/{logoutButtons.tsx → session/logout-buttons.tsx} +2 -2
- package/components/dashboard/admin/{activityLogsSection.tsx → activity-logs/activity-logs-section.tsx} +1 -1
- package/components/dashboard/admin/activity-logs/admin-activity-logs-table.tsx +375 -0
- package/components/dashboard/admin/activity-logs/audit-severity-badge.tsx +50 -0
- package/components/dashboard/admin/activity-logs/security-highlights-collapsible.tsx +129 -0
- package/components/dashboard/admin/{adminActivityLogsSkeleton.tsx → activity-logs/skeletons/activity-logs-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{adminStatsGrid.tsx → home/admin-stats-grid.tsx} +1 -1
- package/components/dashboard/admin/{deviceThrottleCard.tsx → home/device-throttle-card.tsx} +8 -5
- package/components/dashboard/admin/{deviceThrottleTable.tsx → home/device-throttle-table.tsx} +3 -3
- package/components/dashboard/admin/{newDeviceCard.tsx → home/new-device-card.tsx} +6 -2
- package/components/dashboard/admin/{newDeviceTable.tsx → home/new-device-table.tsx} +4 -4
- package/components/dashboard/admin/{sharedDeviceCard.tsx → home/shared-device-card.tsx} +3 -3
- package/components/dashboard/admin/{sharedDeviceTable.tsx → home/shared-device-table.tsx} +3 -3
- package/components/dashboard/admin/{adminStatsGridSkeleton.tsx → home/skeletons/admin-stats-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{broadcastActions.tsx → marketing/broadcast-actions.tsx} +3 -3
- package/components/dashboard/admin/{confirmSendDialog.tsx → marketing/confirm-send-dialog.tsx} +1 -1
- package/components/dashboard/admin/{marketingEmailForm.tsx → marketing/marketing-email-form.tsx} +7 -7
- package/components/dashboard/admin/{marketingSection.tsx → marketing/marketing-section.tsx} +6 -6
- package/components/dashboard/admin/{subscribersCard.tsx → marketing/subscribers-card.tsx} +3 -3
- package/components/dashboard/admin/{feedbackTestForm.tsx → system-settings/feedback-test-form.tsx} +4 -4
- package/components/dashboard/admin/{systemSettingsSkeleton.tsx → system-settings/skeletons/system-settings-skeleton.tsx} +2 -2
- package/components/dashboard/admin/system-settings/system-settings-form.tsx +362 -0
- package/components/dashboard/admin/{systemSettingsSection.tsx → system-settings/system-settings-section.tsx} +3 -2
- package/components/dashboard/admin/users/admin-user-actions.tsx +238 -0
- package/components/dashboard/admin/users/admin-user-profile-card.tsx +70 -0
- package/components/dashboard/admin/users/admin-user-security-card.tsx +47 -0
- package/components/dashboard/admin/users/admin-user-status-card.tsx +89 -0
- package/components/dashboard/admin/{adminUsersTable.tsx → users/admin-users-table.tsx} +129 -132
- package/components/dashboard/admin/{adminUserActivityLogCard.tsx → users/detail/admin-user-activity-log-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserActivityLogTable.tsx → users/detail/admin-user-activity-log-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserConsentCard.tsx → users/detail/admin-user-consent-card.tsx} +4 -4
- package/components/dashboard/admin/{adminUserDevicesCard.tsx → users/detail/admin-user-devices-card.tsx} +2 -2
- package/components/dashboard/admin/{adminUserLoginInfoCard.tsx → users/detail/admin-user-login-info-card.tsx} +3 -3
- package/components/dashboard/admin/{adminUserLoginInfoTable.tsx → users/detail/admin-user-login-info-table.tsx} +3 -3
- package/components/dashboard/admin/{adminUserSessionsCard.tsx → users/detail/admin-user-sessions-card.tsx} +5 -5
- package/components/dashboard/admin/{impersonationLogCard.tsx → users/impersonation-log-card.tsx} +10 -5
- package/components/dashboard/admin/users/impersonation-tab.tsx +255 -0
- package/components/dashboard/admin/users/invite-user-dialog.tsx +80 -0
- package/components/dashboard/admin/{revokeAllSessionsButton.tsx → users/revoke-all-sessions.tsx} +5 -3
- package/components/dashboard/admin/{adminUsersSkeleton.tsx → users/skeletons/admin-users-skeleton.tsx} +2 -2
- package/components/dashboard/admin/{usersSection.tsx → users/users-section.tsx} +1 -1
- package/components/dashboard/{errorFeedback.tsx → common/error-feedback.tsx} +1 -1
- package/components/dashboard/{feedbackDialog.tsx → common/feedback-dialog.tsx} +4 -4
- package/components/dashboard/{sectionErrorFallback.tsx → common/section-error-fallback.tsx} +1 -1
- package/components/dashboard/{verifyEmailButton.tsx → common/verify-email-button.tsx} +2 -2
- package/components/dashboard/{appSidebar.tsx → layout/app-sidebar.tsx} +11 -8
- package/components/dashboard/{dashboardHeader.tsx → layout/dashboard-header.tsx} +1 -1
- package/components/dashboard/{impersonationBanner.tsx → layout/impersonation-banner.tsx} +2 -2
- package/components/dashboard/layout/mobile-nav.tsx +95 -0
- package/components/dashboard/{navStyleToggle.tsx → layout/nav-style-toggle.tsx} +1 -1
- package/components/dashboard/{topNav.tsx → layout/top-nav.tsx} +19 -38
- package/components/dashboard/{installAppCard.tsx → overview/install-app-card.tsx} +2 -2
- package/components/dashboard/{accountDetailsCard.tsx → settings/account-details-card.tsx} +5 -5
- package/components/dashboard/{activityLogsCard.tsx → settings/activity-logs-card.tsx} +6 -6
- package/components/dashboard/{activityLogsSection.tsx → settings/activity-logs-section.tsx} +1 -1
- package/components/dashboard/{adminSection.tsx → settings/admin-section.tsx} +2 -2
- package/components/dashboard/{deleteAccountCard.tsx → settings/delete-account-card.tsx} +7 -7
- package/components/dashboard/{marketingUpdatesCard.tsx → settings/marketing-updates-card.tsx} +3 -3
- package/components/dashboard/{marketingUpdatesSection.tsx → settings/marketing-updates-section.tsx} +1 -1
- package/components/dashboard/{passkeysCard.tsx → settings/passkeys-card.tsx} +8 -8
- package/components/dashboard/{profileCard.tsx → settings/profile-card.tsx} +4 -4
- package/components/dashboard/{sessionsCard.tsx → settings/sessions/sessions-card.tsx} +6 -6
- package/components/dashboard/{sessionsSection.tsx → settings/sessions/sessions-section.tsx} +1 -1
- package/components/dashboard/{sessionsCardSkeleton.tsx → settings/sessions/skeletons/sessions-card-skeleton.tsx} +2 -2
- package/components/dashboard/{activityLogsCardSkeleton.tsx → settings/skeletons/activity-logs-card-skeleton.tsx} +2 -2
- package/components/dashboard/{twoFactorCard.tsx → settings/two-factor-card.tsx} +8 -8
- package/components/email/team/workspace-invite.tsx +51 -0
- package/components/email/{send-email-button.tsx → ui/send-email-button.tsx} +1 -1
- package/components/error-boundary.tsx +32 -0
- package/components/settings/appearance/appearance-section.tsx +64 -0
- package/components/settings/index.ts +5 -0
- package/components/settings/notifications/notifications-section.tsx +31 -0
- package/components/settings/profile/profile-section.tsx +38 -0
- package/components/settings/security/security-section.tsx +24 -0
- package/components/settings/settings-nav.tsx +35 -0
- package/components/site/{cookie-banner.tsx → compliance/cookie-banner.tsx} +6 -6
- package/components/site/push/push-notifications-card.tsx +117 -0
- package/components/ui/collapsible.tsx +9 -0
- package/components/ui/column-picker.tsx +1 -1
- package/components/ui/data-table.tsx +1 -1
- package/components/ui/dialog.tsx +46 -13
- package/components/ui/drawer.tsx +88 -0
- package/components/ui/tabs.tsx +52 -0
- package/dist/activity/logger.d.mts +2 -1
- package/dist/activity/logger.d.ts +2 -1
- package/dist/activity/logger.js +66 -16
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +32 -21
- package/dist/activity/queries.d.ts +32 -21
- package/dist/activity/queries.js +86 -23
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +27 -14
- package/dist/activity/queries.mjs.map +1 -1
- package/dist/admin/queries.d.mts +2 -1
- package/dist/admin/queries.d.ts +2 -1
- package/dist/admin/queries.js +48 -18
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +9 -9
- package/dist/admin/queries.mjs.map +1 -1
- package/dist/api/feedback.js +284 -249
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +14 -12
- package/dist/api/feedback.mjs.map +1 -1
- package/dist/api/marketing.js +302 -267
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +16 -25
- package/dist/api/marketing.mjs.map +1 -1
- package/dist/auth/helpers.d.mts +63 -21
- package/dist/auth/helpers.d.ts +63 -21
- package/dist/auth/helpers.js +314 -268
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +9 -9
- package/dist/auth/index.d.mts +86 -47
- package/dist/auth/index.d.ts +86 -47
- package/dist/auth/index.js +278 -245
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +8 -8
- package/dist/auth-client/index.d.mts +1214 -2526
- package/dist/auth-client/index.d.ts +1214 -2526
- package/dist/auth-client/index.js +37 -3
- package/dist/auth-client/index.js.map +1 -1
- package/dist/auth-client/index.mjs +19 -3
- package/dist/auth-client/index.mjs.map +1 -1
- package/dist/{chunk-KA2KMGPY.mjs → chunk-3BH6BVBQ.mjs} +17 -8
- package/dist/chunk-3BH6BVBQ.mjs.map +1 -0
- package/dist/chunk-D56ENLSX.mjs +6 -0
- package/dist/chunk-D56ENLSX.mjs.map +1 -0
- package/dist/{chunk-HUEDEAY3.mjs → chunk-DCPVEZS7.mjs} +14 -4
- package/dist/chunk-DCPVEZS7.mjs.map +1 -0
- package/dist/{chunk-NQELV53D.mjs → chunk-DWLMCMXF.mjs} +4 -4
- package/dist/chunk-DWLMCMXF.mjs.map +1 -0
- package/dist/{chunk-YH53UPUW.mjs → chunk-EXMUANQ3.mjs} +4 -4
- package/dist/chunk-EXMUANQ3.mjs.map +1 -0
- package/dist/{chunk-VHNGYAIG.mjs → chunk-IH6CMZIN.mjs} +213 -220
- package/dist/chunk-IH6CMZIN.mjs.map +1 -0
- package/dist/chunk-LADVCLEQ.mjs +43 -0
- package/dist/chunk-LADVCLEQ.mjs.map +1 -0
- package/dist/{chunk-A6JXMHOQ.mjs → chunk-NJBRKKLK.mjs} +46 -7
- package/dist/chunk-NJBRKKLK.mjs.map +1 -0
- package/dist/{chunk-6OAHCEDJ.mjs → chunk-QDUPSU5O.mjs} +5 -5
- package/dist/chunk-QDUPSU5O.mjs.map +1 -0
- package/dist/{chunk-JUSU6UZA.mjs → chunk-S23GC776.mjs} +41 -29
- package/dist/chunk-S23GC776.mjs.map +1 -0
- package/dist/{chunk-L242CZ64.mjs → chunk-TIR7KHXL.mjs} +3 -3
- package/dist/chunk-TIR7KHXL.mjs.map +1 -0
- package/dist/{chunk-4F6KE47S.mjs → chunk-ZOQHHFYA.mjs} +7 -4
- package/dist/chunk-ZOQHHFYA.mjs.map +1 -0
- package/dist/config/env.d.mts +3 -0
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.js +12 -2
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +3 -7
- package/dist/db/index.d.ts +3 -7
- package/dist/db/index.js +61 -13
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -5
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.d.mts +2 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.js +62 -14
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.d.mts +4 -3
- package/dist/marketing/index.d.ts +4 -3
- package/dist/marketing/index.js +14 -4
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{email-template-passkey-change-F5Q2SXHD.mjs → passkey-changed-KEGNTIPE.mjs} +2 -2
- package/dist/passkey-changed-KEGNTIPE.mjs.map +1 -0
- package/dist/{email-template-reset-password-QTCQNXOD.mjs → reset-password-64VQEXBW.mjs} +2 -2
- package/dist/reset-password-64VQEXBW.mjs.map +1 -0
- package/dist/{schema-DzC5zdOq.d.mts → schema-BujGgvAy.d.mts} +35 -2
- package/dist/{schema-DzC5zdOq.d.ts → schema-BujGgvAy.d.ts} +35 -2
- package/dist/sessions/queries.js +61 -13
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/sessions/queries.mjs.map +1 -1
- package/dist/settings/queries.d.mts +11 -2
- package/dist/settings/queries.d.ts +11 -2
- package/dist/settings/queries.js +84 -14
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +41 -21
- package/dist/users/queries.d.ts +41 -21
- package/dist/users/queries.js +117 -24
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +57 -17
- package/dist/users/queries.mjs.map +1 -1
- package/dist/{email-template-verify-email-WZDCCAKK.mjs → verify-email-4KMNGDKN.mjs} +2 -2
- package/dist/verify-email-4KMNGDKN.mjs.map +1 -0
- package/lib/{auth-client.ts → auth/client.ts} +22 -2
- package/lib/{maintenance.ts → config/maintenance.ts} +0 -1
- package/lib/push/client.ts +39 -0
- package/lib/security/activity-severity.ts +57 -0
- package/lib/{request-info.ts → utils/request-info.ts} +7 -3
- package/package.json +177 -75
- package/scripts/check-deps.mjs +68 -0
- package/components/dashboard/admin/adminActivityLogsTable.tsx +0 -323
- package/components/dashboard/admin/adminUserStatusCard.tsx +0 -57
- package/components/dashboard/admin/systemSettingsForm.tsx +0 -289
- package/dist/chunk-4C7JHGT5.mjs +0 -30
- package/dist/chunk-4C7JHGT5.mjs.map +0 -1
- package/dist/chunk-4F6KE47S.mjs.map +0 -1
- package/dist/chunk-6OAHCEDJ.mjs.map +0 -1
- package/dist/chunk-A6JXMHOQ.mjs.map +0 -1
- package/dist/chunk-HUEDEAY3.mjs.map +0 -1
- package/dist/chunk-JUSU6UZA.mjs.map +0 -1
- package/dist/chunk-KA2KMGPY.mjs.map +0 -1
- package/dist/chunk-L242CZ64.mjs.map +0 -1
- package/dist/chunk-NQELV53D.mjs.map +0 -1
- package/dist/chunk-VHNGYAIG.mjs.map +0 -1
- package/dist/chunk-YH53UPUW.mjs.map +0 -1
- package/dist/email-template-passkey-change-F5Q2SXHD.mjs.map +0 -1
- package/dist/email-template-reset-password-QTCQNXOD.mjs.map +0 -1
- package/dist/email-template-verify-email-WZDCCAKK.mjs.map +0 -1
- /package/components/dashboard/{heartbeat.tsx → common/heartbeat.tsx} +0 -0
- /package/components/email/{email-template-reset-password.tsx → auth/reset-password.tsx} +0 -0
- /package/components/email/{email-template-verify-email.tsx → auth/verify-email.tsx} +0 -0
- /package/components/email/{email-template-welcome.tsx → auth/welcome.tsx} +0 -0
- /package/components/email/{email-template.tsx → layout/base-layout.tsx} +0 -0
- /package/components/email/{email-template-2.tsx → marketing/general-announcement.tsx} +0 -0
- /package/components/email/{email-template-banned.tsx → security/account-banned.tsx} +0 -0
- /package/components/email/{email-template-new-device.tsx → security/new-device-alert.tsx} +0 -0
- /package/components/email/{email-template-passkey-change.tsx → security/passkey-changed.tsx} +0 -0
- /package/lib/{cookie-consent.ts → security/cookie-consent.ts} +0 -0
- /package/lib/{cookie-names.ts → security/cookie-names.ts} +0 -0
- /package/lib/{device-fingerprint.ts → security/device-fingerprint.ts} +0 -0
- /package/lib/{formatters.ts → utils/formatters.ts} +0 -0
- /package/lib/{recalculate-columns.ts → utils/recalculate-columns.ts} +0 -0
package/README.md
CHANGED
|
@@ -93,6 +93,7 @@ Peer dependencies, the full import list, migrations, adding providers and One Ta
|
|
|
93
93
|
| `bun run migrate:dev` / `:prod` / `:test` | Apply migrations |
|
|
94
94
|
| `bun run studio:dev` | Drizzle Studio |
|
|
95
95
|
| `bun run test` | Unit tests |
|
|
96
|
+
| `bun run cy:run` / `cy:open` | Cypress e2e tests for all login and signup flows (needs `bun dev` running) |
|
|
96
97
|
| `bun run storybook` | Storybook for every component (mock data, no DB needed) |
|
|
97
98
|
| `bun run *:doppler` | Any of the above with secrets from Doppler |
|
|
98
99
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useEffect, useState } from 'react'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import { authClient } from '
|
|
5
|
+
import { authClient } from '../../../lib/auth/client'
|
|
6
6
|
|
|
7
7
|
type Props = {
|
|
8
8
|
/** The `?error=` code better-auth redirected to /login with. */
|
|
@@ -4,14 +4,14 @@ import React, { useEffect, useState } from 'react'
|
|
|
4
4
|
import Link from 'next/link'
|
|
5
5
|
import { useRouter } from 'next/navigation'
|
|
6
6
|
import { z } from 'zod'
|
|
7
|
-
import { Button } from '
|
|
8
|
-
import { Input } from '
|
|
9
|
-
import { PasswordInput } from '
|
|
10
|
-
import { Label } from '
|
|
11
|
-
import { authClient } from '
|
|
12
|
-
import { getVisitorId } from '
|
|
13
|
-
import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '
|
|
14
|
-
import { LoginSchema } from '
|
|
7
|
+
import { Button } from '../../ui/button'
|
|
8
|
+
import { Input } from '../../ui/input'
|
|
9
|
+
import { PasswordInput } from '../../ui/password-input'
|
|
10
|
+
import { Label } from '../../ui/label'
|
|
11
|
+
import { authClient } from '../../../lib/auth/client'
|
|
12
|
+
import { getVisitorId } from '../../../lib/security/device-fingerprint'
|
|
13
|
+
import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../../lib/security/cookie-names'
|
|
14
|
+
import { LoginSchema } from '../../../types/auth/loginSchema'
|
|
15
15
|
import { toast } from 'sonner'
|
|
16
16
|
|
|
17
17
|
type Props = {
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useEffect, useMemo, useState } from 'react'
|
|
4
4
|
import { z } from 'zod'
|
|
5
|
-
import { Button } from '
|
|
6
|
-
import { Input } from '
|
|
7
|
-
import { PasswordInput } from '
|
|
8
|
-
import { Label } from '
|
|
9
|
-
import { authClient } from '
|
|
10
|
-
import { getVisitorId } from '
|
|
11
|
-
import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '
|
|
12
|
-
import { SignupSchema } from '
|
|
5
|
+
import { Button } from '../../ui/button'
|
|
6
|
+
import { Input } from '../../ui/input'
|
|
7
|
+
import { PasswordInput } from '../../ui/password-input'
|
|
8
|
+
import { Label } from '../../ui/label'
|
|
9
|
+
import { authClient } from '../../../lib/auth/client'
|
|
10
|
+
import { getVisitorId } from '../../../lib/security/device-fingerprint'
|
|
11
|
+
import { LOGIN_REFERRER_COOKIE, DEVICE_FINGERPRINT_HEADER } from '../../../lib/security/cookie-names'
|
|
12
|
+
import { SignupSchema } from '../../../types/auth/signupSchema'
|
|
13
13
|
import { toast } from 'sonner'
|
|
14
14
|
|
|
15
15
|
type Props = {
|
|
@@ -87,7 +87,10 @@ const EmailPasswordSignup = ({ callbackUrl }: Props) => {
|
|
|
87
87
|
|
|
88
88
|
if (error) {
|
|
89
89
|
toast.error(error.message || 'Failed to sign up')
|
|
90
|
+
return
|
|
90
91
|
}
|
|
92
|
+
// signUp.email returns no redirect (unlike signIn.email), so callbackURL is not followed client-side.
|
|
93
|
+
window.location.href = callbackUrl || '/dashboard'
|
|
91
94
|
} catch (error) {
|
|
92
95
|
toast.error(error instanceof Error ? error.message : 'Failed to sign up')
|
|
93
96
|
} finally {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Link from 'next/link'
|
|
2
|
-
import { Separator } from "
|
|
3
|
-
import SocialLogin from '
|
|
4
|
-
import EmailPasswordLogin from '
|
|
5
|
-
import EmailPasswordSignup from '
|
|
6
|
-
import PasskeyLogin from '
|
|
2
|
+
import { Separator } from "../../ui/separator"
|
|
3
|
+
import SocialLogin from '../methods/social-login'
|
|
4
|
+
import EmailPasswordLogin from '../forms/login-form'
|
|
5
|
+
import EmailPasswordSignup from '../forms/signup-form'
|
|
6
|
+
import PasskeyLogin from '../methods/passkey-login'
|
|
7
7
|
|
|
8
8
|
type Props = {
|
|
9
9
|
authCardTitle: string
|
|
@@ -1,21 +1,33 @@
|
|
|
1
1
|
import type { ReactNode } from "react"
|
|
2
2
|
import { Check } from "lucide-react"
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
|
|
4
|
+
import Link from "next/link"
|
|
5
|
+
|
|
6
|
+
import { ThemeToggle } from "../../theme/theme-toggle"
|
|
7
|
+
|
|
8
|
+
// Neutral default so the package works out of the box; pass `logo` to brand it.
|
|
9
|
+
const DefaultLogo = () => (
|
|
10
|
+
<Link href="/" className="flex items-center gap-2 font-semibold">
|
|
11
|
+
<span className="flex size-6 items-center justify-center rounded-md bg-foreground text-background text-sm font-bold">
|
|
12
|
+
N
|
|
13
|
+
</span>
|
|
14
|
+
nextjs-template
|
|
15
|
+
</Link>
|
|
16
|
+
)
|
|
6
17
|
|
|
7
18
|
type Props = {
|
|
8
19
|
headline: string
|
|
9
20
|
bullets: string[]
|
|
10
21
|
children: ReactNode
|
|
22
|
+
logo?: ReactNode
|
|
11
23
|
}
|
|
12
24
|
|
|
13
|
-
export function AuthShell({ headline, bullets, children }: Props) {
|
|
25
|
+
export function AuthShell({ headline, bullets, children, logo = <DefaultLogo /> }: Props) {
|
|
14
26
|
return (
|
|
15
27
|
<div className="grid min-h-screen lg:grid-cols-2">
|
|
16
28
|
<div className="relative hidden flex-col justify-center border-r border-border/60 bg-secondary/30 p-10 lg:flex">
|
|
17
29
|
<div className="absolute top-10 left-10">
|
|
18
|
-
|
|
30
|
+
{logo}
|
|
19
31
|
</div>
|
|
20
32
|
<div>
|
|
21
33
|
<h1 className="text-3xl font-bold tracking-tight text-balance">{headline}</h1>
|
|
@@ -33,7 +45,7 @@ export function AuthShell({ headline, bullets, children }: Props) {
|
|
|
33
45
|
<div className="flex flex-col p-6 sm:p-10">
|
|
34
46
|
<div className="flex items-center justify-between lg:justify-end">
|
|
35
47
|
<div className="lg:hidden">
|
|
36
|
-
|
|
48
|
+
{logo}
|
|
37
49
|
</div>
|
|
38
50
|
<ThemeToggle />
|
|
39
51
|
</div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { authClient, useSession } from '
|
|
4
|
-
import { useConsentFor } from '
|
|
3
|
+
import { authClient, useSession } from '../../../lib/auth/client'
|
|
4
|
+
import { useConsentFor } from '../../../lib/security/cookie-consent'
|
|
5
5
|
import { useRouter } from 'next/navigation'
|
|
6
6
|
import React, { useEffect, useRef, useState } from 'react'
|
|
7
7
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
import React, { useState } from 'react'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
5
|
import { KeyRound } from 'lucide-react'
|
|
6
|
-
import { Button } from '
|
|
7
|
-
import { authClient } from '
|
|
6
|
+
import { Button } from '../../ui/button'
|
|
7
|
+
import { authClient } from '../../../lib/auth/client'
|
|
8
8
|
import { toast } from 'sonner'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { Button } from '
|
|
3
|
+
import { Button } from '../../ui/button'
|
|
4
4
|
import { FcGoogle } from "react-icons/fc";
|
|
5
5
|
import React from 'react'
|
|
6
|
-
import { authClient } from "
|
|
7
|
-
import { LOGIN_REFERRER_COOKIE } from "
|
|
6
|
+
import { authClient } from "../../../lib/auth/client";
|
|
7
|
+
import { LOGIN_REFERRER_COOKIE } from "../../../lib/security/cookie-names";
|
|
8
8
|
import { toast } from 'sonner'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useState } from 'react'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import { Button } from '
|
|
6
|
-
import { Input } from '
|
|
7
|
-
import { Label } from '
|
|
8
|
-
import { Checkbox } from '
|
|
9
|
-
import { authClient } from '
|
|
5
|
+
import { Button } from '../../ui/button'
|
|
6
|
+
import { Input } from '../../ui/input'
|
|
7
|
+
import { Label } from '../../ui/label'
|
|
8
|
+
import { Checkbox } from '../../ui/checkbox'
|
|
9
|
+
import { authClient } from '../../../lib/auth/client'
|
|
10
10
|
import { toast } from 'sonner'
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import React, { useState } from 'react'
|
|
4
|
-
import { Button } from '
|
|
5
|
-
import { Input } from '
|
|
6
|
-
import { Label } from '
|
|
7
|
-
import { authClient } from '
|
|
4
|
+
import { Button } from '../../ui/button'
|
|
5
|
+
import { Input } from '../../ui/input'
|
|
6
|
+
import { Label } from '../../ui/label'
|
|
7
|
+
import { authClient } from '../../../lib/auth/client'
|
|
8
8
|
import { toast } from 'sonner'
|
|
9
9
|
|
|
10
10
|
const ForgotPasswordForm = () => {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { useState } from 'react'
|
|
4
4
|
import { useRouter } from 'next/navigation'
|
|
5
|
-
import { Button } from '
|
|
6
|
-
import { PasswordInput } from '
|
|
7
|
-
import { Label } from '
|
|
8
|
-
import { authClient } from '
|
|
5
|
+
import { Button } from '../../ui/button'
|
|
6
|
+
import { PasswordInput } from '../../ui/password-input'
|
|
7
|
+
import { Label } from '../../ui/label'
|
|
8
|
+
import { authClient } from '../../../lib/auth/client'
|
|
9
9
|
import { toast } from 'sonner'
|
|
10
10
|
|
|
11
11
|
type Props = {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import { useEffect } from 'react'
|
|
4
|
-
import { useSession } from '
|
|
5
|
-
import { clearStoredVisitorId, getDeviceSignals, getStoredVisitorId, getVisitorId } from '
|
|
6
|
-
import { useConsentFor, useCookieConsent } from '
|
|
4
|
+
import { useSession } from '../../../lib/auth/client'
|
|
5
|
+
import { clearStoredVisitorId, getDeviceSignals, getStoredVisitorId, getVisitorId } from '../../../lib/security/device-fingerprint'
|
|
6
|
+
import { useConsentFor, useCookieConsent } from '../../../lib/security/cookie-consent'
|
|
7
7
|
|
|
8
8
|
// Mount once (e.g. in the root layout). When a session is present it computes
|
|
9
9
|
// a FingerprintJS device id and hands it to /api/device-check, which emails
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
3
|
import React from 'react'
|
|
4
|
-
import { authClient } from "
|
|
5
|
-
import { Button } from '
|
|
4
|
+
import { authClient } from "../../../lib/auth/client";
|
|
5
|
+
import { Button } from '../../ui/button';
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
const LogoutButtons = () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getActivityLogsFiltered } from "@xk2800/nextjs-template/activity/queries"
|
|
2
|
-
import AdminActivityLogsTable from "./
|
|
2
|
+
import AdminActivityLogsTable from "./admin-activity-logs-table"
|
|
3
3
|
|
|
4
4
|
export default async function ActivityLogsSection() {
|
|
5
5
|
const { logs, total, page, limit, pages } = await getActivityLogsFiltered({ page: 1, limit: 20 })
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from 'react'
|
|
4
|
+
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../../ui/card'
|
|
5
|
+
import { Button } from '../../../ui/button'
|
|
6
|
+
import { Input } from '../../../ui/input'
|
|
7
|
+
import { Badge } from '../../../ui/badge'
|
|
8
|
+
import { Switch } from '../../../ui/switch'
|
|
9
|
+
import { Label } from '../../../ui/label'
|
|
10
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../../ui/select'
|
|
11
|
+
import { DatePickerWithPresets } from '../../../ui/date-picker-with-presets'
|
|
12
|
+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from '../../../ui/sheet'
|
|
13
|
+
import AuditSeverityBadge, { SeverityLegend } from './audit-severity-badge'
|
|
14
|
+
import { CATEGORY_LABELS, SEVERITY_LABELS, categoryOf } from '../../../../lib/security/activity-severity'
|
|
15
|
+
import { format, subDays } from 'date-fns'
|
|
16
|
+
import { Skeleton } from '../../../ui/skeleton'
|
|
17
|
+
import { DataTable, DataTablePagination, type Column } from '../../../ui/data-table'
|
|
18
|
+
import { toast } from 'sonner'
|
|
19
|
+
import { formatDateTime } from '@xk2800/nextjs-template/lib/formatters'
|
|
20
|
+
import { Download } from 'lucide-react'
|
|
21
|
+
|
|
22
|
+
interface ActivityLog {
|
|
23
|
+
id: string
|
|
24
|
+
action: string
|
|
25
|
+
description: string
|
|
26
|
+
ipAddress: string | null
|
|
27
|
+
userAgent: string | null
|
|
28
|
+
metadata: string | null
|
|
29
|
+
createdAt: Date | string
|
|
30
|
+
userId: string | null
|
|
31
|
+
userName: string | null
|
|
32
|
+
userEmail: string | null
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface PaginationData {
|
|
36
|
+
page: number
|
|
37
|
+
limit: number
|
|
38
|
+
total: number
|
|
39
|
+
pages: number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const toYmd = (d: Date) => format(d, 'yyyy-MM-dd')
|
|
43
|
+
|
|
44
|
+
const RANGE_PRESETS = [
|
|
45
|
+
{ value: 'any', label: 'Any time' },
|
|
46
|
+
{ value: 'today', label: 'Today' },
|
|
47
|
+
{ value: '7d', label: 'Last 7 days' },
|
|
48
|
+
{ value: '30d', label: 'Last 30 days' },
|
|
49
|
+
{ value: 'custom', label: 'Custom range' },
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
function parseMetadata(raw: string | null) {
|
|
53
|
+
if (!raw) return null
|
|
54
|
+
try {
|
|
55
|
+
return JSON.stringify(JSON.parse(raw), null, 2)
|
|
56
|
+
} catch {
|
|
57
|
+
return raw
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface AdminActivityLogsTableProps {
|
|
62
|
+
initialLogs: ActivityLog[]
|
|
63
|
+
initialPagination: PaginationData
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const makeColumns = (onView: (log: ActivityLog) => void): Column<ActivityLog>[] => [
|
|
67
|
+
{
|
|
68
|
+
name: 'severity',
|
|
69
|
+
title: 'Severity',
|
|
70
|
+
sticky: true,
|
|
71
|
+
minWidth: 100,
|
|
72
|
+
renderer: (log) => <AuditSeverityBadge action={log.action} />,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'createdAt',
|
|
76
|
+
title: 'Time',
|
|
77
|
+
priority: 0,
|
|
78
|
+
renderer: (log) => (
|
|
79
|
+
<span className="text-sm text-gray-600 dark:text-gray-400">{formatDateTime(log.createdAt)}</span>
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'user',
|
|
84
|
+
title: 'Actor',
|
|
85
|
+
priority: -1,
|
|
86
|
+
minWidth: 240,
|
|
87
|
+
renderer: (log) => (
|
|
88
|
+
<div className="text-sm">
|
|
89
|
+
<div className="font-medium">{log.userName || 'N/A'}</div>
|
|
90
|
+
<div className="text-xs text-gray-500">{log.userEmail}</div>
|
|
91
|
+
</div>
|
|
92
|
+
),
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'action',
|
|
96
|
+
title: 'Event',
|
|
97
|
+
minWidth: 160,
|
|
98
|
+
renderer: (log) => (
|
|
99
|
+
<div className="text-sm">
|
|
100
|
+
<div className="font-medium capitalize">{log.action.replace(/_/g, ' ')}</div>
|
|
101
|
+
<div className="max-w-xs truncate text-xs text-gray-500">{log.description}</div>
|
|
102
|
+
</div>
|
|
103
|
+
),
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'ipAddress',
|
|
107
|
+
title: 'IP Address',
|
|
108
|
+
renderer: (log) => <span className="text-sm font-mono">{log.ipAddress || 'N/A'}</span>,
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'details',
|
|
112
|
+
title: '',
|
|
113
|
+
minWidth: 80,
|
|
114
|
+
renderer: (log) => (
|
|
115
|
+
<Button variant="ghost" size="sm" onClick={() => onView(log)}>View</Button>
|
|
116
|
+
),
|
|
117
|
+
},
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
export default function AdminActivityLogsTable({ initialLogs, initialPagination }: AdminActivityLogsTableProps) {
|
|
121
|
+
const [logs, setLogs] = useState<ActivityLog[]>(initialLogs)
|
|
122
|
+
const [loading, setLoading] = useState(false)
|
|
123
|
+
const [search, setSearch] = useState('')
|
|
124
|
+
const [category, setCategory] = useState('all')
|
|
125
|
+
const [severity, setSeverity] = useState('all')
|
|
126
|
+
const [range, setRange] = useState('any')
|
|
127
|
+
const [live, setLive] = useState(false)
|
|
128
|
+
const [selected, setSelected] = useState<ActivityLog | null>(null)
|
|
129
|
+
const [dateFrom, setDateFrom] = useState('')
|
|
130
|
+
const [dateTo, setDateTo] = useState('')
|
|
131
|
+
const [page, setPage] = useState(1)
|
|
132
|
+
const [pagination, setPagination] = useState<PaginationData | null>(initialPagination)
|
|
133
|
+
const [isExporting, setIsExporting] = useState(false)
|
|
134
|
+
|
|
135
|
+
const requestId = useRef(0)
|
|
136
|
+
|
|
137
|
+
const filterParams = () => ({
|
|
138
|
+
search,
|
|
139
|
+
...(category !== 'all' && { category }),
|
|
140
|
+
...(severity !== 'all' && { severity }),
|
|
141
|
+
...(dateFrom && { dateFrom }),
|
|
142
|
+
...(dateTo && { dateTo }),
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const applyRange = (value: string) => {
|
|
146
|
+
setRange(value)
|
|
147
|
+
const today = new Date()
|
|
148
|
+
if (value === 'today') { setDateFrom(toYmd(today)); setDateTo(toYmd(today)) }
|
|
149
|
+
else if (value === '7d') { setDateFrom(toYmd(subDays(today, 6))); setDateTo(toYmd(today)) }
|
|
150
|
+
else if (value === '30d') { setDateFrom(toYmd(subDays(today, 29))); setDateTo(toYmd(today)) }
|
|
151
|
+
else if (value === 'any') { setDateFrom(''); setDateTo('') }
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const fetchLogs = async (pageNum: number, silent = false) => {
|
|
155
|
+
const currentRequest = ++requestId.current
|
|
156
|
+
if (!silent) setLoading(true)
|
|
157
|
+
try {
|
|
158
|
+
const params = new URLSearchParams({
|
|
159
|
+
page: pageNum.toString(),
|
|
160
|
+
limit: '20',
|
|
161
|
+
...filterParams(),
|
|
162
|
+
})
|
|
163
|
+
const response = await fetch(`/api/admin/activity-logs?${params}`)
|
|
164
|
+
if (!response.ok) throw new Error('Failed to fetch activity logs')
|
|
165
|
+
const data = await response.json()
|
|
166
|
+
if (currentRequest !== requestId.current) return
|
|
167
|
+
setLogs(data.logs)
|
|
168
|
+
setPagination(data.pagination)
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (currentRequest !== requestId.current) return
|
|
171
|
+
if (!silent) toast.error('Failed to load activity logs')
|
|
172
|
+
console.error(error)
|
|
173
|
+
} finally {
|
|
174
|
+
if (currentRequest === requestId.current) setLoading(false)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const isFirstRender = useRef(true)
|
|
179
|
+
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
if (isFirstRender.current) {
|
|
182
|
+
isFirstRender.current = false
|
|
183
|
+
return
|
|
184
|
+
}
|
|
185
|
+
const timer = setTimeout(() => {
|
|
186
|
+
fetchLogs(1)
|
|
187
|
+
setPage(1)
|
|
188
|
+
}, 300)
|
|
189
|
+
return () => clearTimeout(timer)
|
|
190
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
191
|
+
}, [search, category, severity, dateFrom, dateTo])
|
|
192
|
+
|
|
193
|
+
// Live feed: quiet refetch of the current page every 10s.
|
|
194
|
+
useEffect(() => {
|
|
195
|
+
if (!live) return
|
|
196
|
+
const t = setInterval(() => fetchLogs(page, true), 10_000)
|
|
197
|
+
return () => clearInterval(t)
|
|
198
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
199
|
+
}, [live, page, search, category, severity, dateFrom, dateTo])
|
|
200
|
+
|
|
201
|
+
const resetFilters = () => {
|
|
202
|
+
setSearch('')
|
|
203
|
+
setCategory('all')
|
|
204
|
+
setSeverity('all')
|
|
205
|
+
setRange('any')
|
|
206
|
+
setDateFrom('')
|
|
207
|
+
setDateTo('')
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const handleExport = async () => {
|
|
211
|
+
setIsExporting(true)
|
|
212
|
+
try {
|
|
213
|
+
const params = new URLSearchParams(filterParams())
|
|
214
|
+
const response = await fetch(`/api/admin/activity-logs/export?${params}`)
|
|
215
|
+
if (!response.ok) throw new Error('Failed to export activity logs')
|
|
216
|
+
const blob = await response.blob()
|
|
217
|
+
const url = URL.createObjectURL(blob)
|
|
218
|
+
const link = document.createElement('a')
|
|
219
|
+
link.href = url
|
|
220
|
+
link.download = `activity-logs-${new Date().toISOString().slice(0, 10)}.csv`
|
|
221
|
+
document.body.appendChild(link)
|
|
222
|
+
link.click()
|
|
223
|
+
link.remove()
|
|
224
|
+
URL.revokeObjectURL(url)
|
|
225
|
+
} catch (error) {
|
|
226
|
+
toast.error('Failed to export activity logs')
|
|
227
|
+
console.error(error)
|
|
228
|
+
} finally {
|
|
229
|
+
setIsExporting(false)
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const hasFilters = !!(search || category !== 'all' || severity !== 'all' || dateFrom || dateTo)
|
|
234
|
+
const columns = makeColumns(setSelected)
|
|
235
|
+
const metadata = selected ? parseMetadata(selected.metadata) : null
|
|
236
|
+
|
|
237
|
+
return (
|
|
238
|
+
<>
|
|
239
|
+
<Card>
|
|
240
|
+
<CardHeader className="space-y-4">
|
|
241
|
+
<div className="flex flex-row items-start justify-between gap-4">
|
|
242
|
+
<div>
|
|
243
|
+
<CardTitle>Activity Events</CardTitle>
|
|
244
|
+
<CardDescription>
|
|
245
|
+
{pagination ? `Showing ${logs.length} of ${pagination.total} events` : 'Loading...'}
|
|
246
|
+
</CardDescription>
|
|
247
|
+
</div>
|
|
248
|
+
<div className="flex items-center gap-4">
|
|
249
|
+
<div className="flex items-center gap-2">
|
|
250
|
+
<Switch id="live-feed" checked={live} onCheckedChange={setLive} />
|
|
251
|
+
<Label htmlFor="live-feed" className="text-sm">Live feed</Label>
|
|
252
|
+
</div>
|
|
253
|
+
<Button variant="outline" size="sm" onClick={handleExport} disabled={isExporting || logs.length === 0}>
|
|
254
|
+
<Download />
|
|
255
|
+
{isExporting ? 'Exporting...' : 'Export CSV'}
|
|
256
|
+
</Button>
|
|
257
|
+
</div>
|
|
258
|
+
</div>
|
|
259
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
260
|
+
<Input
|
|
261
|
+
placeholder="Search user or IP..."
|
|
262
|
+
value={search}
|
|
263
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
264
|
+
className="max-w-xs"
|
|
265
|
+
/>
|
|
266
|
+
<Select value={category} onValueChange={setCategory}>
|
|
267
|
+
<SelectTrigger className="w-[170px]"><SelectValue /></SelectTrigger>
|
|
268
|
+
<SelectContent>
|
|
269
|
+
<SelectItem value="all">Category: All</SelectItem>
|
|
270
|
+
{Object.entries(CATEGORY_LABELS).map(([v, l]) => <SelectItem key={v} value={v}>{l}</SelectItem>)}
|
|
271
|
+
</SelectContent>
|
|
272
|
+
</Select>
|
|
273
|
+
<Select value={severity} onValueChange={setSeverity}>
|
|
274
|
+
<SelectTrigger className="w-[150px]"><SelectValue /></SelectTrigger>
|
|
275
|
+
<SelectContent>
|
|
276
|
+
<SelectItem value="all">Severity: All</SelectItem>
|
|
277
|
+
{Object.entries(SEVERITY_LABELS).map(([v, l]) => <SelectItem key={v} value={v}>{l}</SelectItem>)}
|
|
278
|
+
</SelectContent>
|
|
279
|
+
</Select>
|
|
280
|
+
<SeverityLegend />
|
|
281
|
+
<Select value={range} onValueChange={applyRange}>
|
|
282
|
+
<SelectTrigger className="w-[150px]"><SelectValue /></SelectTrigger>
|
|
283
|
+
<SelectContent>
|
|
284
|
+
{RANGE_PRESETS.map((p) => <SelectItem key={p.value} value={p.value}>{p.label}</SelectItem>)}
|
|
285
|
+
</SelectContent>
|
|
286
|
+
</Select>
|
|
287
|
+
{range === 'custom' && (
|
|
288
|
+
<>
|
|
289
|
+
<DatePickerWithPresets
|
|
290
|
+
placeholder="From"
|
|
291
|
+
date={dateFrom ? new Date(`${dateFrom}T00:00:00`) : undefined}
|
|
292
|
+
onDateChange={(d) => setDateFrom(d ? toYmd(d) : '')}
|
|
293
|
+
disableFutureDates
|
|
294
|
+
/>
|
|
295
|
+
<DatePickerWithPresets
|
|
296
|
+
placeholder="To"
|
|
297
|
+
date={dateTo ? new Date(`${dateTo}T00:00:00`) : undefined}
|
|
298
|
+
onDateChange={(d) => setDateTo(d ? toYmd(d) : '')}
|
|
299
|
+
disableFutureDates
|
|
300
|
+
/>
|
|
301
|
+
</>
|
|
302
|
+
)}
|
|
303
|
+
{hasFilters && (
|
|
304
|
+
<Button variant="ghost" size="sm" onClick={resetFilters}>Clear</Button>
|
|
305
|
+
)}
|
|
306
|
+
</div>
|
|
307
|
+
</CardHeader>
|
|
308
|
+
<CardContent>
|
|
309
|
+
{loading ? (
|
|
310
|
+
<div className="space-y-4">
|
|
311
|
+
{[...Array(5)].map((_, i) => (
|
|
312
|
+
<Skeleton key={i} className="h-16 w-full" />
|
|
313
|
+
))}
|
|
314
|
+
</div>
|
|
315
|
+
) : logs.length === 0 ? (
|
|
316
|
+
<p className="text-center text-gray-500 py-8">No activity logs found</p>
|
|
317
|
+
) : (
|
|
318
|
+
<DataTable columns={columns} data={logs} getRowId={(log) => log.id} pageSize={false} />
|
|
319
|
+
)}
|
|
320
|
+
|
|
321
|
+
{pagination && (
|
|
322
|
+
<DataTablePagination
|
|
323
|
+
page={page}
|
|
324
|
+
pages={pagination.pages}
|
|
325
|
+
onPageChange={(p) => {
|
|
326
|
+
setPage(p)
|
|
327
|
+
fetchLogs(p)
|
|
328
|
+
}}
|
|
329
|
+
className="mt-6 pt-6"
|
|
330
|
+
/>
|
|
331
|
+
)}
|
|
332
|
+
</CardContent>
|
|
333
|
+
</Card>
|
|
334
|
+
|
|
335
|
+
<Sheet open={!!selected} onOpenChange={(o) => !o && setSelected(null)}>
|
|
336
|
+
<SheetContent className="w-full overflow-y-auto sm:max-w-lg">
|
|
337
|
+
{selected && (
|
|
338
|
+
<>
|
|
339
|
+
<SheetHeader>
|
|
340
|
+
<SheetTitle className="capitalize">{selected.action.replace(/_/g, ' ')}</SheetTitle>
|
|
341
|
+
<SheetDescription>{selected.description}</SheetDescription>
|
|
342
|
+
</SheetHeader>
|
|
343
|
+
<dl className="space-y-4 px-4 pb-4 text-sm">
|
|
344
|
+
<div className="flex items-center gap-2">
|
|
345
|
+
<AuditSeverityBadge action={selected.action} />
|
|
346
|
+
<Badge variant="outline">{CATEGORY_LABELS[categoryOf(selected.action)]}</Badge>
|
|
347
|
+
</div>
|
|
348
|
+
{([
|
|
349
|
+
['Time', formatDateTime(selected.createdAt)],
|
|
350
|
+
['Actor', `${selected.userName || 'N/A'} (${selected.userEmail || selected.userId})`],
|
|
351
|
+
['IP address', selected.ipAddress || 'N/A'],
|
|
352
|
+
['User agent', selected.userAgent || 'N/A'],
|
|
353
|
+
['Event ID', selected.id],
|
|
354
|
+
] as const).map(([k, v]) => (
|
|
355
|
+
<div key={k}>
|
|
356
|
+
<dt className="font-medium text-gray-600">{k}</dt>
|
|
357
|
+
<dd className="break-all">{v}</dd>
|
|
358
|
+
</div>
|
|
359
|
+
))}
|
|
360
|
+
{metadata && (
|
|
361
|
+
<div>
|
|
362
|
+
<dt className="font-medium text-gray-600">Metadata</dt>
|
|
363
|
+
<dd>
|
|
364
|
+
<pre className="mt-1 overflow-x-auto rounded-md bg-muted p-3 text-xs">{metadata}</pre>
|
|
365
|
+
</dd>
|
|
366
|
+
</div>
|
|
367
|
+
)}
|
|
368
|
+
</dl>
|
|
369
|
+
</>
|
|
370
|
+
)}
|
|
371
|
+
</SheetContent>
|
|
372
|
+
</Sheet>
|
|
373
|
+
</>
|
|
374
|
+
)
|
|
375
|
+
}
|