@xk2800/nextjs-template 0.7.1-beta.8 → 0.7.2-beta.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/components/auth/oneTap.tsx +15 -5
- package/components/dashboard/admin/adminActivityLogsTable.tsx +4 -0
- package/components/dashboard/admin/adminUsersTable.tsx +154 -34
- package/components/dashboard/admin/impersonationLogCard.tsx +2 -2
- package/components/dashboard/appSidebar.tsx +2 -2
- package/components/dashboard/deleteAccountCard.tsx +31 -4
- package/components/dashboard/navStyleToggle.tsx +29 -0
- package/components/dashboard/topNav.tsx +95 -0
- package/components/email/email-template-banned.tsx +53 -0
- package/components/ui/alert-dialog.tsx +2 -2
- package/components/ui/avatar.tsx +1 -1
- package/components/ui/badge.tsx +5 -3
- package/components/ui/calendar.tsx +220 -0
- package/components/ui/card.tsx +1 -1
- package/components/ui/category-selector.tsx +215 -0
- package/components/ui/chart.tsx +374 -0
- package/components/ui/column-picker.tsx +140 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/data-table.tsx +44 -6
- package/components/ui/date-picker-with-presets.tsx +122 -0
- package/components/ui/dialog.tsx +2 -2
- package/components/ui/disclaimer.tsx +4 -0
- package/components/ui/dropdown-menu.tsx +3 -3
- package/components/ui/field.tsx +248 -0
- package/components/ui/info-tooltip.tsx +53 -0
- package/components/ui/input.tsx +10 -1
- package/components/ui/label.tsx +1 -1
- package/components/ui/month-selector.tsx +194 -0
- package/components/ui/navigation-menu.tsx +168 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +89 -0
- package/components/ui/select.tsx +1 -1
- package/components/ui/source-selector.tsx +164 -0
- package/components/ui/switch.tsx +3 -3
- package/dist/activity/logger.d.mts +3 -1
- package/dist/activity/logger.d.ts +3 -1
- package/dist/activity/logger.js +20 -0
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/activity/queries.js +20 -0
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +3 -3
- package/dist/admin/queries.js +20 -0
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +3 -3
- package/dist/api/feedback.js +527 -70
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +8 -8
- package/dist/api/marketing.js +527 -70
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +10 -10
- package/dist/auth/helpers.js +525 -68
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +8 -8
- package/dist/auth/index.d.mts +149 -10
- package/dist/auth/index.d.ts +149 -10
- package/dist/auth/index.js +525 -68
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/{chunk-ZJMFE5B2.mjs → chunk-4C7JHGT5.mjs} +4 -4
- package/dist/{chunk-ZJMFE5B2.mjs.map → chunk-4C7JHGT5.mjs.map} +1 -1
- package/dist/{chunk-7F2POZM6.mjs → chunk-4F6KE47S.mjs} +4 -4
- package/dist/chunk-4F6KE47S.mjs.map +1 -0
- package/dist/{chunk-P2G23JMY.mjs → chunk-A6JXMHOQ.mjs} +5 -5
- package/dist/{chunk-P2G23JMY.mjs.map → chunk-A6JXMHOQ.mjs.map} +1 -1
- package/dist/{chunk-TKWNEKK6.mjs → chunk-HUEDEAY3.mjs} +8 -2
- package/dist/chunk-HUEDEAY3.mjs.map +1 -0
- package/dist/{chunk-6Z3WUSDJ.mjs → chunk-JUSU6UZA.mjs} +5 -5
- package/dist/{chunk-6Z3WUSDJ.mjs.map → chunk-JUSU6UZA.mjs.map} +1 -1
- package/dist/{chunk-TR5XFBTD.mjs → chunk-KA2KMGPY.mjs} +17 -3
- package/dist/chunk-KA2KMGPY.mjs.map +1 -0
- package/dist/{chunk-OVKVD2HH.mjs → chunk-L242CZ64.mjs} +3 -3
- package/dist/{chunk-OVKVD2HH.mjs.map → chunk-L242CZ64.mjs.map} +1 -1
- package/dist/{chunk-C6RGN6QA.mjs → chunk-NQELV53D.mjs} +4 -4
- package/dist/{chunk-C6RGN6QA.mjs.map → chunk-NQELV53D.mjs.map} +1 -1
- package/dist/chunk-VHNGYAIG.mjs +899 -0
- package/dist/chunk-VHNGYAIG.mjs.map +1 -0
- package/dist/{chunk-6MDQRT6U.mjs → chunk-YH53UPUW.mjs} +4 -4
- package/dist/{chunk-6MDQRT6U.mjs.map → chunk-YH53UPUW.mjs.map} +1 -1
- package/dist/config/env.d.mts +2 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +6 -0
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +20 -0
- 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 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.js +6 -0
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-CN_Y6EXv.d.mts → schema-DzC5zdOq.d.mts} +146 -2
- package/dist/{schema-CN_Y6EXv.d.ts → schema-DzC5zdOq.d.ts} +146 -2
- package/dist/sessions/queries.js +20 -0
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +1 -1
- package/dist/settings/queries.d.ts +1 -1
- package/dist/settings/queries.js +20 -0
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +3 -0
- package/dist/users/queries.d.ts +3 -0
- package/dist/users/queries.js +20 -0
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +3 -3
- package/lib/recalculate-columns.ts +8 -2
- package/package.json +28 -18
- package/styles/theme.css +23 -3
- package/dist/chunk-7F2POZM6.mjs.map +0 -1
- package/dist/chunk-7QVIOQ47.mjs +0 -462
- package/dist/chunk-7QVIOQ47.mjs.map +0 -1
- package/dist/chunk-TKWNEKK6.mjs.map +0 -1
- package/dist/chunk-TR5XFBTD.mjs.map +0 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { authClient, useSession } from '../../lib/auth-client'
|
|
4
4
|
import { useConsentFor } from '../../lib/cookie-consent'
|
|
5
5
|
import { useRouter } from 'next/navigation'
|
|
6
|
-
import React, { useEffect, useState } from 'react'
|
|
6
|
+
import React, { useEffect, useRef, useState } from 'react'
|
|
7
7
|
|
|
8
8
|
type OneTapProps = {
|
|
9
9
|
/**
|
|
@@ -24,6 +24,8 @@ const OneTap = ({ callbackURL = '/dashboard' }: OneTapProps) => {
|
|
|
24
24
|
// Google's One Tap script is third-party and can use Google's cookies, so
|
|
25
25
|
// it only loads once the visitor consents to the "onetap" purpose.
|
|
26
26
|
const oneTapAllowed = useConsentFor('onetap')
|
|
27
|
+
// Refs survive React strict mode's dev double-effect; a second prompt() aborts the first and GSI logs it as a console error.
|
|
28
|
+
const prompted = useRef(false)
|
|
27
29
|
|
|
28
30
|
useEffect(() => {
|
|
29
31
|
if (process.env.NEXT_PUBLIC_AUTH_ENABLE_ONE_TAP !== 'true') return
|
|
@@ -40,12 +42,20 @@ const OneTap = ({ callbackURL = '/dashboard' }: OneTapProps) => {
|
|
|
40
42
|
if (isPending || session) return
|
|
41
43
|
if (oneTapOffered !== true) return
|
|
42
44
|
if (!oneTapAllowed) return
|
|
45
|
+
if (prompted.current) return
|
|
46
|
+
prompted.current = true
|
|
43
47
|
|
|
48
|
+
// Passing fetchOptions (and no callbackURL) turns off the client's own redirect, so
|
|
49
|
+
// a 2FA challenge ({ twoFactorRedirect }) isn't overwritten by a jump to callbackURL.
|
|
44
50
|
authClient.oneTap({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
fetchOptions: {
|
|
52
|
+
onSuccess: ({ data }) => {
|
|
53
|
+
window.location.href = (data as { twoFactorRedirect?: boolean } | null)?.twoFactorRedirect
|
|
54
|
+
? `/login/2fa?callbackUrl=${encodeURIComponent(callbackURL)}`
|
|
55
|
+
: callbackURL
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
// No onPromptNotification: it makes GSI call the display/skipped-moment methods, which FedCM deprecates.
|
|
49
59
|
})
|
|
50
60
|
}, [session, isPending, callbackURL, oneTapOffered, oneTapAllowed])
|
|
51
61
|
|
|
@@ -77,6 +77,7 @@ const columns: Column<ActivityLog>[] = [
|
|
|
77
77
|
name: 'action',
|
|
78
78
|
title: 'Action',
|
|
79
79
|
sticky: true,
|
|
80
|
+
minWidth: 110,
|
|
80
81
|
renderer: (log) => (
|
|
81
82
|
<Badge variant={actionBadgeVariant[log.action] || 'outline'}>
|
|
82
83
|
{log.action.replace(/_/g, ' ')}
|
|
@@ -86,6 +87,8 @@ const columns: Column<ActivityLog>[] = [
|
|
|
86
87
|
{
|
|
87
88
|
name: 'user',
|
|
88
89
|
title: 'User',
|
|
90
|
+
priority: -1,
|
|
91
|
+
minWidth: 260,
|
|
89
92
|
renderer: (log) => (
|
|
90
93
|
<div className="text-sm">
|
|
91
94
|
<div className="font-medium">{log.userName || 'N/A'}</div>
|
|
@@ -108,6 +111,7 @@ const columns: Column<ActivityLog>[] = [
|
|
|
108
111
|
{
|
|
109
112
|
name: 'createdAt',
|
|
110
113
|
title: 'Time',
|
|
114
|
+
priority: 0,
|
|
111
115
|
renderer: (log) => (
|
|
112
116
|
<span className="text-sm text-gray-600 dark:text-gray-400">
|
|
113
117
|
{formatDateTime(log.createdAt)}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useState, useEffect, useRef } from 'react'
|
|
3
|
+
import { useState, useEffect, useRef, type ReactNode } from 'react'
|
|
4
4
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '../../ui/card'
|
|
5
5
|
import { Button } from '../../ui/button'
|
|
6
6
|
import { Input } from '../../ui/input'
|
|
7
7
|
import { Badge } from '../../ui/badge'
|
|
8
8
|
import { Skeleton } from '../../ui/skeleton'
|
|
9
9
|
import { Checkbox } from '../../ui/checkbox'
|
|
10
|
+
import { Label } from '../../ui/label'
|
|
11
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../../ui/select'
|
|
10
12
|
import { DataTable, DataTablePagination, type Column } from '../../ui/data-table'
|
|
11
13
|
import {
|
|
12
14
|
AlertDialog,
|
|
@@ -25,7 +27,7 @@ import { formatDate, formatDateTime } from '@xk2800/nextjs-template/lib/formatte
|
|
|
25
27
|
import { Download } from 'lucide-react'
|
|
26
28
|
import { authClient, useSession } from '@xk2800/nextjs-template/auth-client'
|
|
27
29
|
|
|
28
|
-
interface
|
|
30
|
+
export interface AdminUser {
|
|
29
31
|
id: string
|
|
30
32
|
name: string | null
|
|
31
33
|
email: string
|
|
@@ -33,11 +35,21 @@ interface User {
|
|
|
33
35
|
banned: boolean
|
|
34
36
|
bannedAt: Date | null
|
|
35
37
|
bannedReason: string | null
|
|
38
|
+
/** Email of the admin who issued the ban. */
|
|
39
|
+
bannedBy?: string | null
|
|
40
|
+
/** Only read when the `plans` prop is passed. */
|
|
41
|
+
plan?: string | null
|
|
36
42
|
lastLoginAt: Date | null
|
|
37
43
|
lastActiveAt: Date | null
|
|
38
44
|
createdAt: Date
|
|
39
45
|
}
|
|
40
46
|
|
|
47
|
+
export type AdminUserPlans<TUser extends AdminUser = AdminUser> = {
|
|
48
|
+
options: { value: string; label: string }[]
|
|
49
|
+
/** Small text under the picker, e.g. a trial end date. */
|
|
50
|
+
note?: (user: TUser) => ReactNode
|
|
51
|
+
}
|
|
52
|
+
|
|
41
53
|
// A user counts as "online" if their heartbeat (sent every 30s while a
|
|
42
54
|
// dashboard tab is open, see components/dashboard/heartbeat.tsx) landed
|
|
43
55
|
// within this window.
|
|
@@ -55,15 +67,38 @@ interface PaginationData {
|
|
|
55
67
|
pages: number
|
|
56
68
|
}
|
|
57
69
|
|
|
58
|
-
interface AdminUsersTableProps {
|
|
59
|
-
initialUsers:
|
|
70
|
+
export interface AdminUsersTableProps<TUser extends AdminUser = AdminUser> {
|
|
71
|
+
initialUsers: TUser[]
|
|
60
72
|
initialPagination: PaginationData
|
|
73
|
+
/**
|
|
74
|
+
* For apps with plans / subscriptions: adds a Plan column with a change-plan picker,
|
|
75
|
+
* which sends `PATCH /api/admin/users/:id` with `{ plan }`. Rows need a `plan` field.
|
|
76
|
+
*/
|
|
77
|
+
plans?: AdminUserPlans<TUser>
|
|
78
|
+
/** App-specific columns (e.g. storage), shown before Status. Rows can carry extra fields. */
|
|
79
|
+
extraColumns?: Column<TUser>[]
|
|
80
|
+
/** Show the Impersonate action. Default true; pass false if impersonation is turned off. */
|
|
81
|
+
impersonation?: boolean
|
|
82
|
+
/**
|
|
83
|
+
* Where a user's name links. Default `/dashboard/admin/users/:id` (the template's user
|
|
84
|
+
* detail page); return null to show the name as plain text (an app without that page).
|
|
85
|
+
*/
|
|
86
|
+
userHref?: (user: TUser) => string | null
|
|
61
87
|
}
|
|
62
88
|
|
|
63
|
-
export default function AdminUsersTable
|
|
89
|
+
export default function AdminUsersTable<TUser extends AdminUser = AdminUser>({
|
|
90
|
+
initialUsers,
|
|
91
|
+
initialPagination,
|
|
92
|
+
plans,
|
|
93
|
+
extraColumns = [],
|
|
94
|
+
impersonation = true,
|
|
95
|
+
userHref = (user) => `/dashboard/admin/users/${user.id}`,
|
|
96
|
+
}: AdminUsersTableProps<TUser>) {
|
|
64
97
|
const router = useRouter()
|
|
65
98
|
const { data: currentSession } = useSession()
|
|
66
|
-
const [users, setUsers] = useState<
|
|
99
|
+
const [users, setUsers] = useState<TUser[]>(initialUsers)
|
|
100
|
+
const [banReason, setBanReason] = useState('')
|
|
101
|
+
const [updatingPlanFor, setUpdatingPlanFor] = useState<string | null>(null)
|
|
67
102
|
const [loading, setLoading] = useState(false)
|
|
68
103
|
const [search, setSearch] = useState('')
|
|
69
104
|
const [page, setPage] = useState(1)
|
|
@@ -201,7 +236,7 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
201
236
|
response = await fetch(`/api/admin/users/${actionUserId}/ban`, {
|
|
202
237
|
method: 'POST',
|
|
203
238
|
headers: { 'Content-Type': 'application/json' },
|
|
204
|
-
body: JSON.stringify({ ban: true, reason: 'Banned by admin' }),
|
|
239
|
+
body: JSON.stringify({ ban: true, reason: banReason.trim() || 'Banned by admin' }),
|
|
205
240
|
})
|
|
206
241
|
successMessage = 'User banned successfully'
|
|
207
242
|
break
|
|
@@ -251,6 +286,7 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
251
286
|
toast.success(successMessage)
|
|
252
287
|
setActionUserId(null)
|
|
253
288
|
setActionType(null)
|
|
289
|
+
setBanReason('')
|
|
254
290
|
await fetchUsers(page, search)
|
|
255
291
|
} catch (error) {
|
|
256
292
|
toast.error(`Failed to ${actionType} user`)
|
|
@@ -260,6 +296,25 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
260
296
|
}
|
|
261
297
|
}
|
|
262
298
|
|
|
299
|
+
const handlePlanChange = async (userId: string, plan: string) => {
|
|
300
|
+
setUpdatingPlanFor(userId)
|
|
301
|
+
try {
|
|
302
|
+
const response = await fetch(`/api/admin/users/${userId}`, {
|
|
303
|
+
method: 'PATCH',
|
|
304
|
+
headers: { 'Content-Type': 'application/json' },
|
|
305
|
+
body: JSON.stringify({ plan }),
|
|
306
|
+
})
|
|
307
|
+
if (!response.ok) throw new Error('Failed to update plan')
|
|
308
|
+
setUsers((prev) => prev.map((u) => (u.id === userId ? { ...u, plan } : u)))
|
|
309
|
+
toast.success('Plan updated')
|
|
310
|
+
} catch (error) {
|
|
311
|
+
toast.error('Failed to update plan')
|
|
312
|
+
console.error(error)
|
|
313
|
+
} finally {
|
|
314
|
+
setUpdatingPlanFor(null)
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
263
318
|
const handleBulkAction = async () => {
|
|
264
319
|
if (!bulkActionType || selectedIds.size === 0) return
|
|
265
320
|
|
|
@@ -386,18 +441,25 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
386
441
|
name: 'name',
|
|
387
442
|
title: 'Name',
|
|
388
443
|
sticky: true,
|
|
389
|
-
renderer: (user) =>
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
444
|
+
renderer: (user) => {
|
|
445
|
+
const label = (
|
|
446
|
+
<>
|
|
447
|
+
<span
|
|
448
|
+
className={`h-2 w-2 rounded-full ${isOnline(user.lastActiveAt) ? 'bg-green-500' : 'bg-gray-300 dark:bg-gray-600'}`}
|
|
449
|
+
title={isOnline(user.lastActiveAt) ? 'Online' : 'Offline'}
|
|
450
|
+
/>
|
|
451
|
+
{user.name || 'N/A'}
|
|
452
|
+
</>
|
|
453
|
+
)
|
|
454
|
+
const href = userHref(user)
|
|
455
|
+
return href ? (
|
|
456
|
+
<Link href={href} className="inline-flex items-center gap-2 font-medium hover:underline">
|
|
457
|
+
{label}
|
|
458
|
+
</Link>
|
|
459
|
+
) : (
|
|
460
|
+
<span className="inline-flex items-center gap-2 font-medium">{label}</span>
|
|
461
|
+
)
|
|
462
|
+
},
|
|
401
463
|
},
|
|
402
464
|
{
|
|
403
465
|
name: 'email',
|
|
@@ -413,12 +475,50 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
413
475
|
</Badge>
|
|
414
476
|
),
|
|
415
477
|
},
|
|
478
|
+
...(plans
|
|
479
|
+
? [{
|
|
480
|
+
name: 'plan',
|
|
481
|
+
title: 'Plan',
|
|
482
|
+
minWidth: 170,
|
|
483
|
+
renderer: (user: TUser) => (
|
|
484
|
+
<>
|
|
485
|
+
<Select
|
|
486
|
+
value={user.plan ?? undefined}
|
|
487
|
+
onValueChange={(value) => handlePlanChange(user.id, value)}
|
|
488
|
+
disabled={updatingPlanFor === user.id}
|
|
489
|
+
>
|
|
490
|
+
<SelectTrigger size="sm" className="w-32 text-xs" aria-label={`Plan for ${user.name || user.email}`}>
|
|
491
|
+
<SelectValue placeholder="—" />
|
|
492
|
+
</SelectTrigger>
|
|
493
|
+
<SelectContent position="popper">
|
|
494
|
+
{plans.options.map((option) => (
|
|
495
|
+
<SelectItem key={option.value} value={option.value} className="text-xs">
|
|
496
|
+
{option.label}
|
|
497
|
+
</SelectItem>
|
|
498
|
+
))}
|
|
499
|
+
</SelectContent>
|
|
500
|
+
</Select>
|
|
501
|
+
{plans.note?.(user) && (
|
|
502
|
+
<p className="mt-1 text-xs text-muted-foreground">{plans.note(user)}</p>
|
|
503
|
+
)}
|
|
504
|
+
</>
|
|
505
|
+
),
|
|
506
|
+
} satisfies Column<TUser>]
|
|
507
|
+
: []),
|
|
508
|
+
...extraColumns,
|
|
416
509
|
{
|
|
417
510
|
name: 'status',
|
|
418
511
|
title: 'Status',
|
|
512
|
+
minWidth: 160,
|
|
419
513
|
renderer: (user) =>
|
|
420
514
|
user.banned ? (
|
|
421
|
-
<
|
|
515
|
+
<div className="space-y-1">
|
|
516
|
+
<Badge variant="destructive">Banned</Badge>
|
|
517
|
+
{user.bannedBy && <p className="text-xs text-muted-foreground">by {user.bannedBy}</p>}
|
|
518
|
+
{user.bannedReason && (
|
|
519
|
+
<p className="text-xs italic text-muted-foreground">“{user.bannedReason}”</p>
|
|
520
|
+
)}
|
|
521
|
+
</div>
|
|
422
522
|
) : (
|
|
423
523
|
<Badge variant="outline">Active</Badge>
|
|
424
524
|
),
|
|
@@ -443,18 +543,20 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
443
543
|
minWidth: 340,
|
|
444
544
|
renderer: (user) => (
|
|
445
545
|
<div className="flex flex-wrap justify-end gap-2">
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
546
|
+
{impersonation && (
|
|
547
|
+
<Button
|
|
548
|
+
variant="outline"
|
|
549
|
+
size="sm"
|
|
550
|
+
disabled={user.id === currentUserId || user.banned}
|
|
551
|
+
title={user.banned ? 'Cannot impersonate a banned user' : undefined}
|
|
552
|
+
onClick={() => {
|
|
553
|
+
setActionUserId(user.id)
|
|
554
|
+
setActionType('impersonate')
|
|
555
|
+
}}
|
|
556
|
+
>
|
|
557
|
+
Impersonate
|
|
558
|
+
</Button>
|
|
559
|
+
)}
|
|
458
560
|
{user.role === 'admin' ? (
|
|
459
561
|
<Button
|
|
460
562
|
variant="outline"
|
|
@@ -526,7 +628,7 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
526
628
|
</div>
|
|
527
629
|
),
|
|
528
630
|
},
|
|
529
|
-
] satisfies Column<
|
|
631
|
+
] satisfies Column<TUser>[]}
|
|
530
632
|
data={users}
|
|
531
633
|
getRowId={(user) => user.id}
|
|
532
634
|
pageSize={false}
|
|
@@ -549,7 +651,13 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
549
651
|
</Card>
|
|
550
652
|
|
|
551
653
|
{/* Action Confirmation Dialog */}
|
|
552
|
-
<AlertDialog
|
|
654
|
+
<AlertDialog
|
|
655
|
+
open={!!actionUserId}
|
|
656
|
+
onOpenChange={() => {
|
|
657
|
+
setActionUserId(null)
|
|
658
|
+
setBanReason('')
|
|
659
|
+
}}
|
|
660
|
+
>
|
|
553
661
|
<AlertDialogContent>
|
|
554
662
|
<AlertDialogHeader>
|
|
555
663
|
<AlertDialogTitle>
|
|
@@ -580,6 +688,18 @@ export default function AdminUsersTable({ initialUsers, initialPagination }: Adm
|
|
|
580
688
|
"You'll be signed in as this user until you stop impersonating. This is logged."}
|
|
581
689
|
</AlertDialogDescription>
|
|
582
690
|
</AlertDialogHeader>
|
|
691
|
+
{actionType === 'ban' && (
|
|
692
|
+
<div className="flex flex-col gap-2">
|
|
693
|
+
<Label htmlFor="ban-reason">Reason (optional, shown to the user)</Label>
|
|
694
|
+
<Input
|
|
695
|
+
id="ban-reason"
|
|
696
|
+
placeholder="e.g. Spam"
|
|
697
|
+
value={banReason}
|
|
698
|
+
onChange={(e) => setBanReason(e.target.value)}
|
|
699
|
+
maxLength={500}
|
|
700
|
+
/>
|
|
701
|
+
</div>
|
|
702
|
+
)}
|
|
583
703
|
<AlertDialogFooter>
|
|
584
704
|
<AlertDialogCancel disabled={isProcessing}>Cancel</AlertDialogCancel>
|
|
585
705
|
<AlertDialogAction
|
|
@@ -38,8 +38,8 @@ export default async function ImpersonationLogCard({ showViewAllLink = true }: I
|
|
|
38
38
|
) : (
|
|
39
39
|
<ul className="divide-y divide-border">
|
|
40
40
|
{events.map((event) => (
|
|
41
|
-
<li key={event.id} className="flex items-center justify-between gap-4 py-3">
|
|
42
|
-
<div className="flex items-center gap-3">
|
|
41
|
+
<li key={event.id} className="md:flex items-center justify-between gap-4 py-3">
|
|
42
|
+
<div className="md:flex items-center gap-3">
|
|
43
43
|
<Badge variant={event.action === 'impersonation_started' ? 'destructive' : 'secondary'}>
|
|
44
44
|
{event.action === 'impersonation_started' ? 'Started' : 'Stopped'}
|
|
45
45
|
</Badge>
|
|
@@ -42,13 +42,13 @@ export interface AppSidebarProps {
|
|
|
42
42
|
brandHref?: string
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
const workspaceLinks = [
|
|
45
|
+
export const workspaceLinks = [
|
|
46
46
|
{ href: "/dashboard", label: "Overview", icon: LayoutDashboard },
|
|
47
47
|
{ href: "/dashboard/data-table", label: "DataTable", icon: Table },
|
|
48
48
|
{ href: "/dashboard/settings", label: "Settings", icon: Settings },
|
|
49
49
|
]
|
|
50
50
|
|
|
51
|
-
const adminLinks = [
|
|
51
|
+
export const adminLinks = [
|
|
52
52
|
{ href: "/dashboard/admin", label: "Admin home", icon: ShieldCheck },
|
|
53
53
|
{ href: "/dashboard/admin/users", label: "Users", icon: Users },
|
|
54
54
|
{ href: "/dashboard/admin/activity-logs", label: "Audit logs", icon: ScrollText },
|
|
@@ -16,8 +16,18 @@ import {
|
|
|
16
16
|
AlertDialogTitle,
|
|
17
17
|
} from '../ui/alert-dialog'
|
|
18
18
|
import { authClient, useSession } from '../../lib/auth-client'
|
|
19
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '../ui/tooltip'
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
type Props = {
|
|
22
|
+
/**
|
|
23
|
+
* When set, the Delete account button is disabled (dimmed) and hovering or focusing it
|
|
24
|
+
* shows this text, e.g. "You have an active subscription. Cancel it first." Enforce the
|
|
25
|
+
* same rule on the server too (an auth hook on /delete-user): this only changes the UI.
|
|
26
|
+
*/
|
|
27
|
+
disabledReason?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function DeleteAccountCard({ disabledReason }: Props = {}) {
|
|
21
31
|
const { data: session } = useSession()
|
|
22
32
|
const email = session?.user.email ?? ''
|
|
23
33
|
// null = still checking. Credential users confirm with their password;
|
|
@@ -78,9 +88,26 @@ export default function DeleteAccountCard() {
|
|
|
78
88
|
</CardDescription>
|
|
79
89
|
</CardHeader>
|
|
80
90
|
<CardContent>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
{disabledReason ? (
|
|
92
|
+
<TooltipProvider>
|
|
93
|
+
<Tooltip>
|
|
94
|
+
<TooltipTrigger asChild>
|
|
95
|
+
{/* A disabled button gets no pointer events, so this focusable wrapper
|
|
96
|
+
carries the hover / keyboard focus that opens the tooltip. */}
|
|
97
|
+
<span tabIndex={0} aria-label={`Delete account unavailable: ${disabledReason}`} className="inline-block cursor-not-allowed">
|
|
98
|
+
<Button variant="destructive" disabled>
|
|
99
|
+
Delete account
|
|
100
|
+
</Button>
|
|
101
|
+
</span>
|
|
102
|
+
</TooltipTrigger>
|
|
103
|
+
<TooltipContent>{disabledReason}</TooltipContent>
|
|
104
|
+
</Tooltip>
|
|
105
|
+
</TooltipProvider>
|
|
106
|
+
) : (
|
|
107
|
+
<Button variant="destructive" onClick={() => setOpen(true)} disabled={hasPassword === null}>
|
|
108
|
+
Delete account
|
|
109
|
+
</Button>
|
|
110
|
+
)}
|
|
84
111
|
</CardContent>
|
|
85
112
|
</Card>
|
|
86
113
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useRouter } from "next/navigation"
|
|
4
|
+
import { PanelLeft, PanelTop } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { Button } from "../ui/button"
|
|
7
|
+
|
|
8
|
+
export type NavStyle = "sidebar" | "topbar"
|
|
9
|
+
|
|
10
|
+
export default function NavStyleToggle({ current }: { current: NavStyle }) {
|
|
11
|
+
const router = useRouter()
|
|
12
|
+
const next: NavStyle = current === "sidebar" ? "topbar" : "sidebar"
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Button
|
|
16
|
+
variant="ghost"
|
|
17
|
+
size="sm"
|
|
18
|
+
onClick={() => {
|
|
19
|
+
document.cookie = `nav-style=${next}; path=/; max-age=31536000; samesite=lax`
|
|
20
|
+
router.refresh()
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
{next === "topbar" ? <PanelTop /> : <PanelLeft />}
|
|
24
|
+
<span className="hidden sm:inline">
|
|
25
|
+
{next === "topbar" ? "Top bar" : "Sidebar"}
|
|
26
|
+
</span>
|
|
27
|
+
</Button>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import Link from "next/link"
|
|
4
|
+
import { usePathname } from "next/navigation"
|
|
5
|
+
import { ArrowLeft, LogOut } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { authClient } from "../../lib/auth-client"
|
|
8
|
+
import { cn } from "../../lib/utils"
|
|
9
|
+
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"
|
|
10
|
+
import { Button } from "../ui/button"
|
|
11
|
+
import { adminLinks, workspaceLinks, type AppSidebarProps } from "./appSidebar"
|
|
12
|
+
|
|
13
|
+
export default function TopNav({
|
|
14
|
+
user,
|
|
15
|
+
isAdmin,
|
|
16
|
+
brandName = "Template",
|
|
17
|
+
brandHref = "/",
|
|
18
|
+
actions,
|
|
19
|
+
}: AppSidebarProps & { actions?: React.ReactNode }) {
|
|
20
|
+
const pathname = usePathname()
|
|
21
|
+
const links = isAdmin ? [...workspaceLinks, ...adminLinks] : workspaceLinks
|
|
22
|
+
const inAdmin = isAdmin && pathname.startsWith("/dashboard/admin")
|
|
23
|
+
const tabs = inAdmin
|
|
24
|
+
? [...adminLinks, { href: "/dashboard", label: "Exit", icon: ArrowLeft, exit: true }]
|
|
25
|
+
: isAdmin
|
|
26
|
+
? [...workspaceLinks, { ...adminLinks[0], label: "Admin" }]
|
|
27
|
+
: workspaceLinks
|
|
28
|
+
const tabActive = (href: string, exit?: boolean) =>
|
|
29
|
+
!exit &&
|
|
30
|
+
(href === "/dashboard" || href === adminLinks[0].href
|
|
31
|
+
? pathname === href
|
|
32
|
+
: pathname.startsWith(href))
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<>
|
|
36
|
+
<header className="sticky top-0 z-20 border-b bg-background">
|
|
37
|
+
<div className="mx-auto flex h-14 max-w-7xl items-center gap-4 px-4 sm:px-6 lg:px-8">
|
|
38
|
+
<Link href={brandHref} className="font-semibold">
|
|
39
|
+
{brandName}
|
|
40
|
+
</Link>
|
|
41
|
+
<nav className="hidden flex-1 items-center gap-1 overflow-x-auto text-sm md:flex">
|
|
42
|
+
{links.map(({ href, label, icon: Icon }) => (
|
|
43
|
+
<Link
|
|
44
|
+
key={href}
|
|
45
|
+
href={href}
|
|
46
|
+
className={cn(
|
|
47
|
+
"flex items-center gap-1.5 whitespace-nowrap rounded-md px-3 py-1.5 text-muted-foreground transition-colors hover:text-foreground",
|
|
48
|
+
pathname === href && "bg-secondary font-medium text-foreground"
|
|
49
|
+
)}
|
|
50
|
+
>
|
|
51
|
+
<Icon className="size-4" />
|
|
52
|
+
{label}
|
|
53
|
+
</Link>
|
|
54
|
+
))}
|
|
55
|
+
</nav>
|
|
56
|
+
<div className="ml-auto flex items-center gap-1 md:ml-0">{actions}</div>
|
|
57
|
+
<Avatar className="size-7">
|
|
58
|
+
<AvatarImage src={user.image ?? undefined} alt={user.name} />
|
|
59
|
+
<AvatarFallback>{user.name?.[0]?.toUpperCase()}</AvatarFallback>
|
|
60
|
+
</Avatar>
|
|
61
|
+
<Button
|
|
62
|
+
variant="ghost"
|
|
63
|
+
size="icon"
|
|
64
|
+
aria-label="Log out"
|
|
65
|
+
onClick={() =>
|
|
66
|
+
authClient.signOut({
|
|
67
|
+
fetchOptions: { onSuccess: () => { window.location.href = "/" } },
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
>
|
|
71
|
+
<LogOut />
|
|
72
|
+
</Button>
|
|
73
|
+
</div>
|
|
74
|
+
</header>
|
|
75
|
+
<nav
|
|
76
|
+
aria-label="Primary"
|
|
77
|
+
className="fixed inset-x-0 bottom-0 z-20 flex border-t bg-background pb-[env(safe-area-inset-bottom)] md:hidden"
|
|
78
|
+
>
|
|
79
|
+
{tabs.map(({ href, label, icon: Icon, ...rest }) => (
|
|
80
|
+
<Link
|
|
81
|
+
key={href}
|
|
82
|
+
href={href}
|
|
83
|
+
className={cn(
|
|
84
|
+
"flex min-w-0 flex-1 flex-col items-center justify-start gap-0.5 px-1 py-2 text-center text-[11px] leading-tight text-muted-foreground",
|
|
85
|
+
tabActive(href, "exit" in rest) && "font-medium text-foreground"
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
<Icon className="size-5" />
|
|
89
|
+
<span className="w-full text-center">{label}</span>
|
|
90
|
+
</Link>
|
|
91
|
+
))}
|
|
92
|
+
</nav>
|
|
93
|
+
</>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Html,
|
|
3
|
+
Head,
|
|
4
|
+
Preview,
|
|
5
|
+
Body,
|
|
6
|
+
Container,
|
|
7
|
+
Section,
|
|
8
|
+
Text,
|
|
9
|
+
Heading,
|
|
10
|
+
Tailwind,
|
|
11
|
+
} from '@react-email/components';
|
|
12
|
+
|
|
13
|
+
interface EmailTemplateBannedProps {
|
|
14
|
+
firstName: string;
|
|
15
|
+
/** Shown in the subject line and body (config.APP_NAME). */
|
|
16
|
+
appName: string;
|
|
17
|
+
/** The reason the admin entered, if any. */
|
|
18
|
+
reason?: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Sent by the admin ban routes (single and bulk) when RESEND_API_KEY is set.
|
|
22
|
+
export function EmailTemplateBanned({ firstName, appName, reason }: EmailTemplateBannedProps) {
|
|
23
|
+
return (
|
|
24
|
+
<Html>
|
|
25
|
+
<Head />
|
|
26
|
+
<Preview>Your {appName} account has been suspended.</Preview>
|
|
27
|
+
<Tailwind>
|
|
28
|
+
<Body className="bg-white font-sans">
|
|
29
|
+
<Container className="mx-auto max-w-[560px] px-0 pt-5 pb-12">
|
|
30
|
+
<Section className="rounded-xl bg-[#f8f9fa] p-10">
|
|
31
|
+
<Heading className="mb-3 text-2xl font-bold text-[#1a1a1a]">
|
|
32
|
+
Your account has been suspended
|
|
33
|
+
</Heading>
|
|
34
|
+
<Text className="mb-6 text-base leading-6 text-[#666666]">
|
|
35
|
+
Hi {firstName}, your {appName} account has been suspended and you can no longer sign in.
|
|
36
|
+
</Text>
|
|
37
|
+
{reason && (
|
|
38
|
+
<Section className="mb-6 rounded border-0 border-l-4 border-solid border-[#f59e0b] bg-[#fffbeb] px-4 py-3">
|
|
39
|
+
<Text className="m-0 text-sm leading-5 text-[#92400e]">
|
|
40
|
+
<strong>Reason:</strong> {reason}
|
|
41
|
+
</Text>
|
|
42
|
+
</Section>
|
|
43
|
+
)}
|
|
44
|
+
<Text className="text-sm leading-5 text-[#999999]">
|
|
45
|
+
If you believe this is a mistake, reply to this email or contact support to appeal.
|
|
46
|
+
</Text>
|
|
47
|
+
</Section>
|
|
48
|
+
</Container>
|
|
49
|
+
</Body>
|
|
50
|
+
</Tailwind>
|
|
51
|
+
</Html>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
|
-
import
|
|
4
|
+
import { AlertDialog as AlertDialogPrimitive } from "radix-ui"
|
|
5
5
|
import { cn } from "../../lib/utils"
|
|
6
6
|
import { buttonVariants } from "./button"
|
|
7
7
|
|
|
@@ -47,7 +47,7 @@ function AlertDialogContent({
|
|
|
47
47
|
<AlertDialogOverlay />
|
|
48
48
|
<AlertDialogPrimitive.Content
|
|
49
49
|
className={cn(
|
|
50
|
-
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-
|
|
50
|
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border-(length:--surface-border-width) border-(--surface-border-color) p-6 shadow-(--dialog-shadow) duration-200 sm:max-w-lg",
|
|
51
51
|
className
|
|
52
52
|
)}
|
|
53
53
|
{...props}
|